@@ -32,14 +32,6 @@ class RingComplex[U](u: Ring[U]) extends Ring[Complex[U]] {
32
32
val mul = (x, y) => Complex (u.sub(u.mul(x.re, y.re), u.mul(x.im, y.im)), u.add(u.mul(x.re, y.im), u.mul(x.im, y.re)))
33
33
}
34
34
35
- class RingComplexExpr [U : Type ](u : Ring [Expr [U ]]) extends Ring [Expr [Complex [U ]]] {
36
- val zero = '(Complex(~u.zero, ~u.zero))
37
- val one = '(Complex(~u.one, ~u.zero))
38
- val add = (x, y) => '(Complex(~u.add( ' ((~ x).re), '((~y).re)), ~u.add( ' ((~ x).im), '((~y).im))))
39
- val sub = (x, y) => '(Complex(~u.sub( ' ((~ x).re), '((~y).re)), ~u.sub( ' ((~ x).im), '((~y).im))))
40
- val mul = (x, y) => '(Complex(~u.sub(u.mul( ' ((~ x).re), '((~y).re)), u.mul( ' ((~ x).im), '((~y).im))), ~u.add(u.mul( ' ((~ x).re), '((~y).im)), u.mul( ' ((~ x).im), '((~y).re)))))
41
- }
42
-
43
35
sealed trait PV [T ] {
44
36
def expr (implicit l : Liftable [T ]): Expr [T ]
45
37
}
@@ -60,7 +52,6 @@ class RingPV[U: Liftable](u: Ring[U], eu: Ring[Expr[U]]) extends Ring[PV[U]] {
60
52
case (x, y) => Dyn (eu.add(x.expr, y.expr))
61
53
}
62
54
val sub = (x : PV [U ], y : PV [U ]) => (x, y) match {
63
- case (Sta (u.zero), x) => x
64
55
case (x, Sta (u.zero)) => x
65
56
case (Sta (x), Sta (y)) => Sta (u.sub(x, y))
66
57
case (x, y) => Dyn (eu.sub(x.expr, y.expr))
@@ -130,7 +121,7 @@ object Test {
130
121
val arr1 = Array (0 , 1 , 2 , 4 , 8 )
131
122
val arr2 = Array (1 , 0 , 1 , 0 , 1 )
132
123
val cmpxArr1 = Array (Complex (1 , 0 ), Complex (2 , 3 ), Complex (0 , 2 ), Complex (3 , 1 ))
133
- val cmpxArr2 = Array (Complex (0 , 1 ), Complex (0 , 0 ), Complex (0 , 0 ), Complex (1 , 0 ))
124
+ val cmpxArr2 = Array (Complex (0 , 1 ), Complex (0 , 0 ), Complex (0 , 1 ), Complex (2 , 0 ))
134
125
135
126
val vec1 = new Vec (arr1.size, i => arr1(i))
136
127
val vec2 = new Vec (arr2.size, i => arr2(i))
@@ -200,21 +191,21 @@ object Test {
200
191
println()
201
192
202
193
import Complex .isLiftable
203
- val blasExprComplexIntPVExpr = new Blas1 (new RingPV (new RingComplex (new RingInt ), new RingComplexExpr ( new RingIntExpr )), new StaticVecOps )
194
+ val blasExprComplexPVInt = new Blas1 [ Int , Complex [ PV [ Int ]]] (new RingComplex (new RingPV [ Int ] (new RingInt , new RingIntExpr )), new StaticVecOps )
204
195
val resCode5 : Expr [Array [Complex [Int ]] => Complex [Int ]] = ' {
205
196
arr =>
206
197
assert(arr.length == ~ cmpxVec2.size.toExpr)
207
198
~ {
208
- blasExprComplexIntPVExpr.dot(
209
- new Vec (cmpxVec2.size, i => Dyn ('(arr(~i.toExpr)))),
210
- cmpxVec2.map(i => Sta (i))
211
- ).expr
199
+ val cpx = blasExprComplexPVInt.dot(
200
+ new Vec (cmpxVec2.size, i => Complex (Dyn ('(arr(~i.toExpr).re)), Dyn( ' (arr(~ i.toExpr).im)))),
201
+ new Vec (cmpxVec2.size, i => Complex (Sta (cmpxVec2.get(i).re), Sta (cmpxVec2.get(i).im)))
202
+ )
203
+ '(Complex(~cpx.re.expr, ~cpx.im.expr))
212
204
}
213
205
}
214
206
println(resCode5.show)
215
207
println(resCode5.run.apply(cmpxArr1))
216
208
println()
217
-
218
209
}
219
210
220
211
}
0 commit comments