Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6317960c
提交
6317960c
authored
5月 12, 2014
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1847 from Hengjean/ptp
added ptp() and associated case test
上级
085ebae0
52da8b11
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
107 行增加
和
1 行删除
+107
-1
basic.txt
doc/library/tensor/basic.txt
+12
-0
basic.py
theano/tensor/basic.py
+21
-0
test_basic.py
theano/tensor/tests/test_basic.py
+69
-1
var.py
theano/tensor/var.py
+5
-0
没有找到文件。
doc/library/tensor/basic.txt
浏览文件 @
6317960c
...
@@ -966,6 +966,18 @@ Reductions
...
@@ -966,6 +966,18 @@ Reductions
* an *int* - computed along this axis
* an *int* - computed along this axis
* a *list of ints* - computed along these axes
* a *list of ints* - computed along these axes
.. function:: ptp(x, axis = None)
Range of values (maximum - minimum) along an axis.
The name of the function comes from the acronym for peak to peak.
:Parameter: *x* Input tensor.
:Parameter: *axis* Axis along which to find the peaks. By default,
flatten the array.
:Returns: A new array holding the result.
Indexing
Indexing
========
========
...
...
theano/tensor/basic.py
浏览文件 @
6317960c
...
@@ -5000,3 +5000,24 @@ def stacklists(arg):
...
@@ -5000,3 +5000,24 @@ def stacklists(arg):
return
stack
(
*
map
(
stacklists
,
arg
))
return
stack
(
*
map
(
stacklists
,
arg
))
else
:
else
:
return
arg
return
arg
def
ptp
(
a
,
axis
=
None
):
"""
Range of values (maximum - minimum) along an axis.
The name of the function comes from the acronym for peak to peak.
:param a : Input tensor.
:param axis : Axis along which to find the peaks. By default,
flatten the array.
:return : A new array holding the result.
"""
a
=
as_tensor_variable
(
a
)
out
=
max
(
a
,
axis
)
-
min
(
a
,
axis
)
return
out
theano/tensor/tests/test_basic.py
浏览文件 @
6317960c
...
@@ -45,7 +45,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
...
@@ -45,7 +45,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
dtensor3
,
SpecifyShape
,
Mean
,
dtensor3
,
SpecifyShape
,
Mean
,
itensor3
,
Tile
,
switch
,
Diagonal
,
Diag
,
itensor3
,
Tile
,
switch
,
Diagonal
,
Diag
,
nonzero
,
flatnonzero
,
nonzero_values
,
nonzero
,
flatnonzero
,
nonzero_values
,
stacklists
,
DimShuffle
,
hessian
)
stacklists
,
DimShuffle
,
hessian
,
ptp
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -6777,6 +6777,74 @@ def test_norm():
...
@@ -6777,6 +6777,74 @@ def test_norm():
f
=
theano
.
function
([
x
],
n
)
f
=
theano
.
function
([
x
],
n
)
assert
numpy
.
allclose
(
f
([
1
,
1
]),
numpy
.
sqrt
(
2
))
assert
numpy
.
allclose
(
f
([
1
,
1
]),
numpy
.
sqrt
(
2
))
class
test_ptp
(
unittest
.
TestCase
):
def
test_scalar
(
self
):
"""
Should return 0 for all scalar
"""
x
=
scalar
(
'x'
)
p
=
ptp
(
x
)
f
=
theano
.
function
([
x
],
p
)
self
.
assertTrue
(
f
(
rand
()
*
20000
-
10000
)
==
0
)
def
test_vector
(
self
):
x
=
vector
(
'x'
)
p
=
ptp
(
x
,
0
)
f
=
theano
.
function
([
x
],
p
)
y
=
rand_ranged
(
-
1000
,
1000
,
[
100
])
result
=
f
(
y
)
numpyResult
=
numpy
.
ptp
(
y
,
0
)
self
.
assertTrue
(
numpy
.
array_equal
(
result
,
numpyResult
))
def
test_matrix_first_axis
(
self
):
x
=
matrix
(
'x'
)
p
=
ptp
(
x
,
1
)
f
=
theano
.
function
([
x
],
p
)
y
=
rand_ranged
(
-
1000
,
1000
,
[
100
,
100
])
result
=
f
(
y
)
numpyResult
=
numpy
.
ptp
(
y
,
1
)
self
.
assertTrue
(
numpy
.
array_equal
(
result
,
numpyResult
))
def
test_matrix_second_axis
(
self
):
x
=
matrix
(
'x'
)
p
=
ptp
(
x
,
0
)
f
=
theano
.
function
([
x
],
p
)
y
=
rand_ranged
(
-
1000
,
1000
,
[
100
,
100
])
result
=
f
(
y
)
numpyResult
=
numpy
.
ptp
(
y
,
0
)
self
.
assertTrue
(
numpy
.
array_equal
(
result
,
numpyResult
))
def
test_matrix_neg_axis
(
self
):
x
=
matrix
(
'x'
)
p
=
ptp
(
x
,
-
1
)
f
=
theano
.
function
([
x
],
p
)
y
=
rand_ranged
(
-
1000
,
1000
,
[
100
,
100
])
result
=
f
(
y
)
numpyResult
=
numpy
.
ptp
(
y
,
-
1
)
self
.
assertTrue
(
numpy
.
array_equal
(
result
,
numpyResult
))
def
test_matrix_no_axis
(
self
):
x
=
matrix
(
'x'
)
p
=
ptp
(
x
)
f
=
theano
.
function
([
x
],
p
)
y
=
rand_ranged
(
-
1000
,
1000
,
[
100
,
100
])
result
=
f
(
y
)
numpyResult
=
numpy
.
ptp
(
y
)
self
.
assertTrue
(
numpy
.
array_equal
(
result
,
numpyResult
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
t
=
TestInferShape
(
'setUp'
)
t
=
TestInferShape
(
'setUp'
)
...
...
theano/tensor/var.py
浏览文件 @
6317960c
...
@@ -552,6 +552,11 @@ class _tensor_py_operators:
...
@@ -552,6 +552,11 @@ class _tensor_py_operators:
def
cumprod
(
self
,
axis
=
None
):
def
cumprod
(
self
,
axis
=
None
):
return
theano
.
tensor
.
extra_ops
.
cumprod
(
self
,
axis
)
return
theano
.
tensor
.
extra_ops
.
cumprod
(
self
,
axis
)
def
ptp
(
self
,
axis
=
None
):
"""see 'theano.tensor.ptp'"""
return
theano
.
tensor
.
ptp
(
self
,
axis
)
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."""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论