# Parametric Matrix¶

class fastmat.Parametric

Bases: fastmat.Matrix.Matrix

Let $$f \D \mathbb{C}^2 \rightarrow \mathbb{C}$$ be any function and two vectors $$x \in \mathbb{C}^m$$ and $$y \in \mathbb{C}^n$$ such that $$(x_j,y_i) \in \Dom(f)$$ for $$i \in [n]$$ and $$j \in [m]$$. Then the matrix $$F \in \mathbb{C}^{n \times m}$$ is defined as

$F_{i,j} = f(x_j,y_i).$

This class is not designed to be super fast, but memory efficient. This means, that everytime the forward or backward projections are called, the elements are generated according to the specified function on the fly.

Note

For small dimensions, where the matrix fits into memory, it is definately more efficient to cast the matrix to a regular Matrix object.

>>> # import the package
>>> import fastmat as fm
>>>
>>> # define parameter
>>> # function for the elements
>>> def f(x, y):
>>>     return x ** 2 - y ** 2
>>>
>>> # define the input array
>>> # for the function f
>>> x = np.linspace(1, 4, 4)
>>>
>>> # construct the transform
>>> F = fm.Parametric(x, x, f)


This yields

$f : \mathbb{C} \rightarrow \mathbb{C}$
$(x_1,x_2)^\mathrm{T} \mapsto x_1^2 - x_2^2$
$x = (1,2,3,4)^\mathrm{T}$
$\begin{split}F = \begin{bmatrix} 1 & 3 & 8 & 15 \\ -3 & 0 & 5 & 12 \\ -8 & -5 & 0 & 7 \\ -15 & -12 & -7 & 0 \end{bmatrix}\end{split}$

We used Cython  to get an efficient implementation in order to reduce computation time. Moreover, it is generally assumed the the defined function is able to use row and column broadcasting during evaluation. If this is not the case, one has to set the flag rangeAccess to False.

__init__

Initialize a Parametric matrix instance.

Parameters: vecX : numpy.ndarray A 1d vector mapping the matrix column index to the x-values of funF. vecY : numpy.ndarray A 1d vector mapping the matrix row index to the y-values of funF. funF : callable with arguments (x, y) A function returning the element at index (x, y). funDtype : numpy.dtype, optional Data type of the values returned by funF Not specified by default (determine the datatype from the element at the first index funF(vecX, vecY). rangeAccess : bool, optional Allow passing row- and column vectors directly to funF. This can lead to significant speed-ups compared to single-element access. Defaults to True. **options : optional Additional optional keyworded arguments. Supports all optional arguments supported by fastmat.Matrix.
fun

Return the parameterizing function

vecX
vecY