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#include <vector>
19
20namespace RDGeom {
22}
23namespace RDKit {
24
25//! a class for efficiently storing vectors of double values
26//! Has additional features compared to std::vector<double>:
27//! construct from and write to pickle
29 public:
30 RealValueVect() = default;
31 //! initialize with a particular size
32 RealValueVect(unsigned int length) : d_length(length) {
33 d_data.resize(d_length, 0.0);
34 }
35
36 //! initialize with a particular size and initial value
37 RealValueVect(unsigned int length, double val) : d_length(length) {
38 d_data.resize(d_length, val);
39 }
40
41 //! constructor from a pickle
42 RealValueVect(const std::string &pkl) {
43 initFromText(pkl.c_str(), pkl.size());
44 };
45
46 //! constructor from a pickle
47 RealValueVect(const char *pkl, unsigned int len) { initFromText(pkl, len); };
48
49 //! return the value at an index
50 double getVal(unsigned int i) const;
51
52 //! support indexing using []
53 double operator[](unsigned int idx) const { return getVal(idx); };
54
55 //! set the value at an index
56 void setVal(unsigned int i, double val);
57
58 //! returns the sum of all the elements in the vect
59 double getTotalVal() const;
60
61 //! returns the length
62 unsigned int getLength() const { return d_length; };
63
64 //! returns the length
65 unsigned int size() const { return getLength(); };
66
67 //! compares 2 vectors and returns false if different
68 bool compareVectors(const RealValueVect &other) const;
69
70 //! in-place operator&
72
73 //! in-place operator|
75
76 //! in-place operator+
78
79 //! in-place operator-
81
82 //! returns a binary string representation (pickle)
83 std::string toString() const;
84
85 void setLength(unsigned int sz) {
86 d_length = sz;
87 d_data.resize(sz);
88 }
89 void setToVal(double val) { std::fill(d_data.begin(), d_data.end(), val); }
90
91 const std::vector<double> &getData() const { return d_data; }
92 std::vector<double> &getData() { return d_data; }
93
94 private:
95 void initFromText(const char *pkl, const unsigned int len);
96 unsigned int d_length = 0;
97 std::vector<double> d_data;
98
99 template <typename O>
100 RealValueVect &applyBinaryOp(const RealValueVect &other, O op);
101}; // end of declaration of class RealValueVect
102
103//! returns L1 Norm of vectors
105 const RealValueVect &v2);
106
107//! returns the sum of vectors
109 const RealValueVect &p2);
110
111//! returns the difference of vectors
113 const RealValueVect &p2);
114
115//! support rvv3 = rvv1|rvv2
116/*!
117
118 operator| returns the maximum value for each element.
119 e.g.:
120 [0,1,2,0] | [0,1,1,1] -> [0,1,2,1]
121
122 */
124 const RealValueVect &p2);
125
126//! support rvv3 = rvv1&rvv2
127/*!
128 operator& returns the minimum value for each element.
129 e.g.:
130 [0,1,2,0] & [0,1,1,1] -> [0,1,1,0]
131
132 */
134 const RealValueVect &p2);
135
136} // end of namespace RDKit
137
138#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:111
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