Basic Linear Algebra and D's Array Operation

Andrew Edwards edwards.ac at gmail.com
Sun May 19 16:17:17 UTC 2019


On Sunday, 19 May 2019 at 10:07:35 UTC, Alex wrote:
> On Sunday, 19 May 2019 at 06:34:18 UTC, Andrew Edwards wrote:
>>
>> So the question is, how do I pull this off in D using just 
>> builtin arrays and phobos?
>>
>> Any assistance is appreciated.
>>
>
> Slice operations exist, but they are defined mainly for arrays 
> and not for arrays of arrays. Some basic operations (like 
> setting) are possible, but as you see, even multiplication 
> fails. You could reinvent something like
>
> ´´´
> 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.

>
> BUT:
> As I saw, in the talk, NDarrays are referenced. The common 
> (widely used and recommended) way to use this functionality in 
> D is by using mir.ndslices.
> http://docs.algorithm.dlang.io/latest/mir_ndslice.html

Yes, I'm aware. I'm actually am using Lubeck to accomplish much 
of this stuff but when it comes to the implementation exercises, 
I have to ditch the library and stick with vanilla D.


More information about the Digitalmars-d-learn mailing list