File: tstackmatrix.nim

package info (click to toggle)
nim 2.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,951,164 kB
  • sloc: sh: 24,599; ansic: 1,771; python: 1,493; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (29 lines) | stat: -rw-r--r-- 574 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
discard """
  output: "(M: 3, N: 3, fp: ...)"
"""

# bug #6843

type
  OrderType = enum colMajor, rowMajor
  Matrix[A] = object
    M, N: int
    fp: ptr A # float pointer
  DoubleArray64[M, N: static[int]] = array[M, array[N, float64]]


proc stackMatrix[M, N: static[int]](a: var DoubleArray64[M, N], order = colMajor): Matrix[float64] =
  Matrix[float64](
    fp: addr a[0][0],
    M: (if order == colMajor: N else: M),
    N: (if order == colMajor: M else: N)
  )

var
  data = [
    [1'f64, 2, 3],
    [4'f64, 5, 6],
    [7'f64, 8, 9]
  ]
  m = stackMatrix(data)
echo m