Skip to content

vectorize(tsrex, n, append=False) ΒΆ

'Vectorize' a tensor expression by extending its dimensionality by one. Each slice along the vectorization dimension of a factorization model represents an independent realization of the original tensor expression. A typical use case is multi-replica optimization.

The dimensionality of each leaf (tensor) node of the expression will be increments using the following rule:

  • If the tensor has a random initializer, then its shape is simply extended, i.e. shape_vectorized = (*shape_vectorized, n).
  • If the tensor has a concrete initializer, then a broadcasting dimension will be appended to the initializer, i.e. initializer_vectorized = initializer_vectorized[..., None].

Parameters:

Name Type Description Default
n int > 0

Size of the vectorization dimension.

required
append bool

If True, the vectorizing index is set to the last index of every leaf. If False, the vectorizing index is set to the first index of every leaf.

False

Returns !!! tsrex A vectorized tensor expression.

Source code in funfact/vectorization.py
def vectorize(tsrex, n, append: bool = False):
    ''''Vectorize' a tensor expression by extending its dimensionality by one.
    Each slice along the vectorization dimension of a factorization model
    represents an independent realization of the original tensor expression.
    A typical use case is multi-replica optimization.

    The dimensionality of each leaf (tensor) node of the expression will be
    increments using the following rule:

    - If the tensor has a random initializer, then its shape is simply
    extended, i.e. `shape_vectorized = (*shape_vectorized, n)`.
    - If the tensor has a concrete initializer, then a broadcasting dimension
    will be appended to the initializer, i.e.
    `initializer_vectorized = initializer_vectorized[..., None]`.

    Args:
        n (int > 0):
            Size of the vectorization dimension.
        append (bool):
            If True, the vectorizing index is set to the last index of every
            leaf. If False, the vectorizing index is set to the first index
            of every leaf.

    Returns
        TsrEx:
            A vectorized tensor expression.
    '''
    return tsrex | IndexnessAnalyzer() \
                 | TypeDeducer() \
                 | Vectorizer(n, index().root, append)
Back to top