Into

Modules

Documentation

classPiiMatrix< T,-1,-1 >

#include <PiiMatrix.h>

A two-dimensional array that models the matrix concept.

Inherits PiiTypelessMatrix, PiiConceptualMatrix< PiiMatrix< T,-1,-1 >, Pii::RandomAccessMatrix >

Description

PiiMatrix only supports POD (plain old data) types as the content type. It will call neither constructors nor destructors. The data of a matrix is cleared by simply setting all bytes to zero, and assignments may be performed with memcpy(). If matrix atrithmetic is to be performed, the corresponding operators of the content type must be defined. Furthermore, for some operations, there must be a constructor for a single numeric argument. An example of a class that can be used as the content type:

 struct MyClass
 {
   MyClass(int i=0, double d=0.0);

   void operator+= (const MyClass&);
   void operator-= (const MyClass&);
   void operator*= (const MyClass&);
   void operator/= (const MyClass&);
   MyClass operator+ (const MyClass&) const;
   MyClass operator- (const MyClass&) const;
   MyClass operator* (const MyClass&) const;
   MyClass operator/ (const MyClass&) const;

   int iValue;
   double dValue;
 };


 PiiMatrix<MyClass> mat(1,1); //resets both ivalue and dvalue to zero
 MyClass mc(1, 2.0);
 mat(0,0) = mc;
 mat *= mc;

Row and column indices in PiiMatrix are always zero-based. The convention in matrix math is to index rows first, and that is what PiiMatrix also does. For performance reasons there is no bound checking. Thus, make sure you don't reference memory outside of the matrix.

Most routines that perform matrix math may throw a PiiMathException. Such an exception may be thrown if the sizes of two matrices do not match for calculation.

The data within a matrix is organized so that the items in a row (scan line) always occupy adjacent memory locations. The pointer to the beginning to each row is returned by row(int). Each row is aligned at a four-byte boundary (unless initialized with an external non-aligned buffer). Therefore, if the data type is less than four bytes wide, it may happen that rows are not stored sequentially.

Usually, matrices use an internally allocated buffer to store the elements. It is however possible to create matrices that refer to other matrices or externally allocated buffers. A modifiable reference to another matrix is created by the operator(int,int,int,int). Changing the contents of such a matrix will change the contents of the original matrix. Reference can be chained; a reference to a reference modifies the original.

 PiiMatrix<char> mat(8,8);
 mat = '+';
 mat(2,1,3,3) = 'a';
 mat(1,5,6,3) = 'b';
 mat(2,6,4,1) = 'c';
 mat(6,0,2,1) = 'x';
 
 //mat looks like this now:
 + + + + + + + +
 + + + + + b b b
 + a a a + b c b
 + a a a + b c b
 + a a a + b c b
 + + + + + b c b
 x + + + + b b b
 x + + + + + + +

Public types

typedef PiiMatrixTraits< PiiMatrix< T,-1,-1 >, Pii::RandomAccessMatrix >
typedef Pii::VaArg< T >::Type

Type for arguments passed through va_args.

Public member functions

Traits::column_iterator

Appends a new column to the right of the last column.

Traits::column_iterator
( )

Appends the given vector (N-by-1 matrix) as a new column to the right of the last column.

Traits::column_iterator
(
  • const T * column
)

Appends the given vector as a new column to the right of the last column.

Traits::column_iterator
(
  • VaArgType firstElement
  • ...
)

Appends the given elements as a new column to the right of the last column.

Traits::row_iterator
( )

Appends the given vector to the end of this matrix.

Traits::row_iterator
(
  • const T * row
)

Appends the given vector to the end of this matrix.

Traits::row_iterator
( )

Appends a new row to the end of the matrix.

Traits::row_iterator
(
  • VaArgType firstElement
  • ...
)

Appends the given elements as a new row to the end of this matrix.

void
( )

Append all rows in other to the end of this matrix.

template<class Matrix>
( )

Assigns the elements of other to the corresponding elements of this.

Traits::iterator
( )

Returns a random-access iterator to the start of the matrix data.

Traits::const_iterator
( )
(
  • int index
)

Returns a row vector that contains the elements of the row at index.

Traits::column_iterator
(
  • int colIndex
)

Returns a random-access iterator to the start of the column at colIndex.

Traits::const_column_iterator
(
  • int colIndex
)
Traits::const_column_iterator
(
  • int colIndex
)
Traits::column_iterator
(
  • int colIndex
)

Returns a random-access iterator to the end of the column at colIndex.

void
( )

Detaches the matrix from shared data.

Traits::iterator
( )

Returns a random-access iterator to the end of the matrix data.

Traits::const_iterator
( )
Traits::column_iterator
(
  • int index = -1
)

Inserts an empty column at the given index.

Traits::column_iterator
( )

Inserts the given column at the given index.

Traits::column_iterator
(
  • int index
  • const T * column
)

Inserts the given column at the given column index.

Traits::column_iterator
(
  • int index
  • VaArgType firstElement
  • ...
)

Inserts a column with the given data elements at the given column index.

Traits::row_iterator
(
  • int index
)

Inserts a new at position index and moves all following rows forwards.

Traits::row_iterator
( )

Inserts the given row at index.

Traits::row_iterator
(
  • int index
  • const T * row
)

Inserts the given row at the given row index.

Traits::row_iterator
(
  • int index
  • VaArgType firstElement
  • ...
)

Insert a row with the given data elements at the given row index.

template<class BinaryFunc, class Matrix>
( )

Applies the adaptable binary function to all elements of this matrix and the correspondng element in other.

template<class BinaryFunc>
(
  • BinaryFunc op
  • typename BinaryFunc::second_argument_type value
)

Applies a binary function to all elements of this matrix and the scalar value.

template<class UnaryFunc>
(
  • UnaryFunc op
)

Applies a unary function to all elements in this matrix.

template<class BinaryFunc, class Matrix>
PiiMatrix< typename BinaryFunc::result_type >
( )

Applies the adaptable binary function op to all elements of this matrix and the corresponding elements in other.

template<class BinaryFunc>
PiiMatrix< typename BinaryFunc::result_type >
(
  • BinaryFunc op
  • typename BinaryFunc::second_argument_type value
)

Applies a binary function to all elements of this matrix and the scalar value.

template<class UnaryFunc>
PiiMatrix< typename UnaryFunc::result_type >
(
  • UnaryFunc op
)

Creates a matrix that contains the result of applying a unary function to all elements in this matrix.

template<class U>

Cast the contents of a matrix to another type.

T &
(
  • int r
  • int c
)

Returns a reference to an item in the matrix.

T &
(
  • int index
)

Access the matrix along its first non-singleton dimension.

(
  • int r
  • int c
  • int rows
  • int columns
)

Returns a mutable reference to a sub-matrix.

(
  • int r
  • int c
  • int rows
  • int columns
)
template<class Matrix>
PiiFilteredMatrix< const PiiMatrix, Matrix >
( )
template<class Matrix>
( )
T
(
  • int index
)
T
(
  • int r
  • int c
)

Returns a copy of an item in the matrix.

( )

Assigns other to this and returns a reference to this.

(
  • T value
)
( )
template<class Matrix>
( )

Creates a deep copy of other and returns a reference to this.

T *
(
  • int r
)

Returns a pointer to the beginning of the given row.

const T *
(
  • int r
)
( )
( )

Constucts a shallow copy of other.

( )

Constructs an empty matrix.

(
  • int rows
  • int columns
  • const T * data
  • int stride = 0
)

Constructs a rows-by-columns matrix whose initial contents are taken from the array pointed to by data.

(
  • int rows
  • int columns
  • VaArgType firstElement
  • ...
)

Constructs a matrix with the given number of rows and columns.

( )

Constructs a rows-by-columns matrix that uses data as its data buffer.

(
  • int rows
  • int columns
)

Constucts a rows-by-columns matrix with all entries initialized to zero.

template<class Matrix>
( )

Constructs a deep copy of other by copying and typecasting each individual element.

void
(
  • int index
)

Removes a column from the matrix.

void
(
  • int index
  • int count
)

Removes count successive columns starting at index.

void
(
  • int index
)

Removes the row at index.

void
(
  • int index
  • int count
)

Removes count successive rows starting at index.

void
(
  • int rows
)

Allocates memory for at least rows matrix rows.

void
(
  • int rows
  • int columns
)

Resizes the matrix to rows-by-columns.

const T *
(
  • int index
)

Returns a pointer to the beginning of row at index.

T *
(
  • int index
)
template<class U>
U &
(
  • int index
)

A utility function that returns a reference to the memory location at the beginning of the given row as the specified type.

template<class U>
const U &
(
  • int index
)
Traits::const_row_iterator
(
  • int rowIndex
)
Traits::row_iterator
(
  • int rowIndex
)

Returns a random-access iterator to the start of the row at rowIndex.

Traits::const_row_iterator
(
  • int rowIndex
)
Traits::row_iterator
(
  • int rowIndex
)

Returns a random-access iterator to the end of the row at rowIndex.

void
(
  • int row1
  • int row2
)

Swaps the places of row1 and row2.

Destroys the matrix.

Static public member functions

static PiiMatrix
(
  • int rows
  • int columns
  • T value
)

Creates a rows-by-columns matrix whose initial contents are set to value.

static PiiMatrix
(
  • int size
)

Creates a size-by-size identity matrix.

static PiiMatrix
(
  • int rows
  • int columns
  • int stride
)

Creates rows-by-columns matrix with initial contents set to zero.

static PiiMatrix
(
  • int rows
  • int columns
  • int stride = 0
)

Creates an uninitialized rows-by-columns matrix.

Function details

  • Traits::column_iterator appendColumn

    ()
    [inline]

    Appends a new column to the right of the last column.

    See also
    • insertColumn(int)

  • Traits::column_iterator appendColumn

    ()
    [inline]

    Appends the given vector (N-by-1 matrix) as a new column to the right of the last column.

    The number of rows in this matrix must be equal to the number of rows in column, unless this matrix is empty. In that case this matrix will be set equal to column.

    See also
    • insertColumn(int, const PiiMatrix&)

  • Traits::column_iterator appendColumn

    (
    • const T * column
    )
    [inline]

    Appends the given vector as a new column to the right of the last column.

    See also
    • insertColumn(int, const T*)

  • Traits::column_iterator appendColumn

    (
    • VaArgType firstElement
    • ...
    )

    Appends the given elements as a new column to the right of the last column.

    See also
    • insertColumn(int, VaArgType, ...)

  • Traits::row_iterator appendRow

    ()
    [inline]

    Appends the given vector to the end of this matrix.

    The size of the row matrix must be 1-by-columns(), unless this matrix is empty. In that case this matrix will be set equal to row.

    See also
    • insertRow(int, const PiiMatrix&)

  • Traits::row_iterator appendRow

    (
    • const T * row
    )
    [inline]

    Appends the given vector to the end of this matrix.

    See also
    • insertRow(int, const T*)

  • Traits::row_iterator appendRow

    ()
    [inline]

    Appends a new row to the end of the matrix.

    The contents of the new row will be set to zero. Returns a row iterator to the beginning of the new row. New rows can be appended without reallocation until capacity() is exceeded.

  • Traits::row_iterator appendRow

    (
    • VaArgType firstElement
    • ...
    )

    Appends the given elements as a new row to the end of this matrix.

    The number of elements must match the number of columns in this matrix.

    See also
    • insertRow(int, VaArgType, ...)

  • void appendRows

    ()

    Append all rows in other to the end of this matrix.

    The number of columns in other must equal to that of this matrix, unless this matrix is empty. In that case this matrix will be set equal to other.

  • template<class Matrix>

    PiiMatrix & assign

    ()

    Assigns the elements of other to the corresponding elements of this.

    Exceptions
    PiiMathException&

    if other and this are not equal in size.

  • Traits::iterator begin

    ()
    [inline]

    Returns a random-access iterator to the start of the matrix data.

    Reimplemented from PiiConceptualMatrix.

  • Traits::const_iterator begin

    ()
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Reimplemented from PiiConceptualMatrix.

  • PiiMatrix column

    (
    • int index
    )

    Returns a row vector that contains the elements of the row at index.

    If you need a column vector, use operator()(int,int,int,int).

  • Traits::column_iterator columnBegin

    (
    • int colIndex
    )
    [inline]

    Returns a random-access iterator to the start of the column at colIndex.

  • Traits::const_column_iterator columnBegin

    (
    • int colIndex
    )
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • Traits::const_column_iterator columnEnd

    (
    • int colIndex
    )
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • Traits::column_iterator columnEnd

    (
    • int colIndex
    )
    [inline]

    Returns a random-access iterator to the end of the column at colIndex.

  • void detach

    ()
    [inline]

    Detaches the matrix from shared data.

    This function makes sure that there are no other references to the shared data, and creates a clone of the data if necessary.

  • Traits::iterator end

    ()
    [inline]

    Returns a random-access iterator to the end of the matrix data.

    Reimplemented from PiiConceptualMatrix.

  • Traits::const_iterator end

    ()
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

    Reimplemented from PiiConceptualMatrix.

  • Traits::column_iterator insertColumn

    (
    • int index = -1
    )

    Inserts an empty column at the given index.

    Any subsequent columns will be shifted forwards. The elements on the new column will be set to zeros.

    New columns can be added without reallocation if the stride is large enough. If there is no more free space, the matrix data will be reallocated with resize().

    Parameters
    index

    the row index of the new column. -1 means last.

    Returns

    an iterator to the beginning of the newly added column

  • Traits::column_iterator insertColumn

    ()

    Inserts the given column at the given index.

    Any subsequent columns will be shifted forwards. The input matrix can be either a column or a row vector.

    Parameters
    index

    the column index of the new column. -1 means last.

    column

    a matrix whose first column or row will be copied to the memory location of the newly added column.

    Returns

    an iterator to the beginning of the newly added column

  • Traits::column_iterator insertColumn

    (
    • int index
    • const T * column
    )

    Inserts the given column at the given column index.

    The data of the new column will be copied from column, which must hold at least rows() elements.

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • Traits::column_iterator insertColumn

    (
    • int index
    • VaArgType firstElement
    • ...
    )

    Inserts a column with the given data elements at the given column index.

    Any subsequent columns will be shifted forwards. The number of elements must be equal to the number of rows in the matrix.

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • Traits::row_iterator insertRow

    (
    • int index
    )

    Inserts a new at position index and moves all following rows forwards.

    The contents of the new row will be set to zero. Returns a row iterator to the beginning of the new row.

    Parameters
    index

    the row index of the new row. -1 means last.

    Returns

    an iterator to the beginning of the newly added row

  • Traits::row_iterator insertRow

    ()

    Inserts the given row at index.

    The input matrix can be either a column or a row vector.

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • Traits::row_iterator insertRow

    (
    • int index
    • const T * row
    )

    Inserts the given row at the given row index.

    The data of the new row will be copied from row, which must hold at least columns() elements.

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • Traits::row_iterator insertRow

    (
    • int index
    • VaArgType firstElement
    • ...
    )

    Insert a row with the given data elements at the given row index.

    The number of element arguments must be equal to the number of columns in the matrix.

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class BinaryFunc, class Matrix>

    PiiMatrix & map

    ()
    [inline]

    Applies the adaptable binary function to all elements of this matrix and the correspondng element in other.

    The matrices must be of equal size. The result is stored in this matrix. For example, to apply the operator-= the other way, do this:

     PiiMatrix<int> a, b;
     a.map(std::minus<int>(), b);

    Exceptions
    PiiMathException&

    if this matrix is not equal to other in size.

  • template<class BinaryFunc>

    PiiMatrix & map

    (
    • BinaryFunc op
    • typename BinaryFunc::second_argument_type value
    )
    [inline]

    Applies a binary function to all elements of this matrix and the scalar value.

    The result is stored in this matrix. An example:

     PiiMatrix<int> a;
     a.map(std::minus<int>(), 5);
     // The same can be achieved with
     a.map(std::bind2nd(std::minus<int>(), 5));
     // ... but which one is more readable?

  • template<class UnaryFunc>

    PiiMatrix & map

    (
    • UnaryFunc op
    )
    [inline]

    Applies a unary function to all elements in this matrix.

    For example, to negate all elements in a matrix, do the following:

     PiiMatrix<int> a;
     a.map(std::negate<int>());

  • template<class BinaryFunc, class Matrix>

    PiiMatrix< typename BinaryFunc::result_type > mapped

    ()
    [inline]

    Applies the adaptable binary function op to all elements of this matrix and the corresponding elements in other.

    The matrices must be of equal size. The result is returned in a new matrix. For example, to explicitly apply the addition operation, do this:

     PiiMatrix<int> a, b;
     PiiMatrix<int> c(a.mapped(std::plus<int>(), b));

    Exceptions
    PiiMathException&

    if this matrix is not equal to other in size.

  • template<class BinaryFunc>

    PiiMatrix< typename BinaryFunc::result_type > mapped

    (
    • BinaryFunc op
    • typename BinaryFunc::second_argument_type value
    )
    [inline]

    Applies a binary function to all elements of this matrix and the scalar value.

    The result is returned in a new matrix. An example:

     PiiMatrix<int> a;
     PiiMatrix<int> c(a.mapped(std::plus<int>(), 5));

  • template<class UnaryFunc>

    PiiMatrix< typename UnaryFunc::result_type > mapped

    (
    • UnaryFunc op
    )
    [inline]

    Creates a matrix that contains the result of applying a unary function to all elements in this matrix.

    For example, to create a negation of a matrix, do the following:

     PiiMatrix<int> a;
     PiiMatrix<int> b(a.mapped(std::negate<int>());
    
     // Different result type (convert complex numbers to real numbers)
     PiiMatrix<std::complex<float> > a;
     PiiMatrix<float> b(a.mapped(Pii::Abs<std::complex<float> >()));

  • template<class U>

    operator PiiMatrix< U >

    ()
    [inline]

    Cast the contents of a matrix to another type.

    If the contents of the original matrix are not of any elementary type, then an appropriate typecast operator for the content class must be defined.

  • T & operator()

    (
    • int r
    • int c
    )
    [inline]

    Returns a reference to an item in the matrix.

    Equal to row(row)[column]. No bound checking will be done for performance reasons.

    Parameters
    r

    the row index

    c

    the column index

    Returns

    a reference to the matrix item at (r,c)

  • T & operator()

    (
    • int index
    )
    [inline]

    Access the matrix along its first non-singleton dimension.

    If the matrix is actually a vector, it is more convenient not to repeat the zero row or column index. This function works with both row and column vectors. If the matrix is not a vector, the first element of the indexth row is returned.

     // Row vector
     PiiMatrix<int> mat(1, 3, 0,1,2);
     QCOMPARE(mat(2), 2);
     // Column vector
     PiiMatrix<int> mat2(3, 1, 0,1,2);
     QCOMPARE(mat2(2), 2);
     // Matrix
     PiiMatrix<int> mat3(3, 2,
                         0, 1, 2,
                         3, 4, 5);
     QCOMPARE(mat3(1), 3);

  • PiiSubmatrix< T > operator()

    (
    • int r
    • int c
    • int rows
    • int columns
    )
    [inline]

    Returns a mutable reference to a sub-matrix.

    Take care that the dimensions of the matrix are not exceeded. If you modify the returned result, the data within this matrix will also change. The const version returns a copy.

     PiiMatrix<int> a(3, 3,
                      1, 2, 3,
                      4, 5, 6,
                      7, 8, 9);
    
     a(0,1,1,2) = 8;
     a(-2,-2,-1,1) = 0;
    
     // a = 1, 8, 8,
     //     4, 0, 6,
     //     7, 0, 9);

    Parameters
    r

    the row of the upper left column of the sub-matrix. If this is negative, it is treated as a backwards index from the last row. -1 means the last row and so on.

    c

    the column of the upper left column of the sub-matrix. Negative index is relative to the last column.

    rows

    the number of rows to include. Negative value means "up to the nth last row".

    columns

    the number of columns to include. Negative value means "up to the nth last column".

  • PiiMatrix operator()

    (
    • int r
    • int c
    • int rows
    • int columns
    )
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class Matrix>

    PiiFilteredMatrix< const PiiMatrix, Matrix > operator()

    ()
  • template<class Matrix>

    PiiFilteredMatrix< PiiMatrix, Matrix > operator()

    ()
  • T operator()

    (
    • int index
    )
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • T operator()

    (
    • int r
    • int c
    )
    [inline]

    Returns a copy of an item in the matrix.

    Parameters
    r

    the row index

    c

    the column index

    Returns

    the matrix item at (r,c)

  • PiiMatrix & operator=

    ()
    [inline]

    Assigns other to this and returns a reference to this.

  • PiiMatrix & operator=

    (
    • T value
    )
    [inline]
  • PiiMatrix & operator=

    ()
    [inline]
  • template<class Matrix>

    PiiMatrix & operator=

    ()

    Creates a deep copy of other and returns a reference to this.

  • T * operator[]

    (
    • int r
    )
    [inline]

    Returns a pointer to the beginning of the given row.

    Same as row(r). The purpose of this function is to allow the use of a matrix as a two-dimensional array:

     PiiMatrix<int> mat(2, 2,
                        1, 2,
                        3, 4);
     QVERIFY(mat[0][1] == mat(0,1));

  • const T * operator[]

    (
    • int r
    )
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • PiiMatrix

    ()
    [inline]
  • PiiMatrix

    ()
    [inline]

    Constucts a shallow copy of other.

    This constructor only increases the reference count of the internal data structure.

     PiiMatrix<int> a(5,5);
     PiiMatrix<int> b(a(1,1,2,2)); // 2-by-2 reference to a
     PiiMatrix<int> c(a);
     PiiMatrix<int> c(b);          // deep copy of b

  • PiiMatrix

    ()
    [inline]

    Constructs an empty matrix.

  • PiiMatrix

    (
    • int rows
    • int columns
    • const T * data
    • int stride = 0
    )
    [inline]

    Constructs a rows-by-columns matrix whose initial contents are taken from the array pointed to by data.

    The array must hold at least rows * columns entries. If stride is set to a value larger than sizeof(T) * columns, row padding is assumed. The data pointer must remain valid throughout the lifetime of the matrix and any shallow copies of it.

     const double data[] = { 1, 2, 3, 4 };
     PiiMatrix<double> mat(2, 2, data);
     QCOMPARE(mat(1,1), 4);
    
     const char* padded = "ABCDEFGH";
     PiiMatrix<char> mat(3, 3, padded, 4);
     QCOMPARE(mat(1,0), 'E');

    Note that stride is always in bytes.

    See also
  • PiiMatrix

    (
    • int rows
    • int columns
    • VaArgType firstElement
    • ...
    )

    Constructs a matrix with the given number of rows and columns.

    Matrix contents are given as a variable-length parameter list in a horizontal raster-scan order. It is handy if you know what you do, but proper care must be taken to ensure correct functioning.

    Only elementary types can be used with this constructor. Complex types cause a compile-time error.

    Take extreme care to ensure that the elements you give in the parameter list are of correct type. Examples:

     PiiMatrix<char> a(3, 1, 'a', 'b', 'c');     //correct, chars are passed as ints
     PiiMatrix<char> b(3, 1, 1, 2, 3);           //correct
     PiiMatrix<float> c(3, 1, 1, 2, 3);          //WRONG! values are passed as ints
     PiiMatrix<float> d(3, 1, 1.0, 2.0, 3.0);    //correct
     PiiMatrix<float> e(3, 1, 1.0f, 2.0f, 3.0f); //WRONG! float constants cannot be used as va_args
     PiiMatrix<double> f(3, 1, 1.0, 2.0, 3.0);   //correct
     PiiMatrix<int> g(3, 1, 1, 2, 3);            //correct
     PiiMatrix<int> g(3, 1, 1, 2);               //WRONG! too few parameters

    Parameters
    rows

    the number of rows

    columns

    the number of columns

    firstElement

    the first element

  • PiiMatrix

    ()
    [inline]

    Constructs a rows-by-columns matrix that uses data as its data buffer.

    This is an overloaded constructor that behaves essentially the same way as the one above. The difference is that accesses to this matrix will modify data. Furthermore, if you set the ownership flag to Pii::ReleaseOwnership, the data pointer will be deallocated with free() when the matrix is destroyed.

     double data[] = { 1, 2, 3, 4 };
     PiiMatrix<double> mat(2, 2, data, Pii::RetainOwnership);
     mat(1,1) = 3;
     QCOMPARE(data[3], 3);
    
     void* bfr = malloc(sizeof(int) * 16);
     // bfr will be deallocated with free() when the matrix is destroyed.
     PiiMatrix<int> mat(2, 7, bfr, Pii::ReleaseOwnership, 8 * sizeof(int));
     mat = 0; // sets all elements in bfr to zeros

  • PiiMatrix

    (
    • int rows
    • int columns
    )
    [inline]

    Constucts a rows-by-columns matrix with all entries initialized to zero.

  • template<class Matrix>

    PiiMatrix

    ()
    [inline, explicit]

    Constructs a deep copy of other by copying and typecasting each individual element.

  • void removeColumn

    (
    • int index
    )
    [inline]

    Removes a column from the matrix.

    All data right of index will be moved left. The stride of the matrix will not change. If you later add a column to the matrix, the data will not be reallocated.

     PiiMatrix<int> mat(3,3, 1,2,3, 4,5,6, 7,8,9);
     mat.removeColumn(1);
     // mat = 1  3
     //       4  6
     //       7  9

  • void removeColumns

    (
    • int index
    • int count
    )
    [inline]

    Removes count successive columns starting at index.

    All columns right of the last removed one will be moved left.

  • void removeRow

    (
    • int index
    )
    [inline]

    Removes the row at index.

    All rows below the removed one will be moved up.

     PiiMatrix<int> mat(3,3, 1,2,3, 4,5,6, 7,8,9);
     mat.removeRow(1);
     // mat = 1 2 3
     //       7 8 9

  • void removeRows

    (
    • int index
    • int count
    )
    [inline]

    Removes count successive rows starting at index.

    All rows below the last removed one will be moved up.

  • void reserve

    (
    • int rows
    )
    [inline]

    Allocates memory for at least rows matrix rows.

    If you know in advance how large the matrix will be, you can avoid unnecessary reallocations while adding new rows. Trying to set rows to a value less than the current capacity has no effect.

    See also
  • void resize

    (
    • int rows
    • int columns
    )

    Resizes the matrix to rows-by-columns.

    The function preserves as much data as possible and sets any new entries to zero. If the currently reserved space is not large enough, matrix data will be reallocated. No reallocation will occur if the size is decreased.

  • const T * row

    (
    • int index
    )
    [inline]

    Returns a pointer to the beginning of row at index.

  • T * row

    (
    • int index
    )
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class U>

    U & rowAs

    (
    • int index
    )
    [inline]

    A utility function that returns a reference to the memory location at the beginning of the given row as the specified type.

    Use this function only if you are absolutely sure that the memory arrangement of the type T matches that of a matrix row.

     PiiMatrix<int> mat(1,3, 1,2,3);
     PiiVector<int,3>& vec = mat.rowAs<PiiVector<int,3> >(0);
     vec[0] = 2;
     QCOMPARE(mat(0,0), 2);

  • template<class U>

    const U & rowAs

    (
    • int index
    )
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • Traits::const_row_iterator rowBegin

    (
    • int rowIndex
    )
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • Traits::row_iterator rowBegin

    (
    • int rowIndex
    )
    [inline]

    Returns a random-access iterator to the start of the row at rowIndex.

  • Traits::const_row_iterator rowEnd

    (
    • int rowIndex
    )
    [inline]

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • Traits::row_iterator rowEnd

    (
    • int rowIndex
    )
    [inline]

    Returns a random-access iterator to the end of the row at rowIndex.

  • void swapRows

    (
    • int row1
    • int row2
    )

    Swaps the places of row1 and row2.

  • ~PiiMatrix

    ()
    [inline]

    Destroys the matrix.

  • static PiiMatrix constant

    (
    • int rows
    • int columns
    • T value
    )
    [inline, static]

    Creates a rows-by-columns matrix whose initial contents are set to value.

    This is faster than first creating and clearing a matrix to zeros and then setting all entries.

     PiiMatrix<float> mat(PiiMatrix<float>::constant(2, 3, 1.0);
     // 1.0 1.0 1.0
     // 1.0 1.0 1.0

  • static PiiMatrix identity

    (
    • int size
    )
    [static]

    Creates a size-by-size identity matrix.

     PiiMatrix<int> mat(PiiMatrix<int>::identity(3));
     // 1 0 0
     // 0 1 0
     // 0 0 1

  • static PiiMatrix padded

    (
    • int rows
    • int columns
    • int stride
    )
    [inline, static]

    Creates rows-by-columns matrix with initial contents set to zero.

    If stride is set to a value larger than sizeof(T)*columns, matrix rows will be padded to stride bytes.

  • static PiiMatrix uninitialized

    (
    • int rows
    • int columns
    • int stride = 0
    )
    [inline, static]

    Creates an uninitialized rows-by-columns matrix.

    This function leaves the contents of the matrix in an unspecified state. It is useful as an optimization if you know you are going to set all matrix entries anyway. If stride is set to a value larger than sizeof(T)*columns, matrix rows will be padded to stride bytes.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.