Type Conversion
Two kinds of type conversion are possible between Rogue Wave matrix classes:
We discuss these two kinds of conversion in the following sections.
Converting Precisions
Converting between matrices of the same shape but different precisions is much the same as converting between scalar types. Both follow similar rules in C++. The following program gives an example of type conversions that are possible using tridiagonal matrices:
#include <rw/lapack/trdgmat.h>
int main()
{
RWTriDiagMat<float> Afloat(5,5); // 1
RWTriDiagMat<double> Adouble = Afloat; // 2
RWTriDiagMat<DComplex> Acomplex = Adouble; // 3
return 0;
}
In each of the conversions above, no information is lost. However, conversions in the opposite direction are narrowing and may cause a loss of precision. These conversions are possible, but you must explicitly use a function provided for this purpose. For example:
#include <rw/lapack/trdgmat.h>
int main()
{
RWTriDiagMat<DComplex> Acomplex(5,5); // 1
RWTriDiagMat<double> Adouble = real(Acomplex); // 2
RWTriDiagMat<float> Afloat= toFloat(Adouble); // 3
return 0;
}
Type conversions between
RWGenMat<T> matrices is different due to their template definition. Automatic conversions are
not generally available. For a complete discussion about type conversions for general matrices, see the Essential
Math Module User’s Guide.
Converting Shapes
In addition to converting from one matrix precision to another, you can convert between matrix shapes. Automatic type conversion can be used to convert any matrix shape to a general matrix of the same precision. Furthermore, symmetric banded, hermitian banded, and tridiagonal matrices can be converted automatically to banded matrices.
You can convert matrices in the opposite direction, as you did precisions, by using explicit functions. For example, the function toSymMat() extracts the symmetric part of a matrix. This function is often used in situations where you have a general matrix that you know is symmetric and you want to recognize this explicitly.