This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mat.nim
45 lines (35 loc) · 1.49 KB
/
mat.nim
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#_____________________________________________________________________________
#
# Linear algebra routines for nimrod
#
# Emre Safak (c) 2014
#_____________________________________________________________________________
import vec
type TMatrix*[R, C: range; T: TNumber] = array[C, array[R, T]]
#_____________________________________________________________________________
#
# Ancillary routines
#_____________________________________________________________________________
# used to cast arrays to their base pointers for C procedures
template `&:`*(x: expr): expr =
when type(x[0]) is array:
cast[ptr type(x[0][0])](addr x)
else:
cast[ptr type(x[0])](addr x)
#_____________________________________________________________________________
#
# Matrix creation routines
#_____________________________________________________________________________
# proc zeros*(n, m: int) : auto {.noSideEffect.} = result = newSeq[float](N)
# proc zeros*(n, m: int, T : typedesc) : auto {.noSideEffect.} = result = newSeq[T](N)
#_____________________________________________________________________________
#
# Informational routines
#_____________________________________________________________________________
proc shape*[R,C,T](x: TMatrix[R,C,T]) : array[0..1, int] =
result[0] = R.high-R.low+1
result[1] = C.high-C.low+1
#_____________________________________________________________________________
#
# Manipulation routines
#_____________________________________________________________________________