Skip to content

linalg

matmul(x1, x2)

Computes the matrix product.

Returns a LazyTensor if either x1 or x2 is a LazyTensor. Otherwise, computes the result eagerly.

Source code in src/finch/interface/eager.py
431
432
433
434
435
436
437
438
439
440
441
def matmul(x1, x2, /):
    """
    Computes the matrix product.

    Returns a LazyTensor if either x1 or x2 is a LazyTensor.
    Otherwise, computes the result eagerly.
    """
    if isinstance(x1, lazy.LazyTensor) or isinstance(x2, lazy.LazyTensor):
        return lazy.matmul(x1, x2)
    c = lazy.matmul(x1, x2)
    return compute(c)

matrix_power(x, n)

Computes the power of a matrix.

Source code in src/finch/interface/eager.py
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
def matrix_power(x, n, /):
    """
    Computes the power of a matrix.
    """
    if isinstance(x, lazy.LazyTensor) and not (isinstance(n, int) and n < 0):
        return lazy.matrix_power(x, n)
    if isinstance(n, int) and n < 0:
        return matrix_power(inv(x), -n)
    try:
        return lazy.asarray(
            to_numpy(scipy_sparse_linalg.matrix_power(to_scipy(lazy.asarray(x)), n))
        )
    except NotImplementedError:
        pass
    return compute(lazy.matrix_power(x, n))

matrix_transpose(x)

Computes the transpose of a matrix or stack of matrices.

Source code in src/finch/interface/eager.py
444
445
446
447
448
449
450
def matrix_transpose(x, /):
    """
    Computes the transpose of a matrix or stack of matrices.
    """
    if isinstance(x, lazy.LazyTensor):
        return lazy.matrix_transpose(x)
    return compute(lazy.matrix_transpose(x))

tensordot(x1, x2, /, *, axes=2)

Computes the tensordot operation.

Returns a LazyTensor if either x1 or x2 is a LazyTensor. Otherwise, computes the result eagerly.

Source code in src/finch/interface/eager.py
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
def tensordot(x1, x2, /, *, axes: int | tuple[Sequence[int], Sequence[int]] = 2):
    """
    Computes the tensordot operation.

    Returns a LazyTensor if either x1 or x2 is a LazyTensor.
    Otherwise, computes the result eagerly.
    """
    if isinstance(x1, lazy.LazyTensor) or isinstance(x2, lazy.LazyTensor):
        return lazy.tensordot(x1, x2, axes=axes)
    return compute(lazy.tensordot(x1, x2, axes=axes))

vecdot(x1, x2, /, *, axis=-1)

Computes the (vector) dot product of two arrays.

Parameters

x1: array The first input tensor. x2: array The second input tensor. axis: int, optional The axis along which to compute the dot product. Default is -1 (last axis).

Returns

out: array A tensor containing the dot product of x1 and x2 along the specified axis.

Source code in src/finch/interface/eager.py
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
def vecdot(x1, x2, /, *, axis=-1):
    """
    Computes the (vector) dot product of two arrays.

    Parameters
    ----------
    x1: array
        The first input tensor.
    x2: array
        The second input tensor.
    axis: int, optional
        The axis along which to compute the dot product. Default is -1 (last axis).

    Returns
    -------
    out: array
        A tensor containing the dot product of `x1` and `x2` along the specified axis.
    """
    if isinstance(x1, lazy.LazyTensor) or isinstance(x2, lazy.LazyTensor):
        return lazy.vecdot(x1, x2, axis=axis)
    return compute(lazy.vecdot(x1, x2, axis=axis))