提交 e8ecd0fc authored 作者: abergeron's avatar abergeron

Merge pull request #3296 from harlouci/numpydoc_typedList_scalar

Numpydoc typed list scalar
差异被折叠。
......@@ -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
......
......@@ -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):
......
"""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)):
......
......@@ -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
"""
inelegant workaround for ValueError: The truth value of an
Inelegant 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):
"""
inelegant workaround for ValueError: The truth value of an
Inelegant 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):
"""
inelegant workaround for ValueError: The truth value of an
Inelegant 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.
"""
......@@ -2,16 +2,20 @@ from theano import gof
class TypedListType(gof.Type):
"""
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):
"""
: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)
"""
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论