On Sunday, 31 May 2020 at 23:10:44 UTC, jmh530 wrote:
On Sunday, 31 May 2020 at 22:40:09 UTC, tastyminerals wrote:
I often print arrays to see how they look and their contents.
NumPy has a nice way of pretty-printing the arrays, and I was
lacking this in D.
For the sake of practice, I wrote a small package. It uses
mir.ndslice but works for both standard D arrays and Mir
Slices.
import pretty_array;
import mir.ndslice;
import std.stdio;
void main() {
auto b = [2, 2, 6].iota!int(1).fuse;
b.prettyArr.writeln;
}
┌ ┐
│┌ ┐│
││ 1 2 3 4 5 6││
││ 7 8 9 10 11 12││
│└ ┘│
│┌ ┐│
││13 14 15 16 17 18││
││19 20 21 22 23 24││
│└ ┘│
└ ┘
https://github.com/tastyminerals/pretty_d_array
There are of course a couple of things to finish like floating
precision and small number suppression.
Still, hope somebody will find it handy.
Interesting.
I had done some work in 2018 for numir format facilities. At
the time mir didn’t have a way to do @nogc formatting, but it
does now. It might be interesting to either revisit that or
think about getting this into mir.
I see. It depends on how much work is needed for any of the
options, right?
For now, I think having a function that does the job suffices for
me at least. Since I always printed tensors in Python to see
what's going on, I was lacking the same functionality in Mir.
I don't code in D on a daily basis but still try to learn by
doing small stuff. I think the current implementation is far from
being included into anything without rigorous code review but
would be glad to see better slice formatting in Mir.