-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to convert a slice to a standard D array (T[]) ? #18
Comments
You can use
|
BTW, for |
... this will return a common D array without allocation |
How about adding such common questions into the main README or the wiki? |
Looks good |
IMO this should be exposed as a method, it's a common case to interoperate between mir and non-mir code. How about:
Likewise, ndarray/flattened using a preallocated buffer (or using Appender!T or an arbitrary allocator) is a common case, and should be exposed in the library. What do you suggest?
(or maybe using ndarrayAlloc flattenedAlloc if name clash is an issue)
|
ndslice will be removed with the next release |
auto asArray(size_t[] packs, T)(Slice!(Contiguous, packs, T*) sl)
{
return sl.unpack.iterator[0..sl.elementsCount];
}
We need other method, something like |
Just sent out the request for removal: |
ya but adding this example (or whatever other similar good example snippet) and upgrading it in the new mir repo |
@9il To be clear, that doesn't exist yet right? (couldn't find it) makeSlice already allows to create new Contiguous slice with a data from another slice. is that the simplest?
|
makeSlice allocates data. So you do not need to use it here. I do not understand the problem with buffer filling and current API. The code in the example will remain the same because the buffer size is very small (like 4x4 pixels), so manual coping will be faster in this case. Current API allows buf.ptr.sliced(sl.shape)[] = sl; This looks pretty clear and simple, IMO |
should that be simply |
For For all slices |
@9il
what do i use for toArray?
actually not super clear from docs
Also, from old experimental.nslice in https://dlang.org/phobos/std_experimental_ndslice.html:
this snippet (
copy sl to the buffer
) seems to indicate no such utility to flatten elements into an array?EDIT: OK i guess it's here:
http://docs.algorithm.dlang.io/latest/mir_ndslice_allocation.html
somehow i find it hard to find, not sure if i'm the only one.
IMO this should be more prominent since we want to make it easy to go from standard D to slices (plenty of examples) as well as opposite direction (very sparse in docs)
not sure why
median
above doesn't use ndarraythe docs (
Creates a common n-dimensional array from a slice.
) are not clear whether it allocates or merely returns a view over the dataThe text was updated successfully, but these errors were encountered: