38 static_assert(std::atomic_ref<double>::is_always_lock_free);
54 return *
this =
static_cast<double>(other);
57 [[nodiscard]]
operator double() const noexcept
59 return std::atomic_ref<double>(
m_data[
m_index]).load(std::memory_order_relaxed);
65 Cell(std::vector<double>& data,
size_t index) noexcept
98 "Weights: row count mismatch. Expected {} rows, received {}",
m_rows,
values.size());
101 for (
const auto& source :
values) {
102 if (source.size() !=
m_cols) {
104 "Weights: column count mismatch at row {}. Expected {} cols, received {}",
row,
m_cols, source.size());
107 for (
double value : source) {
125 [[nodiscard]]
size_t rows() const noexcept {
return m_rows; }
126 [[nodiscard]]
size_t cols() const noexcept {
return m_cols; }
141 [[nodiscard]]
double get(
size_t row,
size_t col)
const noexcept
143 return std::atomic_ref<double>(
const_cast<double&
>(
m_data[
row *
m_cols + col]))
144 .load(std::memory_order_relaxed);
150 [[nodiscard]] std::span<const double>
row(
size_t row)
const noexcept
157 for (
double& slot :
m_data) {
158 std::atomic_ref<double>(slot).store(
value, std::memory_order_relaxed);
164 for (
size_t col = 0; col <
m_cols; ++col) {
166 cell =
static_cast<double>(cell) * factor;
177 for (
size_t col = 0; col <
m_cols; ++col) {
198 for (
size_t i = 0; i <
m_rows; ++i) {
224 void apply_edges(std::span<
const std::pair<size_t, size_t>> edges,
225 double weight = 1.0,
bool symmetric =
true,
bool normalize =
true) noexcept
227 for (
const auto& [
a,
b] : edges) {
236 for (
size_t i = 0; i <
m_rows; ++i) {
255 for (
double weight : weights) {
260 return weights.size();
263 const double target = generator(0.0,
total);
264 double running = 0.0;
265 for (
size_t i = 0; i < weights.size(); ++i) {
266 running += std::max(0.0, weights[i]);
267 if (target <= running) {
271 return weights.size() - 1;
std::vector< std::byte > values
Unified generative infrastructure for stochastic and procedural algorithms.
Cell & operator=(const Cell &other) noexcept
std::vector< double > & m_data
Cell & operator=(double value) noexcept
Cell(std::vector< double > &data, size_t index) noexcept
Proxy for one cell with atomic load and store.
std::span< const double > row(size_t row) const noexcept
Non-atomic view of one row.
void assign(size_t rows, size_t cols, double initial=0.0)
Replace dimensions and reset every cell.
static size_t weighted_pick(std::span< const double > weights, Stochastic &generator)
Weighted random draw over a row of nonnegative weights.
void fill(double value) noexcept
Weights & operator=(std::initializer_list< std::initializer_list< double > > values)
Assign every cell from nested initializer lists.
void apply_edges(std::span< const std::pair< size_t, size_t > > edges, double weight=1.0, bool symmetric=true, bool normalize=true) noexcept
Write an adjacency edge list into this table.
std::vector< double > m_data
Cell operator()(size_t row, size_t col) noexcept
Access one cell.
size_t rows() const noexcept
void uniform_excluding_self() noexcept
Every cell uniform except the diagonal, each row normalized to sum to one.
size_t cols() const noexcept
void scale_row(size_t row, double factor) noexcept
Weights(size_t rows, size_t cols, double initial=0.0)
double get(size_t row, size_t col) const noexcept
Atomic read of one cell.
size_t weighted_pick(size_t row_index, Stochastic &generator) const
Weighted random draw over one row of this table.
void normalize_row(size_t row) noexcept
Scale a row so its cells sum to one.
Rows-by-columns table of doubles with atomic cell access.
@ Runtime
General runtime operations (default fallback)
@ Kinesis
General mathematical and physics algorithns.