Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e8ecd0fc
提交
e8ecd0fc
authored
8月 19, 2015
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3296 from harlouci/numpydoc_typedList_scalar
Numpydoc typed list scalar
上级
d39e2e0e
1023b228
全部展开
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
127 行增加
和
56 行删除
+127
-56
basic.py
theano/scalar/basic.py
+0
-0
basic_scipy.py
theano/scalar/basic_scipy.py
+17
-9
basic_sympy.py
theano/scalar/basic_sympy.py
+5
-1
sharedvar.py
theano/scalar/sharedvar.py
+7
-3
basic.py
theano/typed_list/basic.py
+72
-27
type.py
theano/typed_list/type.py
+26
-16
没有找到文件。
theano/scalar/basic.py
浏览文件 @
e8ecd0fc
差异被折叠。
点击展开。
theano/scalar/basic_scipy.py
浏览文件 @
e8ecd0fc
...
...
@@ -87,14 +87,18 @@ erfc = Erfc(upgrade_to_float_no_complex, name='erfc')
class
Erfcx
(
UnaryScalarOp
):
"""
Implements the scaled complementary error function exp(x**2)*erfc(x) in a numerically stable way for large x. This
is useful for calculating things like log(erfc(x)) = log(erfcx(x)) - x ** 2 without causing underflow. Should only
be used if x is known to be large and positive, as using erfcx(x) for large negative x may instead introduce
overflow problems.
Note: This op can still be executed on GPU, despite not having c_code. When
Implements the scaled complementary error function exp(x**2)*erfc(x) in a
numerically stable way for large x. This is useful for calculating things
like log(erfc(x)) = log(erfcx(x)) - x ** 2 without causing underflow.
Should only be used if x is known to be large and positive, as using
erfcx(x) for large negative x may instead introduce overflow problems.
Notes
-----
This op can still be executed on GPU, despite not having c_code. When
running on GPU, sandbox.cuda.opt.local_gpu_elemwise_[0,1] replaces this op
with sandbox.cuda.elemwise.ErfcxGPU.
"""
def
impl
(
self
,
x
):
if
imported_scipy_special
:
...
...
@@ -124,7 +128,9 @@ class Erfinv(UnaryScalarOp):
"""
Implements the inverse error function.
Note: This op can still be executed on GPU, despite not having c_code. When
Notes
-----
This op can still be executed on GPU, despite not having c_code. When
running on GPU, sandbox.cuda.opt.local_gpu_elemwise_[0,1] replaces this op
with sandbox.cuda.elemwise.ErfinvGPU.
...
...
@@ -237,6 +243,7 @@ gamma = Gamma(upgrade_to_float, name='gamma')
class
GammaLn
(
UnaryScalarOp
):
"""
Log gamma function.
"""
@staticmethod
def
st_impl
(
x
):
...
...
@@ -280,6 +287,7 @@ gammaln = GammaLn(upgrade_to_float, name='gammaln')
class
Psi
(
UnaryScalarOp
):
"""
Derivative of log gamma function.
"""
@staticmethod
def
st_impl
(
x
):
...
...
@@ -360,13 +368,13 @@ psi = Psi(upgrade_to_float, name='psi')
class
Chi2SF
(
BinaryScalarOp
):
"""
Compute (1 - chi2_cdf(x))
ie. chi2 pvalue (chi2 'survival function')
Compute (1 - chi2_cdf(x)) ie. chi2 pvalue (chi2 'survival function').
C code is provided in the Theano_lgpl repository.
This make it faster.
https://github.com/Theano/Theano_lgpl.git
"""
@staticmethod
...
...
theano/scalar/basic_sympy.py
浏览文件 @
e8ecd0fc
...
...
@@ -28,8 +28,11 @@ def theano_dtype(expr):
class
SymPyCCode
(
ScalarOp
):
""" An Operator that wraps SymPy's C code generation
"""
An Operator that wraps SymPy's C code generation.
Examples
--------
>>> from sympy.abc import x, y # SymPy Variables
>>> from theano.scalar.basic_sympy import SymPyCCode
>>> op = SymPyCCode([x, y], x + y)
...
...
@@ -42,6 +45,7 @@ class SymPyCCode(ScalarOp):
>>> f = theano.function([xt, yt], zt)
>>> f(1.0, 2.0)
3.0
"""
def
__init__
(
self
,
inputs
,
expr
,
name
=
None
):
...
...
theano/scalar/sharedvar.py
浏览文件 @
e8ecd0fc
"""A shared variable container for true scalars - for internal use.
"""
A shared variable container for true scalars - for internal use.
Why does this file exist?
-------------------------
...
...
@@ -37,9 +38,12 @@ class ScalarSharedVariable(_scalar_py_operators, SharedVariable):
def
shared
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
):
"""SharedVariable constructor for scalar values. Default: int64 or float64.
"""
SharedVariable constructor for scalar values. Default: int64 or float64.
:note: We implement this using 0-d tensors for now.
Notes
-----
We implement this using 0-d tensors for now.
"""
if
not
isinstance
(
value
,
(
numpy
.
number
,
float
,
int
,
complex
)):
...
...
theano/typed_list/basic.py
浏览文件 @
e8ecd0fc
...
...
@@ -48,6 +48,7 @@ class _typed_list_py_operators:
class
TypedListVariable
(
_typed_list_py_operators
,
Variable
):
"""
Subclass to add the typed list operators to the basic `Variable` class.
"""
TypedListType
.
Variable
=
TypedListVariable
...
...
@@ -104,8 +105,13 @@ getitem = GetItem()
"""
Get specified slice of a typed list.
:param x: typed list.
:param index: the index of the value to return from `x`.
Parameters
----------
x
Typed list.
index
The index of the value to return from `x`.
"""
...
...
@@ -174,8 +180,13 @@ append = Append()
"""
Append an element at the end of another list.
:param x: the base typed list.
:param y: the element to append to `x`.
Parameters
----------
x
The base typed list.
y
The element to append to `x`.
"""
...
...
@@ -250,8 +261,13 @@ extend = Extend()
"""
Append all elements of a list at the end of another list.
:param x: The typed list to extend.
:param toAppend: The typed list that will be added at the end of `x`.
Parameters
----------
x
The typed list to extend.
toAppend
The typed list that will be added at the end of `x`.
"""
...
...
@@ -325,9 +341,15 @@ insert = Insert()
"""
Insert an element at an index in a typed list.
:param x: the typed list to modify.
:param index: the index where to put the new element in `x`.
:param toInsert: The new element to insert.
Parameters
----------
x
The typed list to modify.
index
The index where to put the new element in `x`.
toInsert
The new element to insert.
"""
...
...
@@ -356,9 +378,9 @@ class Remove(Op):
out
[
0
]
=
x
"""
i
nelegant workaround for ValueError: The truth value of an
I
nelegant workaround for ValueError: The truth value of an
array with more than one element is ambiguous. Use a.any() or a.all()
being thrown when trying to remove a matrix from a matrices list
being thrown when trying to remove a matrix from a matrices list
.
"""
for
y
in
range
(
out
[
0
]
.
__len__
()):
if
node
.
inputs
[
0
]
.
ttype
.
values_eq
(
out
[
0
][
y
],
toRemove
):
...
...
@@ -371,13 +393,18 @@ class Remove(Op):
remove
=
Remove
()
"""Remove an element from a typed list.
:param x: the typed list to be changed.
:param toRemove: an element to be removed from the typed list.
Parameters
----------
x
The typed list to be changed.
toRemove
An element to be removed from the typed list.
We only remove the first instance.
:note: Python implementation of remove doesn't work when we want to
remove an ndarray from a list. This implementation works in that
case.
Notes
-----
Python implementation of remove doesn't work when we want to remove an ndarray
from a list. This implementation works in that case.
"""
...
...
@@ -437,7 +464,11 @@ reverse = Reverse()
"""
Reverse the order of a typed list.
:param x: the typed list to be reversed.
Parameters
----------
x
The typed list to be reversed.
"""
...
...
@@ -452,7 +483,7 @@ class Index(Op):
def
perform
(
self
,
node
,
inputs
,
outputs
):
"""
i
nelegant workaround for ValueError: The truth value of an
I
nelegant workaround for ValueError: The truth value of an
array with more than one element is ambiguous. Use a.any() or a.all()
being thrown when trying to remove a matrix from a matrices list
"""
...
...
@@ -480,7 +511,7 @@ class Count(Op):
def
perform
(
self
,
node
,
inputs
,
outputs
):
"""
i
nelegant workaround for ValueError: The truth value of an
I
nelegant workaround for ValueError: The truth value of an
array with more than one element is ambiguous. Use a.any() or a.all()
being thrown when trying to remove a matrix from a matrices list
"""
...
...
@@ -499,13 +530,18 @@ count = Count()
"""
Count the number of times an element is in the typed list.
:param x: The typed list to look into.
:param elem: The element we want to count in list.
Parameters
----------
x
The typed list to look into.
elem
The element we want to count in list.
The elements are compared with equals.
:note: Python implementation of count doesn't work when we want to
count an ndarray from a list. This implementation works in that
case.
Notes
-----
Python implementation of count doesn't work when we want to count an ndarray
from a list. This implementation works in that case.
"""
...
...
@@ -543,7 +579,11 @@ length = Length()
"""
Returns the size of a list.
:param x: typed list.
Parameters
----------
x
Typed list.
"""
...
...
@@ -573,7 +613,12 @@ make_list = MakeList()
"""
Build a Python list from those Theano variable.
:param a: tuple/list of Theano variable
Parameters
----------
a : tuple/list of Theano variable
Notes
-----
All Theano variables must have the same type.
:note: All Theano variable must have the same type.
"""
theano/typed_list/type.py
浏览文件 @
e8ecd0fc
...
...
@@ -2,16 +2,20 @@ from theano import gof
class
TypedListType
(
gof
.
Type
):
def
__init__
(
self
,
ttype
,
depth
=
0
):
"""
:Parameters:
-'ttype' : Type of theano variable this list
will contains, can be another list.
-'depth' : Optionnal parameters, any value
above 0 will create a nested list of this
depth. (0-based)
Parameters
----------
ttype
Type of theano variable this list will contains, can be another list.
depth
Optionnal parameters, any value above 0 will create a nested list of
this depth. (0-based)
"""
def
__init__
(
self
,
ttype
,
depth
=
0
):
if
depth
<
0
:
raise
ValueError
(
'Please specify a depth superior or'
'equal to 0'
)
...
...
@@ -25,10 +29,16 @@ class TypedListType(gof.Type):
def
filter
(
self
,
x
,
strict
=
False
,
allow_downcast
=
None
):
"""
:Parameters:
-'x' : value to filter
-'strict' : if true, only native python list will be accepted
-'allow_downcast' : does not have any utility at the moment
Parameters
----------
x
Value to filter.
strict
If true, only native python list will be accepted.
allow_downcast
Does not have any utility at the moment.
"""
if
strict
:
if
not
isinstance
(
x
,
list
):
...
...
@@ -45,9 +55,9 @@ class TypedListType(gof.Type):
def
__eq__
(
self
,
other
):
"""
two list are equals if they contains the same type.
"""
Two lists are equal if they contain the same type.
"""
return
type
(
self
)
==
type
(
other
)
and
self
.
ttype
==
other
.
ttype
def
__hash__
(
self
):
...
...
@@ -58,8 +68,8 @@ class TypedListType(gof.Type):
def
get_depth
(
self
):
"""
utilitary function to get the 0 based
level of the list
Utilitary function to get the 0 based level of the list.
"""
if
isinstance
(
self
.
ttype
,
TypedListType
):
return
self
.
ttype
.
get_depth
()
+
1
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论