TiledArray has a set of functions that allows you to convert Array object to and from Eigen matrix objects. The purpose of these functions is to allow users to quickly prototype TiledArray algorithms with inputs from or outputs to Eigen matrices.
Because Eigen is a non-distributed library, these functions are not appropriate for production code in distributed computing environments. Therefore, these functions will throw an exception if the number of MPI processes is greater than one. If you require conversion of Eigen matrices in distributed computing environments, you need to write your own algorithm to collect or distribute matrix data. See the Submatrix Copy section for more information.
Conversion Functions
eigen_to_array()
Convert an Eigen matrix into a DistArray object.
Signature
Description
This function will copy the content of matrix into a DistArray object that is tiled according to the trange object. The copy operation is done in parallel, and this function will block until all elements of matrix have been copied into the result array tiles.
Template Parameters
AA DistArray typeDerivedThe Eigen matrix derived type
Parameters
worldThe world where the array will livetrangeThe tiled range of the new arraymatrixThe Eigen matrix to be copied
Returns
A DistArray object (of type A) that contains a copy of matrix
Exceptions
TiledArray::Exception When world size is greater than 1
Usage
Notes
This function will only work in non-distributed environments. If you need to convert an Eigen matrix to a DistArray object, you must implement it yourself. However, you may use eigen_submatrix_to_tensor to make writing such an algorithm easier.
array_to_eigen()
Convert a DistArray object into an Eigen matrix object.
Signature
Description
This function will block until all tiles of array have been set and copied into the new Eigen matrix. Usage:
Template Parameters
TileThe tile type of the arrayPolicyThe policy type of the array
Parameters
arrayThe array to be converted
Exceptions
TiledArray::Exception When world size is greater than 1
Usage
Note
This function will only work in non-distributed environments. If you need to convert an Array object to an Eigen matrix, you must implement it yourself. However, you may use eigen_submatrix_to_tensor to make writing such an algorithm easier.
Eigen Interface
Eigen includes a map class which allows external libraries to work with Eigen. TiledArray provides a set of functions for wrapping Tensor object with Eigen::Map. These map objects may be used as normal Eigen matrices or vectors.
eigen_map()
Construct an m x n Eigen::Map object for a given Tensor object.
Signature
Description
This function will wrap a tensor in an Eigen map object. This object may be used in expressions with other Eigen objects. See Eigen documentation for more details on Map objects.
Template Parameters
TThe tensor element typeAThe tensor allocator type
Parameters
tensorThe tensor objectmThe number of rows in the result matrixnThe number of columns in the result matrix
Returns
An m x n Eigen matrix map for tensor
Exceptions
TiledArray::Exception When m * n is not equal to tensor size.
Usage
Note
The dimensions m and n do not have to match the dimensions of the tensor object, but they size of the tensor must be equal to the size of the resulting Eigen map object.
eigen_map()
Construct a Eigen::Map object for a given Tensor object.
Signature
Description
This function will wrap a tensor in an Eigen map object. This object may be used in expressions with other Eigen objects. See [http://eigen.tuxfamily.org/dox/TutorialMapClass.html Eigen documentation] for more details on Map objects.
Template Parameters
TThe tensor element typeAThe tensor allocator type
Parameters
tensorThe tensor object
Returns
An Eigen matrix map for tensor where the number of rows and columns of the matrix match the dimension sizes of the tensor object.
Exceptions
TiledArray::Exception When tensor dimensions are not equal to 2 or 1.
1.8.20