Re: Format
On Friday, 21 May 2021 at 13:59:13 UTC, drug wrote: 21.05.2021 16:45, newbie пишет: I am following https://wiki.dlang.org/Defining_custom_print_format_specifiers, why sink and formatValue are not @safe? What are the best practice for toString in safe code? Thank you sink is obsolete now, use W(riter) ```D import std.range : isOutputRange; void toString(W)(ref W writer) const if (isOutputRange!(W, char)) { // your stuff } ``` writer can be @safe, @nogc, nothrow etc like you want Thank you, and formatValue?
Format
I am following https://wiki.dlang.org/Defining_custom_print_format_specifiers, why sink and formatValue are not @safe? What are the best practice for toString in safe code? Thank you
Re: mir - Help on how to transform multidimentional arrays.
On Thursday, 29 April 2021 at 15:56:48 UTC, jmh530 wrote: On Thursday, 29 April 2021 at 15:26:15 UTC, Newbie wrote: [snip] Forgot to add the the first array was created using the following code. auto base = iota(2, 5, 3); What you're basically asking for the first one is to convert for row major to column major. There doesn't seem to be a specific function for that, but you can piece it together. The second one is just applying allReversed to the result of that. So we have: ```d /+dub.sdl: dependency "mir-algorithm" version="~>3.10.25" +/ import std.stdio: writeln; import mir.ndslice.topology: iota, flattened, reshape, universal; import mir.ndslice.dynamic: transposed, allReversed; void main() { auto x = iota(2, 5, 3); int err; auto y = x.flattened.reshape([3, 5, 2], err).transposed!(1, 2); auto z = y.allReversed; writeln(x); writeln(y); writeln(z); } ``` First of all thanks for your guidance and i modified your example to get the results I was looking for. auto y2 = base.flattened.reshape([3, 5, 2], err).transposed!(1, 2); produced the following. - |0 10 20| |1 11 21| - |2 12 22| |3 13 23| - |4 14 24| |5 15 25| - |6 16 26| |7 17 27| - |8 18 28| |9 19 29| - and auto y2 = base.flattened.reshape([3, 2, 5], err).transposed!(1, 2); gave me the result i was looking for. - |0 10 20| |1 11 21| |2 12 22| |3 13 23| |4 14 24| - |5 15 25| |6 16 26| |7 17 27| |8 18 28| |9 19 29| - Thanks, Newbie.
Re: mir - Help on how to transform multidimentional arrays.
On Thursday, 29 April 2021 at 15:22:55 UTC, Newbie wrote: mir - Help on how to transform multidimentional arrays. -- | 0 1 2| | 3 4 5| | 6 7 8| | 9 10 11| |12 13 14| -- |15 16 17| |18 19 20| |21 22 23| |24 25 26| |27 28 29| -- How can i transform it into the following types of arrays. -- | 0 10 20| | 1 11 21| | 2 12 22| | 3 13 23| | 4 14 24| -- | 5 15 25| | 6 16 26| | 7 17 27| | 8 18 28| | 9 19 29| -- or -- |29 19 9| |28 18 8| |27 17 7| |26 16 6| |25 15 5| -- |24 14 4| |23 13 3| |22 12 2| |21 11 1| |20 10 0| -- Regards, Newbie. Forgot to add the the first array was created using the following code. auto base = iota(2, 5, 3);
mir - Help on how to transform multidimentional arrays.
mir - Help on how to transform multidimentional arrays. -- | 0 1 2| | 3 4 5| | 6 7 8| | 9 10 11| |12 13 14| -- |15 16 17| |18 19 20| |21 22 23| |24 25 26| |27 28 29| -- How can i transform it into the following types of arrays. -- | 0 10 20| | 1 11 21| | 2 12 22| | 3 13 23| | 4 14 24| -- | 5 15 25| | 6 16 26| | 7 17 27| | 8 18 28| | 9 19 29| -- or -- |29 19 9| |28 18 8| |27 17 7| |26 16 6| |25 15 5| -- |24 14 4| |23 13 3| |22 12 2| |21 11 1| |20 10 0| -- Regards, Newbie.
Re: No Output with shebang.
On Wednesday, 20 August 2014 at 20:21:13 UTC, anonymous wrote: On Wednesday, 20 August 2014 at 20:17:49 UTC, Newbie wrote: #!/usr/bin/gdc import std.stdio; void main() { writeln("Hello, world with automated script running!"); } When I compile the code above normal to an a.out binary it runs like expected. But running it with shebang it does nothing. No output, especially no error message. Nothing. What do I wrong? gdc just compiles the program to a.out. It doesn't run the resulting executable. You need to use something like rdmd instead of gdc. rdmd compiles to some temporary location and then runs the executable. Wow, that was fast. Thanks a lot!
No Output with shebang.
#!/usr/bin/gdc import std.stdio; void main() { writeln("Hello, world with automated script running!"); } When I compile the code above normal to an a.out binary it runs like expected. But running it with shebang it does nothing. No output, especially no error message. Nothing. What do I wrong?