Template Struct KDTreeData
Defined in File KDTree.hpp
Inheritance Relationships
Derived Type
public kden::KernelDensityData< AuxType >(Template Struct KernelDensityData)
Struct Documentation
-
template<typename AuxType = void>
struct KDTreeData The points a KDTree indexes: a non-owning view of a struct of arrays.
Views N points of nDim_ dimensions each, as one flat array of positions (x_, N x nDim_ doubles, point-major: point i occupies x_[i * nDim_] through x_[i * nDim_ + nDim_ - 1]) and, unless AuxType is void, one of auxiliary data (aux_, N elements of AuxType). Building a KDTree over it reorders both together, in place, in the caller’s own storage: the arrays are spans, so they can view any contiguous storage (e.g. an OwnedKDTreeData’s vectors, or arrays owned by Python) without copying it. The storage must outlive any tree built over it. With AuxType void, aux_ is an empty placeholder that occupies no storage.
A type derived from this may add further per-point arrays (as KernelDensityData adds weights) and have the tree reorder them too, by hiding swap() with a version that swaps its own arrays and then calls this one, and likewise extending validate(): the tree is templated on the concrete data type (see KDTreePoints), so calls its versions directly, with no virtual dispatch.
- Template Parameters:
AuxType – Type of the auxiliary data carried by each point (e.g. an index into an original data set), or void (the default) for none
Subclassed by kden::KernelDensityData< AuxType >
Public Functions
-
inline auto size() const -> std::size_t
Number of points.
- Returns:
N, the number of positions (zero if nDim_ is zero)
-
inline auto position(const std::size_t i) const -> std::span<const double>
Position of a point.
- Parameters:
i – Index of the point
- Returns:
A view of its nDim_ coordinates
-
inline auto aux(const std::size_t i) const -> const auto&
Auxiliary data of a point.
- Parameters:
i – Index of the point
- Returns:
Its auxiliary data
-
inline void validate() const
Check that the arrays are consistent with one another, and finite.
Stored positions must be finite: NaN marks unspecified dimensions only in search points, and a non-finite stored coordinate would give a node non-finite bounds, which the search’s pruning bound cannot handle (and would break the ordering the build relies on). Data with non-finite values – e.g. infinite magnitudes for clusters with no luminous stars – must be filtered before building a tree.
- Throws:
std::invalid_argument – if nDim_ is 0, x_’s size is not a multiple of nDim_, aux_ does not have one element per point, or any position coordinate is not finite
-
inline void swap(const std::size_t i, const std::size_t j)
Exchange two points: their positions and auxiliary data.
- Parameters:
i – Index of one point
j – Index of the other
Public Members
-
std::size_t nDim_ = 0
Number of dimensions of each position
-
std::span<double> x_
Positions, N x nDim_, point-major (not owned)
-
KDTreeAuxStorage<AuxType>::View aux_
Auxiliary data, one per point (if AuxType is not void; not owned)