Skip to content

Commit

Permalink
initial implementation for Color
Browse files Browse the repository at this point in the history
  • Loading branch information
jcosborn committed Nov 14, 2024
1 parent db850d4 commit f2ca3c5
Show file tree
Hide file tree
Showing 7 changed files with 746 additions and 299 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
32 changes: 26 additions & 6 deletions src/io/qioInternal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 21 additions & 4 deletions src/maths/matrixConcept.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -408,6 +421,10 @@ proc setColumn*(r:var AsMatrix; x:AsVector; i:int) {.inline.} =
for j in 0..<nr:
assign(r[j,i], x[j])

template `*`*[R,C:static[int],T1,T2](x: typedesc[MatrixArrayObj[R,C,T1]],
y: typedesc[VectorArrayObj[C,T2]]): typedesc =
VectorArray[R,eval(T1)*eval(T2)]

import matrixOps
export matrixOps

Expand Down
Loading

0 comments on commit f2ca3c5

Please sign in to comment.