These are chat archives for libmir/public

20th
Sep 2016
Mathias L. Baumann
@Marenz
Sep 20 2016 20:01
@9il thanks for your suggestions
It took me a while to get familiar with how things work in mir
your suggestion works. Though it would be nicer to read and use if I could even do things like auto res = (aTensor[] * -1.0 + 1.0) * bTensor[] * cTensor[]
Right now I always have to first assign the first par of the calculation to the result variable and apply the rest line by line, like auto res = slice(aTensor); res[] *= -1.0; res[] += 1.0; res[] *= bTensor[]; res[] *= cTensor[];
Ilya Yaroshenko
@9il
Sep 20 2016 20:16
This is done to force user to do not make additional implicit allocations.
You can use ndEach with assumeSameStructure. Also ndEach can iterate multiple tensors at once
Mathias L. Baumann
@Marenz
Sep 20 2016 20:17
hmm but my perElement function didn't have extra allocations and allowed a nice chaining.. isn't something similar possible?
yeah, that's what I did in perElement
wait.. my perElement probably did have implicit allocation
returning a new slice each time
of course.. using .ndMap
Ilya Yaroshenko
@9il
Sep 20 2016 20:24
99% iteration and machine learning algorithms can allocate all required memory only once in the beginning. Then this data can be just for each iteration.
the same situatio with dot function. It allocates without reason
Mathias L. Baumann
@Marenz
Sep 20 2016 20:27
yeah, I just noticed. First goal was to get it working at all ;)
Fixing it now
Ilya Yaroshenko
@9il
Sep 20 2016 20:29
ndEach!((ref a) { a *= lr; })(diff); -> diff[] *= lr;
            auto zip = assumeSameStructure!("a", "b")(a, diff);

            zip.ndEach!(z => z.a -= z.b)();
->
a[] -= diff;
But, with ndslice you can do more faster:
Mathias L. Baumann
@Marenz
Sep 20 2016 20:30
I understood that part now, yes :)
Ilya Yaroshenko
@9il
Sep 20 2016 20:31
auto zip = assumeSameStructure!("a", "b")(a, diff);
zip.ndEach!((z) { z.b *= lr;  z.a -= z.b; });
The last one would 2 times faster for matrixes that does not fit L3 cache
It iterates memory only once
Mathias L. Baumann
@Marenz
Sep 20 2016 20:32
so basically, do as much as you can per iteration
Ilya Yaroshenko
@9il
Sep 20 2016 20:32
yes
Mathias L. Baumann
@Marenz
Sep 20 2016 20:32
alright
Ilya Yaroshenko
@9il
Sep 20 2016 20:33
Also, you can add Yes.vectorized. It will work with recent LDC beta
Mathias L. Baumann
@Marenz
Sep 20 2016 21:07
@9il do you have a smart idea on how to do https://github.com/Marenz/lstm/blob/master/source/app.d#L406-L408 better?