提交 18895b09 authored 作者: Frederic's avatar Frederic

Better doc of extra_ops.

上级 18128f23
...@@ -8,20 +8,7 @@ from theano.sandbox.linalg.ops import diag ...@@ -8,20 +8,7 @@ from theano.sandbox.linalg.ops import diag
class DiffOp(theano.Op): class DiffOp(theano.Op):
"""Calculate the n-th order discrete difference along given axis. # See function diff for docstring
The first order difference is given by out[n] = a[n+1] - a[n]
along the given axis, higher order differences are calculated by
using diff recursively. Wraping of numpy.diff.
Parameter:
x -- Input vector.
Keywords arguments:
n -- The number of times values are differenced, default is 1.
"""
def __init__(self, n=1, axis=-1): def __init__(self, n=1, axis=-1):
self.n = n self.n = n
self.axis = axis self.axis = axis
...@@ -82,36 +69,20 @@ def diff(x, n=1, axis=-1): ...@@ -82,36 +69,20 @@ def diff(x, n=1, axis=-1):
along the given axis, higher order differences are calculated by along the given axis, higher order differences are calculated by
using diff recursively. Wraping of numpy.diff. using diff recursively. Wraping of numpy.diff.
Parameter: :param x: Input tensor variable.
x -- Input vector.
:param n: The number of times values are differenced, default is 1.
Keywords arguments: :param axis: The axis along which the difference is taken,
n -- The number of times values are differenced, default is 1. default is the last axis.
.. versionadded:: 0.6
""" """
return DiffOp(n=n, axis=axis)(x) return DiffOp(n=n, axis=axis)(x)
class BinCountOp(theano.Op): class BinCountOp(theano.Op):
"""Count number of occurrences of each value in array of non-negative ints. # See function bincount for docstring
The number of bins (of size 1) is one larger than the largest
value in x. If minlength is specified, there will be at least
this number of bins in the output array (though it will be longer
if necessary, depending on the contents of x). Each bin gives the
number of occurrences of its index value in x. If weights is
specified the input array is weighted by it, i.e. if a value n
is found at position i, out[n] += weight[i] instead of out[n] += 1.
Wraping of numpy.bincount
Parameter:
x -- 1 dimension, nonnegative ints
Keywords arguments:
weights -- Weights, array of the same shape as x.
minlength -- A minimum number of bins for the output array.
"""
compatible_type = ('int8', 'int16', 'int32', 'int64', compatible_type = ('int8', 'int16', 'int32', 'int64',
'uint8', 'uint16', 'uint32', 'uint64') 'uint8', 'uint16', 'uint32', 'uint64')
...@@ -202,13 +173,14 @@ def bincount(x, weights=None, minlength=None): ...@@ -202,13 +173,14 @@ def bincount(x, weights=None, minlength=None):
is found at position i, out[n] += weight[i] instead of out[n] += 1. is found at position i, out[n] += weight[i] instead of out[n] += 1.
Wraping of numpy.bincount Wraping of numpy.bincount
Parameter: :param x: 1 dimension, nonnegative ints
x -- 1 dimension, nonnegative ints
Keywords arguments: :param weights: array of the same shape as x with corresponding weights.
weights -- Weights, array of the same shape as x. Optional.
minlength -- A minimum number of bins for the output array. :param minlength: A minimum number of bins for the output array.
Optional.
.. versionadded:: 0.6
""" """
return BinCountOp(minlength=minlength)(x, weights) return BinCountOp(minlength=minlength)(x, weights)
...@@ -231,21 +203,7 @@ def squeeze(x): ...@@ -231,21 +203,7 @@ def squeeze(x):
class RepeatOp(theano.Op): class RepeatOp(theano.Op):
"""Repeat elements of an array. # See the repeat function for docstring
It returns an array which has the same shape as `x`, except
along the given axis. The axis is used to speficy along which
axis to repeat values. By default, use the flattened input
array, and return a flat output array.
The number of repetitions for each element is `repeat`.
`repeats` is broadcasted to fit the length of the given `axis`.
:param x: Input data, tensor variable.
:param repeats: int, scalar or tensor variable.
:param axis: int, optional.
"""
def __init__(self, axis=None): def __init__(self, axis=None):
self.axis = axis self.axis = axis
...@@ -365,21 +323,7 @@ def repeat(x, repeats, axis=None): ...@@ -365,21 +323,7 @@ def repeat(x, repeats, axis=None):
class Bartlett(gof.Op): class Bartlett(gof.Op):
""" # See function bartlett for docstring
An instance of this class returns the Bartlett spectral window in the
time-domain. The Bartlett window is very similar to a triangular window,
except that the end points are at zero. It is often used in signal
processing for tapering a signal, without generating too much ripple in
the frequency domain.
input : (integer scalar) Number of points in the output window. If zero or
less, an empty vector is returned.
output : (vector of doubles) The triangular window, with the maximum value
normalized to one (the value one appears only if the number of samples is
odd), with the first and last samples equal to zero.
"""
def __eq__(self, other): def __eq__(self, other):
return type(self) == type(other) return type(self) == type(other)
...@@ -414,33 +358,34 @@ class Bartlett(gof.Op): ...@@ -414,33 +358,34 @@ class Bartlett(gof.Op):
def grad(self, inputs, output_grads): def grad(self, inputs, output_grads):
return [None for i in inputs] return [None for i in inputs]
bartlett_ = Bartlett()
bartlett = Bartlett() #I create a function only to have the doc show well.
def bartlett(M):
"""An instance of this class returns the Bartlett spectral window in the
class FillDiagonal(gof.Op): time-domain. The Bartlett window is very similar to a triangular window,
""" except that the end points are at zero. It is often used in signal
An instance of this class returns a copy of an array with all elements of processing for tapering a signal, without generating too much ripple in
the main diagonal set to a specified scalar value. the frequency domain.
inputs: :param M: (integer scalar) Number of points in the output
window. If zero or less, an empty vector is returned.
a : Rectangular array of at least two dimensions. :return: (vector of doubles) The triangular window, with the
val : Scalar value to fill the diagonal whose type must be compatible with maximum value normalized to one (the value one appears only if
that of array 'a' (i.e. 'val' cannot be viewed as an upcast of 'a'). the number of samples is odd), with the first and last samples
equal to zero.
output: .. versionadded:: 0.6
An array identical to 'a' except that its main diagonal is filled with """
scalar 'val'. (For an array 'a' with a.ndim >= 2, the main diagonal is the return bartlett_(M)
list of locations a[i, i, ..., i] (i.e. with indices all identical).)
Support rectangular matrix and tensor with more then 2 dimensions
if the later have all dimensions are equals.
"""
class FillDiagonal(gof.Op):
# See function fill_diagonal for docstring
def __eq__(self, other): def __eq__(self, other):
return type(self) == type(other) return type(self) == type(other)
...@@ -499,6 +444,27 @@ class FillDiagonal(gof.Op): ...@@ -499,6 +444,27 @@ class FillDiagonal(gof.Op):
wr_a = fill_diagonal(grad, 0) # valid for any number of dimensions wr_a = fill_diagonal(grad, 0) # valid for any number of dimensions
wr_val = diag(grad).sum() # diag is only valid for matrices wr_val = diag(grad).sum() # diag is only valid for matrices
return [wr_a, wr_val] return [wr_a, wr_val]
fill_diagonal_ = FillDiagonal()
#I create a function only to have the doc show well.
def fill_diagonal(a, val):
""" Returns a copy of an array with all
elements of the main diagonal set to a specified scalar value.
:param a: Rectangular array of at least two dimensions.
:param val: Scalar value to fill the diagonal whose type must be
compatible with that of array 'a' (i.e. 'val' cannot be viewed
as an upcast of 'a').
:return: An array identical to 'a' except that its main diagonal
is filled with scalar 'val'. (For an array 'a' with a.ndim >=
2, the main diagonal is the list of locations a[i, i, ..., i]
(i.e. with indices all identical).)
fill_diagonal = FillDiagonal() Support rectangular matrix and tensor with more then 2 dimensions
if the later have all dimensions are equals.
.. versionadded:: 0.6
"""
return fill_diagonal_(a, val)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论