On Sunday, 19 May 2019 at 16:17:17 UTC, Andrew Edwards wrote:
´´´
import std;

void main()
{
    int[][] M = [[1,2,3],[1,2,3],[1,2,3]];
    M.recursiveMultiplier(4);
    writeln(M);
}

void recursiveMultiplier(T, V)(T arr, V val) @nogc
{
    static if(isArray!(ElementType!T))
        arr.each!(el => el.recursiveMultiplier(val));
    else
        arr[] = arr[] * val;
}
´´´

Can you do me a favor and extend it to cover the cases where V is either an array or multidimensional array? The text I'm using has exercise to implement a bunch of matrix operations so that would help out a lot.


Not really. For a general matrix-matrix multiplication special algorithms exist. ndslices use blas for calculation. For different numeric types, things get involved very fast, not to speak about special algorithms for special-formed matrices. And I don't even know, which representation (row/column major) you expect ;)

The operation itself is, however, a simple one. To implement a basic version I would cite
http://rosettacode.org/wiki/Matrix_multiplication#D

Reply via email to