From f2ca3c596964fbea42a2a6d9b681b81de3b0c08b Mon Sep 17 00:00:00 2001 From: James Osborn Date: Wed, 13 Nov 2024 23:28:56 -0600 Subject: [PATCH] initial implementation for Color --- .github/workflows/test.yml | 3 +- src/io/qioInternal.nim | 32 +++- src/maths/matrixConcept.nim | 25 ++- src/physics/color.nim | 292 +----------------------------- src/physics/colorOld.nim | 289 ++++++++++++++++++++++++++++++ src/physics/colorTensor.nim | 57 ++++++ src/physics/tensorwrap.nim | 347 ++++++++++++++++++++++++++++++++++++ 7 files changed, 746 insertions(+), 299 deletions(-) create mode 100644 src/physics/colorOld.nim create mode 100644 src/physics/colorTensor.nim create mode 100644 src/physics/tensorwrap.nim diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8cd40fd..4afcadc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,13 +5,14 @@ on: branches: - 'devel' - 'master' + - 'tensorwrap' jobs: build: strategy: matrix: mpi-impl: [openmpi, mpich] - nim-branch: [version-1-6, version-2-0, devel] + nim-branch: [version-2-0, version-2-2, devel] fuel-compat: [0, 1] fail-fast: false name: nim-${{ matrix.nim-branch }}-${{ matrix.mpi-impl }}-FUELCompat:${{ matrix.fuel-compat }} diff --git a/src/io/qioInternal.nim b/src/io/qioInternal.nim index 5a5a1b8..139c34c 100644 --- a/src/io/qioInternal.nim +++ b/src/io/qioInternal.nim @@ -44,10 +44,30 @@ template IOname*[T](x:typedesc[T]):string = # "QDP_F" & $N & "_ColorMatrix" #template IOname*[N:static int](x:typedesc[Color[MatrixArray[N,N,DComplex]]]):string = # "QDP_D" & $N & "_ColorMatrix" -template IOname*[N:static int,T](x:typedesc[Color[MatrixArray[N,N,T]]]):string = - when T is SComplex: - "QDP_F" & $N & "_ColorMatrix" - elif T is DComplex: - "QDP_D" & $N & "_ColorMatrix" +# template IOname*[N:static int,T](x:typedesc[Color[MatrixArray[N,N,T]]]):string = +# static: echo $x.type +# when T is SComplex: +# "QDP_F" & $N & "_ColorMatrix" +# elif T is DComplex: +# "QDP_D" & $N & "_ColorMatrix" +# else: +# IOnameDefault type T +# #template IOname*(x:typedesc[Color[AsMatrix]]):string = +# static: echo $x.type +# when x.index(int,int) is SComplex: +# "QDP_F" & $x.Nc & "_ColorMatrix" +# elif x.index(int,int) is DComplex: +# "QDP_D" & $x.Nc & "_ColorMatrix" +# else: +# IOnameDefault x +template IOname*[T](x:typedesc[Color[T]]):string = + mixin Nc + when T is AsMatrix: + when x.index(int,int) is SComplex: + "QDP_F" & $x.getNc & "_ColorMatrix" + elif x.index(int,int) is DComplex: + "QDP_D" & $x.getNc & "_ColorMatrix" + else: + IOnameDefault x else: - IOnameDefault type T + IOnameDefault x diff --git a/src/maths/matrixConcept.nim b/src/maths/matrixConcept.nim index 21355db..b5be25c 100644 --- a/src/maths/matrixConcept.nim +++ b/src/maths/matrixConcept.nim @@ -41,6 +41,9 @@ template createAsType2(t,c:untyped) = c(index(X.type[], type T)) else: index(X[], T) + template index*[X:t](x: typedesc[X]; i,j: typedesc[int]): typedesc = + mixin index + index(X[], int, int) template `[]`*(x: t; i: Scalar): untyped = c(x[][i]) template `[]`*(x:t; i,j:SomeInteger):untyped = #echoType: x @@ -65,10 +68,12 @@ template createAsType2(t,c:untyped) = x[][i] = y template `[]=`*(x: t; i,j: SomeInteger; y: typed) = x[][i,j] = y - template len*(x:t):untyped = getConst(x[].len) - template nrows*(x:t):untyped = getConst(x[].nrows) - template ncols*(x:t):untyped = getConst(x[].ncols) - template len*(x:typedesc[t]):auto = getConst(x[].len) + template len*(x:t):int = getConst(x[].len) + template nrows*(x:t):int = getConst(x[].nrows) + template ncols*(x:t):int = getConst(x[].ncols) + template len*(x:typedesc[t]):int = getConst(x[].len) + template nrows*(x:typedesc[t]):int = getConst(x[].nrows) + template ncols*(x:typedesc[t]):int = getConst(x[].ncols) #template mvLevel*(x:t):untyped = # mixin mvLevel # mvLevel(x[]) @@ -99,6 +104,9 @@ template has*[T:AsMatrix](x: typedesc[T], y: typedesc): bool = when y is AsMatrix: true else: has(T.type[], y) +template `*`*(x: typedesc[AsMatrix], y: typedesc[AsVector]): typedesc = + asVector(eval(x[]) * eval(y[])) + #declareScalar(AsScalar) #declareScalar(AsVarScalar) #declareVector(AsVector) @@ -226,7 +234,12 @@ template index*[I,J:static[int],T,K](x: typedesc[MatrixArrayObj[I,J,T]]; else: false # error +template index*[I,J:static[int],T](x: typedesc[MatrixArrayObj[I,J,T]]; + k,l: typedesc[int]): typedesc = + T + template `len`*(x:MatrixArrayObj):untyped = x.I +template nrows*(x:typedesc[MatrixArrayObj]):int = x.I template nrows*(x:MatrixArrayObj):untyped = x.I template ncols*(x:MatrixArrayObj):untyped = x.J template `[]`*(x:MatrixArrayObj):untyped = x.mat @@ -408,6 +421,10 @@ proc setColumn*(r:var AsMatrix; x:AsVector; i:int) {.inline.} = for j in 0..