lsst.afw  22.0.1-35-g9503da760+64490af121
Public Member Functions | List of all members
lsst::afw::math::KdTree< T > Class Template Reference

The data for GaussianProcess is stored in a KD tree to facilitate nearest-neighbor searches. More...

#include <GaussianProcess.h>

Public Member Functions

 KdTree (const KdTree &)=delete
 
KdTreeoperator= (const KdTree &)=delete
 
 KdTree (KdTree &&)=delete
 
KdTreeoperator= (KdTree &&)=delete
 
 KdTree ()=default
 
void Initialize (ndarray::Array< T, 2, 2 > const &dt)
 Build a KD Tree to store the data for GaussianProcess. More...
 
void findNeighbors (ndarray::Array< int, 1, 1 > neighdex, ndarray::Array< double, 1, 1 > dd, ndarray::Array< const T, 1, 1 > const &v, int n_nn) const
 Find the nearest neighbors of a point. More...
 
getData (int ipt, int idim) const
 Return one element of one node on the tree. More...
 
ndarray::Array< T, 1, 1 > getData (int ipt) const
 Return an entire node from the tree. More...
 
void addPoint (ndarray::Array< const T, 1, 1 > const &v)
 Add a point to the tree. More...
 
void removePoint (int dex)
 Remove a point from the tree. More...
 
int getNPoints () const
 return the number of data points stored in the tree More...
 
void getTreeNode (ndarray::Array< int, 1, 1 > const &v, int dex) const
 Return the _tree information for a given data point. More...
 

Detailed Description

template<typename T>
class lsst::afw::math::KdTree< T >

The data for GaussianProcess is stored in a KD tree to facilitate nearest-neighbor searches.

Note: I have removed the ability to arbitrarily specify a distance function. The KD Tree nearest neighbor search algorithm only makes sense in the case of Euclidean distances, so I have forced KdTree to use Euclidean distances.

Definition at line 224 of file GaussianProcess.h.

Constructor & Destructor Documentation

◆ KdTree() [1/3]

template<typename T >
lsst::afw::math::KdTree< T >::KdTree ( const KdTree< T > &  )
delete

◆ KdTree() [2/3]

template<typename T >
lsst::afw::math::KdTree< T >::KdTree ( KdTree< T > &&  )
delete

◆ KdTree() [3/3]

template<typename T >
lsst::afw::math::KdTree< T >::KdTree ( )
default

Member Function Documentation

◆ addPoint()

template<typename T >
void lsst::afw::math::KdTree< T >::addPoint ( ndarray::Array< const T, 1, 1 > const &  v)

Add a point to the tree.

Allot more space in _tree and data if needed.

Parameters
[in]vthe point you are adding to the tree
Exceptions
pex::exceptions::RuntimeErrorif the branch ending in the new point is not properly constructed

Definition at line 210 of file GaussianProcess.cc.

◆ findNeighbors()

template<typename T >
void lsst::afw::math::KdTree< T >::findNeighbors ( ndarray::Array< int, 1, 1 >  neighdex,
ndarray::Array< double, 1, 1 >  dd,
ndarray::Array< const T, 1, 1 > const &  v,
int  n_nn 
) const

Find the nearest neighbors of a point.

Parameters
[out]neighdexthis is where the indices of the nearest neighbor points will be stored
[out]ddthis is where the distances to the nearest neighbors will be stored
[in]vthe point whose neighbors you want to find
[in]n_nnthe number of nearest neighbors you want to find

neighbors will be returned in ascending order of distance

note that distance is forced to be the Euclidean distance

Definition at line 135 of file GaussianProcess.cc.

◆ getData() [1/2]

template<typename T >
ndarray::Array< T, 1, 1 > lsst::afw::math::KdTree< T >::getData ( int  ipt) const

Return an entire node from the tree.

Parameters
[in]iptthe index of the node to return

I currently have this as a return-by-value method. When I tried it as a return-by-reference, the compiler gave me

warning: returning reference to local temporary object

Based on my reading of Stack Overflow, this is because ndarray was implicitly creating a new ndarray::Array<T,1,1> object and passing a reference thereto. It is unclear to me whether or not this object would be destroyed once the call to getData was complete.

The code still compiled, ran, and passed the unit tests, but the above behavior seemed to me like it could be dangerous (and, because ndarray was still creating a new object, it did not seem like we were saving any time), so I reverted to return-by-value.

Definition at line 200 of file GaussianProcess.cc.

◆ getData() [2/2]

template<typename T >
T lsst::afw::math::KdTree< T >::getData ( int  ipt,
int  idim 
) const

Return one element of one node on the tree.

Parameters
[in]iptthe index of the node to return
[in]idimthe index of the dimension to return

Definition at line 185 of file GaussianProcess.cc.

◆ getNPoints()

template<typename T >
int lsst::afw::math::KdTree< T >::getNPoints

return the number of data points stored in the tree

Definition at line 274 of file GaussianProcess.cc.

◆ getTreeNode()

template<typename T >
void lsst::afw::math::KdTree< T >::getTreeNode ( ndarray::Array< int, 1, 1 > const &  v,
int  dex 
) const

Return the _tree information for a given data point.

Parameters
[out]vthe array in which to store the entry from _tree
[in]dexthe index of the node whose information you are requesting

Definition at line 279 of file GaussianProcess.cc.

◆ Initialize()

template<typename T >
void lsst::afw::math::KdTree< T >::Initialize ( ndarray::Array< T, 2, 2 > const &  dt)

Build a KD Tree to store the data for GaussianProcess.

Parameters
[in]dtan array, the rows of which are the data points (dt[i][j] is the jth component of the ith data point)
Exceptions
pex::exceptions::RuntimeErrorif the tree is not properly constructed

Definition at line 104 of file GaussianProcess.cc.

◆ operator=() [1/2]

template<typename T >
KdTree& lsst::afw::math::KdTree< T >::operator= ( const KdTree< T > &  )
delete

◆ operator=() [2/2]

template<typename T >
KdTree& lsst::afw::math::KdTree< T >::operator= ( KdTree< T > &&  )
delete

◆ removePoint()

template<typename T >
void lsst::afw::math::KdTree< T >::removePoint ( int  dex)

Remove a point from the tree.

Reorganize what remains so that the tree remains self-consistent

Parameters
[in]dexthe index of the point you want to remove from the tree
Exceptions
pex::exceptions::RuntimeErrorif the entire tree is not poperly constructed after the point has been removed

Definition at line 582 of file GaussianProcess.cc.


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