Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
43cfa11a
提交
43cfa11a
authored
5月 21, 2014
作者:
Tanjay94
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed swapaxes function in var, indentation error in test_basic and added lstsq…
Fixed swapaxes function in var, indentation error in test_basic and added lstsq function in ops with tests.
上级
26f2112e
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
89 行增加
和
72 行删除
+89
-72
ops.py
theano/sandbox/linalg/ops.py
+49
-61
test_linalg.py
theano/sandbox/linalg/tests/test_linalg.py
+31
-3
test_basic.py
theano/tensor/tests/test_basic.py
+3
-1
var.py
theano/tensor/var.py
+6
-7
没有找到文件。
theano/sandbox/linalg/ops.py
浏览文件 @
43cfa11a
...
@@ -1215,14 +1215,14 @@ def eigvalsh(a, b, lower=True):
...
@@ -1215,14 +1215,14 @@ def eigvalsh(a, b, lower=True):
return
Eigvalsh
(
lower
)(
a
,
b
)
return
Eigvalsh
(
lower
)(
a
,
b
)
<<<<<<<
HEAD
def
matrix_power
(
M
,
n
):
def
matrix_power
(
M
,
n
):
result
=
1
result
=
1
for
i
in
xrange
(
n
):
for
i
in
xrange
(
n
):
result
=
theano
.
dot
(
result
,
M
)
result
=
theano
.
dot
(
result
,
M
)
return
result
return
result
=======
def
norm
(
x
,
ord
,
axis
):
def
norm
(
x
,
ord
):
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
ndim
=
x
.
ndim
ndim
=
x
.
ndim
if
ndim
==
0
:
if
ndim
==
0
:
...
@@ -1246,62 +1246,50 @@ def norm(x,ord,axis):
...
@@ -1246,62 +1246,50 @@ def norm(x,ord,axis):
except
TypeError
:
except
TypeError
:
raise
ValueError
raise
ValueError
return
z
return
z
elif
ndim
>=
2
:
elif
ndim
==
2
:
if
axis
==
None
:
if
ord
==
None
or
ord
==
'fro'
:
if
ord
==
None
or
ord
==
'fro'
:
z
=
(
tensor
.
sum
(
abs
(
x
**
2
)))
**
(
0.5
)
z
=
(
tensor
.
sum
(
abs
(
x
**
2
)))
**
(
0.5
)
return
z
return
z
elif
ord
==
'inf'
:
elif
ord
==
'inf'
:
z
=
tensor
.
sum
(
abs
(
x
),
1
)
z
=
tensor
.
sum
(
abs
(
x
),
1
)
return
tensor
.
max
(
z
)
return
tensor
.
max
(
z
)
elif
ord
==
'-inf'
:
elif
ord
==
'-inf'
:
z
=
tensor
.
sum
(
abs
(
x
),
1
)
z
=
tensor
.
sum
(
abs
(
x
),
1
)
return
tensor
.
min
(
z
)
return
tensor
.
min
(
z
)
elif
ord
==
1
:
elif
ord
==
1
:
z
=
tensor
.
sum
(
abs
(
x
),
0
)
z
=
tensor
.
sum
(
abs
(
x
),
0
)
return
tensor
.
max
(
z
)
return
tensor
.
max
(
z
)
elif
ord
==
-
1
:
elif
ord
==
-
1
:
z
=
tensor
.
sum
(
abs
(
x
),
0
)
z
=
tensor
.
sum
(
abs
(
x
),
0
)
return
tensor
.
min
(
z
)
return
tensor
.
min
(
z
)
else
:
raise
ValueError
(
0
)
else
:
else
:
try
:
raise
ValueError
(
0
)
axis
+
1
if
ord
==
None
:
z
=
(
tensor
.
sum
(
x
**
2
,
axis
))
**
(
0.5
)
return
z
class
lstsq
(
theano
.
Op
):
elif
ord
==
'inf'
:
def
__eq__
(
self
,
other
):
z
=
tensor
.
max
(
abs
(
x
),
axis
)
pass
return
z
elif
ord
==
'-inf'
:
def
__hash__
(
self
):
z
=
tensor
.
min
(
abs
(
x
),
axis
)
return
hash
(
type
(
self
))
return
z
elif
ord
==
0
:
def
__str__
(
self
):
z
=
tensor
.
sum
(
tensor
.
neq
(
x
,
0
),
axis
)
return
self
.
__class__
.
__name__
return
z
else
:
def
make_node
(
self
,
x
,
y
,
rcond
):
try
:
x
=
theano
.
tensor
.
as_tensor_variable
(
x
)
z
=
(
tensor
.
sum
(
abs
(
x
**
ord
),
axis
))
**
(
1.
/
ord
)
y
=
theano
.
tensor
.
as_tensor_variable
(
y
)
except
TypeError
:
rcond
=
theano
.
tensor
.
as_tensor_variable
(
rcond
)
raise
ValueError
return
theano
.
Apply
(
self
,
[
x
,
y
,
rcond
],
[
y
.
type
(),
theano
.
tensor
.
dvector
(),
theano
.
tensor
.
lscalar
(),
theano
.
tensor
.
dvector
()])
return
z
except
TypeError
:
def
perform
(
self
,
node
,
inputs
,
outputs
):
if
ord
==
None
or
ord
==
'fro'
:
x
=
inputs
[
0
]
z
=
(
tensor
.
sum
(
abs
(
x
**
2
),
axis
))
**
(
0.5
)
y
=
inputs
[
1
]
return
z
rcond
=
inputs
[
2
]
elif
ord
==
'inf'
:
zz
=
numpy
.
linalg
.
lstsq
(
inputs
[
0
],
inputs
[
1
],
inputs
[
2
])
z
=
tensor
.
sum
(
abs
(
x
),
1
)
outputs
[
0
][
0
]
=
zz
[
0
]
return
tensor
.
max
(
z
,
axis
)
outputs
[
1
][
0
]
=
zz
[
1
]
elif
ord
==
'-inf'
:
outputs
[
2
][
0
]
=
zz
[
2
]
z
=
tensor
.
sum
(
abs
(
x
),
1
)
outputs
[
3
][
0
]
=
zz
[
3
]
return
tensor
.
min
(
z
,
axis
)
>>>>>>>
Fixed
swapaxes
function
in
var
,
indentation
error
in
test_basic
and
added
lstsq
function
in
ops
with
tests
.
elif
ord
==
1
:
z
=
tensor
.
sum
(
abs
(
x
),
0
)
return
tensor
.
max
(
z
,
axis
)
elif
ord
==
-
1
:
z
=
tensor
.
sum
(
abs
(
x
),
0
)
return
tensor
.
min
(
z
,
axis
)
else
:
raise
ValueError
(
0
)
>>>>>>>
Added
norm
function
.
theano/sandbox/linalg/tests/test_linalg.py
浏览文件 @
43cfa11a
...
@@ -651,6 +651,34 @@ class T_NormTests(unittest.TestCase):
...
@@ -651,6 +651,34 @@ class T_NormTests(unittest.TestCase):
def
test_no_enough_dimensions
(
self
):
def
test_no_enough_dimensions
(
self
):
self
.
assertRaises
(
ValueError
,
norm
,
[[
2
,
1
],[
3
,
4
]],
None
,
3
)
self
.
assertRaises
(
ValueError
,
norm
,
[[
2
,
1
],[
3
,
4
]],
None
,
3
)
def
test
(
self
):
def
test
():
x
=
theano
.
tensor
.
matrix
()
x
=
theano
.
tensor
.
matrix
()
x
.
swapaxes
()
x
.
swapaxes
(
0
,
1
)
class
T_lstsq
(
unittest
.
TestCase
):
def
test_correct_solution
(
self
):
x
=
tensor
.
lmatrix
()
y
=
tensor
.
lmatrix
()
z
=
tensor
.
lscalar
()
b
=
theano
.
sandbox
.
linalg
.
ops
.
lstsq
()(
x
,
y
,
z
)
f
=
function
([
x
,
y
,
z
],
b
)
TestMatrix1
=
numpy
.
asarray
([[
2
,
1
],[
3
,
4
]])
TestMatrix2
=
numpy
.
asarray
([[
17
,
20
],[
43
,
50
]])
TestScalar
=
numpy
.
asarray
(
1
)
f
=
function
([
x
,
y
,
z
],
b
)
m
=
f
(
TestMatrix1
,
TestMatrix2
,
TestScalar
)
self
.
assertTrue
(
numpy
.
allclose
(
TestMatrix2
,
numpy
.
dot
(
TestMatrix1
,
m
[
0
])))
def
test_wrong_coefficient_matrix
(
self
):
x
=
tensor
.
vector
()
y
=
tensor
.
vector
()
z
=
tensor
.
scalar
()
b
=
theano
.
sandbox
.
linalg
.
ops
.
lstsq
()(
x
,
y
,
z
)
f
=
function
([
x
,
y
,
z
],
b
)
self
.
assertRaises
(
numpy
.
linalg
.
linalg
.
LinAlgError
,
f
,
[
2
,
1
],[
2
,
1
],
1
)
def
test_wrong_rcond_dimension
(
self
):
x
=
tensor
.
vector
()
y
=
tensor
.
vector
()
z
=
tensor
.
vector
()
b
=
theano
.
sandbox
.
linalg
.
ops
.
lstsq
()(
x
,
y
,
z
)
f
=
function
([
x
,
y
,
z
],
b
)
self
.
assertRaises
(
numpy
.
linalg
.
LinAlgError
,
f
,
[
2
,
1
],[
2
,
1
],[
2
,
1
])
theano/tensor/tests/test_basic.py
浏览文件 @
43cfa11a
...
@@ -46,7 +46,9 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
...
@@ -46,7 +46,9 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
itensor3
,
Tile
,
switch
,
Diagonal
,
Diag
,
itensor3
,
Tile
,
switch
,
Diagonal
,
Diag
,
nonzero
,
flatnonzero
,
nonzero_values
,
nonzero
,
flatnonzero
,
nonzero_values
,
stacklists
,
DimShuffle
,
hessian
,
ptp
,
power
,
stacklists
,
DimShuffle
,
hessian
,
ptp
,
power
,
swapaxes
)
swapaxes
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
...
theano/tensor/var.py
浏览文件 @
43cfa11a
...
@@ -556,7 +556,13 @@ class _tensor_py_operators:
...
@@ -556,7 +556,13 @@ class _tensor_py_operators:
"""see 'theano.tensor.ptp'"""
"""see 'theano.tensor.ptp'"""
return
theano
.
tensor
.
ptp
(
self
,
axis
)
return
theano
.
tensor
.
ptp
(
self
,
axis
)
def
swapaxes
(
self
,
axis1
,
axis2
):
"""Return 'tensor.swapaxes(self, axis1, axis2)
If a matrix is provided with the right axes, its transpose will be returned.
"""
return
theano
.
tensor
.
basic
.
swapaxes
(
self
,
axis1
,
axis2
)
class
TensorVariable
(
_tensor_py_operators
,
Variable
):
class
TensorVariable
(
_tensor_py_operators
,
Variable
):
"""Subclass to add the tensor operators to the basic `Variable` class."""
"""Subclass to add the tensor operators to the basic `Variable` class."""
...
@@ -699,11 +705,4 @@ class TensorConstant(_tensor_py_operators, Constant):
...
@@ -699,11 +705,4 @@ class TensorConstant(_tensor_py_operators, Constant):
copy
.
deepcopy
(
self
.
data
,
memo
),
copy
.
deepcopy
(
self
.
data
,
memo
),
copy
.
deepcopy
(
self
.
name
,
memo
))
copy
.
deepcopy
(
self
.
name
,
memo
))
def
swapaxes
(
self
,
axis1
,
axis2
):
"""Return 'tensor.swapaxes(self, axis1, axis2)
If a matrix is provided with the right axes, its transpose will be returned.
"""
return
theano
.
tensor
.
basic
.
swapaxes
(
self
,
axis1
,
axis2
)
TensorType
.
Constant
=
TensorConstant
TensorType
.
Constant
=
TensorConstant
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论