On Saturday, 3 June 2017 at 05:21:13 UTC, 9il wrote:
On Friday, 2 June 2017 at 16:08:20 UTC, Zz wrote:
Hi,

Just tried migrating from std.experimental.ndslice to mir-algorithm.

Is there a guide on how migrate old code?

I used the following imports before and using then with ndslice.

import std.experimental.ndslice;
import std.algorithm : each, max, sort;
import std.range : iota, repeat;

simplified example of how it was used.
auto a = cr.iota.sliced(r, c);
auto b = a.reshape(c, r).transposed!1;

auto c = a.reversed!1;
auto d = a.reshape(c, r).transposed!1.reversed!1;

auto f = new int[cr].sliced(r, c);
auto h = f.transposed(1);

how can I do the following in mir-algorithm.

Note: I will be going through the documentation.

Zz

Hello Zz,

std.experimental.ndslice -> mir.ndslice

std.range : iota, repeat -> mir.ndslice.topology: iota, repeat;
std.algorithm : each; -> mir.ndslice.algorithm: each;
std.algorithm : max; -> mir.utility: max;
std.algorithm : sort; -> mir.ndslice.sorting: sort;


Note, that Mir functions has different semantics compared with Phobos! For example, each iterates deep elements, so should be combined with `pack` to iterates rows instead of elements.

Ndslices work with Phobos functions but it is suggested to use Mir analogs if any.

// Mir's iota! It is already 2D ndslice :-)
auto a = [r, c].iota;

auto b = a
   // returns flattened iota, a has Contiguous kind,
   // so the result type would be equal to `iota(r*c)`
    .flattened
    // convert 1D iota ndslice to 2D iota ndslice
    .sliced(c, r)
    // It is required to use transposed
    // Convert ndslice kind from Contiguous to Universal.
    .universal
    // Transpose the Universal ndslice
    .transposed;

auto c = a.universal.reversed!1;
auto d = a.flattened.sliced(c, r).universal.transposed!1.reversed!1; // see also `rotated`

auto f = slice!int(c, r); // new int[cr].sliced(r, c); works too.
auto h = f.universal.transposed(1);

-------
Mir ndslices have three kinds: http://docs.algorithm.dlang.io/latest/mir_ndslice_slice.html#.SliceKind

If you have any questions feel free to ask at the Gitter:
https://gitter.im/libmir/public

Best,
Ilya

Best,
Ilya

Thanks

Reply via email to