Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
March 09, 2017 Lazy concatenation and padding utilities | ||||
---|---|---|---|---|
| ||||
Hello Ndslice got [1] lazy multidimensional concatenation and padding utilities: 1. stack 2. pad 2. padEdge 3. padSymmetric 4. padWrap `stack` can be used for ndslices instead of `chain`. --- import mir.ndslice.allocation: slice; import mir.ndslice.stack: stack; auto d = stack(a, b, c).slice; --- ndslice allocation and assign utilities are optimised to work with stacks. For example the code above is significantly faster then --- import std.array: array; import std.range: chain; auto d = chain(a, b, c).array; --- because `slice` uses external iteration for `Stack` data structure. [1] http://docs.algorithm.dlang.io/latest/mir_ndslice_stack.html Best regards, Ilya |
March 09, 2017 Re: Lazy concatenation and padding utilities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On Thursday, 9 March 2017 at 08:59:28 UTC, Ilya Yaroshenko wrote:
> Ndslice got [1] lazy multidimensional concatenation and padding utilities:
Nice. Is this dependent on choosing either RC- or GC-based allocation?
|
March 09, 2017 Re: Lazy concatenation and padding utilities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Thursday, 9 March 2017 at 09:10:47 UTC, Nordlöw wrote: > On Thursday, 9 March 2017 at 08:59:28 UTC, Ilya Yaroshenko wrote: >> Ndslice got [1] lazy multidimensional concatenation and padding utilities: > > Nice. Is this dependent on choosing either RC- or GC-based allocation? No, they are completely generic. The new ndslice uses iterators under the hood. An iterator for manually allocated memory (with `makeSlice!T`) and GC allocated memory (with `slice!T`) is just a pointer type of T*. You can use `slicedField` [1] to create ndslice on top of a RC-array. slicedField will create iterator on top of the rc-array using FieldIterator [2], and return ndslice based on the iterator. This is quite simple RC arrays can be very simple: only `auto ref opIndex(size_t index)` and `length` are required. `front`, `opSlice` and other RAR primitives are not used by FieldIterator. [1] http://docs.algorithm.dlang.io/latest/mir_ndslice_slice.html#slicedField [2] http://docs.algorithm.dlang.io/latest/mir_ndslice_iterator.html#FieldIterator |
March 09, 2017 Re: Lazy concatenation and padding utilities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Thursday, 9 March 2017 at 09:10:47 UTC, Nordlöw wrote:
> On Thursday, 9 March 2017 at 08:59:28 UTC, Ilya Yaroshenko wrote:
>> Ndslice got [1] lazy multidimensional concatenation and padding utilities:
>
> Nice. Is this dependent on choosing either RC- or GC-based allocation?
... continue prev. reply:
stack and pad* functions are 100% lazy and do not allocate anything.
If you have allocated slice of the same shape you can do the following:
preallocated_slice[] = stack(a, b, c);
where preallocated_slice was created on top of RC-array using `slicedField`.
|
March 09, 2017 Re: Lazy concatenation and padding utilities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On Thursday, 9 March 2017 at 08:59:28 UTC, Ilya Yaroshenko wrote: > [1] http://docs.algorithm.dlang.io/latest/mir_ndslice_stack.html > renamed: http://docs.algorithm.dlang.io/latest/mir_ndslice_concatenation.html |
March 09, 2017 Re: Lazy concatenation and padding utilities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On Thursday, 9 March 2017 at 08:59:28 UTC, Ilya Yaroshenko wrote:
> Hello
>
> Ndslice got [1] lazy multidimensional concatenation and padding utilities:
> 1. stack
> 2. pad
> 2. padEdge
> 3. padSymmetric
> 4. padWrap
>
>
> `stack` can be used for ndslices instead of `chain`.
>
> ---
> import mir.ndslice.allocation: slice;
> import mir.ndslice.stack: stack;
>
> auto d = stack(a, b, c).slice;
> ---
>
> ndslice allocation and assign utilities are optimised to work with stacks. For example the code above is significantly faster then
>
> ---
> import std.array: array;
> import std.range: chain;
>
> auto d = chain(a, b, c).array;
> ---
>
> because `slice` uses external iteration for `Stack` data structure.
>
> [1] http://docs.algorithm.dlang.io/latest/mir_ndslice_stack.html
>
> Best regards,
> Ilya
`stack` was renamed to `concatenation` to much numpy and Matlab
|
March 09, 2017 Re: Lazy concatenation and padding utilities | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On Thursday, 9 March 2017 at 13:46:57 UTC, Ilya Yaroshenko wrote: > > `stack` was renamed to `concatenation` to much numpy and Matlab Numpy does have stack, but this is more similar to the concatenate function (I'd prefer this to concatenation). Matlab just calls it cat, which is easier to type, but less informative. https://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.stack.html https://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.concatenate.html#numpy.concatenate https://www.mathworks.com/help/matlab/ref/cat.html |
Copyright © 1999-2021 by the D Language Foundation