Re: How to sum multidimensional arrays?

2020-03-01 Thread AB via Digitalmars-d-learn
On Saturday, 29 February 2020 at 19:04:12 UTC, p.shkadzko wrote: On Friday, 28 February 2020 at 16:51:10 UTC, AB wrote: On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: [...] Your Example with a minimal 2D array. module test2; import std.random : Xorshift,

Re: How to sum multidimensional arrays?

2020-02-29 Thread p.shkadzko via Digitalmars-d-learn
On Friday, 28 February 2020 at 16:51:10 UTC, AB wrote: On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: [...] Your Example with a minimal 2D array. module test2; import std.random : Xorshift, unpredictableSeed, uniform; import std.range : generate, take, chunks;

Re: How to sum multidimensional arrays?

2020-02-28 Thread bachmeier via Digitalmars-d-learn
On Friday, 28 February 2020 at 16:51:10 UTC, AB wrote: See https://dlang.org/spec/operatoroverloading.html#array-ops for a better overview of the required operators or mir.ndslice for an nD implementation. Here's an old version of some of the things I've been using:

Re: How to sum multidimensional arrays?

2020-02-28 Thread AB via Digitalmars-d-learn
On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: I'd like to sum 2D arrays. Let's create 2 random 2D arrays and sum them. ``` import std.random : Xorshift, unpredictableSeed, uniform; import std.range : generate, take, chunks; import std.array : array; static T[][]

Re: How to sum multidimensional arrays?

2020-02-27 Thread 9il via Digitalmars-d-learn
On Thursday, 27 February 2020 at 23:15:28 UTC, p.shkadzko wrote: And it works effortlessly! Sum of two 5000 x 6000 int arrays is just 0.105 sec! (on a Windows machine though but with weaker CPU). I bet using mir.ndslice instead of D arrays would be even faster. Yes, the output for the

Re: How to sum multidimensional arrays?

2020-02-27 Thread p.shkadzko via Digitalmars-d-learn
On Thursday, 27 February 2020 at 15:48:53 UTC, bachmeier wrote: On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: [...] This works but it does not look very efficient considering we flatten and then calling array twice. It will get even worse with 3D arrays. Is there a better

Re: How to sum multidimensional arrays?

2020-02-27 Thread p.shkadzko via Digitalmars-d-learn
On Thursday, 27 February 2020 at 16:31:07 UTC, 9il wrote: On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: Is there a better way without relying on mir.ndslice? ndslice Poker Face /+dub.sdl: dependency "mir-algorithm" version="~>3.7.17" dependency "mir-random"

Re: How to sum multidimensional arrays?

2020-02-27 Thread jmh530 via Digitalmars-d-learn
On Thursday, 27 February 2020 at 16:39:15 UTC, 9il wrote: [snip] Few performances nitpick for your example to be fair with benchmarking againt the test: 1. Random (default) is slower then Xorfish. 2. double is twice larger then int and requires twice more memory, so it would be twice slower

Re: How to sum multidimensional arrays?

2020-02-27 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: void main() { int[][] m1 = rndMatrix(10, 2, 3); int[][] m2 = rndMatrix(10, 2, 3); auto c = m1[] + m2[]; } I think you're trying to do this: int[][] m1 = rndMatrix(10, 2, 3); int[][] m2 = rndMatrix(10, 2, 3);

Re: How to sum multidimensional arrays?

2020-02-27 Thread 9il via Digitalmars-d-learn
On Thursday, 27 February 2020 at 16:31:49 UTC, jmh530 wrote: On Thursday, 27 February 2020 at 15:28:01 UTC, p.shkadzko wrote: On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: This works but it does not look very efficient considering we flatten and then calling array twice. It

Re: How to sum multidimensional arrays?

2020-02-27 Thread jmh530 via Digitalmars-d-learn
On Thursday, 27 February 2020 at 15:28:01 UTC, p.shkadzko wrote: On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: This works but it does not look very efficient considering we flatten and then calling array twice. It will get even worse with 3D arrays. And yes, benchmarks

Re: How to sum multidimensional arrays?

2020-02-27 Thread 9il via Digitalmars-d-learn
On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: Is there a better way without relying on mir.ndslice? ndslice Poker Face /+dub.sdl: dependency "mir-algorithm" version="~>3.7.17" dependency "mir-random" version="~>2.2.10" +/ import mir.ndslice; import mir.random: threadLocal;

Re: How to sum multidimensional arrays?

2020-02-27 Thread bachmeier via Digitalmars-d-learn
On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: [...] This works but it does not look very efficient considering we flatten and then calling array twice. It will get even worse with 3D arrays. Is there a better way without relying on mir.ndslice? Is there a reason you

Re: How to sum multidimensional arrays?

2020-02-27 Thread p.shkadzko via Digitalmars-d-learn
On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote: This works but it does not look very efficient considering we flatten and then calling array twice. It will get even worse with 3D arrays. And yes, benchmarks show that summing 2D arrays like in the example above is

How to sum multidimensional arrays?

2020-02-27 Thread p.shkadzko via Digitalmars-d-learn
I'd like to sum 2D arrays. Let's create 2 random 2D arrays and sum them. ``` import std.random : Xorshift, unpredictableSeed, uniform; import std.range : generate, take, chunks; import std.array : array; static T[][] rndMatrix(T)(T max, in int rows, in int cols) { Xorshift rnd;