Array in elixir

Hello; my 2 non-exhaustive cents.

In the last line the code multiplies two 100x100 random matrix, a and b, for a hundred times.

t is set to the current time, to start timing the operation (benchmarking), but the code is missing a second time measure, after the 100 iterations, to actually make use of t, and make sense of the 100 repetition of

Enum.each(1..iters... 

Then we should go on and read the multiply/2 functions to understand its recursive implementation through multiply/3 (and how it uses the recursive transpose/1 function)

I’d start from the end-cases:

def multiply(_, []), do: []

here it looks that multiplying anything for an empty list the result is always an empty list, no need to process more.

def multiply(result, [], []), do: result

here when the function is called with some result list, and two empty list, it looks we got to the end of computation, and the function returns the final result.

def multiply(result, [], _), do: result

same here, but the function is ignoring the third argument: if results are present and the second list is empty, returns the result.

So… now i’d look at the entry-points for Matrix.multiply(a, b), it seems this one:

def multiply(a = [x | _],b = [y | _]) when is_list(a) and is_list(b) and is_list(x) and is_list(y) do
    multiply([], a, transpose(b))
end

which invokes the multiply/3 recursive function with a first empty list as result accumulator, the a matrix, and the b matrix transposed.

(Here you would like to step in the transpose/1 function to understand its recursive implementation too). … [to be continued]

P.S. >>> see a much more informed discussion about Arrays <<<