21#ifndef __ANTARES_LIBS_ARRAY_MATRIX_H__
22#define __ANTARES_LIBS_ARRAY_MATRIX_H__
28#include <yuni/io/file.h>
30#include <antares/memory/memory.h>
31#include "antares/jit/jit.h"
42template<
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*;
550int MatrixTestForPositiveValues(
const char* msg,
const Matrix<>* m);
559int MatrixTestIfValuesAreHigherThan(
const char* msg,
const Matrix<>* m,
const double value);
568int MatrixTestIfValuesAreLowerThan(
const char* msg,
const Matrix<>* m,
const double value);
576int MatrixTestForNegativeValues(
const char* msg,
const Matrix<>* m);
584int MatrixTestForPositiveValues_LimitWidth(
const char* msg,
const Matrix<>* m, uint maxWidth);
592template<
class T1,
class T2>
593bool MatrixTestForAtLeastOnePositiveValue(
const Matrix<T1, T2>& m);
A n-by-n matrix.
Definition jit.h:30
JIT::Informations * jit
Just-in-time informations.
Definition matrix.h:447
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:446
@ filesizeHardLimit
A Hard-coded maximum filesize.
Definition matrix.h:91
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
void swap(MatrixType &rhs) noexcept
Swap contents of Matrix with another.
Definition matrix.hxx:1569
void multiplyColumnBy(uint x, const U &c)
Multiply or divide a column by a given value.
Definition matrix.hxx:1418
void fillUnit()
Make the matrix an unit matrix (identity matrix)
Definition matrix.hxx:362
virtual ~Matrix()
Destructor.
Definition matrix.hxx:276
void reset()
Empty the matrix and mark it as modified.
Definition matrix.hxx:548
ColumnType & operator[](uint column)
operator []
Definition matrix.hxx:1746
T Type
Type.
Definition matrix.h:47
void unloadFromMemory() const
Try to remove from memory all data from the matrix.
Definition matrix.hxx:1644
void fill(const T &v)
Fill the matrix with a given value.
Definition matrix.hxx:348
Matrix & operator=(const Matrix &rhs)
Assignement.
Definition matrix.hxx:1580
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:375
Matrix & operator=(const Matrix< U > &rhs)
Assignement.
T findLowerBound() const
Find the lower bound.
Definition matrix.hxx:1468
void pasteToColumn(uint x, const U *data)
Copy values into a given column in the matrix.
Definition matrix.hxx:468
typename Antares::Memory::Stored< T >::Type ColumnType
Column type.
Definition matrix.h:62
T * TypePtr
Pointer.
Definition matrix.h:49
ColumnType * entry
All entries of the matrix (bidimensional array)
Definition matrix.h:445
T findUpperBound() const
Find the upper bound.
Definition matrix.hxx:1486
void print() const
Print the matrix to std::cout (debug)
Definition matrix.hxx:1616
bool empty() const
Get if the matrix is empty.
Definition matrix.hxx:526
ReadWriteT ReadWriteType
Read / Write type.
Definition matrix.h:54
Matrix< T, ReadWriteT > MatrixType
Matrix type.
Definition matrix.h:51
void zero()
Make the matrix a zero matrix.
Definition matrix.hxx:293
uint width
Width of the matrix.
Definition matrix.h:441
void markAsModified() const
Mark the matrix as modified.
Definition matrix.hxx:517
ColumnType & column(uint n)
Get the Nth column.
Definition matrix.hxx:1762
uint height
Height of the matrix.
Definition matrix.h:443
void columnToZero(uint x)
Set to zero a entire column.
Definition matrix.hxx:506
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:425
void fillColumn(uint x, const T &value)
Set a entire column with a given value.
Definition matrix.hxx:492
void copyFrom(const Matrix< U, V > &rhs)
Copy values from another matrix.
Definition matrix.hxx:1505
void makeAllEntriesAbsolute()
Make all entries absolute.
Definition matrix.hxx:1455
bool containsOnlyZero() const
Get if the matrix only contains zero.
Definition matrix.hxx:1150
void circularShiftRows(uint count)
Shift all rows.
Definition matrix.hxx:1681
std::set< MatrixPtr > Vector
Vector.
Definition matrix.h:59
void resizeWithoutDataLost(uint x, uint y, const T &defVal=T())
Resize the matrix without destroying its content.
Definition matrix.hxx:1316
void averageTimeseries(bool roundValues=true)
Compute the average of all timeseries (derated mode)
Definition matrix.hxx:303
Matrix()
Default Constructor.
Definition matrix.hxx:202
Yuni::Clob BufferType
A buffer, for large amount of data.
Definition matrix.h:65
void resize(uint w, uint h, bool fixedSize=false)
Resize the matrix.
Definition matrix.hxx:555
void multiplyAllEntriesBy(const U &c)
Multiply all entries by a given value.
Definition matrix.hxx:1391
void clear()
Empty the matrix.
Definition matrix.hxx:532
void roundAllEntries()
Round all entries.
Definition matrix.hxx:1442
virtual bool openFile(Yuni::IO::File::Stream &file, const AnyString &filename) const
Trying to open a file.
Definition matrix.hxx:1239