Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f7daa82c
提交
f7daa82c
authored
5月 14, 2014
作者:
Tanjay94
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added norm function.
上级
334081ee
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
104 行增加
和
0 行删除
+104
-0
ops.py
theano/sandbox/linalg/ops.py
+85
-0
test_linalg.py
theano/sandbox/linalg/tests/test_linalg.py
+19
-0
没有找到文件。
theano/sandbox/linalg/ops.py
浏览文件 @
f7daa82c
...
@@ -1215,8 +1215,93 @@ def eigvalsh(a, b, lower=True):
...
@@ -1215,8 +1215,93 @@ 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
):
x
=
as_tensor_variable
(
x
)
ndim
=
x
.
ndim
if
ndim
==
0
:
raise
TypeError
elif
ndim
==
1
:
if
ord
==
None
:
z
=
(
tensor
.
sum
(
x
**
2
))
**
(
0.5
)
return
z
elif
ord
==
'inf'
:
z
=
tensor
.
max
(
abs
(
x
))
return
z
elif
ord
==
'-inf'
:
z
=
tensor
.
min
(
abs
(
x
))
return
z
elif
ord
==
0
:
z
=
(
x
[
x
.
nonzero
()])
.
shape
[
0
]
return
z
else
:
try
:
z
=
(
tensor
.
sum
(
abs
(
x
**
ord
)))
**
(
1.
/
ord
)
except
TypeError
:
raise
ValueError
return
z
elif
ndim
>=
2
:
if
axis
==
None
:
if
ord
==
None
or
ord
==
'fro'
:
z
=
(
tensor
.
sum
(
abs
(
x
**
2
)))
**
(
0.5
)
return
z
elif
ord
==
'inf'
:
z
=
tensor
.
sum
(
abs
(
x
),
1
)
return
tensor
.
max
(
z
)
elif
ord
==
'-inf'
:
z
=
tensor
.
sum
(
abs
(
x
),
1
)
return
tensor
.
min
(
z
)
elif
ord
==
1
:
z
=
tensor
.
sum
(
abs
(
x
),
0
)
return
tensor
.
max
(
z
)
elif
ord
==
-
1
:
z
=
tensor
.
sum
(
abs
(
x
),
0
)
return
tensor
.
min
(
z
)
else
:
raise
ValueError
(
0
)
else
:
try
:
axis
+
1
if
ord
==
None
:
z
=
(
tensor
.
sum
(
x
**
2
,
axis
))
**
(
0.5
)
return
z
elif
ord
==
'inf'
:
z
=
tensor
.
max
(
abs
(
x
),
axis
)
return
z
elif
ord
==
'-inf'
:
z
=
tensor
.
min
(
abs
(
x
),
axis
)
return
z
elif
ord
==
0
:
z
=
tensor
.
sum
(
tensor
.
neq
(
x
,
0
),
1
)
return
z
else
:
try
:
z
=
(
tensor
.
sum
(
abs
(
x
**
ord
),
axis
))
**
(
1.
/
ord
)
except
TypeError
:
raise
ValueError
return
z
except
TypeError
:
if
ord
==
None
or
ord
==
'fro'
:
z
=
(
tensor
.
sum
(
abs
(
x
**
2
),
axis
))
**
(
0.5
)
return
z
elif
ord
==
'inf'
:
z
=
tensor
.
sum
(
abs
(
x
),
1
)
return
tensor
.
max
(
z
,
axis
)
elif
ord
==
'-inf'
:
z
=
tensor
.
sum
(
abs
(
x
),
1
)
return
tensor
.
min
(
z
,
axis
)
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
浏览文件 @
f7daa82c
...
@@ -31,7 +31,9 @@ from theano.sandbox.linalg.ops import (cholesky,
...
@@ -31,7 +31,9 @@ from theano.sandbox.linalg.ops import (cholesky,
imported_scipy
,
imported_scipy
,
Eig
,
Eig
,
inv_as_solve
inv_as_solve
norm
)
)
from
theano.sandbox.linalg
import
eig
,
eigh
,
eigvalsh
from
theano.sandbox.linalg
import
eig
,
eigh
,
eigvalsh
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.attrib
import
attr
from
nose.plugins.attrib
import
attr
...
@@ -611,6 +613,7 @@ def test_eigvalsh_grad():
...
@@ -611,6 +613,7 @@ def test_eigvalsh_grad():
[
a
,
b
],
rng
=
numpy
.
random
)
[
a
,
b
],
rng
=
numpy
.
random
)
<<<<<<<
HEAD
class
Matrix_power
():
class
Matrix_power
():
def
test_numpy_compare
(
self
):
def
test_numpy_compare
(
self
):
...
@@ -631,3 +634,19 @@ class Matrix_power():
...
@@ -631,3 +634,19 @@ class Matrix_power():
f
=
function
([
A
],
[
Q
])
f
=
function
([
A
],
[
Q
])
a
=
rng
.
rand
(
4
,
3
)
.
astype
(
theano
.
config
.
floatX
)
a
=
rng
.
rand
(
4
,
3
)
.
astype
(
theano
.
config
.
floatX
)
self
.
assertRaises
(
ValueError
,
f
,
a
)
self
.
assertRaises
(
ValueError
,
f
,
a
)
class
T_NormTests
(
unittest
.
TestCase
):
def
test_wrong_type_of_ord_for_vector
(
self
):
self
.
assertRaises
(
ValueError
,
norm
,
[
2
,
1
],
'fro'
,
0
)
def
test_wrong_type_of_ord_for_vector_in_matrix
(
self
):
self
.
assertRaises
(
ValueError
,
norm
,
[[
2
,
1
],[
3
,
4
]],
'fro'
,
0
)
def
test_wrong_type_of_ord_for_vector_in_tensor
(
self
):
self
.
assertRaises
(
ValueError
,
norm
,
[[[
2
,
1
],[
3
,
4
]],[[
6
,
5
],[
7
,
8
]]],
'fro'
,
0
)
def
test_wrong_type_of_ord_for_matrix
(
self
):
self
.
assertRaises
(
ValueError
,
norm
,
[[
2
,
1
],[
3
,
4
]],
0
,
None
)
def
test_wrong_type_of_ord_for_matrix_in_tensor
(
self
):
self
.
assertRaises
(
ValueError
,
norm
,
[[[
2
,
1
],[
3
,
4
]],[[
6
,
5
],[
7
,
8
]]],
0
,
None
)
def
test_non_tensorial_input
(
self
):
self
.
assertRaises
(
TypeError
,
norm
,
3
,
None
,
None
)
def
test_no_enough_dimensions
(
self
):
self
.
assertRaises
(
ValueError
,
norm
,
[[
2
,
1
],[
3
,
4
]],
None
,
3
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论