bundles / scipy 1.17.1 / scipy / linalg / _basic / matmul_toeplitz
function
scipy.linalg._basic:matmul_toeplitz
source: /scipy/linalg/_basic.py :2259
Signature
def matmul_toeplitz ( c_or_cr , x , check_finite = False , workers = None ) Summary
Efficient Toeplitz Matrix-Matrix Multiplication using FFT
Extended Summary
This function returns the matrix multiplication between a Toeplitz matrix and a dense matrix.
The Toeplitz matrix has constant diagonals, with c as its first column and r as its first row. If r is not given, r == conjugate(c) is assumed.
The documentation is written assuming array arguments are of specified "core" shapes. However, array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details.
Parameters
c_or_cr: array_like or tuple of (array_like, array_like)The vector
c, or a tuple of arrays (c,r). If not supplied,r = conjugate(c)is assumed; in this case, if c[0] is real, the Toeplitz matrix is Hermitian. r[0] is ignored; the first row of the Toeplitz matrix is[c[0], r[1:]].x: (M,) or (M, K) array_likeMatrix with which to multiply.
check_finite: bool, optionalWhether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (result entirely NaNs) if the inputs do contain infinities or NaNs.
workers: int, optionalTo pass to scipy.fft.fft and ifft. Maximum number of workers to use for parallel computation. If negative, the value wraps around from
os.cpu_count(). See scipy.fft.fft for more details.
Returns
T @ x: (M,) or (M, K) ndarrayThe result of the matrix multiplication
T @ x. Shape of return matches shape ofx.
Notes
The Toeplitz matrix is embedded in a circulant matrix and the FFT is used to efficiently calculate the matrix-matrix product.
Because the computation is based on the FFT, integer inputs will result in floating point outputs. This is unlike NumPy's matmul, which preserves the data type of the input.
This is partly based on the implementation that can be found in [1], licensed under the MIT license. More information about the method can be found in reference [2]. References [3] and [4] have more reference implementations in Python.
Examples
Multiply the Toeplitz matrix T with matrix x:: [ 1 -1 -2 -3] [1 10] T = [ 3 1 -1 -2] x = [2 11] [ 6 3 1 -1] [2 11] [10 6 3 1] [5 19] To specify the Toeplitz matrix, only the first column and the first row are needed.import numpy as np c = np.array([1, 3, 6, 10]) # First column of T r = np.array([1, -1, -2, -3]) # First row of T x = np.array([[1, 10], [2, 11], [2, 11], [5, 19]])✓
from scipy.linalg import toeplitz, matmul_toeplitz matmul_toeplitz((c, r), x)✓
toeplitz(c, r) @ x
✓n = 1000000 matmul_toeplitz([1] + [0]*(n-1), np.ones(n))✓
See also
- solve_toeplitz
Solve a Toeplitz system using Levinson Recursion
- toeplitz
Toeplitz matrix
Aliases
-
scipy.linalg.matmul_toeplitz