← Documentation
ADS-IDAC Engine 5.0.0
factor.hpp
Go to the documentation of this file.
1#pragma once
11#include "bncore/graph/node.hpp"
12#include <vector>
13
14namespace bncore {
15
22class Factor {
23public:
30 Factor(const std::vector<NodeId> &scope,
31 const std::vector<std::size_t> &state_sizes);
41 Factor(const std::vector<NodeId> &scope,
42 const std::vector<std::size_t> &state_sizes, double *preallocated_ptr);
43
45 [[nodiscard]] const std::vector<NodeId> &scope() const { return scope_; }
46
65 [[nodiscard]] Factor multiply(const Factor &other,
66 class BumpAllocator *allocator = nullptr) const;
78 [[nodiscard]] Factor
79 marginalize(const std::vector<NodeId> &marg_vars,
80 class BumpAllocator *allocator = nullptr) const;
81
83 DenseTensor &tensor() { return tensor_; }
85 [[nodiscard]] const DenseTensor &tensor() const { return tensor_; }
86
90 void bind_data(double *ptr);
91
92 // Core math operations
93
94private:
95 std::vector<NodeId> scope_;
97};
98
99} // namespace bncore
Fixed-capacity scratch buffer of doubles with pointer-bump allocation.
Dense row-major array of doubles with a fixed shape.
A potential over an ordered scope of variables.
Definition: factor.hpp:22
Factor multiply(const Factor &other, class BumpAllocator *allocator=nullptr) const
Product of two factors.
Definition: factor.cpp:27
DenseTensor tensor_
Definition: factor.hpp:96
Factor(const std::vector< NodeId > &scope, const std::vector< std::size_t > &state_sizes)
Creates a factor that owns zero-initialized storage.
Definition: factor.cpp:6
void bind_data(double *ptr)
Redirects the value table to a caller buffer. See DenseTensor::bind_data().
Definition: factor.cpp:25
std::vector< NodeId > scope_
Definition: factor.hpp:95
const std::vector< NodeId > & scope() const
Variables of the factor, in tensor dimension order.
Definition: factor.hpp:45
Factor marginalize(const std::vector< NodeId > &marg_vars, class BumpAllocator *allocator=nullptr) const
Sums variables out of the factor.
Definition: factor.cpp:151
DenseTensor & tensor()
The value table.
Definition: factor.hpp:83
const DenseTensor & tensor() const
The value table, read only.
Definition: factor.hpp:85
bncore::DenseTensor, a row-major multi-dimensional array of doubles that either owns its storage or b...
Basic BNCore types: the NodeId variable handle and the VariableMetadata record that Graph stores for ...