 |
RDKit
Open-source cheminformatics and machine learning.
|
Go to the documentation of this file.
11 #ifndef __RD_VECTOR_H__
12 #define __RD_VECTOR_H__
22 #include <boost/random.hpp>
23 #include <boost/smart_ptr.hpp>
36 TYPE *data =
new TYPE[N];
37 memset(
static_cast<void *
>(data), 0, d_size *
sizeof(TYPE));
44 TYPE *data =
new TYPE[N];
47 for (i = 0; i < N; i++) {
66 d_size = other.
size();
67 const TYPE *otherData = other.
getData();
68 TYPE *data =
new TYPE[d_size];
70 memcpy(
static_cast<void *
>(data),
static_cast<const void *
>(otherData),
71 d_size *
sizeof(TYPE));
78 unsigned int size()
const {
return d_size; }
81 inline TYPE
getVal(
unsigned int i)
const {
87 inline void setVal(
unsigned int i, TYPE val) {
103 inline TYPE *
getData() {
return d_data.get(); }
117 const TYPE *otherData = other.
getData();
118 memcpy(
static_cast<void *
>(d_data.get()),
119 static_cast<const void *
>(otherData), d_size *
sizeof(TYPE));
126 const TYPE *otherData = other.
getData();
127 TYPE *data = d_data.get();
129 for (i = 0; i < d_size; i++) {
130 data[i] += otherData[i];
137 PRECONDITION(d_size == other.
size(),
"Size mismatch in vector subtraction");
138 const TYPE *otherData = other.
getData();
139 TYPE *data = d_data.get();
141 for (i = 0; i < d_size; i++) {
142 data[i] -= otherData[i];
150 for (i = 0; i < d_size; i++) {
159 for (i = 0; i < d_size; i++) {
167 TYPE res = (TYPE)0.0;
169 TYPE *data = d_data.get();
170 for (i = 0; i < d_size; i++) {
171 res += data[i] * data[i];
181 TYPE res = (TYPE)0.0;
183 TYPE *data = d_data.get();
184 for (i = 0; i < d_size; i++) {
185 res += fabs(data[i]);
192 TYPE res = (TYPE)(-1.0);
194 TYPE *data = d_data.get();
195 for (i = 0; i < d_size; i++) {
196 if (fabs(data[i]) > res) {
206 TYPE res = (TYPE)(-1.0);
207 unsigned int i,
id = d_size;
208 TYPE *data = d_data.get();
209 for (i = 0; i < d_size; i++) {
210 if (fabs(data[i]) > res) {
220 TYPE res = (TYPE)(-1.e8);
221 unsigned int i,
id = d_size;
222 TYPE *data = d_data.get();
223 for (i = 0; i < d_size; i++) {
234 TYPE res = (TYPE)(1.e8);
235 unsigned int i,
id = d_size;
236 TYPE *data = d_data.get();
237 for (i = 0; i < d_size; i++) {
249 "Size mismatch in vector doct product");
250 const TYPE *oData = other.
getData();
252 TYPE res = (TYPE)(0.0);
253 TYPE *data = d_data.get();
254 for (i = 0; i < d_size; i++) {
255 res += (data[i] * oData[i]);
262 TYPE val = this->
normL2();
274 generator.seed(seed);
279 generator.seed(clock() + 1);
283 TYPE *data = d_data.get();
284 for (i = 0; i < d_size; i++) {
285 data[i] = randSource();
299 template <
typename T>
302 if (numer == 0.0)
return 0.0;
304 if (denom == 0.0)
return 0.0;
305 return numer / denom;
310 template <
typename TYPE>
313 unsigned int siz = vec.
size();
314 target <<
"Size: " << siz <<
" [";
316 for (i = 0; i < siz; i++) {
317 target << std::setw(7) << std::setprecision(3) << vec.
getVal(i) <<
", ";
TYPE & operator[](unsigned int i)
void normalize()
Normalize the vector using the L2 norm.
double TanimotoSimilarity(const Vector< T > &v1, const Vector< T > &v2)
returns the algebraic tanimoto similarity [defn' from JCIM 46:587-96 (2006)]
TYPE normL1() const
L1 norm.
boost::minstd_rand rng_type
unsigned int size() const
return the size (dimension) of the vector
Vector< TYPE > & operator-=(const Vector< TYPE > &other)
elementwise subtraction, vectors must be the same size.
Vector(unsigned int N)
Initialize with only a size.
unsigned int largestAbsValId() const
Gets the ID of the entry that has the largest absolute value i.e. the entry being used for the L-infi...
const TYPE * getData() const
returns a const pointer to our data array
Vector< TYPE > & assign(const Vector< TYPE > &other)
Copy operator.
unsigned int smallestValId() const
Gets the ID of the entry that has the smallest value.
Vector(unsigned int N, TYPE val)
Initialize with a size and default value.
A class to represent vectors of numbers.
TYPE normLinfinity() const
L-infinity norm.
boost::uniform_real uniform_double
void setToRandom(unsigned int seed=0)
Set to a random unit vector.
unsigned int largestValId() const
Gets the ID of the entry that has the largest value.
TYPE operator[](unsigned int i) const
Vector(const Vector &other)
copy constructor
std::ostream & operator<<(std::ostream &target, const RDNumeric::Vector< TYPE > &vec)
ostream operator for Vectors
boost::shared_array< TYPE > DATA_SPTR
void setVal(unsigned int i, TYPE val)
sets the index at a particular value
Vector< TYPE > & operator+=(const Vector< TYPE > &other)
elementwise addition, vectors must be the same size.
Vector< TYPE > & operator/=(TYPE scale)
division by a scalar
TYPE dotProduct(const Vector< TYPE > other) const
returns the dot product between two Vectors
Vector< TYPE > & operator*=(TYPE scale)
multiplication by a scalar
#define PRECONDITION(expr, mess)
TYPE getVal(unsigned int i) const
returns the value at a particular index
boost::variate_generator< rng_type &, uniform_double > double_source_type
Vector(unsigned int N, DATA_SPTR data)
Initialize from a smart pointer.
TYPE * getData()
returns a pointer to our data array
TYPE normL2Sq() const
L2 norm squared.
Vector< double > DoubleVector
TYPE normL2() const
L2 norm.