21 #ifndef __ANTARES_LIBS_ARRAY_MATRIX_H__
22 #define __ANTARES_LIBS_ARRAY_MATRIX_H__
27 #include <yuni/yuni.h>
28 #include <yuni/io/file.h>
30 #include <antares/memory/memory.h>
31 #include "antares/jit/jit.h"
42 template<
class T =
double,
class ReadWriteT = T>
62 using ColumnType =
typename Antares::Memory::Stored<T>::Type;
114 template<
class U,
class V>
130 template<
class U,
class V>
133 template<
class U,
class V>
183 virtual bool openFile(Yuni::IO::File::Stream& file,
const AnyString& filename)
const;
185 virtual void saveBufferToFile(std::string& buffer, Yuni::IO::File::Stream& f)
const;
199 bool print_dimensions =
false,
200 bool saveEvenIfAllZero =
false)
const;
213 template<
class PredicateT>
216 bool print_dimensions,
217 PredicateT& predicate,
218 bool saveEvenIfAllZero =
false)
const;
222 virtual Yuni::IO::Error loadFromFileToBuffer(
BufferType& buffer,
223 const AnyString& filename)
const
228 template<
class PredicateT>
229 void saveToFileDescriptor(std::string& data,
231 bool print_dimensions,
232 PredicateT& predicate)
const
234 saveToBuffer(data, precision, print_dimensions, predicate,
false);
246 void resize(uint w, uint h,
bool fixedSize =
false);
270 void reset(uint w, uint h,
bool fixedSize =
false);
285 void fill(
const T& v);
304 void divideColumnBy(uint x,
const U& c);
365 template<
class PredicateT>
451 template<
class U = Type>
452 inline U operator()(
const U& value)
const
458 void saveToBuffer(std::string& data, uint precision = 6)
const;
460 template<
class PredicateT>
461 void saveToBuffer(std::string& data,
463 bool print_dimensions,
464 PredicateT& predicate,
465 bool saveEvenIfAllZero)
const;
471 bool internalLoadCSVFile(
const AnyString& filename,
478 bool internalLoadJITData(
const AnyString& filename,
486 template<
class PredicateT>
487 bool internalSaveCSVFile(
const AnyString& filename,
489 bool print_dimensions,
490 PredicateT& predicate,
491 bool saveEvenIfAllZero)
const;
493 bool loadFromBuffer(
const AnyString& filename,
502 bool loadAllJITData()
const;
507 void reverseRows(uint
column, uint start, uint end);
523 using ConstType =
const U*;
550 template<
class T1,
class T2>
551 bool MatrixTestForAtLeastOnePositiveValue(
const Matrix<T1, T2>& m);
555 #include "matrix.hxx"
A n-by-n matrix.
Definition: matrix.h:44
JIT::Informations * jit
Just-in-time informations.
Definition: matrix.h:447
void zero()
Make the matrix a zero matrix.
Definition: matrix.hxx:292
uint height
Height of the matrix.
Definition: matrix.h:443
void columnToZero(uint x)
Set to zero a entire column.
Definition: matrix.hxx:505
void copyFrom(const Matrix< U, V > &rhs)
Copy values from another matrix.
Definition: matrix.hxx:1485
void pasteToColumn(uint x, const U *data)
Copy values into a given column in the matrix.
Definition: matrix.hxx:467
Options
Options when loading a file.
Definition: matrix.h:71
@ optImmediate
Do not postpone the loading.
Definition: matrix.h:79
@ optQuiet
Do not produce warnings/errors.
Definition: matrix.h:77
@ optNeverFails
The loading never fails.
Definition: matrix.h:85
@ optFixedSize
The matrix can not see its size modified.
Definition: matrix.h:75
@ optNoWarnIfEmpty
Do not warn if the file is empty.
Definition: matrix.h:83
@ optMarkAsModified
mark the matrix as modified after loading
Definition: matrix.h:81
@ optNone
None.
Definition: matrix.h:73
ColumnType & operator[](uint column)
operator []
Definition: matrix.hxx:1726
void reset()
Empty the matrix and mark it as modified.
Definition: matrix.hxx:547
virtual bool openFile(Yuni::IO::File::Stream &file, const AnyString &filename) const
Trying to open a file.
Definition: matrix.hxx:1223
void markAsModified() const
Mark the matrix as modified.
Definition: matrix.hxx:516
Matrix()
Default Constructor.
Definition: matrix.hxx:201
void makeAllEntriesAbsolute()
Make all entries absolute.
Definition: matrix.hxx:1435
T Type
Type.
Definition: matrix.h:47
void circularShiftRows(uint count)
Shift all rows.
Definition: matrix.hxx:1661
Matrix & operator=(const Matrix &rhs)
Assignement.
Definition: matrix.hxx:1560
@ filesizeHardLimit
A Hard-coded maximum filesize.
Definition: matrix.h:91
ColumnType & column(uint n)
Get the Nth column.
Definition: matrix.hxx:1742
Matrix & operator=(const Matrix< U > &rhs)
Assignement.
bool forceReload(bool reload=false) const
Force the Load of data (if not done) for the next save and mark the matrix as modified.
Definition: matrix.hxx:374
typename Antares::Memory::Stored< T >::Type ColumnType
Column type.
Definition: matrix.h:62
bool empty() const
Get if the matrix is empty.
Definition: matrix.hxx:525
T * TypePtr
Pointer.
Definition: matrix.h:49
ColumnType * entry
All entries of the matrix (bidimensional array)
Definition: matrix.h:445
bool containsOnlyZero() const
Get if the matrix only contains zero.
Definition: matrix.hxx:1134
ReadWriteT ReadWriteType
Read / Write type.
Definition: matrix.h:54
Matrix< T, ReadWriteT > MatrixType
Matrix type.
Definition: matrix.h:51
void roundAllEntries()
Round all entries.
Definition: matrix.hxx:1422
void resize(uint w, uint h, bool fixedSize=false)
Resize the matrix.
Definition: matrix.hxx:554
T findUpperBound() const
Find the upper bound.
Definition: matrix.hxx:1466
virtual ~Matrix()
Destructor.
Definition: matrix.hxx:275
void resizeWithoutDataLost(uint x, uint y, const T &defVal=T())
Resize the matrix without destroying its content.
Definition: matrix.hxx:1296
void swap(MatrixType &rhs) noexcept
Swap contents of Matrix with another.
Definition: matrix.hxx:1549
void print() const
Print the matrix to std::cout (debug)
Definition: matrix.hxx:1596
void clear()
Empty the matrix.
Definition: matrix.hxx:531
void fill(const T &v)
Fill the matrix with a given value.
Definition: matrix.hxx:347
std::set< MatrixPtr > Vector
Vector.
Definition: matrix.h:59
void multiplyColumnBy(uint x, const U &c)
Multiply or divide a column by a given value.
Definition: matrix.hxx:1398
Yuni::Clob BufferType
A buffer, for large amount of data.
Definition: matrix.h:65
uint width
Width of the matrix.
Definition: matrix.h:441
void averageTimeseries(bool roundValues=true)
Compute the average of all timeseries (derated mode)
Definition: matrix.hxx:302
virtual bool loadFromCSVFile(const AnyString &filename, uint minWidth, uint maxHeight, uint options=optNone, BufferType *buffer=NULL)
Load entries from a CSV file.
Definition: matrix.hxx:424
void unloadFromMemory() const
Try to remove from memory all data from the matrix.
Definition: matrix.hxx:1624
void fillColumn(uint x, const T &value)
Set a entire column with a given value.
Definition: matrix.hxx:491
void fillUnit()
Make the matrix an unit matrix (identity matrix)
Definition: matrix.hxx:361
T findLowerBound() const
Find the lower bound.
Definition: matrix.hxx:1448
bool saveToCSVFile(const AnyString &filename, uint precision=6, bool print_dimensions=false, bool saveEvenIfAllZero=false) const
Write the content of a matrix into a single file.
Definition: matrix.hxx:445
void multiplyAllEntriesBy(const U &c)
Multiply all entries by a given value.
Definition: matrix.hxx:1371