complex data type #235
Replies: 2 comments
-
I just noticed that there's a note in the Limitations of the documentation stating that complex numbers are not currently supported. I've spent the weekend porting some code over to warp and it's veeeeery fast! I implemented what I need so far for complex numbers. It's just not very clean at the moment. Here is a portion of what I have: @wp.struct
class ComplexFloat:
real: wp.float32
imag: wp.float32
def __init__(self, real: wp.float32, imag: wp.float32) -> None:
self.real = real
self.imag = imag
@wp.struct
class ComplexVec3:
real: wp.vec3
imag: wp.vec3
def __init__(self, real: wp.vec3, imag: wp.vec3) -> None:
self.real = real
self.imag = imag
@wp.func
def complex_add(c1: ComplexFloat, c2: ComplexFloat) -> ComplexFloat:
return ComplexFloat(c1.real + c2.real, c1.imag + c2.imag)
@wp.func
def complex_add(c1: ComplexFloat, c2: wp.float32) -> ComplexFloat:
return ComplexFloat(c1.real + c2, c1.imag)
@wp.func
def complex_add(c1: ComplexVec3, c2: ComplexVec3) -> ComplexVec3:
return ComplexVec3(c1.real + c2.real, c1.imag + c2.imag) I tried doing add, multiply etc inside the object ( @wp.struct
class ComplexFloat:
real: wp.float32
imag: wp.float32
def __init__(self, real: wp.float32, imag: wp.float32) -> None:
self.real = real
self.imag = imag
def __neg__(self):
return ComplexFloat(-self.real, -self.imag) raise WarpCodegenError(
warp.codegen.WarpCodegenError: Error while parsing function "xxxx" at /home/jason/workspace/xxxxx.py:120:
E = -ComplexFloat(0.0, distance)
;Couldn't find function overload for 'neg' that matched inputs with types: [MathLib.ComplexFloat] I tried adding @wp.func to __neg__ but I get a different error: warp.codegen.WarpCodegenError: Incomplete argument annotations on function __neg__ Any suggestions on how to get this working? |
Beta Was this translation helpful? Give feedback.
-
You are free to create |
Beta Was this translation helpful? Give feedback.
-
Are there any plans to incorporate the complex data type into warp? It would be very helpful for electro-magnetic use cases.
Beta Was this translation helpful? Give feedback.
All reactions