Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c8c2c4f7
提交
c8c2c4f7
authored
4月 08, 2008
作者:
olivier@olivier-desktop
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added dtypes to scalar
上级
250d45dd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
24 行删除
+48
-24
_test_tensor.py
_test_tensor.py
+0
-13
scalar.py
scalar.py
+48
-11
没有找到文件。
_test_tensor.py
浏览文件 @
c8c2c4f7
...
@@ -450,7 +450,6 @@ class T_mul(unittest.TestCase):
...
@@ -450,7 +450,6 @@ class T_mul(unittest.TestCase):
b
=
astensor
(
0.0
)
b
=
astensor
(
0.0
)
check_eq2_both
(
self
,
[
a
,
b
],
mul
(
a
,
b
),
[
3.0
,
4.0
],
12.0
)
check_eq2_both
(
self
,
[
a
,
b
],
mul
(
a
,
b
),
[
3.0
,
4.0
],
12.0
)
check_eq2_both
(
self
,
[
a
,
b
],
mul
(
b
,
a
),
[
-
1.0
,
2.0
],
-
2.0
)
check_eq2_both
(
self
,
[
a
,
b
],
mul
(
b
,
a
),
[
-
1.0
,
2.0
],
-
2.0
)
#self.failUnless(isinstance(mul(a,b).owner, Scale))
a
=
astensor
(
numpy
.
ones
(
2
))
a
=
astensor
(
numpy
.
ones
(
2
))
b
=
astensor
(
numpy
.
ones
(
2
))
b
=
astensor
(
numpy
.
ones
(
2
))
...
@@ -458,7 +457,6 @@ class T_mul(unittest.TestCase):
...
@@ -458,7 +457,6 @@ class T_mul(unittest.TestCase):
bb
=
numpy
.
asarray
([
-
0.5
,
2.0
])
bb
=
numpy
.
asarray
([
-
0.5
,
2.0
])
check_eq2_both
(
self
,
[
a
,
b
],
mul
(
a
,
b
),
[
aa
,
bb
],
numpy
.
asarray
([
0.25
,
8.0
]))
check_eq2_both
(
self
,
[
a
,
b
],
mul
(
a
,
b
),
[
aa
,
bb
],
numpy
.
asarray
([
0.25
,
8.0
]))
check_eq2_both
(
self
,
[
a
,
b
],
mul
(
a
,
b
),
[
bb
,
aa
],
numpy
.
asarray
([
0.25
,
8.0
]))
check_eq2_both
(
self
,
[
a
,
b
],
mul
(
a
,
b
),
[
bb
,
aa
],
numpy
.
asarray
([
0.25
,
8.0
]))
#self.failUnless(isinstance(mul(a,b).owner, MulElemwise))
def
test_scalar
(
self
):
def
test_scalar
(
self
):
r
=
numpy
.
random
.
rand
(
2
,
3
)
r
=
numpy
.
random
.
rand
(
2
,
3
)
...
@@ -490,16 +488,6 @@ class T_mul(unittest.TestCase):
...
@@ -490,16 +488,6 @@ class T_mul(unittest.TestCase):
def
test_grad_col
(
self
):
def
test_grad_col
(
self
):
verify_grad
(
self
,
Mul
,
[
numpy
.
random
.
rand
(
3
,
5
),
numpy
.
random
.
rand
(
3
,
1
)])
verify_grad
(
self
,
Mul
,
[
numpy
.
random
.
rand
(
3
,
5
),
numpy
.
random
.
rand
(
3
,
1
)])
# def test_operator(self):
# a = astensor([1,1])
# aa = astensor([1,1])
# b = astensor(4)
# self.failUnless(isinstance((a*b).owner, Scale))
# self.failUnless(isinstance((b*a).owner, Scale))
# self.failUnless(isinstance((a*aa).owner, MulElemwise))
# self.failUnless(isinstance((aa*a).owner, MulElemwise))
def
test_wrong_shapes
(
self
):
def
test_wrong_shapes
(
self
):
a
=
astensor
(
numpy
.
ones
(
3
))
a
=
astensor
(
numpy
.
ones
(
3
))
b
=
astensor
(
numpy
.
ones
(
4
))
b
=
astensor
(
numpy
.
ones
(
4
))
...
@@ -734,7 +722,6 @@ class t_gemm(unittest.TestCase):
...
@@ -734,7 +722,6 @@ class t_gemm(unittest.TestCase):
self
.
rand
(
3
,
5
),
self
.
rand
(
5
,
4
),
1.0
)
self
.
rand
(
3
,
5
),
self
.
rand
(
5
,
4
),
1.0
)
def
test12
(
self
):
self
.
cmp
(
self
.
rand
(
3
,
4
),
-
1.0
,
def
test12
(
self
):
self
.
cmp
(
self
.
rand
(
3
,
4
),
-
1.0
,
self
.
rand
(
3
,
5
),
self
.
rand
(
5
,
4
),
-
1.0
)
self
.
rand
(
3
,
5
),
self
.
rand
(
5
,
4
),
-
1.0
)
t_gemm
=
None
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
scalar.py
浏览文件 @
c8c2c4f7
...
@@ -25,6 +25,7 @@ class Scalar(ResultBase):
...
@@ -25,6 +25,7 @@ class Scalar(ResultBase):
def
__init__
(
self
,
dtype
,
name
=
None
):
def
__init__
(
self
,
dtype
,
name
=
None
):
ResultBase
.
__init__
(
self
,
role
=
None
,
name
=
name
)
ResultBase
.
__init__
(
self
,
role
=
None
,
name
=
name
)
self
.
dtype
=
dtype
self
.
dtype
=
dtype
self
.
dtype_specs
()
def
__get_constant
(
self
):
def
__get_constant
(
self
):
return
self
.
_constant
return
self
.
_constant
...
@@ -49,8 +50,17 @@ class Scalar(ResultBase):
...
@@ -49,8 +50,17 @@ class Scalar(ResultBase):
# and self.data == other.data
# and self.data == other.data
def
dtype_specs
(
self
):
def
dtype_specs
(
self
):
return
{
'float64'
:
(
float
,
'npy_float64'
,
'PyFloat_Check'
,
'PyFloat_AsDouble'
,
'PyFloat_FromDouble'
),
try
:
'int32'
:
(
int
,
'npy_int32'
,
'PyInt_Check'
,
'PyInt_AsLong'
,
'PyInt_FromLong'
)}[
self
.
dtype
]
return
{
'float32'
:
(
float
,
'npy_float32'
,
'PyFloat_Check'
,
'PyFloat_AsDouble'
,
'PyFloat_FromDouble'
),
'float64'
:
(
float
,
'npy_float64'
,
'PyFloat_Check'
,
'PyFloat_AsDouble'
,
'PyFloat_FromDouble'
),
'int8'
:
(
int
,
'npy_int8'
,
'PyInt_Check'
,
'PyInt_AsLong'
,
'PyInt_FromLong'
),
'int16'
:
(
int
,
'npy_int16'
,
'PyInt_Check'
,
'PyInt_AsLong'
,
'PyInt_FromLong'
),
'int32'
:
(
int
,
'npy_int32'
,
'PyInt_Check'
,
'PyInt_AsLong'
,
'PyInt_FromLong'
),
'int64'
:
(
int
,
'npy_int64'
,
'PyInt_Check'
,
'PyInt_AsLong'
,
'PyInt_FromLong'
),
'complex128'
:
(
complex
,
'theano_complex128'
,
'PyComplex_Check'
,
'PyComplex_AsCComplex'
,
'PyComplex_FromCComplex'
),
'complex64'
:
(
complex
,
'theano_complex64'
,
None
,
None
,
None
)}[
self
.
dtype
]
except
KeyError
:
raise
TypeError
(
"Unsupported dtype for
%
s:
%
s"
%
(
self
.
__class__
.
__name__
,
self
.
dtype
))
def
c_declare
(
self
,
name
,
sub
):
def
c_declare
(
self
,
name
,
sub
):
return
"""
return
"""
...
@@ -89,6 +99,42 @@ class Scalar(ResultBase):
...
@@ -89,6 +99,42 @@ class Scalar(ResultBase):
def
c_cleanup
(
self
,
name
,
sub
):
def
c_cleanup
(
self
,
name
,
sub
):
return
""
return
""
def
c_support_code
(
cls
):
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
)
def
__copy__
(
self
):
def
__copy__
(
self
):
"""
"""
Return a copy of this instance (with its own attributes)
Return a copy of this instance (with its own attributes)
...
@@ -128,15 +174,6 @@ class ScalarMixedOp(GuardedOp):
...
@@ -128,15 +174,6 @@ class ScalarMixedOp(GuardedOp):
def
perform
(
self
):
def
perform
(
self
):
self
.
outputs
[
0
]
.
data
=
self
.
impl
(
*
[
input
.
data
for
input
in
self
.
inputs
])
self
.
outputs
[
0
]
.
data
=
self
.
impl
(
*
[
input
.
data
for
input
in
self
.
inputs
])
# def c_var_names(self):
# (self, inames, onames), _1, _2, _3 = inspect.getargspec(self.c_impl)
# inames = utils.from_return_values(inames)
# onames = utils.from_return_values(onames)
# return [inames, onames]
# def c_code(self):
# return self.c_impl(self.inputs, self.outputs)
def
upcast
(
dtype
,
*
dtypes
):
def
upcast
(
dtype
,
*
dtypes
):
z
=
numpy
.
zeros
((),
dtype
=
dtype
)
z
=
numpy
.
zeros
((),
dtype
=
dtype
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论