1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay
21 #ifndef __PARAMEDMEM_MEDCOUPLINGMATRIX_HXX__
22 #define __PARAMEDMEM_MEDCOUPLINGMATRIX_HXX__
24 #include "MEDCoupling.hxx"
25 #include "MEDCouplingTimeLabel.hxx"
26 #include "MEDCouplingRefCountObject.hxx"
27 #include "MEDCouplingMemArray.hxx"
28 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
30 #include "InterpKernelException.hxx"
35 * The aim of this class is \b NOT to reimplement all linear algebra but only to store a dense matrix.
36 * It only provides basic set/get and basic operations and bindings to linear algebra libraries (numpy/scipy) and a compatible format to Petsc.
38 class DenseMatrix : public RefCountObject, public TimeLabel
41 MEDCOUPLING_EXPORT static DenseMatrix *New(int nbRows, int nbCols);
42 MEDCOUPLING_EXPORT static DenseMatrix *New(DataArrayDouble *array, int nbRows, int nbCols);
43 MEDCOUPLING_EXPORT DenseMatrix *deepCpy() const;
44 MEDCOUPLING_EXPORT DenseMatrix *shallowCpy() const;
45 MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
46 MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
47 MEDCOUPLING_EXPORT void updateTime() const;
49 MEDCOUPLING_EXPORT int getNumberOfRows() const { return _nb_rows; }
50 MEDCOUPLING_EXPORT int getNumberOfCols() const { return _nb_cols; }
51 MEDCOUPLING_EXPORT int getNbOfElems() const { return _nb_rows*_nb_cols; }
52 MEDCOUPLING_EXPORT void reBuild(DataArrayDouble *array, int nbRows=-1, int nbCols=-1);
53 MEDCOUPLING_EXPORT void reShape(int nbRows, int nbCols);
54 MEDCOUPLING_EXPORT void transpose();
56 MEDCOUPLING_EXPORT bool isEqual(const DenseMatrix& other, double eps) const;
57 MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DenseMatrix& other, double eps, std::string& reason) const;
58 MEDCOUPLING_EXPORT DataArrayDouble *matVecMult(const DataArrayDouble *vec) const;
59 MEDCOUPLING_EXPORT static DataArrayDouble *MatVecMult(const DenseMatrix *mat, const DataArrayDouble *vec);
60 MEDCOUPLING_EXPORT static DenseMatrix *Add(const DenseMatrix *a1, const DenseMatrix *a2);
61 MEDCOUPLING_EXPORT void addEqual(const DenseMatrix *other);
62 MEDCOUPLING_EXPORT static DenseMatrix *Substract(const DenseMatrix *a1, const DenseMatrix *a2);
63 MEDCOUPLING_EXPORT void substractEqual(const DenseMatrix *other);
64 MEDCOUPLING_EXPORT static DenseMatrix *Multiply(const DenseMatrix *a1, const DenseMatrix *a2);
65 MEDCOUPLING_EXPORT static DenseMatrix *Multiply(const DenseMatrix *a1, const DataArrayDouble *a2);
67 MEDCOUPLING_EXPORT const DataArrayDouble *getData() const { return _data; }
68 MEDCOUPLING_EXPORT DataArrayDouble *getData() { return _data; }
71 DenseMatrix(int nbRows, int nbCols);
72 DenseMatrix(DataArrayDouble *array, int nbRows, int nbCols);
73 int getNumberOfRowsExt(int nbRows) const;
74 int getNumberOfColsExt(int nbCols) const;
75 void checkValidData() const;
76 static void CheckArraySizes(DataArrayDouble *array, int nbRows, int nbCols);
77 static void CheckSameSize(const DenseMatrix *a1, const DenseMatrix *a2);
78 static void CheckCompatibleSizeForMul(const DenseMatrix *a1, const DenseMatrix *a2);
82 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> _data;