Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
94d510be
提交
94d510be
authored
9月 30, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tests pass on 32bit
上级
6e463193
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
10 行删除
+26
-10
_test_tensor.py
_test_tensor.py
+6
-6
tensor.py
tensor.py
+20
-4
没有找到文件。
_test_tensor.py
浏览文件 @
94d510be
...
@@ -536,14 +536,15 @@ DotTester = make_tester(name = 'DotTester',
...
@@ -536,14 +536,15 @@ DotTester = make_tester(name = 'DotTester',
#useful mostly for unit tests
#useful mostly for unit tests
def
_approx_eq
(
a
,
b
,
eps
=
1.0e-
9
):
def
_approx_eq
(
a
,
b
,
eps
=
1.0e-
4
):
a
=
numpy
.
asarray
(
a
)
a
=
numpy
.
asarray
(
a
)
b
=
numpy
.
asarray
(
b
)
b
=
numpy
.
asarray
(
b
)
if
a
.
shape
!=
b
.
shape
:
if
a
.
shape
!=
b
.
shape
:
if
_approx_eq
.
debug
:
if
_approx_eq
.
debug
:
print
a
.
shape
,
b
.
shape
print
a
.
shape
,
b
.
shape
return
False
return
False
if
numpy
.
max
(
numpy
.
abs
(
a
-
b
))
>=
eps
:
abs_rel_err
=
numeric_grad
.
abs_rel_err
(
a
,
b
)
if
numpy
.
max
(
abs_rel_err
)
>=
eps
:
if
_approx_eq
.
debug
:
if
_approx_eq
.
debug
:
print
a
,
b
print
a
,
b
return
False
return
False
...
@@ -861,7 +862,6 @@ class T_subtensor(unittest.TestCase):
...
@@ -861,7 +862,6 @@ class T_subtensor(unittest.TestCase):
self
.
failUnless
(
tval
.
shape
==
())
self
.
failUnless
(
tval
.
shape
==
())
self
.
failUnless
(
numpy
.
all
(
tval
==
0
))
self
.
failUnless
(
numpy
.
all
(
tval
==
0
))
def
test_grad_1d
(
self
):
def
test_grad_1d
(
self
):
n
=
as_tensor
(
numpy
.
random
.
rand
(
2
,
3
))
n
=
as_tensor
(
numpy
.
random
.
rand
(
2
,
3
))
z
=
scal
.
constant
(
0
)
z
=
scal
.
constant
(
0
)
...
@@ -872,7 +872,6 @@ class T_subtensor(unittest.TestCase):
...
@@ -872,7 +872,6 @@ class T_subtensor(unittest.TestCase):
s1
=
'array([ 1.55009327, 0. , 0. ])'
s1
=
'array([ 1.55009327, 0. , 0. ])'
self
.
failUnless
(
repr
(
gval
[
0
,:])
==
s0
)
self
.
failUnless
(
repr
(
gval
[
0
,:])
==
s0
)
self
.
failUnless
(
repr
(
gval
[
1
,:])
==
s1
)
self
.
failUnless
(
repr
(
gval
[
1
,:])
==
s1
)
def
test_grad_0d
(
self
):
def
test_grad_0d
(
self
):
n
=
as_tensor
(
numpy
.
random
.
rand
(
2
,
3
))
n
=
as_tensor
(
numpy
.
random
.
rand
(
2
,
3
))
t
=
n
[
1
,
0
]
t
=
n
[
1
,
0
]
...
@@ -1521,7 +1520,8 @@ class t_gemm(unittest.TestCase):
...
@@ -1521,7 +1520,8 @@ class t_gemm(unittest.TestCase):
f
=
function
([
tz
,
ta
,
tx
,
ty
,
tb
],
gemm
(
tz
,
ta
,
tx
,
ty
,
tb
),
mode
=
compile
.
Mode
(
optimizer
=
None
,
linker
=
l
))
f
=
function
([
tz
,
ta
,
tx
,
ty
,
tb
],
gemm
(
tz
,
ta
,
tx
,
ty
,
tb
),
mode
=
compile
.
Mode
(
optimizer
=
None
,
linker
=
l
))
f
(
z
,
a
,
x
,
y
,
b
)
f
(
z
,
a
,
x
,
y
,
b
)
self
.
failUnless
(
_approx_eq
(
z_after
,
z
),
(
z_orig
,
z_after
,
z
))
self
.
failUnless
(
_approx_eq
(
z_after
,
z
),
(
z_orig
,
z_after
,
z
,
z_after
-
z
))
f
(
z
.
T
,
a
,
y
.
T
,
x
.
T
,
b
)
f
(
z
.
T
,
a
,
y
.
T
,
x
.
T
,
b
)
self
.
failUnless
(
_approx_eq
(
z_after
,
z
))
self
.
failUnless
(
_approx_eq
(
z_after
,
z
))
...
@@ -1778,7 +1778,7 @@ if __name__ == '__main__':
...
@@ -1778,7 +1778,7 @@ if __name__ == '__main__':
if
0
:
if
0
:
unittest
.
main
()
unittest
.
main
()
else
:
else
:
testcase
=
AbsInplaceTester
testcase
=
T_Join_and_Split
suite
=
unittest
.
TestLoader
()
suite
=
unittest
.
TestLoader
()
suite
=
suite
.
loadTestsFromTestCase
(
testcase
)
suite
=
suite
.
loadTestsFromTestCase
(
testcase
)
...
...
tensor.py
浏览文件 @
94d510be
...
@@ -369,6 +369,7 @@ def _multi(*fns):
...
@@ -369,6 +369,7 @@ def _multi(*fns):
fscalar
=
Tensor
(
'float32'
,
())
fscalar
=
Tensor
(
'float32'
,
())
dscalar
=
Tensor
(
'float64'
,
())
dscalar
=
Tensor
(
'float64'
,
())
bscalar
=
Tensor
(
'int8'
,
())
bscalar
=
Tensor
(
'int8'
,
())
wscalar
=
Tensor
(
'int16'
,
())
iscalar
=
Tensor
(
'int32'
,
())
iscalar
=
Tensor
(
'int32'
,
())
lscalar
=
Tensor
(
'int64'
,
())
lscalar
=
Tensor
(
'int64'
,
())
def
scalar
(
name
=
None
,
dtype
=
'float64'
):
def
scalar
(
name
=
None
,
dtype
=
'float64'
):
...
@@ -376,9 +377,13 @@ def scalar(name = None, dtype = 'float64'):
...
@@ -376,9 +377,13 @@ def scalar(name = None, dtype = 'float64'):
return
type
(
name
)
return
type
(
name
)
scalars
,
fscalars
,
dscalars
,
iscalars
,
lscalars
=
_multi
(
scalar
,
fscalar
,
dscalar
,
iscalar
,
lscalar
)
scalars
,
fscalars
,
dscalars
,
iscalars
,
lscalars
=
_multi
(
scalar
,
fscalar
,
dscalar
,
iscalar
,
lscalar
)
int_types
=
bscalar
,
wscalar
,
iscalar
,
lscalar
float_types
=
fscalar
,
dscalar
fvector
=
Tensor
(
'float32'
,
(
False
,
))
fvector
=
Tensor
(
'float32'
,
(
False
,
))
dvector
=
Tensor
(
'float64'
,
(
False
,
))
dvector
=
Tensor
(
'float64'
,
(
False
,
))
bvector
=
Tensor
(
'int8'
,
(
False
,))
bvector
=
Tensor
(
'int8'
,
(
False
,))
wvector
=
Tensor
(
'int16'
,
(
False
,))
ivector
=
Tensor
(
'int32'
,
(
False
,
))
ivector
=
Tensor
(
'int32'
,
(
False
,
))
lvector
=
Tensor
(
'int64'
,
(
False
,
))
lvector
=
Tensor
(
'int64'
,
(
False
,
))
def
vector
(
name
=
None
,
dtype
=
'float64'
):
def
vector
(
name
=
None
,
dtype
=
'float64'
):
...
@@ -386,9 +391,13 @@ def vector(name = None, dtype = 'float64'):
...
@@ -386,9 +391,13 @@ def vector(name = None, dtype = 'float64'):
return
type
(
name
)
return
type
(
name
)
vectors
,
fvectors
,
dvectors
,
ivectors
,
lvectors
=
_multi
(
vector
,
fvector
,
dvector
,
ivector
,
lvector
)
vectors
,
fvectors
,
dvectors
,
ivectors
,
lvectors
=
_multi
(
vector
,
fvector
,
dvector
,
ivector
,
lvector
)
int_vector_types
=
bvector
,
wvector
,
ivector
,
lvector
float_vector_types
=
fvector
,
dvector
fmatrix
=
Tensor
(
'float32'
,
(
False
,
False
))
fmatrix
=
Tensor
(
'float32'
,
(
False
,
False
))
dmatrix
=
Tensor
(
'float64'
,
(
False
,
False
))
dmatrix
=
Tensor
(
'float64'
,
(
False
,
False
))
bmatrix
=
Tensor
(
'int8'
,
(
False
,
False
))
bmatrix
=
Tensor
(
'int8'
,
(
False
,
False
))
wmatrix
=
Tensor
(
'int16'
,
(
False
,
False
))
imatrix
=
Tensor
(
'int32'
,
(
False
,
False
))
imatrix
=
Tensor
(
'int32'
,
(
False
,
False
))
lmatrix
=
Tensor
(
'int64'
,
(
False
,
False
))
lmatrix
=
Tensor
(
'int64'
,
(
False
,
False
))
def
matrix
(
name
=
None
,
dtype
=
'float64'
):
def
matrix
(
name
=
None
,
dtype
=
'float64'
):
...
@@ -396,9 +405,13 @@ def matrix(name = None, dtype = 'float64'):
...
@@ -396,9 +405,13 @@ def matrix(name = None, dtype = 'float64'):
return
type
(
name
)
return
type
(
name
)
matrices
,
fmatrices
,
dmatrices
,
imatrices
,
lmatrices
=
_multi
(
matrix
,
fmatrix
,
dmatrix
,
imatrix
,
lmatrix
)
matrices
,
fmatrices
,
dmatrices
,
imatrices
,
lmatrices
=
_multi
(
matrix
,
fmatrix
,
dmatrix
,
imatrix
,
lmatrix
)
int_matrix_types
=
bmatrix
,
wmatrix
,
imatrix
,
lmatrix
float_matrix_types
=
fmatrix
,
dmatrix
frow
=
Tensor
(
'float32'
,
(
True
,
False
))
frow
=
Tensor
(
'float32'
,
(
True
,
False
))
drow
=
Tensor
(
'float64'
,
(
True
,
False
))
drow
=
Tensor
(
'float64'
,
(
True
,
False
))
brow
=
Tensor
(
'int8'
,
(
True
,
False
))
brow
=
Tensor
(
'int8'
,
(
True
,
False
))
wrow
=
Tensor
(
'int16'
,
(
True
,
False
))
irow
=
Tensor
(
'int32'
,
(
True
,
False
))
irow
=
Tensor
(
'int32'
,
(
True
,
False
))
lrow
=
Tensor
(
'int64'
,
(
True
,
False
))
lrow
=
Tensor
(
'int64'
,
(
True
,
False
))
def
row
(
name
=
None
,
dtype
=
'float64'
):
def
row
(
name
=
None
,
dtype
=
'float64'
):
...
@@ -409,6 +422,7 @@ rows, frows, drows, irows, lrows = _multi(row, frow, drow, irow, lrow)
...
@@ -409,6 +422,7 @@ rows, frows, drows, irows, lrows = _multi(row, frow, drow, irow, lrow)
fcol
=
Tensor
(
'float32'
,
(
False
,
True
))
fcol
=
Tensor
(
'float32'
,
(
False
,
True
))
dcol
=
Tensor
(
'float64'
,
(
False
,
True
))
dcol
=
Tensor
(
'float64'
,
(
False
,
True
))
bcol
=
Tensor
(
'int8'
,
(
False
,
True
))
bcol
=
Tensor
(
'int8'
,
(
False
,
True
))
wcol
=
Tensor
(
'int16'
,
(
False
,
True
))
icol
=
Tensor
(
'int32'
,
(
False
,
True
))
icol
=
Tensor
(
'int32'
,
(
False
,
True
))
lcol
=
Tensor
(
'int64'
,
(
False
,
True
))
lcol
=
Tensor
(
'int64'
,
(
False
,
True
))
def
col
(
name
=
None
,
dtype
=
'float64'
):
def
col
(
name
=
None
,
dtype
=
'float64'
):
...
@@ -1375,9 +1389,9 @@ class Split(Op):
...
@@ -1375,9 +1389,9 @@ class Split(Op):
axis
=
as_tensor
(
axis
)
axis
=
as_tensor
(
axis
)
splits
=
as_tensor
(
splits
)
splits
=
as_tensor
(
splits
)
if
splits
.
type
!=
lvector
:
if
splits
.
type
not
in
int_vector_types
:
raise
TypeError
(
'splits must have type tensor.lvector'
,
splits
.
type
)
raise
TypeError
(
'splits must have type tensor.lvector'
,
splits
.
type
)
if
axis
.
type
!=
lscalar
:
if
axis
.
type
not
in
int_types
:
raise
TypeError
(
'axis must have type lscalar'
,
axis
.
type
)
raise
TypeError
(
'axis must have type lscalar'
,
axis
.
type
)
inputs
=
[
x
,
axis
,
splits
]
inputs
=
[
x
,
axis
,
splits
]
...
@@ -1464,8 +1478,8 @@ class Join(Op):
...
@@ -1464,8 +1478,8 @@ class Join(Op):
bcastable
[
axis
]
=
False
bcastable
[
axis
]
=
False
inputs
=
[
as_tensor
(
axis
)]
+
as_tensor_args
inputs
=
[
as_tensor
(
axis
)]
+
as_tensor_args
if
inputs
[
0
]
.
type
!=
lscalar
:
if
inputs
[
0
]
.
type
not
in
int_types
:
raise
TypeError
(
'Axis could not be cast to
lscalar'
,
axi
s
)
raise
TypeError
(
'Axis could not be cast to
an integer type'
,
axis
,
inputs
[
0
]
.
type
,
int_type
s
)
outputs
=
[
tensor
(
dtype
=
dtypes
[
0
],
outputs
=
[
tensor
(
dtype
=
dtypes
[
0
],
broadcastable
=
bcastable
)]
broadcastable
=
bcastable
)]
...
@@ -1506,6 +1520,7 @@ class Join(Op):
...
@@ -1506,6 +1520,7 @@ class Join(Op):
for
k
in
range
(
len
(
sizes_along_axis
))]
for
k
in
range
(
len
(
sizes_along_axis
))]
def
vec_length
(
self
,
node
):
def
vec_length
(
self
,
node
):
"""Guess the length of a Join Result"""
assert
isinstance
(
node
.
owner
.
op
,
Join
)
assert
isinstance
(
node
.
owner
.
op
,
Join
)
if
node
.
ndim
!=
1
:
if
node
.
ndim
!=
1
:
raise
TypeError
(
'argument must be symbolic vector'
)
raise
TypeError
(
'argument must be symbolic vector'
)
...
@@ -1515,6 +1530,7 @@ class Join(Op):
...
@@ -1515,6 +1530,7 @@ class Join(Op):
# the question is whether all the inputs are broadcastable.
# the question is whether all the inputs are broadcastable.
if
all
(
i
.
broadcastable
[
0
]
for
i
in
tensors
):
if
all
(
i
.
broadcastable
[
0
]
for
i
in
tensors
):
return
len
(
tensors
)
return
len
(
tensors
)
raise
ValueError
(
"could not determine vector length"
)
@_redefine_asRoutine
(
Join
())
@_redefine_asRoutine
(
Join
())
def
join
(
axis
,
*
tensors
):
def
join
(
axis
,
*
tensors
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论