/usr/include/openturns/MatrixImplementation.hxx is in libopenturns-dev 1.9-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | // -*- C++ -*-
/**
* @brief MatrixImplementation implements the classical mathematical Matrix
*
* Copyright 2005-2017 Airbus-EDF-IMACS-Phimeca
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef OPENTURNS_MATRIXIMPLEMENTATION_HXX
#define OPENTURNS_MATRIXIMPLEMENTATION_HXX
#include "openturns/PersistentCollection.hxx"
#include "openturns/Description.hxx"
#include "openturns/Point.hxx"
#include "openturns/Collection.hxx"
BEGIN_NAMESPACE_OPENTURNS
/**
* @class MatrixImplementation
*
* MatrixImplementation implements the classical mathematical MatrixImplementation
*/
// Forward declaration of ComplexMatrixImplementation
class ComplexMatrixImplementation;
class OT_API MatrixImplementation
: public PersistentCollection<Scalar>
{
CLASSNAME;
#ifndef SWIG
/** Declaration of friend operators */
friend MatrixImplementation operator * (const Scalar s,
const MatrixImplementation & matrix)
{
return matrix.operator * (s);
}
#endif
public:
typedef Collection<Scalar> ScalarCollection;
typedef Collection<Complex> ComplexCollection;
/** Default constructor */
MatrixImplementation();
/** Constructor with size (rowDim and colDim) */
MatrixImplementation(const UnsignedInteger rowDim,
const UnsignedInteger colDim);
/** Constructor from range of external collection */
template <class InputIterator>
MatrixImplementation(const UnsignedInteger rowDim,
const UnsignedInteger colDim,
const InputIterator first,
const InputIterator last);
/** Constructor from external collection */
/** If the dimensions of the matrix and of the collection */
/** do not correspond, either the collection is truncated */
/** or the rest of the matrix is filled with zeros */
MatrixImplementation(const UnsignedInteger rowDim,
const UnsignedInteger colDim,
const ScalarCollection & elementsValues);
/** Virtual constructor */
virtual MatrixImplementation * clone() const;
/** String converter */
virtual String __repr__() const;
virtual String __str__(const String & offset = "") const;
/** Operator () gives access to the elements of the MatrixImplementation (to modify these elements) */
/** The element of the MatrixImplementation is designated by its row number i and its column number j */
Scalar & operator () (const UnsignedInteger i,
const UnsignedInteger j);
/** Operator () gives access to the elements of the MatrixImplementation (read only) */
/** The element of the MatrixImplementation is designated by its row number i and its column number j */
const Scalar & operator () (const UnsignedInteger i,
const UnsignedInteger j) const;
/** Get the dimensions of the MatrixImplementation */
/** Number of rows */
UnsignedInteger getNbRows() const;
/** Number of columns */
UnsignedInteger getNbColumns() const;
/** Dimension (for square matrices only */
UnsignedInteger getDimension() const;
/** MatrixImplementation transpose */
MatrixImplementation transpose () const;
/** Row extraction */
const MatrixImplementation getRow(const UnsignedInteger rowIndex) const;
const MatrixImplementation getRowSym(const UnsignedInteger rowIndex) const;
/** Column extration */
const MatrixImplementation getColumn(const UnsignedInteger columnIndex) const;
const MatrixImplementation getColumnSym(const UnsignedInteger columnIndex) const;
/** MatrixImplementation addition (must have the same dimensions) */
MatrixImplementation operator + (const MatrixImplementation & matrix) const;
/** In-place MatrixImplementation addition (must have the same dimensions) */
MatrixImplementation & operator += (const MatrixImplementation & matrix);
/** MatrixImplementation substraction (must have the same dimensions) */
MatrixImplementation operator - (const MatrixImplementation & matrix) const;
/** In-place MatrixImplementation substraction (must have the same dimensions) */
MatrixImplementation & operator -= (const MatrixImplementation & matrix);
/** MatrixImplementation multiplications (must have consistent dimensions) */
MatrixImplementation genProd (const MatrixImplementation & matrix,
const Bool transposeLeft = false,
const Bool transposeRight = false) const;
MatrixImplementation symProd (const MatrixImplementation & m,
const char symSide) const;
/** MatrixImplementation integer power */
MatrixImplementation genPower(const UnsignedInteger n) const;
MatrixImplementation symPower(const UnsignedInteger n) const;
/** Multiplications with a Point (must have consistent dimensions) */
Point genVectProd (const Point & pt,
const Bool transpose = false) const;
Point symVectProd (const Point & pt) const;
/** Using triangular matrix */
ScalarCollection triangularVectProd (const ScalarCollection & pt,
const char side = 'L') const;
ScalarCollection triangularVectProd (const Point & pt,
const char side = 'L') const;
/** Multiplication with a Scalar */
MatrixImplementation operator * (const Scalar s) const;
/** In-place Multiplication with a Scalar */
MatrixImplementation & operator *= (const Scalar s);
/** Division by a Scalar*/
MatrixImplementation operator / (const Scalar s) const;
/** In-place Division by a Scalar*/
MatrixImplementation & operator /= (const Scalar s);
/** Symmetrize MatrixImplementation in case it is a symmetric matrix (stored as a triangular matrix) */
void symmetrize() const;
/** Triangularize MatrixImplementation in case it is a triangular matrix (stored as a square matrix) */
void triangularize(const Bool isLowerTriangular) const;
/** Resolution of a linear system in case of a rectangular matrix */
Point solveLinearSystemRect(const Point & b,
const Bool keepIntact = true);
MatrixImplementation solveLinearSystemRect(const MatrixImplementation & b,
const Bool keepIntact = true);
/** Resolution of a linear system in case of a square matrix */
Point solveLinearSystemSquare(const Point & b,
const Bool keepIntact = true);
MatrixImplementation solveLinearSystemSquare(const MatrixImplementation & b,
const Bool keepIntact = true);
/** Resolution of a linear system in case of a triangular matrix */
Point solveLinearSystemTri(const Point & b,
const Bool keepIntact = true,
const Bool lower = true,
const Bool transpose = false);
MatrixImplementation solveLinearSystemTri(const MatrixImplementation & b,
const Bool keepIntact = true,
const Bool lower = true,
const Bool transpose = false);
/** Resolution of a linear system in case of a symmetric matrix */
Point solveLinearSystemSym(const Point & b,
const Bool keepIntact = true);
MatrixImplementation solveLinearSystemSym(const MatrixImplementation & b,
const Bool keepIntact = true);
/** Resolution of a linear system in case of a covariance matrix */
Point solveLinearSystemCov(const Point & b,
const Bool keepIntact = true);
MatrixImplementation solveLinearSystemCov(const MatrixImplementation & b,
const Bool keepIntact = true);
/** Triangular matrix product : side argument L/R for the position of the triangular matrix, up/lo to tell if it */
MatrixImplementation triangularProd(const MatrixImplementation & m,
const char side = 'L',
const char uplo = 'L') const;
/** Compute determinant */
Scalar computeLogAbsoluteDeterminant(Scalar & sign,
const Bool keepIntact = true);
Scalar computeDeterminant(const Bool keepIntact = true);
Scalar computeLogAbsoluteDeterminantSym(Scalar & sign,
const Bool keepIntact = true);
Scalar computeDeterminantSym(const Bool keepIntact = true);
/** Compute trace */
Scalar computeTrace() const;
/** Compute eigenvalues */
ComplexCollection computeEigenValuesSquare(const Bool keepIntact = true);
ComplexCollection computeEVSquare(ComplexMatrixImplementation & v,
const Bool keepIntact = true);
Point computeEigenValuesSym(const Bool keepIntact = true);
Point computeEVSym(MatrixImplementation & v,
const Bool keepIntact = true);
/** Compute singular values */
Point computeSingularValues(const Bool keepIntact = true);
/** Build the singular value decomposition */
Point computeSVD(MatrixImplementation & u,
MatrixImplementation & vT,
const Bool fullSVD = false,
const Bool keepIntact = true);
/** Check if the matrix is symmetric */
virtual Bool isSymmetric() const;
/** Check if the matrix is SPD */
virtual Bool isPositiveDefinite(const Bool keepIntact = true);
/** Check if the matrix values belong to (-1;1) */
virtual Bool hasUnitRange() const;
/** Set small elements to zero */
virtual MatrixImplementation clean(const Scalar threshold) const;
virtual MatrixImplementation cleanSym(const Scalar threshold) const;
/** Build the Cholesky factorization of the matrix */
virtual MatrixImplementation computeCholesky(const Bool keepIntact = true);
/** Update in-place the Cholesky factor L of an SPD matrix M given a rank-one update vv^T, ie L becomes Lnew such that LnewLnew^t = Mnew with Mnew = M + vv^t */
static void CholeskyUpdate(MatrixImplementation & cholesky,
const Point & vector);
/** Downdate in-place the Cholesky factor L of an SPD matrix M given a rank-one downdate vv^T, ie L becomes Lnew such that LnewLnew^t = Mnew with Mnew = M - vv^t */
static void CholeskyDowndate(MatrixImplementation & cholesky,
const Point & vector);
/** Build the QR factorization of the matrix */
virtual MatrixImplementation computeQR(MatrixImplementation & R,
const Bool fullQR = false,
const Bool keepIntact = true);
/** Compute the Gram matrix associated to the matrix */
virtual MatrixImplementation computeGram(const Bool transpose = true) const;
/** Comparison operators */
Bool operator == (const MatrixImplementation & rhs) const;
inline Bool operator != (const MatrixImplementation & rhs) const
{
return !((*this) == rhs);
}
/** Empty returns true if there is no element in the MatrixImplementation */
Bool isEmpty() const;
/** Returns true if triangular lower or upper */
Bool isTriangular(Bool lower = true) const;
/** Method save() stores the object through the StorageManager */
void save(Advocate & adv) const;
/** Method load() reloads the object from the StorageManager */
void load(Advocate & adv);
// These functions are only intended to be used by SWIG, DO NOT use them for your own purpose !
// INTENTIONALY NOT DOCUMENTED
const Scalar * __baseaddress__ () const;
UnsignedInteger __elementsize__ () const;
UnsignedInteger __stride__ (UnsignedInteger dim) const;
protected:
/** MatrixImplementation Dimensions */
UnsignedInteger nbRows_;
UnsignedInteger nbColumns_;
/** Position conversion function : the indices i & j are used to compute the actual position of the element in the collection */
inline UnsignedInteger convertPosition (const UnsignedInteger i,
const UnsignedInteger j) const;
}; /* class MatrixImplementation */
inline UnsignedInteger MatrixImplementation::convertPosition (const UnsignedInteger i,
const UnsignedInteger j) const
{
return i + nbRows_ * j ;
}
/** Constructor from range of external collection */
template <class InputIterator>
MatrixImplementation::MatrixImplementation(const UnsignedInteger rowDim,
const UnsignedInteger colDim,
const InputIterator first,
const InputIterator last)
: PersistentCollection<Scalar>(rowDim * colDim, 0.0),
nbRows_(rowDim),
nbColumns_(colDim)
{
this->assign(first, last);
}
END_NAMESPACE_OPENTURNS
#endif /* OPENTURNS_MATRIXIMPLEMENTATION_HXX */
|