Comments (14)
this snippet (copy sl to the buffer) seems to indicate no such utility to flatten elements into an array?
You can use flattened
to use flat representation (it is not an array).
http://docs.algorithm.dlang.io/latest/mir_ndslice_topology.html#.flattened
not sure why median above doesn't use ndarray
median
uses preallocated buffer.
from mir-algorithm.
BTW, for Slice!(Contiguous, packs, T*)
you can always do sl.iterator[0 .. sl.elementsCount]
.
from mir-algorithm.
... this will return a common D array without allocation
from mir-algorithm.
How about adding such common questions into the main README or the wiki?
I hope that @timotheecour won't be the last one to try to transition ;-)
from mir-algorithm.
Looks good
from mir-algorithm.
- arrayview
BTW, for Slice!(Contiguous, packs, T*) you can always do sl.iterator[0 .. sl.elementsCount].
IMO this should be exposed as a method, it's a common case to interoperate between mir and non-mir code.
How about:
auto arrayview(S)(S slice) if (isContiguous!S){
return sl.iterator[0 .. sl.elementsCount];
}
- ndarray/flattened with existing buffer
not sure why median above doesn't use ndarray
median uses preallocated buffer.
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?
How about overloads:
auto darray=myslice.ndarray(Mallocator.instance);
auto darray=myslice.flattened(Mallocator.instance);
(or maybe using ndarrayAlloc flattenedAlloc if name clash is an issue)
- is there a plan to upgrade the reference example in https://dlang.org/phobos/std_experimental_ndslice.html with the new mir? (hopefully with a better
buf[n++] = e;
replaced as discussed above)
from mir-algorithm.
is there a plan to upgrade the reference example in https://dlang.org/phobos/std_experimental_ndslice.html with the new mir? (hopefully with a better buf[n++] = e; replaced as discussed above)
ndslice will be removed with the next release
from mir-algorithm.
auto arrayview(S)(S slice) if (isContiguous!S){
return sl.iterator[0 .. sl.elementsCount];
}
auto asArray(size_t[] packs, T)(Slice!(Contiguous, packs, T*) sl)
{
return sl.unpack.iterator[0..sl.elementsCount];
}
auto darray=myslice.ndarray(Mallocator.instance);
auto darray=myslice.flattened(Mallocator.instance);
makeSlice
already allows to create new Contiguous slice with a data from another slice.
Then asArray
can be used to get array representation.
hopefully with a better buf[n++] = e; replaced as discussed above
We need other method, something like copy
to an array.
from mir-algorithm.
Is there a plan to upgrade the reference example in https://dlang.org/phobos/std_experimental_ndslice.html with the new mir?
ndslice will be removed with the next release
Just sent out the request for removal:
dlang/phobos#5187
from mir-algorithm.
is there a plan to upgrade the reference example in https://dlang.org/phobos/std_experimental_ndslice.html with the new mir? (hopefully with a better buf[n++] = e; replaced as discussed above)
ndslice will be removed with the next release
ya but adding this example (or whatever other similar good example snippet) and upgrading it in the new mir repo
from mir-algorithm.
@9il
asArray
sounds good assuming all the asX
do not allocate as well.
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.
Then asArray can be used to get array representation.
We need other method, something like copy to an array.
is that the simplest?
import std.algorithm:copy;
myslice.makeSlice.asArray.copy(buffer);
// or something like: myslice.flattened(Allocater from buffer); ?
from mir-algorithm.
@9il
asArray sounds good assuming all the asX do not allocate as well.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.
Then asArray can be used to get array representation.
We need other method, something like copy to an array.is that the simplest?
import std.algorithm:copy;
myslice.makeSlice.asArray.copy(buffer);
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
from mir-algorithm.
BTW, for Slice!(Contiguous, packs, T*) you can always do sl.iterator[0 .. sl.elementsCount]
should that be simply sl.iterator.array
? (ie a.toArray
can be done via a.iterator.array
)
from mir-algorithm.
BTW, for Slice!(Contiguous, packs, T*) you can always do sl.iterator[0 .. sl.elementsCount]
should that be simply sl.iterator.array ? (ie a.toArray can be done via a.iterator.array)
For Slice!(Contiguous, packs, T*)
slices it is just sl.field
(without data reallocation).
For all slices sl.field.array
allocates new array and copies slice data to it, array
is from std.array
.
from mir-algorithm.
Related Issues (20)
- Enhance functionality of `RefTuple` `label`s HOT 4
- labels support HOT 9
- Compilation fails on Linux aarch64 with hardfloat HOT 3
- Replace asserts with `should`s
- fuse on array of string HOT 1
- [feature request] Add numpy.genfromtxt() HOT 32
- add static check for supported complier versions directly in the code
- Bitwise operations on `bitSlice` HOT 1
- U+23F4 is graphical as of Unicode v7
- filter and each compiler error HOT 2
- Improve user-friendliness of `shouldApprox` for floating point slices HOT 1
- Sum doesn't work for const(Slice!T*) HOT 1
- `stairs` with 0 or 1 on diagonals HOT 1
- How to reference mir (and lubeck) libraries HOT 2
- 32 bit windows LDC build fails HOT 6
- dmd 2.103.0 deprecation warnings about class/interface alias this HOT 1
- is lightScope of Slice!(RCI!T, N) thread-safe? HOT 1
- Cannot writeln entire object when mixing zip/map
- const conversion with labels HOT 4
- lightImmutable not handling Labels properly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mir-algorithm.