rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
scalar_value.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include "numerical_type.hpp"
6#include "fixed_width_float.hpp"
7#include "../memory/byte.hpp"
8
9#include <array>
10#include <complex>
11#include <cstddef>
12#include <stdexcept>
13
14namespace rexlib
15{
16
21 : public std::exception
22{
23public:
24 using exception::exception;
25};
26
35{
36public:
43 template <typename T>
44 scalar_value(const T &value) noexcept;
45 scalar_value(const scalar_value &other) = default;
46 scalar_value(scalar_value &&other) = default;
47 ~scalar_value() = default;
48
49 scalar_value& operator=(const scalar_value &other) = default;
50 scalar_value& operator=(scalar_value &&other) = default;
51
59 template <typename T>
60 const T& get() const;
61
69 template <typename T>
71
78
80 // The largest representable scalar determines the storage size and
81 // alignment. All representable scalars are trivially copyable, which makes
82 // scalar_value trivially copyable as well.
83 using largest_type = std::complex<float64_t>;
84 static const std::size_t storage_size = sizeof(largest_type);
85 static const std::size_t storage_alignment = alignof(largest_type);
86
87 alignas(storage_alignment) std::array<byte, storage_size> m_storage;
88 numerical_type m_data_type;
89};
90
108
124
125} // namespace rexlib
126
127#include "scalar_value.inl"
Container for multidimensional numeric data.
Definition array.hpp:31
Exception thrown when accessing a scalar_value with an incorrect type.
Definition scalar_value.hpp:22
Owns a copy of a dynamically typed scalar value.
Definition scalar_value.hpp:35
const T & get() const
Type-safe access to the stored value.
const T * get_if() const noexcept
Type-safe, non-throwing access to the stored value.
numerical_type get_data_type() const noexcept
Get the numerical type of the stored value.
scalar_value(const T &value) noexcept
Construct a new scalar value object holding a copy of the input.
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10
T scalar_value_cast(const scalar_value &value)
Convert the value held by a scalar_value into a concrete type.
numerical_type
Representation of all considered numerical types for computations.
Definition numerical_type.hpp:19
REXLIB_CONSTEXPR auto visit(F &&func, const dynamic_subscript &subscript)
Invoke the provided function with the value held by the dynamic subscript.