Two kinds of type conversion are possible between Rogue Wave matrix classes:
Conversion between matrices with the same shape but different precisions; for example, from a FloatBandMat to a DoubleBandMat.
Conversion between matrices with the same precision but different shapes; for example, from a DComplexSymMat to an RWGenMat<DComplex>.
We discuss these two kinds of conversion in the following sections.
>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/dtrdgmat.h> #include <rw/ctrdgmat.h> #include <rw/ftrdgmat.h> main() { FloatTriDiagMat Afloat(5,5); // 1 DoubleTriDiagMat Adouble = Afloat; // 2 DComplexTriDiagMat Acomplex = Adouble; // 3 }
//1 | This line creates a 5 x 5 tridiagonal matrix of floats. |
//2 | This line demonstrates that this matrix can be converted automatically to a matrix of doubles. |
//3 | This line shows that this matrix can be converted to a matrix of complex. |
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/dtrdgmat.h> #include <rw/ctrdgmat.h> #include <rw/ftrdgmat.h> main() { DComplexTriDiagMat Acomplex(5,5); // 1 DoubleTriDiagMat Adouble = real(Acomplex); // 2 FloatTriDiagMat Afloat= toFloat(Adouble); // 3 }
//1 | This line defines a 5 x 5 complex tridiagonal matrix. |
//2 | Takes the real part of the complex matrix and stores it as a matrix of doubles. |
//3 | Converts a matrix of doubles to a matrix of floats. |
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 Math.h++ User's Guide.
>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.
>©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.