Skip to content

Finalize experimental types

Ashar edited this page Aug 25, 2020 · 1 revision

Future Work

Add a new experimental subdirectory inside tensor, which provides matrix and vector types that are type aliases for existing tensor types. Add type traits for the experimental types such as is_matrix, add all functions that existed in ublas::matrix to new types as free functions. Add examples demonstrating the usage of new experimental types. We can put them in examples/tensor/experimental. Also, add unit tests so code coverage doesn't degrade.

Awaiting on Discussion

Should we allow the matrix types and vector types to be creatable from implied or explicit tensor extents.

Case 1: (Implied) A tensor of extents {1,2,3,1} is convertible into a matrix type if we squeeze the extents (Squeezing means removing extents with value 1). This yields a matrix of extents {2,3}.

Example:

ublas::experimental::dynamic_matrix a<int> = dynamic_tensor<int>({1,2,3,1}); // a's extent is {2,3}
ublas::experimental::static_matrix b<int> = static_tensor<int, 2,3,1,1>{} // b's extent is <2,3>
ublas::experimental::dynamic_matrix c<int> = dynamic_tensor<int>({4,3}); // c's extent is {4,3}
ublas::experimental::static_matrix d<int> = static_tensor<int, 2,3>{} // b's extent is <2,3>

Benefits:

  • Tensor contractions results can be directly assigned to matrices and vectors.
  • More flexible and limited restriction on matrix types

Case 2: (Explicit) Matrix constructor restricts the tensor to be rank 2. If the above extent tensor is to be assigned to a matrix type, the extents must be squeezed by the user.

Example:

ublas::experimental::dynamic_matrix a<int> = squeeze(dynamic_tensor<int>({1,2,3,1})); // a's extent is {2,3}
ublas::experimental::static_matrix b<int> = squeeze(static_tensor<int, 2,3,1,1>{}) // b's extent is <2,3>
ublas::experimental::dynamic_matrix c<int> = dynamic_tensor<int>({4,3}); // c's extent is {4,3}
ublas::experimental::static_matrix d<int> = static_tensor<int, 2,3>{} // b's extent is <2,3>