FlatLinearOperator

  • full name: tenpy.linalg.sparse.FlatLinearOperator

  • parent module: tenpy.linalg.sparse

  • type: class

class tenpy.linalg.sparse.FlatLinearOperator(npc_matvec, leg, dtype, charge_sector=0, vec_label=None)[source]

Bases: scipy.sparse.linalg.interface.LinearOperator

Square Linear operator acting on numpy arrays based on a matvec acting on npc Arrays.

Note that this class represents a square linear operator. In terms of charges, this means it has legs [self.leg.conj(), self.leg] and trivial (zero) qtotal.

Parameters
npc_matvecfunction

Function to calculate the action of the linear operator on an npc vector (with the specified leg). Has to return an npc vector with the same leg.

legLegCharge

Leg of the vector on which npc_matvec can act on.

dtypenp.dtype

The data type of the arrays.

charge_sectorNone | charges | 0

Selects the charge sector of the vector onto which the Linear operator acts. None stands for all sectors, 0 stands for the zero-charge sector. Defaults to 0, i.e., assumes the dominant eigenvector is in charge sector 0.

vec_labelNone | str

Label to be set to the npc vector before acting on it with npc_matvec. Ignored if None.

Attributes
charge_sector

Charge sector of the vector which is acted on.

possible_charge_sectorsndarray[QTYPE, ndim=2]

Each row corresponds to one possible choice for charge_sector.

shape(int, int)

The dimensions for the selected charge sector.

dtypenp.dtype

The data type of the arrays.

legLegCharge

Leg of the vector on which npc_matvec can act on.

vec_labelNone | str

Label to be set to the npc vector before acting on it with npc_matvec. Ignored if None.

npc_matvecfunction

Function to calculate the action of the linear operator on an npc vector (with one leg).

matvec_countint

The number of times npc_matvec was called.

_maskndarray[ndim=1, bool]

The indices of leg corresponding to the charge_sector to be diagonalized.

_npc_matvec_multilegfunction | None

Only set if initalized with from_guess_with_pipe(). The npc_matvec function to be wrapped around. Takes the npc Array in multidimensional form and returns it that way.

_labels_splitlist of str

Only set if initalized with from_guess_with_pipe(). Labels of the guess before combining them into a pipe (stored as leg).

Methods

__call__(self, x)

Call self as a function.

adjoint(self)

Hermitian adjoint.

dot(self, x)

Matrix-matrix or matrix-vector multiplication.

flat_to_npc(self, vec)

Convert flat vector of selected charge sector into npc Array.

from_NpcArray(mat[, charge_sector])

Create a FlatLinearOperator from a square Array.

from_guess_with_pipe(npc_matvec, v0_guess[, …])

Create a FlatLinearOperator` from a matvec function acting on multiple legs.

matmat(self, X)

Matrix-matrix multiplication.

matvec(self, x)

Matrix-vector multiplication.

npc_to_flat(self, npc_vec)

Convert npc Array with qtotal = self.charge_sector into ndarray.

rmatmat(self, X)

Adjoint matrix-matrix multiplication.

rmatvec(self, x)

Adjoint matrix-vector multiplication.

transpose(self)

Transpose this linear operator.

classmethod from_NpcArray(mat, charge_sector=0)[source]

Create a FlatLinearOperator from a square Array.

Parameters
matArray

A square matrix, with contractable legs.

charge_sectorNone | charges | 0

Selects the charge sector of the vector onto which the Linear operator acts. None stands for all sectors, 0 stands for the zero-charge sector. Defaults to 0, i.e., assumes the dominant eigenvector is in charge sector 0.

classmethod from_guess_with_pipe(npc_matvec, v0_guess, labels_split=None, dtype=None)[source]

Create a FlatLinearOperator` from a matvec function acting on multiple legs.

This function creates a wrapper matvec function to allow acting on a “vector” with multiple legs. The wrapper combines the legs into a LegPipe before calling the actual matvec function, and splits them again in the end.

Parameters
npc_matvecfunction

Function to calculate the action of the linear operator on an npc vector with the given split labels labels_split. Has to return an npc vector with the same legs.

v0_guessArray

Initial guess/starting vector which can be applied to npc_matvec.

labels_splitNone | list of str

Labels of v0_guess in the order in which they are to be combined into a LegPipe. None defaults to v0_guess.get_leg_labels().

dtypenp.dtype | None

The data type of the arrays. None defaults to dtype of v0_guess (!).

Returns
lin_opcls

Instance of the class to be used as linear operator

guess_flatnp.ndarray

Numpy vector representing the guess v0_guess.

property charge_sector

Charge sector of the vector which is acted on.

flat_to_npc(self, vec)[source]

Convert flat vector of selected charge sector into npc Array.

Parameters
vec1D ndarray

Numpy vector to be converted. Should have the entries according to self.charge_sector.

Returns
npc_vecArray

Same as vec, but converted into a flat array.

npc_to_flat(self, npc_vec)[source]

Convert npc Array with qtotal = self.charge_sector into ndarray.

Parameters
npc_vecArray

Npc Array to be converted. Should only have entries in self.charge_sector.

Returns
vec1D ndarray

Same as npc_vec, but converted into a flat Numpy array.

property H

Hermitian adjoint.

Returns the Hermitian adjoint of self, aka the Hermitian conjugate or Hermitian transpose. For a complex matrix, the Hermitian adjoint is equal to the conjugate transpose.

Can be abbreviated self.H instead of self.adjoint().

Returns
A_HLinearOperator

Hermitian adjoint of self.

property T

Transpose this linear operator.

Returns a LinearOperator that represents the transpose of this one. Can be abbreviated self.T instead of self.transpose().

adjoint(self)

Hermitian adjoint.

Returns the Hermitian adjoint of self, aka the Hermitian conjugate or Hermitian transpose. For a complex matrix, the Hermitian adjoint is equal to the conjugate transpose.

Can be abbreviated self.H instead of self.adjoint().

Returns
A_HLinearOperator

Hermitian adjoint of self.

dot(self, x)

Matrix-matrix or matrix-vector multiplication.

Parameters
xarray_like

1-d or 2-d array, representing a vector or matrix.

Returns
Axarray

1-d or 2-d array (depending on the shape of x) that represents the result of applying this linear operator on x.

matmat(self, X)

Matrix-matrix multiplication.

Performs the operation y=A*X where A is an MxN linear operator and X dense N*K matrix or ndarray.

Parameters
X{matrix, ndarray}

An array with shape (N,K).

Returns
Y{matrix, ndarray}

A matrix or ndarray with shape (M,K) depending on the type of the X argument.

Notes

This matmat wraps any user-specified matmat routine or overridden _matmat method to ensure that y has the correct type.

matvec(self, x)

Matrix-vector multiplication.

Performs the operation y=A*x where A is an MxN linear operator and x is a column vector or 1-d array.

Parameters
x{matrix, ndarray}

An array with shape (N,) or (N,1).

Returns
y{matrix, ndarray}

A matrix or ndarray with shape (M,) or (M,1) depending on the type and shape of the x argument.

Notes

This matvec wraps the user-specified matvec routine or overridden _matvec method to ensure that y has the correct shape and type.

rmatmat(self, X)

Adjoint matrix-matrix multiplication.

Performs the operation y = A^H * x where A is an MxN linear operator and x is a column vector or 1-d array, or 2-d array. The default implementation defers to the adjoint.

Parameters
X{matrix, ndarray}

A matrix or 2D array.

Returns
Y{matrix, ndarray}

A matrix or 2D array depending on the type of the input.

Notes

This rmatmat wraps the user-specified rmatmat routine.

rmatvec(self, x)

Adjoint matrix-vector multiplication.

Performs the operation y = A^H * x where A is an MxN linear operator and x is a column vector or 1-d array.

Parameters
x{matrix, ndarray}

An array with shape (M,) or (M,1).

Returns
y{matrix, ndarray}

A matrix or ndarray with shape (N,) or (N,1) depending on the type and shape of the x argument.

Notes

This rmatvec wraps the user-specified rmatvec routine or overridden _rmatvec method to ensure that y has the correct shape and type.

transpose(self)

Transpose this linear operator.

Returns a LinearOperator that represents the transpose of this one. Can be abbreviated self.T instead of self.transpose().