Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7dcce643
提交
7dcce643
authored
3月 19, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed and tested complex operations for +-*/
上级
fb352f6b
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
41 行增加
和
27 行删除
+41
-27
_test_tensor.py
_test_tensor.py
+12
-13
base_tensor.py
base_tensor.py
+28
-13
tensor.py
tensor.py
+1
-1
没有找到文件。
_test_tensor.py
浏览文件 @
7dcce643
...
...
@@ -205,19 +205,18 @@ class T_subtensor(unittest.TestCase):
class
T_add
(
unittest
.
TestCase
):
def
test_complex128
(
self
):
a
=
tinit
(
numpy
.
ones
(
3
,
dtype
=
'complex128'
))
b
=
tinit
(
numpy
.
ones
(
3
,
dtype
=
'complex128'
))
f
=
Function
([
a
,
b
],
[
a
+
b
],
linker_cls
=
gof
.
CLinker
)
self
.
failUnless
(
numpy
.
all
((
a
.
data
+
b
.
data
)
==
f
(
a
.
data
,
b
.
data
)))
def
test_complex128b
(
self
):
a
=
tinit
(
numpy
.
ones
(
3
,
dtype
=
'complex128'
)
+
0.5
j
)
b
=
tinit
(
numpy
.
ones
(
3
,
dtype
=
'complex128'
))
f
=
Function
([
a
,
b
],
[
a
+
b
],
linker_cls
=
gof
.
CLinker
)
self
.
failUnless
(
numpy
.
all
((
a
.
data
+
b
.
data
)
==
f
(
a
.
data
,
b
.
data
)))
def
test_complex_all_ops
(
self
):
for
nbits
in
(
64
,
128
):
a
=
tinit
(
numpy
.
ones
(
3
,
dtype
=
'complex
%
i'
%
nbits
)
+
0.5
j
)
b
=
tinit
(
numpy
.
ones
(
3
,
dtype
=
'complex
%
i'
%
nbits
)
+
1.5
j
)
tests
=
((
"+"
,
lambda
x
,
y
:
x
+
y
),
(
"-"
,
lambda
x
,
y
:
x
-
y
),
(
"*"
,
lambda
x
,
y
:
x
*
y
),
(
"/"
,
lambda
x
,
y
:
x
/
y
))
for
s
,
fn
in
tests
:
f
=
Function
([
a
,
b
],
[
fn
(
a
,
b
)],
linker_cls
=
gof
.
CLinker
)
self
.
failUnless
(
numpy
.
all
(
fn
(
a
.
data
,
b
.
data
)
==
f
(
a
.
data
,
b
.
data
)))
class
T_abs
(
unittest
.
TestCase
):
...
...
base_tensor.py
浏览文件 @
7dcce643
...
...
@@ -169,25 +169,40 @@ class BaseTensor(ResultBase):
return
[]
def
c_support_code
(
cls
):
operator_template
=
"""
me operator
%(op)
s(me y) {
me ret;
ret.real = this->real
%(op)
s y.real;
ret.imag = this->imag
%(op)
s y.imag;
return ret;
}
"""
template
=
"""
struct theano_complex
%(nbits)
s : public npy_complex
%(nbits)
s
{
typedef theano_complex
%(nbits)
s
m
e;
typedef npy_
complex
%(nbits)
s bas
e;
typedef theano_complex
%(nbits)
s
complex_typ
e;
typedef npy_
float
%(half_nbits)
s scalar_typ
e;
%(operators)
s
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;
}
};
"""
d
=
dict
(
operators
=
"
\n
"
.
join
([
operator_template
%
dict
(
op
=
op
)
for
op
in
[
"+"
,
"-"
,
"*"
,
"/"
]]))
return
template
%
dict
(
d
,
nbits
=
64
)
+
template
%
dict
(
d
,
nbits
=
128
)
return
template
%
dict
(
nbits
=
64
,
half_nbits
=
32
)
+
template
%
dict
(
nbits
=
128
,
half_nbits
=
64
)
############################
...
...
tensor.py
浏览文件 @
7dcce643
...
...
@@ -471,7 +471,7 @@ class SubElemwise(_Elemwise):
def
grad
(
self
,
(
x
,
y
),
gz
):
return
gz
,
-
gz
def
c_foreach
(
self
,
(
x_i
,
y_i
),
(
z_i
,
)):
return
"
z_i = x_i - y
_i;"
return
"
%(z)
s_i =
%(x)
s_i -
%(y)
s
_i;"
sub_elemwise
=
_constructor
(
SubElemwise
)
class
SubElemwiseInplace
(
SubElemwise
.
inplace_version
()):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论