Dot(var/Matrix/M) // Performs dot product of src and M if possible and returns the dot product. Otherwise return null
// I can't return 0 because 0 is an actual dot product
var/list/M1 = src.matrix ; var/list/L1 = M1[1]
var/list/M2 = M.matrix ; var/list/L2 = M2[1]
/*
L1 and L2 store number of rows via length.
The dot product is defined as long each matrix has as many rows as the other has columns and vice versa
*/
if(src.cols != L2.len || L1.len != M.cols) return null // Not defined in this case
var/Matrix/Dot = new(L1.len, M.cols)
var/sum = 0
for(var/row = 1 to M.cols)
for(var/col = 1 to src.cols)
L1 = list() // Gotta rewrite the list each time through
/*
What I'm essentially doing here, is creating vectors and dotting them and putting the sum in the proper spot in the final
matrix. The first vector is the row of the first matrix, and the second vector is the column of the second matrix.
*/
for(var/i = 1 to src.cols)
L1 += M1[row][i]
L2 = M2[col]
sum = 0
for(var/i = 1 to L1.len)
sum += L1[i] * L2[i] // This line is stated in runtime error
Dot.ChangeValue(col, row, sum)
return Dot // return the dot product (does not modify either matrix in operation)
mob
verb
Test()
var/Matrix/M = new(100, 100)
var/Matrix/M2 = new(100, 100)
M2.ConstAdd(1)
for(var/i = 1 to 100)
for(var/j = 1 to 100)
M.ChangeValue(i, j, rand(1, 100))
var/i = 100
while(i)
M2 = M2.Dot(M)
i --
Problem description:
I was running some tests on my Dot products because I need to use them for my AutoPath library, and I come across this issue. The loop is most certainly not infinite, but it is trying to run a loop 10000 times, so maybe that's causing it? Any ideas on how to handle this?
EDIT: Please note that the test proc works fine on smaller matrices.