Pretty-printing D arrays with Mir
jmh530
john.michael.hall at gmail.com
Sun May 31 23:10:44 UTC 2020
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.
More information about the Digitalmars-d-announce
mailing list