Element-wise Operations
This module implements some basic element-wise operations such as addition or division.
Because aliasing is not a problem for element-wise operations, you can make the operations
in-place simply by repeating x or y in out. Following examples are therefore valid
and produce expected results:
ceygen.elemwise.add_mm(x, y, x)
ceygen.elemwise.multiply_vv(a, b, b)
Note
This module exists only as a stop-gap until support for
element-wise operations with memoryviews are implemented in Cython. It will be phased
out once Cython with Mark Florisson’s array expressions pull request merged is
released.
Vector-scalar Operations
-
ceygen.elemwise.add_vs(x, y[, out=None])
Add scalar y to each coefficient of vector x and return the resulting vector.
Note: there’s no subtract_vs, just add opposite number.
Parameters: |
- x (dtype[:]) – first addend (vector)
- y (dtype) – second addend (scalar)
- out (dtype[:]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:]
|
-
ceygen.elemwise.multiply_vs(x, y[, out=None])
Multiply each coefficient of vector x by scalar y and return the resulting vector.
Note: there’s no divide_vs, just multiply by inverse number.
Parameters: |
- x (dtype[:]) – first factor (vector)
- y (dtype) – second factor (scalar)
- out (dtype[:]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:]
|
-
ceygen.elemwise.power_vs(x, y[, out=None])
Compute y-th power of each coefficient of vector x.
Parameters: |
- x (dtype[:]) – base (vector)
- y (dtype) – exponent (scalar)
- out (dtype[:]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:]
|
Vector-vector Operations
-
ceygen.elemwise.add_vv(x, y[, out=None])
Vector-vector addition: x + y
Parameters: |
- x (dtype[:]) – first addend
- y (dtype[:]) – second addend
- out (dtype[:]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:]
|
-
ceygen.elemwise.subtract_vv(x, y[, out=None])
Vector-vector subtraction: x - y
Parameters: |
- x (dtype[:]) – minuend
- y (dtype[:]) – subtrahend
- out (dtype[:]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:]
|
-
ceygen.elemwise.multiply_vv(x, y[, out=None])
Vector-vector element-wise multiplication: x * y
Parameters: |
- x (dtype[:]) – first factor
- y (dtype[:]) – second factor
- out (dtype[:]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:]
|
-
ceygen.elemwise.divide_vv(x, y[, out=None])
Vector-vector element-wise division: x / y
Parameters: |
- x (dtype[:]) – numerator
- y (dtype[:]) – denominator
- out (dtype[:]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:]
|
Matrix-scalar Operations
-
ceygen.elemwise.add_ms(x, y[, out=None])
Add scalar y to each coefficient of matrix x and return the resulting matrix.
Note: there’s no subtract_ms, just add opposite number.
Parameters: |
- x (dtype[:, :]) – first addend (matrix)
- y (dtype) – second addend (scalar)
- out (dtype[:, :]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:, :]
|
-
ceygen.elemwise.multiply_ms(x, y[, out=None])
Multiply each coefficient of matrix x by scalar y and return the resulting matrix.
Note: there’s no divide_ms, just multiply by inverse number.
Parameters: |
- x (dtype[:, :]) – first factor (vector)
- y (dtype) – second factor (scalar)
- out (dtype[:, :]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:, :]
|
-
ceygen.elemwise.power_ms(x, y[, out=None])
Compute y-th power of each coefficient of matrix x.
Parameters: |
- x (dtype[:, :]) – base (matrix)
- y (dtype) – exponent (scalar)
- out (dtype[:, :]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:, :]
|
Matrix-matrix Operations
-
ceygen.elemwise.add_mm(x, y[, out=None])
Matrix-matrix addition: x + y
Parameters: |
- x (dtype[:, :]) – first addend
- y (dtype[:, :]) – second addend
- out (dtype[:, :]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:, :]
|
-
ceygen.elemwise.subtract_mm(x, y[, out=None])
Matrix-matrix subtraction: x - y
Parameters: |
- x (dtype[:, :]) – minuend
- y (dtype[:, :]) – subtrahend
- out (dtype[:, :]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:, :]
|
-
ceygen.elemwise.multiply_mm(x, y[, out=None])
Matrix-matrix element-wise multiplication: x * y
Parameters: |
- x (dtype[:, :]) – first factor
- y (dtype[:, :]) – second factor
- out (dtype[:, :]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:, :]
|
-
ceygen.elemwise.divide_mm(x, y[, out=None])
Matrix-matrix element-wise division: x / y
Parameters: |
- x (dtype[:, :]) – numerator
- y (dtype[:, :]) – denominator
- out (dtype[:, :]) – memory view to write the result to. Specifying this optional
argument means that Ceygen doesn’t have to allocate memory for the result (allocating
memory involves acquiring the GIL and calling many expensive Python functions). Once
specified, it must must have correct dimensions to store the result of this operation
(otherwise you get ValueError); the same out instance will be also
returned. As an exception from the general rule, you may repeat x (or y) here
for this element-wise operation.
|
Raises : | ValueError if argument dimensions aren’t
appropriate for this operation or if arguments are otherwise invalid.
|
Raises : | TypeError if you pass an argument that doesn’t
support buffer interface (e.g. a plain list). Use preferrably a Cython memoryview
and resort to Python array, Cython array or a
NumPy array.
|
Return type: | dtype[:, :]
|