www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Lazy concatenation and padding utilities

reply Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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
Mar 09
next sibling parent reply =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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?
Mar 09
next sibling parent Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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
Mar 09
prev sibling parent Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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`.
Mar 09
prev sibling next sibling parent Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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
Mar 09
prev sibling parent reply Ilya Yaroshenko <ilyayaroshenko gmail.com> writes:
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
Mar 09
parent jmh530 <john.michael.hall gmail.com> writes:
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
Mar 09