libmir / mir

Mir (backports): Sparse tensors, Hoffman
http://mir.libmir.org
Boost Software License 1.0
210 stars 20 forks source link

non-uniform indexing assignment #340

Closed timotheecour closed 6 years ago

timotheecour commented 8 years ago

This is the assignment version of https://github.com/libmir/mir/issues/321

LHS should be a Slice!(N,T*), RHS should be a scalar T or Slice!(N2, T2) (could be implicit)

auto a=iotaSlice(4,8).slice;
a.indexed[R(), [2,3,7]] = 0; // set all values in 4x3 submatrix to 0
a.indexed[0..2, [2,3,7]] = iotaSlice(2,3); // set all values in 2x3 submatrix from another matrix
a.indexed[0, [2,3,7]] = [1,4,5];
a.indexed[0, [2,3,4]] = [1,2,3,4]; // could also use: a[0,R(2,5)] uniform indexing in this case
a.indexed[0, [0,2,4,6]] = [1,2,3,4]; // could also use: a[0,R(0,7,2)] uniform indexing with stride in this case

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/37895220-non-uniform-indexing-assignment?utm_campaign=plugin&utm_content=tracker%2F18251717&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18251717&utm_medium=issues&utm_source=github).
9il commented 6 years ago

This should work in v0.8.0

    import mir.ndslice;
    auto a = iota(4, 8).slice;
    a[iota($ - 2), [1, 3, 2].sliced] = iota(2, 3);