tstackmatrix.nim 574 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. output: "(M: 3, N: 3, fp: ...)"
  3. """
  4. # bug #6843
  5. type
  6. OrderType = enum colMajor, rowMajor
  7. Matrix[A] = object
  8. M, N: int
  9. fp: ptr A # float pointer
  10. DoubleArray64[M, N: static[int]] = array[M, array[N, float64]]
  11. proc stackMatrix[M, N: static[int]](a: var DoubleArray64[M, N], order = colMajor): Matrix[float64] =
  12. Matrix[float64](
  13. fp: addr a[0][0],
  14. M: (if order == colMajor: N else: M),
  15. N: (if order == colMajor: M else: N)
  16. )
  17. var
  18. data = [
  19. [1'f64, 2, 3],
  20. [4'f64, 5, 6],
  21. [7'f64, 8, 9]
  22. ]
  23. m = stackMatrix(data)
  24. echo m