cppqed-multidiagonal 0.4.0
Multidiagonal sparse operator algebra for C++QED
Loading...
Searching...
No Matches
MultiArrayComplex.h File Reference
#include "MultiArray.h"
#include <Eigen/Dense>
#include <boost/serialization/complex.hpp>
#include <complex>
Include dependency graph for MultiArrayComplex.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  boost
 
namespace  boost::json
 
namespace  cppqedutils
 Namespace alias for Boost.Hana, used for compile-time sequences and heterogeneous containers.
 

Concepts

concept  cppqedutils::scalar
 Concept satisfied by scalar numeric types usable as operator coefficients: any type convertible to double or dcomp.
 

Typedefs

typedef std::complex< double > dcomp
 Double-precision complex number. Named to resemble a built-in type rather than a class.
 
using CMatrix = Eigen::MatrixX< dcomp >
 Dense complex matrix type (Eigen dynamic-size).
 
using CVector = Eigen::VectorX< dcomp >
 Dense complex vector type (Eigen dynamic-size).
 

Functions

bool isNonZero (dcomp c)
 Returns true if either the real or imaginary part of c is non-zero.
 
bool hasRealPart (dcomp c)
 Returns true if the real part of c is non-zero.
 
bool hasImagPart (dcomp c)
 Returns true if the imaginary part of c is non-zero.
 
bool absCompare (dcomp c1, dcomp c2)
 Comparator by absolute value, for use with sorting algorithms.
 
bool realCompare (dcomp c1, dcomp c2)
 Comparator by real part, for use with sorting algorithms.
 
auto sqr (auto &&x) noexcept(noexcept(x *x)) -> decltype(x *x)
 Generic square: x*x. Return type is deduced; noexcept and SFINAE are propagated.
 
double relativeDeviation (const auto &a, const auto &b)
 Relative deviation between two values: |a-b| / (|a|+|b|). Returns 0 if both are zero.
 
double sqrAbs (dcomp v)
 Squared absolute value of a complex number: |v|^2 = re^2 + im^2, computed as such (std::norm), not as the square of the rounded std::abs.
 
dcomp textbookProduct (dcomp a, dcomp b)
 Complex product by the textbook formula \((a+ib)(c+id)=(ac-bd)+i(ad+bc)\), for hot loops.
 
template<class T >
void boost::json::tag_invoke (value_from_tag, value &jv, const std::complex< T > &c)
 Boost.JSON serialization for std::complex<T>: emits a two-element JSON array [re, im].
 
template<class T >
std::complex< T > boost::json::tag_invoke (value_to_tag< std::complex< T > >, const value &jv)
 Boost.JSON deserialization for std::complex<T>: reads from a two-element JSON array [re, im].
 
template<size_t RANK>
auto cppqedutils::vectorize (MultiArray< dcomp, RANK > &ma)
 Maps a mutable MultiArray<dcomp,RANK> to an Eigen column vector (no data copy).
 
template<size_t RANK>
auto cppqedutils::vectorize (const MultiArray< dcomp, RANK > &ma)
 Maps a const MultiArray<dcomp,RANK> to a const Eigen column vector (no data copy).
 
template<size_t TWO_TIMES_RANK>
requires ( !(TWO_TIMES_RANK%2) )
Extents< TWO_TIMES_RANK/2 > cppqedutils::halveExtents (Extents< TWO_TIMES_RANK > extents)
 Extracts the first half of a rank-2R extent array, verifying that both halves are equal.
 
template<size_t TWO_TIMES_RANK>
auto cppqedutils::matricize (MultiArray< dcomp, TWO_TIMES_RANK > &ma)
 Maps a mutable rank-2R MultiArray<dcomp> to an Eigen square matrix (no data copy). The matrix dimension is prod(extents[0..R-1]); requires equal first and second half extents.
 
template<size_t TWO_TIMES_RANK>
auto cppqedutils::matricize (const MultiArray< dcomp, TWO_TIMES_RANK > &ma)
 Maps a const rank-2R MultiArray<dcomp> to a const Eigen square matrix (no data copy).
 
template<size_t RANK1, size_t RANK2>
auto cppqedutils::directProduct (const MultiArray< dcomp, RANK1 > &m1, const MultiArray< dcomp, RANK2 > &m2, std::function< dcomp(dcomp, dcomp)> func=std::multiplies< dcomp >{})
 Tensor (outer) product of two complex multi-arrays.
 
template<size_t RANK>
MultiArray< dcomp, RANK > & cppqedutils::conj (MultiArray< dcomp, RANK > &ma)
 In-place complex conjugation of all elements of ma.
 
template<size_t RANK>
double cppqedutils::frobeniusNormSqr (const MultiArray< dcomp, RANK > &ma)
 Squared Frobenius norm: \(\sum_{i}|a_i|^2\). Returns 0 for an empty array.
 
template<size_t RANK>
double cppqedutils::frobeniusNorm (const MultiArray< dcomp, RANK > &ma)
 Frobenius norm: \(\sqrt{\sum_{i}|a_i|^2}\).
 
template<size_t TWO_TIMES_RANK>
void cppqedutils::hermitianConjugateSelf (MultiArrayView< dcomp, TWO_TIMES_RANK > mav)
 In-place Hermitian conjugation of a rank-2R matrix view mav.
 
template<size_t TWO_TIMES_RANK>
void cppqedutils::twoTimesRealPartOfSelf (MultiArrayView< dcomp, TWO_TIMES_RANK > mav)
 In-place replacement of a rank-2R matrix view mav with M + M† (twice its Hermitian part).
 

Typedef Documentation

◆ CMatrix

using CMatrix = Eigen::MatrixX<dcomp>

Dense complex matrix type (Eigen dynamic-size).

◆ CVector

using CVector = Eigen::VectorX<dcomp>

Dense complex vector type (Eigen dynamic-size).

◆ dcomp

typedef std::complex<double> dcomp

Double-precision complex number. Named to resemble a built-in type rather than a class.

Function Documentation

◆ absCompare()

bool absCompare ( dcomp  c1,
dcomp  c2 
)
inline

Comparator by absolute value, for use with sorting algorithms.

◆ hasImagPart()

bool hasImagPart ( dcomp  c)
inline

Returns true if the imaginary part of c is non-zero.

◆ hasRealPart()

bool hasRealPart ( dcomp  c)
inline

Returns true if the real part of c is non-zero.

◆ isNonZero()

bool isNonZero ( dcomp  c)
inline

Returns true if either the real or imaginary part of c is non-zero.

◆ realCompare()

bool realCompare ( dcomp  c1,
dcomp  c2 
)
inline

Comparator by real part, for use with sorting algorithms.

◆ relativeDeviation()

double relativeDeviation ( const auto &  a,
const auto &  b 
)

Relative deviation between two values: |a-b| / (|a|+|b|). Returns 0 if both are zero.

◆ sqr()

auto sqr ( auto &&  x) -> decltype(x*x)
noexcept

Generic square: x*x. Return type is deduced; noexcept and SFINAE are propagated.

See also
https://stackoverflow.com/a/64849248/1171157

◆ sqrAbs()

double sqrAbs ( dcomp  v)
inline

Squared absolute value of a complex number: |v|^2 = re^2 + im^2, computed as such (std::norm), not as the square of the rounded std::abs.

◆ textbookProduct()

dcomp textbookProduct ( dcomp  a,
dcomp  b 
)
inline

Complex product by the textbook formula \((a+ib)(c+id)=(ac-bd)+i(ad+bc)\), for hot loops.

By default, GCC and Clang multiply std::complex according to C99 Annex G: when both parts of the textbook result are NaN, a library call (__muldc3) tries to recover an infinite result. That check keeps loops from vectorizing. This function omits the recovery, so its speed does not depend on -fcx-limited-range. Otherwise it evaluates the same expression as the default: the two differ only where an infinite operand makes both parts NaN.

See also
Performance of MultiDiagonal for what the check costs.