84namespace ca_metrics_detail {
87inline constexpr std::uint64_t
fnv_basis = 14695981039346656037ull;
88inline constexpr std::uint64_t
fnv_prime = 1099511628211ull;
91inline constexpr std::uint64_t
fnv1a_step(std::uint64_t
h,
const std::uint8_t b)
noexcept
93 h ^=
static_cast<std::uint64_t
>(b);
102 static_assert(std::is_trivially_copyable_v<T>,
103 "frame_hash requires trivially copyable cell states");
104 std::uint8_t buf[
sizeof(
T)];
107 for (std::size_t i = 0; i <
sizeof(
T); ++i)
132template <
typename Lattice,
typename F>
156 else if constexpr (Lattice::rank == 3)
161 for (ca_size_t i = 0; i < n0; ++i)
162 for (ca_size_t j = 0; j < n1; ++j)
163 for (ca_size_t
k = 0;
k < n2; ++
k)
169 static_assert(Lattice::rank <= 3,
"for_each_cell currently supports rank <= 3");
174template <
typename Lattice>
187template <
typename Lattice>
203template <
typename Lattice>
211template <
typename Lattice>
222template <
typename Lattice>
240template <
typename Lattice>
247 if constexpr (std::is_integral_v<S>
or std::is_enum_v<S>)
249 const long long iv =
static_cast<long long>(v);
251 ++
hist[
static_cast<std::size_t
>(
iv)];
275template <
typename Lattice>
285 const double inv = 1.0 /
static_cast<double>(
total);
289 const double p =
static_cast<double>(c) *
inv;
290 h -= p * std::log(p);
310template <
typename Lattice>
313 std::uint64_t
h = ca_metrics_detail::fnv_basis;
316 h = ca_metrics_detail::fnv1a_mix(
h, v);
322template <
typename Lattice>
332 if (a.at_node(i) != b.at_node(i))
336 else if constexpr (Lattice::rank == 1)
342 if (a.
at(c) != b.
at(c))
347 else if constexpr (Lattice::rank == 2)
355 if (a.
at(c) != b.
at(c))
360 else if constexpr (Lattice::rank == 3)
371 if (a.
at(c) != b.
at(c))
378 static_assert(Lattice::rank <= 3,
"frames_equal currently supports rank <= 3");
385template <
typename Lattice>
389 <<
"cell_diff_count: lattices have different extents";
397 if (a.at_node(i) != b.at_node(i))
400 else if constexpr (Lattice::rank == 1)
406 if (a.
at(c) != b.
at(c))
410 else if constexpr (Lattice::rank == 2)
418 if (a.
at(c) != b.
at(c))
422 else if constexpr (Lattice::rank == 3)
433 if (a.
at(c) != b.
at(c))
439 static_assert(Lattice::rank <= 3,
"cell_diff_count currently supports rank <= 3");
Exception handling system with formatted messages for Aleph-w.
#define ah_length_error_if(C)
Throws std::length_error if condition holds.
size_t size_t int32_t value
Common typedefs and tag types for the Cellular Automata module.
Simple dynamic array with automatic resizing and functional operations.
Lattice that adds boundary-aware access on top of a storage.
typename Storage::state_type state_type
const extents_type & extents() const noexcept
typename Storage::coord_type coord_type
static constexpr std::size_t rank
ca_size_t size() const noexcept
state_type at(const coord_type &c) const
Strict access: throws if c is out of range.
size_t size() const noexcept
Count the number of elements of the list.
Detect whether L exposes a graph-style at_node(size_t) accessor.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
std::uint64_t fnv1a_mix(std::uint64_t h, const T &value) noexcept
Mix every byte of value (in little-endian order) into an FNV-1a hash.
constexpr std::uint64_t fnv_basis
FNV-1a 64-bit basis and prime constants.
constexpr std::uint64_t fnv_prime
constexpr std::uint64_t fnv1a_step(std::uint64_t h, const std::uint8_t b) noexcept
Mix one byte into an FNV-1a hash.
double shannon_entropy(const Lattice &lat, std::size_t max_state)
Shannon entropy in nats of the [0, max_state) distribution.
Array< ca_size_t > state_histogram(const Lattice &lat, std::size_t max_state)
Count occurrences of every integer state in [0, max_state).
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
ca_size_t total_cells(const Lattice &lat) noexcept
std::uint64_t frame_hash(const Lattice &lat)
Deterministic 64-bit FNV-1a hash of the lattice cells.
void for_each_cell(const Lattice &lat, F &&f)
Visit every cell of a lattice in canonical row-major order.
double density(const Lattice &lat, const typename Lattice::state_type &s)
ca_size_t count_state(const Lattice &lat, const typename Lattice::state_type &s)
ca_size_t count_alive(const Lattice &lat)
double alive_density(const Lattice &lat)
std::size_t ca_size_t
Unsigned size component used for extents and counts.
ca_size_t cell_diff_count(const Lattice &a, const Lattice &b)
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
std::decay_t< typename HeadC::Item_Type > T
bool diff(const C1 &c1, const C2 &c2, Eq e=Eq())
Check if two containers differ.
Dynamic array container with automatic resizing.
C++20 concepts for the Cellular Automata module.
static bool frames_equal(const L &a, const L &b)