RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
RealValueVect.h
Go to the documentation of this file.
1//
2// Copyright (c) 2014-2024, Novartis Institutes for BioMedical Research and
3// other RDKit contributors
4//
5// @@ All Rights Reserved @@
6// This file is part of the RDKit.
7// The contents are covered by the terms of the BSD license
8// which is included in the file license.txt, found at the root
9// of the RDKit source tree.
10//
11#include <RDGeneral/export.h>
12#ifndef RD_REAL_VALUE_VECT_20140407
13#define RD_REAL_VALUE_VECT_20140407
14
15#include <boost/smart_ptr.hpp>
16#include <string>
17#include <cstring>
18
19namespace RDGeom {
20class UniformRealValueGrid3D;
21}
22namespace RDKit {
23
24//! a class for efficiently storing vectors of double values
25//! Has additional features compared to std::vector<double>:
26//! construct from and write to pickle
28 public:
29 RealValueVect() = default;
30 //! initialize with a particular size
31 RealValueVect(unsigned int length) : d_length(length) {
32 d_data.resize(d_length, 0.0);
33 }
34
35 //! initialize with a particular size and initial value
36 RealValueVect(unsigned int length, double val) : d_length(length) {
37 d_data.resize(d_length, val);
38 }
39
40 //! constructor from a pickle
41 RealValueVect(const std::string &pkl) {
42 initFromText(pkl.c_str(), pkl.size());
43 };
44
45 //! constructor from a pickle
46 RealValueVect(const char *pkl, unsigned int len) { initFromText(pkl, len); };
47
48 //! return the value at an index
49 double getVal(unsigned int i) const;
50
51 //! support indexing using []
52 double operator[](unsigned int idx) const { return getVal(idx); };
53
54 //! set the value at an index
55 void setVal(unsigned int i, double val);
56
57 //! returns the sum of all the elements in the vect
58 double getTotalVal() const;
59
60 //! returns the length
61 unsigned int getLength() const { return d_length; };
62
63 //! returns the length
64 unsigned int size() const { return getLength(); };
65
66 //! compares 2 vectors and returns false if different
67 bool compareVectors(const RealValueVect &other) const;
68
69 //! in-place operator&
71
72 //! in-place operator|
74
75 //! in-place operator+
77
78 //! in-place operator-
80
81 //! returns a binary string representation (pickle)
82 std::string toString() const;
83
84 void setLength(unsigned int sz) {
85 d_length = sz;
86 d_data.resize(sz);
87 }
88 void setToVal(double val) { std::fill(d_data.begin(), d_data.end(), val); }
89
90 const std::vector<double> &getData() const { return d_data; }
91 std::vector<double> &getData() { return d_data; }
92
93 private:
94 void initFromText(const char *pkl, const unsigned int len);
95 unsigned int d_length = 0;
96 std::vector<double> d_data;
97
98 template <typename O>
99 RealValueVect &applyBinaryOp(const RealValueVect &other, O op);
100}; // end of declaration of class RealValueVect
101
102//! returns L1 Norm of vectors
104 const RealValueVect &v2);
105
106//! returns the sum of vectors
108 const RealValueVect &p2);
109
110//! returns the difference of vectors
112 const RealValueVect &p2);
113
114//! support rvv3 = rvv1|rvv2
115/*!
116
117 operator| returns the maximum value for each element.
118 e.g.:
119 [0,1,2,0] | [0,1,1,1] -> [0,1,2,1]
120
121 */
123 const RealValueVect &p2);
124
125//! support rvv3 = rvv1&rvv2
126/*!
127 operator& returns the minimum value for each element.
128 e.g.:
129 [0,1,2,0] & [0,1,1,1] -> [0,1,1,0]
130
131 */
133 const RealValueVect &p2);
134
135} // end of namespace RDKit
136
137#endif
std::vector< double > & getData()
RealValueVect & operator|=(const RealValueVect &other)
in-place operator|
unsigned int size() const
returns the length
double getTotalVal() const
returns the sum of all the elements in the vect
RealValueVect(const char *pkl, unsigned int len)
constructor from a pickle
void setVal(unsigned int i, double val)
set the value at an index
RealValueVect(const std::string &pkl)
constructor from a pickle
RealValueVect & operator-=(const RealValueVect &other)
in-place operator-
unsigned int getLength() const
returns the length
RealValueVect(unsigned int length, double val)
initialize with a particular size and initial value
RealValueVect & operator+=(const RealValueVect &other)
in-place operator+
double getVal(unsigned int i) const
return the value at an index
void setLength(unsigned int sz)
RealValueVect(unsigned int length)
initialize with a particular size
std::string toString() const
returns a binary string representation (pickle)
RealValueVect & operator&=(const RealValueVect &other)
in-place operator&
void setToVal(double val)
double operator[](unsigned int idx) const
support indexing using []
const std::vector< double > & getData() const
bool compareVectors(const RealValueVect &other) const
compares 2 vectors and returns false if different
#define RDKIT_DATASTRUCTS_EXPORT
Definition export.h:81
Std stuff.
RDKIT_DATASTRUCTS_EXPORT RealValueVect operator&(const RealValueVect &p1, const RealValueVect &p2)
support rvv3 = rvv1&rvv2
RDKIT_DATASTRUCTS_EXPORT unsigned int computeL1Norm(const DiscreteValueVect &v1, const DiscreteValueVect &v2)
RDKIT_DATASTRUCTS_EXPORT DiscreteValueVect operator-(const DiscreteValueVect &p1, const DiscreteValueVect &p2)
RDKIT_DATASTRUCTS_EXPORT DiscreteValueVect operator+(const DiscreteValueVect &p1, const DiscreteValueVect &p2)
RDKIT_DATASTRUCTS_EXPORT RealValueVect operator|(const RealValueVect &p1, const RealValueVect &p2)
support rvv3 = rvv1|rvv2