MLIR  18.0.0git
Public Member Functions | Static Public Member Functions | List of all members
mlir::presburger::Matrix< T > Class Template Reference

This is a class to represent a resizable matrix. More...

#include "mlir/Analysis/Presburger/Matrix.h"

+ Inheritance diagram for mlir::presburger::Matrix< T >:

Public Member Functions

 Matrix ()=delete
 
 Matrix (unsigned rows, unsigned columns, unsigned reservedRows=0, unsigned reservedColumns=0)
 Construct a matrix with the specified number of rows and columns. More...
 
T & at (unsigned row, unsigned column)
 Access the element at the specified row and column. More...
 
at (unsigned row, unsigned column) const
 
T & operator() (unsigned row, unsigned column)
 
operator() (unsigned row, unsigned column) const
 
void swapColumns (unsigned column, unsigned otherColumn)
 Swap the given columns. More...
 
void swapRows (unsigned row, unsigned otherRow)
 Swap the given rows. More...
 
unsigned getNumRows () const
 
unsigned getNumColumns () const
 
unsigned getNumReservedRows () const
 Return the maximum number of rows/columns that can be added without incurring a reallocation. More...
 
unsigned getNumReservedColumns () const
 
void reserveRows (unsigned rows)
 Reserve enough space to resize to the specified number of rows without reallocations. More...
 
MutableArrayRef< T > getRow (unsigned row)
 Get a [Mutable]ArrayRef corresponding to the specified row. More...
 
ArrayRef< T > getRow (unsigned row) const
 
void setRow (unsigned row, ArrayRef< T > elems)
 Set the specified row to elems. More...
 
void insertColumns (unsigned pos, unsigned count)
 Insert columns having positions pos, pos + 1, ... More...
 
void insertColumn (unsigned pos)
 
void insertRows (unsigned pos, unsigned count)
 Insert rows having positions pos, pos + 1, ... More...
 
void insertRow (unsigned pos)
 
void removeColumns (unsigned pos, unsigned count)
 Remove the columns having positions pos, pos + 1, ... More...
 
void removeColumn (unsigned pos)
 
void removeRows (unsigned pos, unsigned count)
 Remove the rows having positions pos, pos + 1, ... More...
 
void removeRow (unsigned pos)
 
void copyRow (unsigned sourceRow, unsigned targetRow)
 
void fillRow (unsigned row, const T &value)
 
void fillRow (unsigned row, int64_t value)
 
void addToRow (unsigned sourceRow, unsigned targetRow, const T &scale)
 Add scale multiples of the source row to the target row. More...
 
void addToRow (unsigned sourceRow, unsigned targetRow, int64_t scale)
 
void addToRow (unsigned row, ArrayRef< T > rowVec, const T &scale)
 Add scale multiples of the rowVec row to the specified row. More...
 
void addToColumn (unsigned sourceColumn, unsigned targetColumn, const T &scale)
 Add scale multiples of the source column to the target column. More...
 
void addToColumn (unsigned sourceColumn, unsigned targetColumn, int64_t scale)
 
void negateColumn (unsigned column)
 Negate the specified column. More...
 
void negateRow (unsigned row)
 Negate the specified row. More...
 
SmallVector< T, 8 > preMultiplyWithRow (ArrayRef< T > rowVec) const
 The given vector is interpreted as a row vector v. More...
 
SmallVector< T, 8 > postMultiplyWithColumn (ArrayRef< T > colVec) const
 The given vector is interpreted as a column vector v. More...
 
void resize (unsigned newNRows, unsigned newNColumns)
 Resize the matrix to the specified dimensions. More...
 
void resizeHorizontally (unsigned newNColumns)
 
void resizeVertically (unsigned newNRows)
 
unsigned appendExtraRow ()
 Add an extra row at the bottom of the matrix and return its position. More...
 
unsigned appendExtraRow (ArrayRef< T > elems)
 Same as above, but copy the given elements into the row. More...
 
void print (raw_ostream &os) const
 Print the matrix. More...
 
void dump () const
 
bool hasConsistentState () const
 Return whether the Matrix is in a consistent state with all its invariants satisfied. More...
 

Static Public Member Functions

static Matrix identity (unsigned dimension)
 Return the identity matrix of the specified dimension. More...
 

Detailed Description

template<typename T>
class mlir::presburger::Matrix< T >

This is a class to represent a resizable matrix.

More columns and rows can be reserved than are currently used. The data is stored as a single 1D array, viewed as a 2D matrix with nRows rows and nReservedColumns columns, stored in row major form. Thus the element at (i, j) is stored at data[i*nReservedColumns + j]. The reserved but unused columns always have all zero values. The reserved rows are just reserved space in the underlying SmallVector's capacity. This class only works for the types MPInt and Fraction, since the method implementations are in the Matrix.cpp file. Only these two types have been explicitly instantiated there.

Definition at line 40 of file Matrix.h.

Constructor & Destructor Documentation

◆ Matrix() [1/2]

template<typename T >
mlir::presburger::Matrix< T >::Matrix ( )
delete

◆ Matrix() [2/2]

template<typename T >
Matrix::Matrix ( unsigned  rows,
unsigned  columns,
unsigned  reservedRows = 0,
unsigned  reservedColumns = 0 
)

Construct a matrix with the specified number of rows and columns.

The number of reserved rows and columns will be at least the number specified, and will always be sufficient to accomodate the number of rows and columns specified.

Initially, the entries are initialized to ero.

Definition at line 17 of file Matrix.cpp.

References max().

Member Function Documentation

◆ addToColumn() [1/2]

template<typename T >
void Matrix::addToColumn ( unsigned  sourceColumn,
unsigned  targetColumn,
const T &  scale 
)

◆ addToColumn() [2/2]

template<typename T >
void mlir::presburger::Matrix< T >::addToColumn ( unsigned  sourceColumn,
unsigned  targetColumn,
int64_t  scale 
)
inline

Definition at line 148 of file Matrix.h.

References mlir::presburger::Matrix< T >::addToColumn().

◆ addToRow() [1/3]

template<typename T >
void Matrix::addToRow ( unsigned  row,
ArrayRef< T >  rowVec,
const T &  scale 
)

Add scale multiples of the rowVec row to the specified row.

Definition at line 200 of file Matrix.cpp.

◆ addToRow() [2/3]

template<typename T >
void Matrix::addToRow ( unsigned  sourceRow,
unsigned  targetRow,
const T &  scale 
)

Add scale multiples of the source row to the target row.

Definition at line 195 of file Matrix.cpp.

Referenced by mlir::presburger::Matrix< T >::addToRow(), and mlir::presburger::MultiAffineFunction::subtract().

◆ addToRow() [3/3]

template<typename T >
void mlir::presburger::Matrix< T >::addToRow ( unsigned  sourceRow,
unsigned  targetRow,
int64_t  scale 
)
inline

Definition at line 139 of file Matrix.h.

References mlir::presburger::Matrix< T >::addToRow().

◆ appendExtraRow() [1/2]

template<typename T >
unsigned Matrix::appendExtraRow

◆ appendExtraRow() [2/2]

template<typename T >
unsigned Matrix::appendExtraRow ( ArrayRef< T >  elems)

Same as above, but copy the given elements into the row.

The length of elems must be equal to the number of columns.

Definition at line 45 of file Matrix.cpp.

◆ at() [1/2]

template<typename T >
T& mlir::presburger::Matrix< T >::at ( unsigned  row,
unsigned  column 
)
inline

Access the element at the specified row and column.

Definition at line 58 of file Matrix.h.

Referenced by mlir::presburger::Matrix< T >::operator()().

◆ at() [2/2]

template<typename T >
T mlir::presburger::Matrix< T >::at ( unsigned  row,
unsigned  column 
) const
inline

Definition at line 64 of file Matrix.h.

◆ copyRow()

template<typename T >
void Matrix::copyRow ( unsigned  sourceRow,
unsigned  targetRow 
)

◆ dump()

template<typename T >
void Matrix::dump

Definition at line 270 of file Matrix.cpp.

References print().

◆ fillRow() [1/2]

template<typename T >
void Matrix::fillRow ( unsigned  row,
const T &  value 
)

◆ fillRow() [2/2]

template<typename T >
void mlir::presburger::Matrix< T >::fillRow ( unsigned  row,
int64_t  value 
)
inline

◆ getNumColumns()

template<typename T >
unsigned mlir::presburger::Matrix< T >::getNumColumns ( ) const
inline

◆ getNumReservedColumns()

template<typename T >
unsigned mlir::presburger::Matrix< T >::getNumReservedColumns ( ) const
inline

Definition at line 89 of file Matrix.h.

◆ getNumReservedRows()

template<typename T >
unsigned Matrix::getNumReservedRows

Return the maximum number of rows/columns that can be added without incurring a reallocation.

Definition at line 32 of file Matrix.cpp.

Referenced by mlir::presburger::IntegerRelation::getNumReservedEqualities(), and mlir::presburger::IntegerRelation::getNumReservedInequalities().

◆ getNumRows()

template<typename T >
unsigned mlir::presburger::Matrix< T >::getNumRows ( ) const
inline

◆ getRow() [1/2]

template<typename T >
MutableArrayRef< T > Matrix::getRow ( unsigned  row)

◆ getRow() [2/2]

template<typename T >
ArrayRef< T > Matrix::getRow ( unsigned  row) const

Definition at line 92 of file Matrix.cpp.

◆ hasConsistentState()

template<typename T >
bool Matrix::hasConsistentState

Return whether the Matrix is in a consistent state with all its invariants satisfied.

Definition at line 272 of file Matrix.cpp.

Referenced by mlir::presburger::IntegerRelation::hasConsistentState().

◆ identity()

template<typename T >
Matrix< T > Matrix::identity ( unsigned  dimension)
static

Return the identity matrix of the specified dimension.

Definition at line 25 of file Matrix.cpp.

◆ insertColumn()

template<typename T >
void Matrix::insertColumn ( unsigned  pos)

Definition at line 103 of file Matrix.cpp.

Referenced by mlir::presburger::DivisionRepr::insertDiv().

◆ insertColumns()

template<typename T >
void Matrix::insertColumns ( unsigned  pos,
unsigned  count 
)

Insert columns having positions pos, pos + 1, ...

pos + count - 1. Columns that were at positions 0 to pos - 1 will stay where they are; columns that were at positions pos to nColumns - 1 will be pushed to the right. pos should be at most nColumns.

Definition at line 104 of file Matrix.cpp.

Referenced by mlir::presburger::DivisionRepr::insertDiv(), and mlir::presburger::MultiAffineFunction::mergeDivs().

◆ insertRow()

template<typename T >
void Matrix::insertRow ( unsigned  pos)

Definition at line 159 of file Matrix.cpp.

◆ insertRows()

template<typename T >
void Matrix::insertRows ( unsigned  pos,
unsigned  count 
)

Insert rows having positions pos, pos + 1, ...

pos + count - 1. Rows that were at positions 0 to pos - 1 will stay where they are; rows that were at positions pos to nColumns - 1 will be pushed to the right. pos should be at most nRows.

Definition at line 160 of file Matrix.cpp.

Referenced by mlir::presburger::DivisionRepr::insertDiv().

◆ negateColumn()

template<typename T >
void Matrix::negateColumn ( unsigned  column)

Negate the specified column.

Definition at line 216 of file Matrix.cpp.

Referenced by mlir::presburger::IntMatrix::computeHermiteNormalForm().

◆ negateRow()

template<typename T >
void Matrix::negateRow ( unsigned  row)

◆ operator()() [1/2]

template<typename T >
T& mlir::presburger::Matrix< T >::operator() ( unsigned  row,
unsigned  column 
)
inline

Definition at line 70 of file Matrix.h.

References mlir::presburger::Matrix< T >::at().

◆ operator()() [2/2]

template<typename T >
T mlir::presburger::Matrix< T >::operator() ( unsigned  row,
unsigned  column 
) const
inline

Definition at line 72 of file Matrix.h.

References mlir::presburger::Matrix< T >::at().

◆ postMultiplyWithColumn()

template<typename T >
SmallVector< T, 8 > Matrix::postMultiplyWithColumn ( ArrayRef< T >  colVec) const

The given vector is interpreted as a column vector v.

Pre-multiply v with this matrix, say M, and return Mv.

Definition at line 237 of file Matrix.cpp.

Referenced by mlir::presburger::LinearTransform::postMultiplyWithColumn(), and mlir::presburger::MultiAffineFunction::valueAt().

◆ preMultiplyWithRow()

template<typename T >
SmallVector< T, 8 > Matrix::preMultiplyWithRow ( ArrayRef< T >  rowVec) const

The given vector is interpreted as a row vector v.

Post-multiply v with this matrix, say M, and return vM.

Definition at line 226 of file Matrix.cpp.

Referenced by mlir::presburger::LinearTransform::preMultiplyWithRow().

◆ print()

template<typename T >
void Matrix::print ( raw_ostream &  os) const

Print the matrix.

Definition at line 262 of file Matrix.cpp.

Referenced by mlir::presburger::MultiAffineFunction::print(), and mlir::presburger::DivisionRepr::print().

◆ removeColumn()

template<typename T >
void Matrix::removeColumn ( unsigned  pos)

◆ removeColumns()

template<typename T >
void Matrix::removeColumns ( unsigned  pos,
unsigned  count 
)

Remove the columns having positions pos, pos + 1, ...

pos + count - 1. Rows that were at positions 0 to pos - 1 will stay where they are; columns that were at positions pos + count - 1 or later will be pushed to the right. The columns to be deleted must be valid rows: pos + count - 1 must be at most nColumns - 1.

Definition at line 146 of file Matrix.cpp.

◆ removeRow()

template<typename T >
void Matrix::removeRow ( unsigned  pos)

◆ removeRows()

template<typename T >
void Matrix::removeRows ( unsigned  pos,
unsigned  count 
)

Remove the rows having positions pos, pos + 1, ...

pos + count - 1. Rows that were at positions 0 to pos - 1 will stay where they are; rows that were at positions pos + count - 1 or later will be pushed to the right. The rows to be deleted must be valid rows: pos + count - 1 must be at most nRows - 1.

Definition at line 174 of file Matrix.cpp.

Referenced by mlir::presburger::IntegerRelation::removeEqualityRange(), mlir::presburger::IntegerRelation::removeInequalityRange(), and mlir::presburger::MultiAffineFunction::removeOutputs().

◆ reserveRows()

template<typename T >
void Matrix::reserveRows ( unsigned  rows)

Reserve enough space to resize to the specified number of rows without reallocations.

Definition at line 36 of file Matrix.cpp.

Referenced by mlir::presburger::IntegerRelation::append(), and mlir::presburger::Simplex::makeProduct().

◆ resize()

template<typename T >
void Matrix::resize ( unsigned  newNRows,
unsigned  newNColumns 
)

Resize the matrix to the specified dimensions.

If a dimension is smaller, the values are truncated; if it is bigger, the new values are initialized to zero.

Due to the representation of the matrix, resizing vertically (adding rows) is less expensive than increasing the number of columns beyond nReservedColumns.

Definition at line 60 of file Matrix.cpp.

◆ resizeHorizontally()

template<typename T >
void Matrix::resizeHorizontally ( unsigned  newNColumns)

◆ resizeVertically()

template<typename T >
void Matrix::resizeVertically ( unsigned  newNRows)

◆ setRow()

template<typename T >
void Matrix::setRow ( unsigned  row,
ArrayRef< T >  elems 
)

Set the specified row to elems.

Definition at line 96 of file Matrix.cpp.

Referenced by mlir::presburger::DivisionRepr::setDiv().

◆ swapColumns()

template<typename T >
void Matrix::swapColumns ( unsigned  column,
unsigned  otherColumn 
)

◆ swapRows()

template<typename T >
void Matrix::swapRows ( unsigned  row,
unsigned  otherRow 
)

Swap the given rows.

Definition at line 70 of file Matrix.cpp.

Referenced by mlir::presburger::SimplexBase::swapRows().


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