tymatrix.nim 432 B

12345678910111213141516171819202122
  1. template reject(e) =
  2. static: assert(not compiles(e))
  3. type
  4. TMatrix[T; M, N: static[int]] = array[M*N, T]
  5. proc `*`[T; R, N, C](a: TMatrix[T, R, N], b: TMatrix[T, N, C]): TMatrix[T, R, C] =
  6. discard
  7. var m1: TMatrix[int, 6, 4]
  8. var m2: TMatrix[int, 4, 3]
  9. var m3: TMatrix[int, 3, 3]
  10. var m4 = m1*m2
  11. static: assert m4.M == 6 and m4.N == 3
  12. reject m1 * m3 # not compatible
  13. var m5 = m2 * m3
  14. static: assert high(m5) == 11 # 4*3 - 1