Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
47278f72
提交
47278f72
authored
1月 31, 2016
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3883 from skaae/bessel
[WIP] add bessel0
上级
dfce3aee
14fdf308
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
117 行增加
和
23 行删除
+117
-23
basic_scipy.py
theano/scalar/basic_scipy.py
+56
-23
basic.py
theano/tensor/basic.py
+10
-0
inplace.py
theano/tensor/inplace.py
+10
-0
test_basic.py
theano/tensor/tests/test_basic.py
+41
-0
没有找到文件。
theano/scalar/basic_scipy.py
浏览文件 @
47278f72
...
@@ -231,12 +231,6 @@ class Gamma(UnaryScalarOp):
...
@@ -231,12 +231,6 @@ class Gamma(UnaryScalarOp):
if
node
.
inputs
[
0
]
.
type
in
float_types
:
if
node
.
inputs
[
0
]
.
type
in
float_types
:
return
"""
%(z)
s = tgamma(
%(x)
s);"""
%
locals
()
return
"""
%(z)
s = tgamma(
%(x)
s);"""
%
locals
()
raise
NotImplementedError
(
'only floating point is implemented'
)
raise
NotImplementedError
(
'only floating point is implemented'
)
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
gamma
=
Gamma
(
upgrade_to_float
,
name
=
'gamma'
)
gamma
=
Gamma
(
upgrade_to_float
,
name
=
'gamma'
)
...
@@ -275,12 +269,6 @@ class GammaLn(UnaryScalarOp):
...
@@ -275,12 +269,6 @@ class GammaLn(UnaryScalarOp):
return
"""
%(z)
s =
return
"""
%(z)
s =
lgamma(
%(x)
s);"""
%
locals
()
lgamma(
%(x)
s);"""
%
locals
()
raise
NotImplementedError
(
'only floating point is implemented'
)
raise
NotImplementedError
(
'only floating point is implemented'
)
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
gammaln
=
GammaLn
(
upgrade_to_float
,
name
=
'gammaln'
)
gammaln
=
GammaLn
(
upgrade_to_float
,
name
=
'gammaln'
)
...
@@ -357,12 +345,6 @@ class Psi(UnaryScalarOp):
...
@@ -357,12 +345,6 @@ class Psi(UnaryScalarOp):
return
"""
%(z)
s =
return
"""
%(z)
s =
_psi(
%(x)
s);"""
%
locals
()
_psi(
%(x)
s);"""
%
locals
()
raise
NotImplementedError
(
'only floating point is implemented'
)
raise
NotImplementedError
(
'only floating point is implemented'
)
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
psi
=
Psi
(
upgrade_to_float
,
name
=
'psi'
)
psi
=
Psi
(
upgrade_to_float
,
name
=
'psi'
)
...
@@ -386,11 +368,62 @@ class Chi2SF(BinaryScalarOp):
...
@@ -386,11 +368,62 @@ class Chi2SF(BinaryScalarOp):
return
Chi2SF
.
st_impl
(
x
,
k
)
return
Chi2SF
.
st_impl
(
x
,
k
)
else
:
else
:
super
(
Chi2SF
,
self
)
.
impl
(
x
,
k
)
super
(
Chi2SF
,
self
)
.
impl
(
x
,
k
)
chi2sf
=
Chi2SF
(
upgrade_to_float
,
name
=
'chi2sf'
)
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
class
J1
(
UnaryScalarOp
):
return
hash
(
type
(
self
))
"""
Bessel function of the 1'th kind
"""
chi2sf
=
Chi2SF
(
upgrade_to_float
,
name
=
'chi2sf'
)
@staticmethod
def
st_impl
(
x
):
return
scipy
.
special
.
j1
(
x
)
def
impl
(
self
,
x
):
if
imported_scipy_special
:
return
self
.
st_impl
(
x
)
else
:
super
(
J1
,
self
)
.
impl
(
x
)
def
grad
(
self
,
inp
,
grads
):
raise
NotImplementedError
()
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
=
inp
z
,
=
out
if
node
.
inputs
[
0
]
.
type
in
float_types
:
return
"""
%(z)
s =
j1(
%(x)
s);"""
%
locals
()
raise
NotImplementedError
(
'only floating point is implemented'
)
j1
=
J1
(
upgrade_to_float
,
name
=
'j1'
)
class
J0
(
UnaryScalarOp
):
"""
Bessel function of the 0'th kind
"""
@staticmethod
def
st_impl
(
x
):
return
scipy
.
special
.
j0
(
x
)
def
impl
(
self
,
x
):
if
imported_scipy_special
:
return
self
.
st_impl
(
x
)
else
:
super
(
J0
,
self
)
.
impl
(
x
)
def
grad
(
self
,
inp
,
grads
):
x
,
=
inp
gz
,
=
grads
return
[
gz
*
-
1
*
j1
(
x
)]
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
=
inp
z
,
=
out
if
node
.
inputs
[
0
]
.
type
in
float_types
:
return
"""
%(z)
s =
j0(
%(x)
s);"""
%
locals
()
raise
NotImplementedError
(
'only floating point is implemented'
)
j0
=
J0
(
upgrade_to_float
,
name
=
'j0'
)
theano/tensor/basic.py
浏览文件 @
47278f72
...
@@ -2202,6 +2202,16 @@ def chi2sf(x, k):
...
@@ -2202,6 +2202,16 @@ def chi2sf(x, k):
"""chi squared survival function"""
"""chi squared survival function"""
@_scal_elemwise
def
j0
(
a
):
"""Bessel function of the 0'th kind"""
@_scal_elemwise
def
j1
(
a
):
"""Bessel function of the 1'th kind"""
@_scal_elemwise
@_scal_elemwise
def
real
(
z
):
def
real
(
z
):
"""Return real component of complex-valued tensor `z`"""
"""Return real component of complex-valued tensor `z`"""
...
...
theano/tensor/inplace.py
浏览文件 @
47278f72
...
@@ -284,6 +284,16 @@ def chi2sf_inplace(x, k):
...
@@ -284,6 +284,16 @@ def chi2sf_inplace(x, k):
"""chi squared survival function"""
"""chi squared survival function"""
@_scal_inplace
def
j0_inplace
(
a
):
"""Bessel function of the 0'th kind"""
@_scal_inplace
def
j1_inplace
(
a
):
"""Bessel function of the 0'th kind"""
@_scal_inplace
@_scal_inplace
def
second_inplace
(
a
):
def
second_inplace
(
a
):
"""Fill `a` with `b`"""
"""Fill `a` with `b`"""
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
47278f72
...
@@ -1683,6 +1683,8 @@ if imported_scipy_special:
...
@@ -1683,6 +1683,8 @@ if imported_scipy_special:
expected_gammaln
=
scipy
.
special
.
gammaln
expected_gammaln
=
scipy
.
special
.
gammaln
expected_psi
=
scipy
.
special
.
psi
expected_psi
=
scipy
.
special
.
psi
expected_chi2sf
=
lambda
x
,
df
:
scipy
.
stats
.
chi2
.
sf
(
x
,
df
)
.
astype
(
x
.
dtype
)
expected_chi2sf
=
lambda
x
,
df
:
scipy
.
stats
.
chi2
.
sf
(
x
,
df
)
.
astype
(
x
.
dtype
)
expected_j0
=
scipy
.
special
.
j0
expected_j1
=
scipy
.
special
.
j1
skip_scipy
=
False
skip_scipy
=
False
if
LooseVersion
(
scipy_version
)
>=
LooseVersion
(
"0.12.0"
):
if
LooseVersion
(
scipy_version
)
>=
LooseVersion
(
"0.12.0"
):
expected_erfcx
=
scipy
.
special
.
erfcx
expected_erfcx
=
scipy
.
special
.
erfcx
...
@@ -1700,6 +1702,8 @@ else:
...
@@ -1700,6 +1702,8 @@ else:
expected_gammaln
=
[]
expected_gammaln
=
[]
expected_psi
=
[]
expected_psi
=
[]
expected_chi2sf
=
[]
expected_chi2sf
=
[]
expected_j0
=
[]
expected_j1
=
[]
skip_scipy
=
"scipy is not present"
skip_scipy
=
"scipy is not present"
skip_scipy12
=
"scipy is not present"
skip_scipy12
=
"scipy is not present"
...
@@ -1867,6 +1871,43 @@ Chi2SFInplaceTester = makeBroadcastTester(
...
@@ -1867,6 +1871,43 @@ Chi2SFInplaceTester = makeBroadcastTester(
skip
=
skip_scipy
,
skip
=
skip_scipy
,
name
=
'Chi2SF'
)
name
=
'Chi2SF'
)
_good_broadcast_unary_j
=
dict
(
normal
=
(
rand_ranged
(
0.1
,
8
,
(
2
,
3
)),),)
J0Tester
=
makeBroadcastTester
(
op
=
tensor
.
j0
,
expected
=
expected_j0
,
good
=
_good_broadcast_unary_j
,
grad
=
_good_broadcast_unary_j
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
skip
=
skip_scipy
)
J0InplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
j0_inplace
,
expected
=
expected_j0
,
good
=
_good_broadcast_unary_j
,
grad
=
_good_broadcast_unary_j
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
inplace
=
True
,
skip
=
skip_scipy
)
J1Tester
=
makeBroadcastTester
(
op
=
tensor
.
j1
,
expected
=
expected_j1
,
good
=
_good_broadcast_unary_j
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
skip
=
skip_scipy
)
J1InplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
j1_inplace
,
expected
=
expected_j1
,
good
=
_good_broadcast_unary_j
,
eps
=
2e-10
,
mode
=
mode_no_scipy
,
inplace
=
True
,
skip
=
skip_scipy
)
ZerosLikeTester
=
makeBroadcastTester
(
ZerosLikeTester
=
makeBroadcastTester
(
op
=
tensor
.
zeros_like
,
op
=
tensor
.
zeros_like
,
expected
=
numpy
.
zeros_like
,
expected
=
numpy
.
zeros_like
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论