libmir / mir-algorithm

Dlang Core Library
http://mir-algorithm.libmir.org
Other
173 stars 37 forks source link

Cannot writeln entire object when mixing zip/map #467

Open jmh530 opened 1 year ago

jmh530 commented 1 year ago

The code below calls byDim on a matrix and then zips it with a vector. I then call map on the combined group (in this case, I reduced it to remove what I was actually doing with it, the code originally was subtracting values of mu from each column).

If I try to print Z[0] or Z[1], I don't have any problems, but if I try to print Z itself, then I get a long error message that starts with a complaint that generating an inout copy constructor failed. I don't have the same problem with Y, suggesting this might be the result of the interaction with zip and map together.

/+dub.sdl:
dependency "mir-algorithm" version="*"
+/
import mir.ndslice.allocation: mininitRcslice;
import mir.ndslice.topology: byDim, map, zip;
import std.stdio: writeln;

void main()
{
    static immutable a = [0.07, 0.125];
    static immutable b = [[-0.1667, -0.1365],
                          [-0.0446,  0.1997],
                          [ 0.0764,  0.3813],
                          [ 0.3230,  0.2999],
                          [-0.0507, -0.2872],
                          [ 0.0130,  0.0975],
                          [ 0.0227,  0.0560],
                          [ 0.0595,  0.1658],
                          [ 0.0374,  0.1834],
                          [ 0.1034,  0.2740]];

    auto mu = mininitRcslice!double(2);
    auto X = mininitRcslice!double(10, 2);
    mu[] = a;
    X[] = b;
    auto Y = X.byDim!1.zip(mu);
    auto Z = Y.map!((a, b) => a);

    writeln(Z[0]); //works
    writeln(Z[1]); //works
    writeln(Z); //fails with long error message
}