matrix.nim 407 B

123456789101112131415
  1. type
  2. Matrix*[M, N: static[int]; T] = object
  3. data: array[M*N, T]
  4. proc `[]`*(M: Matrix; m, n: int): M.T =
  5. M.data[m * M.N + n]
  6. proc `[]=`*(M: var Matrix; m, n: int; v: M.T) =
  7. M.data[m * M.N + n] = v
  8. # Adapt the Matrix type to the concept's requirements
  9. template Rows*(M: type Matrix): untyped = M.M
  10. template Cols*(M: type Matrix): untyped = M.N
  11. template ValueType*(M: type Matrix): typedesc = M.T