RDKit: SquareMatrix.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

SquareMatrix.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #ifndef __RD_SQUARE_MATRIX_H__
11 #define __RD_SQUARE_MATRIX_H__
12
13 #include "Matrix.h"
14
15 namespace RDNumeric {
16 template <typename TYPE>
17 class SquareMatrix : public Matrix<TYPE> {
18 public:
19 //! brief Square matrix of size N
20 SquareMatrix(){};
21
22 explicit SquareMatrix(unsigned int N) : Matrix<TYPE>(N, N){};
23
24 SquareMatrix(unsigned int N, TYPE val) : Matrix<TYPE>(N, N, val){};
25
26 SquareMatrix(unsigned int N, typename Matrix<TYPE>::DATA_SPTR data)
27 : Matrix<TYPE>(N, N, data){};
28
29 // inline unsigned int size() const {
30 // return d_nRows;
31 //};
32
33 virtual SquareMatrix<TYPE> &operator*=(TYPE scale) {
34 Matrix<TYPE>::operator*=(scale);
35 return *this;
36 }
37
38 //! In place matrix multiplication
39 virtual SquareMatrix<TYPE> &operator*=(const SquareMatrix<TYPE> &B) {
40 CHECK_INVARIANT(this->d_nCols == B.numRows(),
41 "Size mismatch during multiplication");
42
43 const TYPE *bData = B.getData();
44 TYPE *newData = new TYPE[this->d_dataSize];
45 unsigned int i, j, k;
46 unsigned int idA, idAt, idC, idCt, idB;
47 TYPE *data = this->d_data.get();
48 for (i = 0; i < this->d_nRows; i++) {
49 idA = i * this->d_nRows;
50 idC = idA;
51 for (j = 0; j < this->d_nCols; j++) {
52 idCt = idC + j;
53 newData[idCt] = (TYPE)(0.0);
54 for (k = 0; k < this->d_nCols; k++) {
55 idAt = idA + k;
56 idB = k * this->d_nRows + j;
57 newData[idCt] += (data[idAt] * bData[idB]);
58 }
59 }
60 }
61 boost::shared_array<TYPE> tsptr(newData);
62 this->d_data.swap(tsptr);
63 return (*this);
64 }
65
66 //! In place matrix transpose
67 virtual SquareMatrix<TYPE> &transposeInplace() {
68 unsigned int i, j;
69 unsigned int id1, id1t, id2;
70 TYPE temp;
71 TYPE *data = this->d_data.get();
72 for (i = 1; i < this->d_nRows; i++) {
73 id1 = i * this->d_nCols;
74 for (j = 0; j < i; j++) {
75 id1t = id1 + j;
76 id2 = j * this->d_nCols + i;
77 temp = data[id1t];
78 data[id1t] = data[id2];
79 data[id2] = temp;
80 }
81 }
82 return (*this);
83 }
84 };
85 typedef SquareMatrix<double> DoubleSquareMatrix;
86 }
87
88 #endif
RDNumeric::Matrix::d_data
DATA_SPTR d_data
Definition: Matrix.h:235
RDKit::Drawing::N
Definition: MolDrawing.h:44
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:99
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