Basic Linear Algebra and D's Array Operation
Alex
sascha.orlov at gmail.com
Sun May 19 17:13:11 UTC 2019
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
More information about the Digitalmars-d-learn
mailing list