Core Data Types and Functions

This module provides basic linear algebra operations such as vector and matrix products as provided by the <Eigen/Core> include.

Core Data Types

ceygen.dtype.dtype

Cython fused type, a selection of C char, short, int, long, float and double (Python float).

ceygen.dtype.nonint_dtype

Cython fused type for methods that cannot work with integer types (such as inv()).

ceygen.dtype.vector(size, like)

Convenience function to create a new vector (cython.view.array) and return a memoryview of it. This function is declared with gil (it can be called without the GIL held, but acquires it during execution) and is rather expensive (as many Python calls are done).

Parameters:
  • size (int) – number of elements of the desired vector
  • like (dtype *) – dummy pointer to desired data type; value not used
Return type:

dtype[:]

ceygen.dtype.matrix(rows, col, like)

Convenience function to create a new matrix (cython.view.array) and return a memoryview of it. This function is declared with gil (it can be called without the GIL held, but acquires it during execution) and is rather expensive (as many Python calls are done).

Parameters:
  • rows (int) – number of rows of the desired matrix
  • cols (int) – number of columns of the desired matrix
  • like (dtype *) – dummy pointer to desired data type; value not used
Return type:

dtype[:, :]

Linear Algebra Functions

ceygen.core.dot_vv(x, y)

Vector-vector dot product, returns a scalar of appropriate type.

Parameters:
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.core.dot_mv(x, y[, out=None])

Matrix-(column) vector product, returns a vector of appropriate type.

Parameters:
  • x (dtype[:, :]) – first factor (matrix)
  • y (dtype[:]) – second factor (vector)
  • 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. Warning: don’t repeat x (or y) here, it would give incorrect result without any error. Perhaps there’s an in-place variant instead?
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.core.dot_vm(x, y[, out=None])

(Row) vector-matrix product, returns a vector of appropriate type. This is equivalent to dotvm(y.T, x) because there’s no distinction between row and column vectors in Cython memoryviews, but calling this function directly may incur slightly less overhead.

Parameters:
  • x (dtype[:]) – first factor (vector)
  • y (dtype[:, :]) – second factor (matrix)
  • 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. Warning: don’t repeat x (or y) here, it would give incorrect result without any error. Perhaps there’s an in-place variant instead?
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.core.dot_mm(x, y[, out=None])

Matrix-matrix product, returns a matrix of appropriate type and dimensions. You may of course use this function to multiply matrices that are in fact vectors, you just need to pay attention to column-vector vs. row-vector distinction this time.

If both x and y are contiguous in some way (either C or Fortran, independently), this function takes optimized code path that doesn’t involve memory allocation in Eigen; speed gains are around 40% for matrices around 2*2 – 24*24 size. No special markup is needed to trigger this. See also set_is_malloc_allowed().

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. Warning: don’t repeat x (or y) here, it would give incorrect result without any error. Perhaps there’s an in-place variant instead?
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[:, :]

Miscellaneous Functions

ceygen.core.set_is_malloc_allowed(allowed)

Set the internal Eigen flag whether it is allowed to allocate memory on heap.

If this flag is False and Eigen will try to allocate memory on heap, it will assert which causes ValueError to be raised by Ceygen. This is useful to ensure you use the most optimized code path. Defaults to True. Note: for this to work, Ceygen defines EIGEN_RUNTIME_NO_MALLOC preprocessor directive before including Eigen.

See http://eigen.tuxfamily.org/dox/TopicPreprocessorDirectives.html

ceygen.core.eigen_version()

Return version of Eigen which Ceygen was compiled against as a tuple of three integers, for example (3, 1, 2).

Return type:tuple of 3 ints

Table Of Contents

Previous topic

Ceygen Change Log

Next topic

Element-wise Operations

This Page