Pretty-printing D arrays with Mir
jmh530
john.michael.hall at gmail.com
Mon Jun 1 21:25:02 UTC 2020
On Monday, 1 June 2020 at 19:51:34 UTC, tastyminerals wrote:
> [snip]
>
> 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.
Yeah, mir is kind of bare bones for some stuff.
I had meant to include the link before
https://github.com/libmir/numir/pull/10
If you look at some of the unittests you can see how it's
different. I separated out the different tensors with extra lines
between them, which isn't as easy to read. However, I think
bigger than a 3-d tensor is relatively uncommon. It might be some
work to get it to work since all the functions would need to be
re-written to take into account the mir's new format facilities,
but I probably wouldn't have to change the unittests too much.
I just tried to use the mir.format for the first time (code
below). The documentation is a bit lacking at this point. The
`print` function is like `put` function for an output range but
with some additional functionality I don't understand yet. I
think for it to be used completely in a @nogc manner, you would
need a @nogc `writeln` function as well.
/+dub.sdl:
dependency "mir-algorithm" version="*"
+/
import mir.format;
import mir.appender: ScopedBuffer;
import std.stdio: writeln;
void main() {
FormatSpec formatSpec;
formatSpec.format = 'f';
formatSpec.precision = 3;
auto x = withFormat(1.5f, formatSpec);
ScopedBuffer!char w;
w.print(x);
w.data.writeln;
}
More information about the Digitalmars-d-announce
mailing list