RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
RDNumeric::Vector< TYPE > Class Template Reference

A class to represent vectors of numbers. More...

#include <Vector.h>

Public Types

typedef std::shared_ptr< TYPE[]> DATA_SPTR
 

Public Member Functions

constexpr Vector (unsigned int N)
 Initialize with only a size.
 
constexpr Vector (unsigned int N, TYPE val)
 Initialize with a size and default value.
 
constexpr Vector (unsigned int N, DATA_SPTR data)
 Initialize from a smart pointer.
 
constexpr Vector (const Vector &other)
 copy constructor
 
constexpr ~Vector ()=default
 
constexpr unsigned int size () const
 return the size (dimension) of the vector
 
TYPE getVal (unsigned int i) const
 returns the value at a particular index
 
void setVal (unsigned int i, TYPE val)
 sets the index at a particular value
 
TYPE operator[] (unsigned int i) const
 
TYPE & operator[] (unsigned int i)
 
constexpr TYPE * getData ()
 returns a pointer to our data array
 
constexpr const TYPE * getData () const
 returns a const pointer to our data array
 
Vector< TYPE > & assign (const Vector< TYPE > &other)
 Copy operator.
 
Vector< TYPE > & operator+= (const Vector< TYPE > &other)
 elementwise addition, vectors must be the same size.
 
Vector< TYPE > & operator-= (const Vector< TYPE > &other)
 elementwise subtraction, vectors must be the same size.
 
constexpr Vector< TYPE > & operator*= (TYPE scale)
 multiplication by a scalar
 
constexpr Vector< TYPE > & operator/= (TYPE scale)
 division by a scalar
 
constexpr TYPE normL2Sq () const
 L2 norm squared.
 
constexpr TYPE normL2 () const
 L2 norm.
 
constexpr TYPE normL1 () const
 L1 norm.
 
constexpr TYPE normLinfinity () const
 L-infinity norm.
 
constexpr 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-infinity norm.
 
constexpr unsigned int largestValId () const
 Gets the ID of the entry that has the largest value.
 
constexpr unsigned int smallestValId () const
 Gets the ID of the entry that has the smallest value.
 
TYPE dotProduct (const Vector< TYPE > other) const
 returns the dot product between two Vectors
 
constexpr void normalize ()
 Normalize the vector using the L2 norm.
 
void setToRandom (unsigned int seed=0)
 Set to a random unit vector.
 

Detailed Description

template<class TYPE>
class RDNumeric::Vector< TYPE >

A class to represent vectors of numbers.

Definition at line 30 of file Vector.h.

Member Typedef Documentation

◆ DATA_SPTR

template<class TYPE>
typedef std::shared_ptr<TYPE[]> RDNumeric::Vector< TYPE >::DATA_SPTR

Definition at line 32 of file Vector.h.

Constructor & Destructor Documentation

◆ Vector() [1/4]

template<class TYPE>
RDNumeric::Vector< TYPE >::Vector ( unsigned int N)
inlineexplicitconstexpr

Initialize with only a size.

Definition at line 35 of file Vector.h.

◆ Vector() [2/4]

template<class TYPE>
RDNumeric::Vector< TYPE >::Vector ( unsigned int N,
TYPE val )
inlineconstexpr

Initialize with a size and default value.

Definition at line 43 of file Vector.h.

◆ Vector() [3/4]

template<class TYPE>
RDNumeric::Vector< TYPE >::Vector ( unsigned int N,
DATA_SPTR data )
inlineconstexpr

Initialize from a smart pointer.

NOTE: the data is not copied in this case

Definition at line 55 of file Vector.h.

◆ Vector() [4/4]

template<class TYPE>
RDNumeric::Vector< TYPE >::Vector ( const Vector< TYPE > & other)
inlineconstexpr

copy constructor

We make a copy of the other vector's data.

Definition at line 63 of file Vector.h.

◆ ~Vector()

template<class TYPE>
RDNumeric::Vector< TYPE >::~Vector ( )
constexprdefault

Member Function Documentation

◆ assign()

template<class TYPE>
Vector< TYPE > & RDNumeric::Vector< TYPE >::assign ( const Vector< TYPE > & other)
inline

Copy operator.

We make a copy of the other Vector's data.

Definition at line 112 of file Vector.h.

◆ dotProduct()

template<class TYPE>
TYPE RDNumeric::Vector< TYPE >::dotProduct ( const Vector< TYPE > other) const
inline

returns the dot product between two Vectors

Definition at line 244 of file Vector.h.

Referenced by RDNumeric::TanimotoSimilarity().

◆ getData() [1/2]

◆ getData() [2/2]

template<class TYPE>
const TYPE * RDNumeric::Vector< TYPE >::getData ( ) const
inlineconstexpr

returns a const pointer to our data array

Definition at line 103 of file Vector.h.

◆ getVal()

template<class TYPE>
TYPE RDNumeric::Vector< TYPE >::getVal ( unsigned int i) const
inline

returns the value at a particular index

Definition at line 78 of file Vector.h.

Referenced by operator<<().

◆ largestAbsValId()

template<class TYPE>
unsigned int RDNumeric::Vector< TYPE >::largestAbsValId ( ) const
inlineconstexpr

Gets the ID of the entry that has the largest absolute value i.e. the entry being used for the L-infinity norm.

Definition at line 202 of file Vector.h.

◆ largestValId()

template<class TYPE>
unsigned int RDNumeric::Vector< TYPE >::largestValId ( ) const
inlineconstexpr

Gets the ID of the entry that has the largest value.

Definition at line 216 of file Vector.h.

◆ normalize()

template<class TYPE>
void RDNumeric::Vector< TYPE >::normalize ( )
inlineconstexpr

Normalize the vector using the L2 norm.

Definition at line 258 of file Vector.h.

Referenced by RDNumeric::Vector< double >::setToRandom().

◆ normL1()

template<class TYPE>
TYPE RDNumeric::Vector< TYPE >::normL1 ( ) const
inlineconstexpr

L1 norm.

Definition at line 177 of file Vector.h.

◆ normL2()

template<class TYPE>
TYPE RDNumeric::Vector< TYPE >::normL2 ( ) const
inlineconstexpr

L2 norm.

Definition at line 174 of file Vector.h.

Referenced by RDNumeric::Vector< double >::normalize().

◆ normL2Sq()

template<class TYPE>
TYPE RDNumeric::Vector< TYPE >::normL2Sq ( ) const
inlineconstexpr

L2 norm squared.

Definition at line 163 of file Vector.h.

Referenced by RDNumeric::Vector< double >::normL2(), and RDNumeric::TanimotoSimilarity().

◆ normLinfinity()

template<class TYPE>
TYPE RDNumeric::Vector< TYPE >::normLinfinity ( ) const
inlineconstexpr

L-infinity norm.

Definition at line 188 of file Vector.h.

◆ operator*=()

template<class TYPE>
Vector< TYPE > & RDNumeric::Vector< TYPE >::operator*= ( TYPE scale)
inlineconstexpr

multiplication by a scalar

Definition at line 145 of file Vector.h.

◆ operator+=()

template<class TYPE>
Vector< TYPE > & RDNumeric::Vector< TYPE >::operator+= ( const Vector< TYPE > & other)
inline

elementwise addition, vectors must be the same size.

Definition at line 121 of file Vector.h.

◆ operator-=()

template<class TYPE>
Vector< TYPE > & RDNumeric::Vector< TYPE >::operator-= ( const Vector< TYPE > & other)
inline

elementwise subtraction, vectors must be the same size.

Definition at line 133 of file Vector.h.

◆ operator/=()

template<class TYPE>
Vector< TYPE > & RDNumeric::Vector< TYPE >::operator/= ( TYPE scale)
inlineconstexpr

division by a scalar

Definition at line 154 of file Vector.h.

◆ operator[]() [1/2]

template<class TYPE>
TYPE & RDNumeric::Vector< TYPE >::operator[] ( unsigned int i)
inline

Definition at line 94 of file Vector.h.

◆ operator[]() [2/2]

template<class TYPE>
TYPE RDNumeric::Vector< TYPE >::operator[] ( unsigned int i) const
inline

Definition at line 89 of file Vector.h.

◆ setToRandom()

template<class TYPE>
void RDNumeric::Vector< TYPE >::setToRandom ( unsigned int seed = 0)
inline

Set to a random unit vector.

Definition at line 267 of file Vector.h.

◆ setVal()

template<class TYPE>
void RDNumeric::Vector< TYPE >::setVal ( unsigned int i,
TYPE val )
inline

sets the index at a particular value

Definition at line 84 of file Vector.h.

◆ size()

◆ smallestValId()

template<class TYPE>
unsigned int RDNumeric::Vector< TYPE >::smallestValId ( ) const
inlineconstexpr

Gets the ID of the entry that has the smallest value.

Definition at line 230 of file Vector.h.


The documentation for this class was generated from the following file: