nifty7.operators.diagonal_operator module

class DiagonalOperator(diagonal, domain=None, spaces=None)[source]

Bases: nifty7.operators.endomorphic_operator.EndomorphicOperator

Represents a LinearOperator which is diagonal.

The NIFTy DiagonalOperator class is a subclass derived from the EndomorphicOperator. It multiplies an input field pixel-wise with its diagonal.

Parameters
  • diagonal (Field) – The diagonal entries of the operator.

  • domain (Domain, tuple of Domain or DomainTuple, optional) – The domain on which the Operator’s input Field is defined. If None, use the domain of “diagonal”.

  • spaces (int or tuple of int, optional) – The elements of “domain” on which the operator acts. If None, it acts on all elements.

Notes

Formally, this operator always supports all operation modes (times, adjoint_times, inverse_times and inverse_adjoint_times), even if there are diagonal elements with value 0 or infinity. It is the user’s responsibility to apply the operator only in appropriate ways (e.g. call inverse_times only if there are no zeros on the diagonal).

This shortcoming will hopefully be fixed in the future.

__repr__()[source]

Return repr(self).

apply(x, mode)[source]

Applies the Operator to a given x, in a specified mode.

Parameters
  • x (Field) – The input Field, defined on the Operator’s domain or target, depending on mode.

  • mode (int) –

    • TIMES: normal application

    • ADJOINT_TIMES: adjoint application

    • INVERSE_TIMES: inverse application

    • ADJOINT_INVERSE_TIMES or INVERSE_ADJOINT_TIMES: adjoint inverse application

Returns

The processed Field defined on the Operator’s target or domain, depending on mode.

Return type

Field

draw_sample_with_dtype(dtype, from_inverse=False)[source]

Generates a sample from a Gaussian distribution with zero mean, covariance given by the operator and specified data type.

This method is implemented only for operators which actually draw samples (e.g. DiagonalOperator). Operators which process the sample (like SandwichOperator) implement only draw_sample().

May or may not be implemented. Only optional.

Parameters
  • dtype (numpy.dtype or dict of numpy.dtype) – Dtype used for sampling from this operator. If the domain of op is a MultiDomain, the dtype can either be specified as one value for all components of the MultiDomain or in form of a dictionary whose keys need to conincide the with keys of the MultiDomain.

  • from_inverse (bool (default : False)) – if True, the sample is drawn from the inverse of the operator

Returns

A sample from the Gaussian of given covariance.

Return type

Field or MultiField

get_sqrt()[source]

Return operator op which obeys self == op.adjoint @ op.

Note that this function is only implemented for operators with real spectrum.

Returns

Operator which is the square root of self

Return type

EndomorphicOperator

process_sample(samp, from_inverse)[source]