avocado-old/packages/math/matrix.js
2019-03-17 23:45:48 -05:00

32 lines
731 B
JavaScript

// Matrix operations.
// **Matrix** is a utility class to help with matrix operations. A
// matrix is implemented as an n-element array. Data is stored in row-major
// order.
export copy = (matrix) => matrix.map((row) => [...row])
export equals = (l, r) ->
return false unless l.length is r.length
return true if l.length is 0
return false unless l[0].length is r[0].length
for lrow, y in l
rrow = r[y]
for lindex, x in lrow
unless lindex is rrow[x]
return false
return true
export size = (matrix) ->
return 0 if 0 is matrix.length
return matrix.length * matrix[0].length
export sizeVector = (matrix) ->
return [0, 0] if 0 is matrix.length
return [matrix[0].length, matrix.length]