SquareMatrix.h
Go to the documentation of this file.
//
// Copyright (C) 2004-2006 Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#ifndef __RD_SQUARE_MATRIX_H__
#define __RD_SQUARE_MATRIX_H__
#include "Matrix.h"
namespace RDNumeric {
template <typename TYPE>
class SquareMatrix : public Matrix<TYPE> {
public:
//! brief Square matrix of size N
SquareMatrix(){};
explicit SquareMatrix(unsigned int N) : Matrix<TYPE>(N, N){};
SquareMatrix(unsigned int N, TYPE val) : Matrix<TYPE>(N, N, val){};
SquareMatrix(unsigned int N, typename Matrix<TYPE>::DATA_SPTR data)
: Matrix<TYPE>(N, N, data){};
// inline unsigned int size() const {
// return d_nRows;
//};
virtual SquareMatrix<TYPE> &operator*=(TYPE scale) {
Matrix<TYPE>::operator*=(scale);
return *this;
}
//! In place matrix multiplication
virtual SquareMatrix<TYPE> &operator*=(const SquareMatrix<TYPE> &B) {
CHECK_INVARIANT(this->d_nCols == B.numRows(),
"Size mismatch during multiplication");
const TYPE *bData = B.getData();
TYPE *newData = new TYPE[this->d_dataSize];
unsigned int i, j, k;
unsigned int idA, idAt, idC, idCt, idB;
TYPE *data = this->d_data.get();
for (i = 0; i < this->d_nRows; i++) {
idA = i * this->d_nRows;
idC = idA;
for (j = 0; j < this->d_nCols; j++) {
idCt = idC + j;
newData[idCt] = (TYPE)(0.0);
for (k = 0; k < this->d_nCols; k++) {
idAt = idA + k;
idB = k * this->d_nRows + j;
newData[idCt] += (data[idAt] * bData[idB]);
}
}
}
boost::shared_array<TYPE> tsptr(newData);
this->d_data.swap(tsptr);
return (*this);
}
//! In place matrix transpose
virtual SquareMatrix<TYPE> &transposeInplace() {
unsigned int i, j;
unsigned int id1, id1t, id2;
TYPE temp;
TYPE *data = this->d_data.get();
for (i = 1; i < this->d_nRows; i++) {
id1 = i * this->d_nCols;
for (j = 0; j < i; j++) {
id1t = id1 + j;
id2 = j * this->d_nCols + i;
temp = data[id1t];
data[id1t] = data[id2];
data[id2] = temp;
}
}
return (*this);
}
};
typedef SquareMatrix<double> DoubleSquareMatrix;
}
#endif
RDNumeric::Matrix::d_data
DATA_SPTR d_data
Definition: Matrix.h:235
RDKit::Drawing::N
Definition: MolDrawing.h:41
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix(unsigned int N, TYPE val)
Definition: SquareMatrix.h:24
RDNumeric::Matrix::numRows
unsigned int numRows() const
returns the number of rows
Definition: Matrix.h:78
RDNumeric
Definition: AlignPoints.h:17
RDNumeric::SquareMatrix::operator*=
virtual SquareMatrix< TYPE > & operator*=(TYPE scale)
Multiplication by a scalar.
Definition: SquareMatrix.h:33
CHECK_INVARIANT
#define CHECK_INVARIANT(expr, mess)
Definition: Invariant.h:95
RDNumeric::Matrix::operator*=
virtual Matrix< TYPE > & operator*=(TYPE scale)
Multiplication by a scalar.
Definition: Matrix.h:183
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix()
brief Square matrix of size N
Definition: SquareMatrix.h:20
RDNumeric::DoubleSquareMatrix
SquareMatrix< double > DoubleSquareMatrix
Definition: SquareMatrix.h:85
RDNumeric::SquareMatrix
Definition: SquareMatrix.h:17
RDNumeric::Matrix::d_nCols
unsigned int d_nCols
Definition: Matrix.h:233
RDNumeric::Matrix
A matrix class for general, non-square matrices.
Definition: Matrix.h:28
RDNumeric::Matrix::DATA_SPTR
boost::shared_array< TYPE > DATA_SPTR
Definition: Matrix.h:30
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix(unsigned int N, typename Matrix< TYPE >::DATA_SPTR data)
Definition: SquareMatrix.h:26
Matrix.h
RDNumeric::SquareMatrix::operator*=
virtual SquareMatrix< TYPE > & operator*=(const SquareMatrix< TYPE > &B)
In place matrix multiplication.
Definition: SquareMatrix.h:39
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix(unsigned int N)
Definition: SquareMatrix.h:22
RDNumeric::Matrix::d_nRows
unsigned int d_nRows
Definition: Matrix.h:231
RDNumeric::Matrix::d_dataSize
unsigned int d_dataSize
Definition: Matrix.h:234
RDNumeric::Matrix::getData
TYPE * getData()
returns a pointer to our data array
Definition: Matrix.h:127
RDNumeric::SquareMatrix::transposeInplace
virtual SquareMatrix< TYPE > & transposeInplace()
In place matrix transpose.
Definition: SquareMatrix.h:67