Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
Antares::Matrix< T, ReadWriteT > Class Template Reference

A n-by-n matrix. More...

#include <matrix.h>

Classes

struct  PredicateIdentity
 

Public Types

enum  Options {
  optNone = 0 , optFixedSize = 1 , optQuiet = 2 , optImmediate = 4 ,
  optMarkAsModified = 8 , optNoWarnIfEmpty = 16 , optNeverFails = 32
}
 Options when loading a file. More...
 
enum  { filesizeHardLimit = 1536 * 1024 * 1024 }
 
using Type = T
 Type.
 
using TypePtr = T*
 Pointer.
 
using MatrixType = Matrix<T, ReadWriteT>
 Matrix type.
 
using ReadWriteType = ReadWriteT
 Read / Write type.
 
using MatrixPtr = Matrix<T>*
 Pointer.
 
using Vector = std::set<MatrixPtr>
 Vector.
 
using ColumnType = typename Antares::Memory::Stored<T>::Type
 Column type.
 
using BufferType = Yuni::Clob
 A buffer, for large amount of data.
 

Public Member Functions

template<class U >
Matrix< T, ReadWriteT > & operator= (const Matrix< U > &rhs)
 
Constructors & Destructor
 Matrix ()
 Default Constructor.
 
 Matrix (const Matrix &rhs)
 Copy constructor.
 
 Matrix (Matrix &&rhs) noexcept
 Move constructor.
 
template<class U , class V >
 Matrix (const Matrix< U, V > &rhs)
 Copy constructor.
 
 Matrix (uint w, uint h)
 Constructor with a initial size.
 
virtual ~Matrix ()
 Destructor.
 
Copy / Paste
template<class U , class V >
void copyFrom (const Matrix< U, V > &rhs)
 Copy values from another matrix.
 
template<class U , class V >
void copyFrom (const Matrix< U, V > *rhs)
 
void swap (MatrixType &rhs) noexcept
 Swap contents of Matrix with another.
 
File manipulation
virtual bool loadFromCSVFile (const AnyString &filename, uint minWidth, uint maxHeight, uint options=optNone, BufferType *buffer=NULL)
 Load entries from a CSV file.
 
bool loadFromCSVFile (const AnyString &filename, uint minWidth, uint maxHeight, BufferType *buffer)
 
bool loadFromCSVFile (const AnyString &filename)
 
virtual bool openFile (Yuni::IO::File::Stream &file, const AnyString &filename) const
 Trying to open a file.
 
virtual void saveBufferToFile (std::string &buffer, Yuni::IO::File::Stream &f) const
 
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.
 
template<class PredicateT >
bool saveToCSVFile (const AnyString &filename, uint precision, bool print_dimensions, PredicateT &predicate, bool saveEvenIfAllZero=false) const
 Write the content of a matrix into a single file.
 
virtual Yuni::IO::Error loadFromFileToBuffer (BufferType &buffer, const AnyString &filename) const
 
template<class PredicateT >
void saveToFileDescriptor (std::string &data, uint precision, bool print_dimensions, PredicateT &predicate) const
 
Operations on columns and rows
void resize (uint w, uint h, bool fixedSize=false)
 Resize the matrix.
 
void resizeWithoutDataLost (uint x, uint y, const T &defVal=T())
 Resize the matrix without destroying its content.
 
void clear ()
 Empty the matrix.
 
void reset ()
 Empty the matrix and mark it as modified.
 
void reset (uint w, uint h, bool fixedSize=false)
 Resize a matrix and reset its values.
 
ColumnTypecolumn (uint n)
 Get the Nth column.
 
const ColumnTypecolumn (uint n) const
 Get the Nth column (const)
 
void zero ()
 Make the matrix a zero matrix.
 
void fill (const T &v)
 Fill the matrix with a given value.
 
void fillUnit ()
 Make the matrix an unit matrix (identity matrix)
 
template<class U >
void multiplyAllEntriesBy (const U &c)
 Multiply all entries by a given value.
 
template<class U >
void multiplyColumnBy (uint x, const U &c)
 Multiply or divide a column by a given value.
 
template<class U >
void divideColumnBy (uint x, const U &c)
 
void averageTimeseries (bool roundValues=true)
 Compute the average of all timeseries (derated mode)
 
void roundAllEntries ()
 Round all entries.
 
findLowerBound () const
 Find the lower bound.
 
findUpperBound () const
 Find the upper bound.
 
void makeAllEntriesAbsolute ()
 Make all entries absolute.
 
template<class U >
void pasteToColumn (uint x, const U *data)
 Copy values into a given column in the matrix.
 
void fillColumn (uint x, const T &value)
 Set a entire column with a given value.
 
void columnToZero (uint x)
 Set to zero a entire column.
 
bool containsOnlyZero () const
 Get if the matrix only contains zero.
 
template<class PredicateT >
bool containsOnlyZero (PredicateT &predicate) const
 Get if the matrix only contains zero.
 
void circularShiftRows (uint count)
 Shift all rows.
 
void circularShiftRows (uint column, uint count)
 Shift all rows of a specific column.
 
Memory Management
bool forceReload (bool reload=false) const
 Force the Load of data (if not done) for the next save and mark the matrix as modified.
 
void unloadFromMemory () const
 Try to remove from memory all data from the matrix.
 
void markAsModified () const
 Mark the matrix as modified.
 
bool empty () const
 Get if the matrix is empty.
 
void print () const
 Print the matrix to std::cout (debug)
 

Operators

uint width
 Width of the matrix.
 
uint height
 Height of the matrix.
 
ColumnTypeentry
 All entries of the matrix (bidimensional array)
 
JIT::Informationsjit
 Just-in-time informations.
 
Matrixoperator= (const Matrix &rhs)
 Assignement.
 
Matrixoperator= (Matrix &&rhs) noexcept
 
template<class U >
Matrixoperator= (const Matrix< U > &rhs)
 Assignement.
 
ColumnTypeoperator[] (uint column)
 operator []
 
const ColumnTypeoperator[] (uint column) const
 
void saveToBuffer (std::string &data, uint precision=6) const
 
template<class PredicateT >
void saveToBuffer (std::string &data, uint precision, bool print_dimensions, PredicateT &predicate, bool saveEvenIfAllZero) const
 

Detailed Description

template<class T, class ReadWriteT>
class Antares::Matrix< T, ReadWriteT >

A n-by-n matrix.

Template Parameters
TA pod type for each cell of the matrix
ReadWriteTThe type to use when reading/saving the matrix

Member Enumeration Documentation

◆ anonymous enum

template<class T , class ReadWriteT >
anonymous enum
Enumerator
filesizeHardLimit 

A Hard-coded maximum filesize.

◆ Options

template<class T , class ReadWriteT >
enum Antares::Matrix::Options

Options when loading a file.

Enumerator
optNone 

None.

optFixedSize 

The matrix can not see its size modified.

optQuiet 

Do not produce warnings/errors.

optImmediate 

Do not postpone the loading.

optMarkAsModified 

mark the matrix as modified after loading

optNoWarnIfEmpty 

Do not warn if the file is empty.

optNeverFails 

The loading never fails.

Member Function Documentation

◆ columnToZero()

template<class T , class ReadWriteT >
void Antares::Matrix< T, ReadWriteT >::columnToZero ( uint x)
inline

Set to zero a entire column.

Parameters
xThe column index (zero-based)

◆ containsOnlyZero()

template<class T , class ReadWriteT >
template<class PredicateT >
bool Antares::Matrix< T, ReadWriteT >::containsOnlyZero ( PredicateT & predicate) const

Get if the matrix only contains zero.

Parameters
predicateA predicate to modify the values on the fly

◆ empty()

template<class T , class ReadWriteT >
bool Antares::Matrix< T, ReadWriteT >::empty ( ) const
inline

Get if the matrix is empty.

This method is equivalent to :

if (!matrix.width() || !matrix.height())
; // empty

◆ fillColumn()

template<class T , class ReadWriteT >
void Antares::Matrix< T, ReadWriteT >::fillColumn ( uint x,
const T & value )

Set a entire column with a given value.

Parameters
xThe column index (zero-based)
dataThe data to copy

◆ forceReload()

template<class T , class ReadWriteT >
bool Antares::Matrix< T, ReadWriteT >::forceReload ( bool reload = false) const

Force the Load of data (if not done) for the next save and mark the matrix as modified.

This method is only useful if the load-on-demand is used. The matrix will be marked as modified to force the written.

Parameters
reloadTrue to load all JIT data
Returns
True if the data was really loaded (reload = true)

◆ loadFromCSVFile()

template<class T , class ReadWriteT >
bool Antares::Matrix< T, ReadWriteT >::loadFromCSVFile ( const AnyString & filename,
uint minWidth,
uint maxHeight,
uint options = optNone,
BufferType * buffer = NULL )
virtual

Load entries from a CSV file.

The data might not be actually loaded, if the load-on-demand is enabled. If the param fixedSize is false, the number of columns will be automatically detected from the first row in the CSV file.

Parameters
filenameA filename to a CSV file
minWidthThe minimum allowed width
maxHeightThe new height
fixedSizeTrue to not automatically determine the width of the matrix
warningTrue to produce warnings when an error occurs
immediateTrue to not postpone the loading
bufferAn optional buffer for reading the file
Returns
True if the operation succeeded

Reimplemented in Matrix_load_bypass< T, ReadWriteT >.

◆ markAsModified()

template<class T , class ReadWriteT >
void Antares::Matrix< T, ReadWriteT >::markAsModified ( ) const
inline

Mark the matrix as modified.

This routine has no effect when the UI is not present

◆ openFile()

template<class T , class ReadWriteT >
bool Antares::Matrix< T, ReadWriteT >::openFile ( Yuni::IO::File::Stream & file,
const AnyString & filename ) const
virtual

Trying to open a file.

Parameters
fileThe file object
filenameThe full path of the file we try to open
Returns
True if file could be opened, False otherwise (no enough permission or wrong path)

Reimplemented in Matrix_easy_to_fill< T, ReadWriteT >, and Matrix_easy_to_fill< double, double >.

◆ pasteToColumn()

template<class T , class ReadWriteT >
template<class U >
void Antares::Matrix< T, ReadWriteT >::pasteToColumn ( uint x,
const U * data )

Copy values into a given column in the matrix.

Parameters
xThe column index (zero-based)
dataThe data to copy

◆ reset()

template<class T , class ReadWriteT >
void Antares::Matrix< T, ReadWriteT >::reset ( uint w,
uint h,
bool fixedSize = false )
inline

Resize a matrix and reset its values.

Parameters
heightThe height of the matrix
See also
resize()
zero()

◆ resize()

template<class T , class ReadWriteT >
void Antares::Matrix< T, ReadWriteT >::resize ( uint w,
uint h,
bool fixedSize = false )

Resize the matrix.

All data will be lost in the process.

Parameters
wThe new width
hThe new height

◆ saveToCSVFile() [1/2]

template<class T , class ReadWriteT >
template<class PredicateT >
bool Antares::Matrix< T, ReadWriteT >::saveToCSVFile ( const AnyString & filename,
uint precision,
bool print_dimensions,
PredicateT & predicate,
bool saveEvenIfAllZero = false ) const

Write the content of a matrix into a single file.

If JIT is enabled, the matrix will be resized to 0x0 if the write is successful.

Parameters
mThe matrix
filenameThe file where to write data
predicateA predicate for modyfing values on the fly
Returns
A non-zero value if the operation succeeded, 0 otherwise

◆ saveToCSVFile() [2/2]

template<class T , class ReadWriteT >
bool Antares::Matrix< T, ReadWriteT >::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.

If JIT is enabled, the matrix will be resized to 0x0 if the write is successful.

Parameters
mThe matrix
filenameThe file where to write data
Returns
A non-zero value if the operation succeeded, 0 otherwise

◆ unloadFromMemory()

template<class T , class ReadWriteT >
void Antares::Matrix< T, ReadWriteT >::unloadFromMemory ( ) const

Try to remove from memory all data from the matrix.

This is possible only when enough informations is provided by the JIT structure and when the matrix is not modified


The documentation for this class was generated from the following files: