提交 39500b2b authored 作者: Frederic Bastien's avatar Frederic Bastien

implement casting from float32(64) to complex64(128).

上级 3c7f8139
......@@ -165,9 +165,31 @@ class Scalar(Type):
ret.imag = (this->imag * y.real - this->real * y.imag) / y_norm_square;
return ret;
}
complex_type operator =(scalar_type y) {
complex_type ret;
ret.real=y;
ret.imag=0;
return ret;
}
complex_type operator =(scalar_type y) {
complex_type ret;
ret.real=y;
ret.imag=0;
return ret;
}
%(upcast)s
};
"""
return template % dict(nbits = 64, half_nbits = 32) + template % dict(nbits = 128, half_nbits = 64)
# todo: use C templating
return template % dict(nbits = 64, half_nbits = 32, upcast="") + template % dict(nbits = 128, half_nbits = 64, upcast="""
complex_type operator =(npy_float64 y) {
complex_type ret;
ret.real=y;
ret.imag=0;
return ret;
}
""")
int8 = Scalar('int8')
......
......@@ -428,42 +428,7 @@ class TensorType(Type):
def c_support_code(cls):
"""Override `CLinkerOp.c_support_code` """
template = """
struct theano_complex%(nbits)s : public npy_complex%(nbits)s
{
typedef theano_complex%(nbits)s complex_type;
typedef npy_float%(half_nbits)s scalar_type;
complex_type operator +(complex_type y) {
complex_type ret;
ret.real = this->real + y.real;
ret.imag = this->imag + y.imag;
return ret;
}
complex_type operator -(complex_type y) {
complex_type ret;
ret.real = this->real - y.real;
ret.imag = this->imag - y.imag;
return ret;
}
complex_type operator *(complex_type y) {
complex_type ret;
ret.real = this->real * y.real - this->imag * y.imag;
ret.imag = this->real * y.imag + this->imag * y.real;
return ret;
}
complex_type operator /(complex_type y) {
complex_type ret;
scalar_type y_norm_square = y.real * y.real + y.imag * y.imag;
ret.real = (this->real * y.real + this->imag * y.imag) / y_norm_square;
ret.imag = (this->imag * y.real - this->real * y.imag) / y_norm_square;
return ret;
}
};
"""
return template % dict(nbits = 64, half_nbits = 32) + template % dict(nbits = 128, half_nbits = 64)
# todo: use C templating
return scal.Scalar("int8").c_support_code()
# Easy constructors
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论