RDKit: RealValueVect.h Source File

| 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
27 class RDKIT_DATASTRUCTS_EXPORT RealValueVect {
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&
70 RealValueVect &operator&=(const RealValueVect &other);
71
72 //! in-place operator|
73 RealValueVect &operator|=(const RealValueVect &other);
74
75 //! in-place operator+
76 RealValueVect &operator+=(const RealValueVect &other);
77
78 //! in-place operator-
79 RealValueVect &operator-=(const RealValueVect &other);
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
103 RDKIT_DATASTRUCTS_EXPORT double computeL1Norm(const RealValueVect &v1,
104 const RealValueVect &v2);
105
106//! returns the sum of vectors
107 RDKIT_DATASTRUCTS_EXPORT RealValueVect operator+(const RealValueVect &p1,
108 const RealValueVect &p2);
109
110//! returns the difference of vectors
111 RDKIT_DATASTRUCTS_EXPORT RealValueVect operator-(const RealValueVect &p1,
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 */
122 RDKIT_DATASTRUCTS_EXPORT RealValueVect operator|(const RealValueVect &p1,
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 */
132 RDKIT_DATASTRUCTS_EXPORT RealValueVect operator&(const RealValueVect &p1,
133 const RealValueVect &p2);
134
135} // end of namespace RDKit
136
137#endif
RDGeom::UniformRealValueGrid3D
Definition UniformRealValueGrid3D.h:21
RDKit::RealValueVect
Definition RealValueVect.h:27
RDKit::RealValueVect::getData
std::vector< double > & getData()
Definition RealValueVect.h:91
RDKit::RealValueVect::operator|=
RealValueVect & operator|=(const RealValueVect &other)
in-place operator|
RDKit::RealValueVect::size
unsigned int size() const
returns the length
Definition RealValueVect.h:64
RDKit::RealValueVect::getTotalVal
double getTotalVal() const
returns the sum of all the elements in the vect
RDKit::RealValueVect::RealValueVect
RealValueVect(const char *pkl, unsigned int len)
constructor from a pickle
Definition RealValueVect.h:46
RDKit::RealValueVect::setVal
void setVal(unsigned int i, double val)
set the value at an index
RDKit::RealValueVect::RealValueVect
RealValueVect(const std::string &pkl)
constructor from a pickle
Definition RealValueVect.h:41
RDKit::RealValueVect::operator-=
RealValueVect & operator-=(const RealValueVect &other)
in-place operator-
RDKit::RealValueVect::RealValueVect
RealValueVect()=default
RDKit::RealValueVect::getLength
unsigned int getLength() const
returns the length
Definition RealValueVect.h:61
RDKit::RealValueVect::RealValueVect
RealValueVect(unsigned int length, double val)
initialize with a particular size and initial value
Definition RealValueVect.h:36
RDKit::RealValueVect::operator+=
RealValueVect & operator+=(const RealValueVect &other)
in-place operator+
RDKit::RealValueVect::getVal
double getVal(unsigned int i) const
return the value at an index
RDKit::RealValueVect::setLength
void setLength(unsigned int sz)
Definition RealValueVect.h:84
RDKit::RealValueVect::RealValueVect
RealValueVect(unsigned int length)
initialize with a particular size
Definition RealValueVect.h:31
RDKit::RealValueVect::toString
std::string toString() const
returns a binary string representation (pickle)
RDKit::RealValueVect::operator&=
RealValueVect & operator&=(const RealValueVect &other)
in-place operator&
RDKit::RealValueVect::setToVal
void setToVal(double val)
Definition RealValueVect.h:88
RDKit::RealValueVect::operator[]
double operator[](unsigned int idx) const
support indexing using []
Definition RealValueVect.h:52
RDKit::RealValueVect::getData
const std::vector< double > & getData() const
Definition RealValueVect.h:90
RDKit::RealValueVect::compareVectors
bool compareVectors(const RealValueVect &other) const
compares 2 vectors and returns false if different
export.h
RDKIT_DATASTRUCTS_EXPORT
#define RDKIT_DATASTRUCTS_EXPORT
Definition export.h:89
RDGeom
Definition TorsionAngleContribs.h:17
RDKit::v1
Definition ReactionParser.h:91
RDKit::v2
Definition ReactionParser.h:71
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::operator&
RDKIT_DATASTRUCTS_EXPORT RealValueVect operator&(const RealValueVect &p1, const RealValueVect &p2)
support rvv3 = rvv1&rvv2
RDKit::computeL1Norm
RDKIT_DATASTRUCTS_EXPORT unsigned int computeL1Norm(const DiscreteValueVect &v1, const DiscreteValueVect &v2)
RDKit::operator-
RDKIT_DATASTRUCTS_EXPORT DiscreteValueVect operator-(const DiscreteValueVect &p1, const DiscreteValueVect &p2)
RDKit::operator+
RDKIT_DATASTRUCTS_EXPORT DiscreteValueVect operator+(const DiscreteValueVect &p1, const DiscreteValueVect &p2)
RDKit::operator|
RDKIT_DATASTRUCTS_EXPORT RealValueVect operator|(const RealValueVect &p1, const RealValueVect &p2)
support rvv3 = rvv1|rvv2