RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
Loading...
Searching...
No Matches
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
#include <
RDGeneral/export.h
>
11
#ifndef __RD_SQUARE_MATRIX_H__
12
#define __RD_SQUARE_MATRIX_H__
13
14
#include "
Matrix.h
"
15
16
namespace
RDNumeric
{
17
template
<
typename
TYPE>
18
class
SquareMatrix
:
public
Matrix
<TYPE> {
19
public
:
20
//! brief Square matrix of size N
21
SquareMatrix
() {}
22
23
explicit
SquareMatrix
(
unsigned
int
N) :
Matrix
<TYPE>(N, N) {}
24
25
SquareMatrix
(
unsigned
int
N, TYPE val) :
Matrix
<TYPE>(N, N, val) {}
26
27
SquareMatrix
(
unsigned
int
N,
typename
Matrix<TYPE>::DATA_SPTR
data)
28
:
Matrix
<TYPE>(N, N, data) {}
29
30
SquareMatrix
(
const
SquareMatrix
&B) =
default
;
31
SquareMatrix
(
SquareMatrix<TYPE>
&&B) =
default
;
32
SquareMatrix
&
operator=
(
const
SquareMatrix<TYPE>
&B) =
default
;
33
SquareMatrix
&
operator=
(
SquareMatrix<TYPE>
&&B) =
default
;
34
~SquareMatrix
() =
default
;
35
36
SquareMatrix<TYPE>
&
operator*=
(TYPE scale)
override
{
37
Matrix<TYPE>::operator*=
(scale);
38
return
*
this
;
39
}
40
41
//! In place matrix multiplication
42
virtual
SquareMatrix<TYPE>
&
operator*=
(
const
SquareMatrix<TYPE>
&B) {
43
CHECK_INVARIANT
(this->
d_nCols
== B.
numRows
(),
44
"Size mismatch during multiplication"
);
45
46
const
TYPE *bData = B.
getData
();
47
TYPE *newData =
new
TYPE[this->
d_dataSize
];
48
unsigned
int
i, j, k;
49
unsigned
int
idA, idAt, idC, idCt, idB;
50
TYPE *data = this->
d_data
.get();
51
for
(i = 0; i < this->
d_nRows
; i++) {
52
idA = i * this->d_nRows;
53
idC = idA;
54
for
(j = 0; j < this->
d_nCols
; j++) {
55
idCt = idC + j;
56
newData[idCt] = (TYPE)(0.0);
57
for
(k = 0; k < this->d_nCols; k++) {
58
idAt = idA + k;
59
idB = k * this->d_nRows + j;
60
newData[idCt] += (data[idAt] * bData[idB]);
61
}
62
}
63
}
64
boost::shared_array<TYPE> tsptr(newData);
65
this->
d_data
.swap(tsptr);
66
return
(*
this
);
67
}
68
69
//! In place matrix transpose
70
virtual
SquareMatrix<TYPE>
&
transposeInplace
() {
71
unsigned
int
i, j;
72
unsigned
int
id1, id1t, id2;
73
TYPE temp;
74
TYPE *data = this->
d_data
.get();
75
for
(i = 1; i < this->
d_nRows
; i++) {
76
id1 = i * this->
d_nCols
;
77
for
(j = 0; j < i; j++) {
78
id1t = id1 + j;
79
id2 = j * this->d_nCols + i;
80
temp = data[id1t];
81
data[id1t] = data[id2];
82
data[id2] = temp;
83
}
84
}
85
return
(*
this
);
86
}
87
};
88
typedef
SquareMatrix<double>
DoubleSquareMatrix
;
89
}
// namespace RDNumeric
90
91
#endif
CHECK_INVARIANT
#define CHECK_INVARIANT(expr, mess)
Definition
Invariant.h:100
Matrix.h
RDNumeric::Matrix::Matrix
Matrix(unsigned int nRows, unsigned int nCols)
Initialize with a size.
Definition
Matrix.h:33
RDNumeric::Matrix< double >::d_dataSize
unsigned int d_dataSize
Definition
Matrix.h:255
RDNumeric::Matrix< double >::d_nRows
unsigned int d_nRows
Definition
Matrix.h:253
RDNumeric::Matrix::getData
TYPE * getData()
returns a pointer to our data array
Definition
Matrix.h:148
RDNumeric::Matrix::numRows
unsigned int numRows() const
returns the number of rows
Definition
Matrix.h:86
RDNumeric::Matrix::operator*=
virtual Matrix< TYPE > & operator*=(TYPE scale)
Multiplication by a scalar.
Definition
Matrix.h:204
RDNumeric::Matrix< double >::d_data
DATA_SPTR d_data
Definition
Matrix.h:256
RDNumeric::Matrix< double >::d_nCols
unsigned int d_nCols
Definition
Matrix.h:254
RDNumeric::Matrix::DATA_SPTR
boost::shared_array< TYPE > DATA_SPTR
Definition
Matrix.h:30
RDNumeric::SquareMatrix
Definition
SquareMatrix.h:18
RDNumeric::SquareMatrix::operator=
SquareMatrix & operator=(const SquareMatrix< TYPE > &B)=default
RDNumeric::SquareMatrix::~SquareMatrix
~SquareMatrix()=default
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix()
brief Square matrix of size N
Definition
SquareMatrix.h:21
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix(const SquareMatrix &B)=default
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix(unsigned int N, typename Matrix< TYPE >::DATA_SPTR data)
Definition
SquareMatrix.h:27
RDNumeric::SquareMatrix::transposeInplace
virtual SquareMatrix< TYPE > & transposeInplace()
In place matrix transpose.
Definition
SquareMatrix.h:70
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix(unsigned int N, TYPE val)
Definition
SquareMatrix.h:25
RDNumeric::SquareMatrix::operator*=
virtual SquareMatrix< TYPE > & operator*=(const SquareMatrix< TYPE > &B)
In place matrix multiplication.
Definition
SquareMatrix.h:42
RDNumeric::SquareMatrix::operator*=
SquareMatrix< TYPE > & operator*=(TYPE scale) override
Multiplication by a scalar.
Definition
SquareMatrix.h:36
RDNumeric::SquareMatrix::operator=
SquareMatrix & operator=(SquareMatrix< TYPE > &&B)=default
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix(SquareMatrix< TYPE > &&B)=default
RDNumeric::SquareMatrix::SquareMatrix
SquareMatrix(unsigned int N)
Definition
SquareMatrix.h:23
export.h
RDNumeric
Definition
AlignPoints.h:18
RDNumeric::DoubleSquareMatrix
SquareMatrix< double > DoubleSquareMatrix
Definition
SquareMatrix.h:88
Numerics
SquareMatrix.h
Generated on
for RDKit by
1.17.0