diff options
author | Zahary Karadjov <zahary@gmail.com> | 2017-06-10 23:52:05 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-06-20 11:29:42 +0200 |
commit | 36c4f0a89c675ee7c03a265287bde03166b2686b (patch) | |
tree | 88b5c6021859fb8be5f272c128a395ee0f9eb9e6 | |
parent | b101a59734982f55bf9112062be179bd062ae866 (diff) | |
download | Nim-36c4f0a89c675ee7c03a265287bde03166b2686b.tar.gz |
close #1051
-rw-r--r-- | tests/metatype/tstaticvector.nim | 54 | ||||
-rw-r--r-- | tests/statictypes/texplicitprocparams.nim | 2 |
2 files changed, 46 insertions, 10 deletions
diff --git a/tests/metatype/tstaticvector.nim b/tests/metatype/tstaticvector.nim index 69ee0e935..1a7bdeafe 100644 --- a/tests/metatype/tstaticvector.nim +++ b/tests/metatype/tstaticvector.nim @@ -2,7 +2,9 @@ discard """ output: '''0 0 2 -100''' +100 +30.0 [data = [2.0]] +''' """ type @@ -16,13 +18,12 @@ type proc foo*[N, T](a: StaticVector[N, T]): T = 0.T proc foobar*[N, T](a, b: StaticVector[N, T]): T = 0.T - var a: StaticVector[3, int] echo foo(a) # OK echo foobar(a, a) # <--- hangs compiler -# bug #3112 +# https://github.com/nim-lang/Nim/issues/3112 type Vector[N: static[int]] = array[N, float64] @@ -30,10 +31,45 @@ type a: Vector[Na] b: Vector[Nb] -when isMainModule: - var v: TwoVectors[2, 100] - echo v[0].len - echo v[1].len - #let xx = 50 - v[1][50] = 0.0 +var v: TwoVectors[2, 100] +echo v[0].len +echo v[1].len +#let xx = 50 +v[1][50] = 0.0 + +# https://github.com/nim-lang/Nim/issues/1051 + +type + TMatrix[N,M: static[int], T] = object + data: array[0..M*N-1, T] + + TMat4f = TMatrix[4,4,float32] + TVec3f = TMatrix[1,3,float32] + TVec4f = TMatrix[1,4,float32] + + TVec[N: static[int]; T] = TMatrix[1,N,T] + +proc dot*(a, b: TVec): TVec.T = + #assert(a.data.len == b.data.len) + for i in 1..a.data.len: + result += a.data[i-1] * b.data[i-1] + +proc row*(a: TMatrix; i: int): auto = + result = TVec[TMatrix.M, TMatrix.T]() + for idx in 1 .. TMatrix.M: + result.data[idx-1] = a.data[(TMatrix.N * (idx-1)) + (i-1)] + +proc col*(a: TMatrix; j: int): auto = + result = TVec[TMatrix.N, TMatrix.T]() + for idx in 0 .. <TMatrix.N: + result.data[idx] = a.data[(TMatrix.N * (idx)) + (j-1)] + +proc mul*(a: TMat4f; b: TMat4f): TMat4f = + for i in 1..4: + for j in 1..4: + result.data[(4 * (j-1)) + (i-1)] = dot(row(a,i), col(b,j)) + +var test = TVec4f(data: [1.0'f32, 2.0'f32, 3.0'f32, 4.0'f32]) + +echo dot(test,test), " ", repr(col(test, 2)) diff --git a/tests/statictypes/texplicitprocparams.nim b/tests/statictypes/texplicitprocparams.nim index 149330cb7..d1e717dbf 100644 --- a/tests/statictypes/texplicitprocparams.nim +++ b/tests/statictypes/texplicitprocparams.nim @@ -10,7 +10,7 @@ type x: int proc initOdArray*[As: static[int], T](len: int): OdArray[As, T] = - result.l = len + result.x = len echo initOdArray[10, int](100) |