Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions source/mir/ndslice/slice.d
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,34 @@ auto sliced(size_t N, Iterator)(return scope Iterator iterator, size_t[N] length
assert(slice[1, 2] == 12);
}

/++
Creates an n-dimensional slice-shell over an iterator having the exact elemnt count as that of the array.
Params:
iterator = An iterator, a pointer, or an array.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be a dynamic array or an ndslice: those have length.
So you will have two tiny overloads.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. added the second overload👍.
can you tell me why circleci is failing everytime? unable to figure out

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

circleci is deprecated I think

lengths = A list of lengths for each dimension
Returns:
n-dimensional slice
+/
auto slicedExactly(size_t N, Iterator)(return scope Iterator iterator, size_t[N] lengths...)
Comment thread
Iskaban10 marked this conversation as resolved.
Outdated
if (!__traits(isStaticArray, Iterator) && N
&& !is(Iterator : Slice!(_Iterator, _N, kind), _Iterator, size_t _N, SliceKind kind))
{
static if (isDynamicArray!Iterator)
{
assert(lengthsProduct(lengths) == iterator.length, "array length should be exactly equal to the product of constructed ndslice dimensions");
}
return iterator.sliced(lengths);
}

/// Test case for Issue 313 https://github.com/libmir/mir-algorithm/issues/313
@safe pure nothrow @nogc unittest
{
int[6] values= [1, 2, 3, 4, 5, 6];
auto arr = values[];
auto s = arr.slicedExactly(2, 3);
assert(s.elementCount == arr.length);
}

/++
Creates an 1-dimensional slice-shell over an array.
Params:
Expand Down
Loading