31template <
class ElementType>
struct FullGenerator
35 template <
class Indices> [[nodiscard]]
UNI20_HOST_DEVICE constexpr ElementType operator()(Indices
const&)
const
41template <
class ElementType>
struct ZeroGenerator
43 template <
class Indices> [[nodiscard]]
UNI20_HOST_DEVICE constexpr ElementType operator()(Indices
const&)
const
45 return ElementType{0};
49template <
class ElementType>
struct OneGenerator
51 template <
class Indices> [[nodiscard]]
UNI20_HOST_DEVICE constexpr ElementType operator()(Indices
const&)
const
53 return ElementType{1};
57template <
class ElementType>
struct EyeGenerator
59 template <
class Indices>
60 [[nodiscard]]
UNI20_HOST_DEVICE constexpr ElementType operator()(Indices
const& indices)
const
62 if constexpr (std::tuple_size_v<std::remove_cvref_t<Indices>> > 1)
64 for (std::size_t axis = 1; axis < indices.size(); ++axis)
65 if (indices[axis] != indices[0])
return ElementType{0};
67 return ElementType{1};
77template <Scalar ElementType,
class Extents,
class Generator>
class GeneratedTensor {
87 using mapping_type =
typename layout_type::template mapping<extents_type>;
89 using mdspan_type = stdex::mdspan<element_type const, extents_type, layout_type, accessor_type>;
93 : extents_(
std::move(
extents)), generator_(
std::move(generator))
112 [[nodiscard]]
constexpr auto extent(std::size_t axis)
const noexcept ->
index_type {
return extents_.extent(axis); }
115 [[nodiscard]]
static constexpr std::size_t
rank() noexcept {
return extents_type::rank(); }
118 template <
class... Index>
119 requires(
sizeof...(Index) == extents_type::rank())
120 [[nodiscard]]
constexpr element_type operator[](Index... indices)
const
122 return this->
mdspan()[indices...];
131template <
Scalar ElementType, std::integral... Extents> [[nodiscard]]
auto full(ElementType
value, Extents... extents)
133 auto shape = detail::make_tensor_extents(extents...);
134 using shape_type =
decltype(shape);
135 using generator_type = detail::FullGenerator<ElementType>;
140template <
Scalar ElementType, std::integral... Extents> [[nodiscard]]
auto zeros(Extents... extents)
142 auto shape = detail::make_tensor_extents(extents...);
143 using shape_type =
decltype(shape);
144 using generator_type = detail::ZeroGenerator<ElementType>;
149template <
Scalar ElementType, std::integral... Extents> [[nodiscard]]
auto ones(Extents... extents)
151 auto shape = detail::make_tensor_extents(extents...);
152 using shape_type =
decltype(shape);
153 using generator_type = detail::OneGenerator<ElementType>;
161template <
Scalar ElementType, std::integral... Extents> [[nodiscard]]
auto eye(Extents... extents)
163 auto shape = detail::make_tensor_extents(extents...);
164 using shape_type =
decltype(shape);
165 using generator_type = detail::EyeGenerator<ElementType>;
Compact read-only tensor evaluated from logical indices.
Definition generated.hpp:77
Extents extents_type
Definition generated.hpp:81
typename extents_type::index_type index_type
Definition generated.hpp:85
element_type value_type
Definition generated.hpp:80
constexpr auto mdspan() const -> mdspan_type
Resolve a self-contained generated mdspan descriptor.
Definition generated.hpp:103
static constexpr auto backend_selector() noexcept -> backend_selector_type
Return the host fallback selector used when no concrete storage operand is present.
Definition generated.hpp:97
constexpr auto extent(std::size_t axis) const noexcept -> index_type
Return one generated tensor extent.
Definition generated.hpp:112
constexpr GeneratedTensor(extents_type extents, generator_type generator)
Construct from extents and compact generator state.
Definition generated.hpp:92
constexpr auto extents() const noexcept -> extents_type const &
Return the generated tensor extents.
Definition generated.hpp:109
ElementType element_type
Definition generated.hpp:79
static constexpr std::size_t rank() noexcept
Return the tensor's static rank.
Definition generated.hpp:115
typename storage_policy::backend_selector_type backend_selector_type
Definition generated.hpp:84
Generator generator_type
Definition generated.hpp:82
stdex::mdspan< element_type const, extents_type, layout_type, accessor_type > mdspan_type
Definition generated.hpp:89
typename layout_type::template mapping< extents_type > mapping_type
Definition generated.hpp:87
Accessor that evaluates a generator at the logical index encoded by an offset.
Definition generated_accessor.hpp:33
Project compiler annotations shared by host and device code.
#define UNI20_HOST_DEVICE
Definition compiler_attributes.hpp:12
Concept for numeric scalar types (integer, real, or complex).
Definition scalar_concepts.hpp:81
locale_t value
Definition data_table.cpp:49
Read-only mdspan accessor for values generated from logical indices.
Synthetic mdspan layout for values generated from logical indices.
Storage policy marker for compact generated tensor values.
Configured gateway to Uni20's mdspan implementation.
Definition async/async.hpp:26
auto zeros(Extents... extents)
Return a generated tensor filled with scalar zeros.
Definition generated.hpp:140
auto eye(Extents... extents)
Return a generated tensor equal to one exactly when all indices agree.
Definition generated.hpp:161
auto ones(Extents... extents)
Return a generated tensor filled with scalar ones.
Definition generated.hpp:149
auto full(ElementType value, Extents... extents)
Return a generated tensor filled with one scalar value.
Definition generated.hpp:131
Checked helpers for constructing runtime tensor extents.
Synthetic non-strided layout used by generated tensor accessors.
Definition generated_layout.hpp:23
Backend-neutral storage policy for tensors generated from compact state.
Definition generated_storage.hpp:19
linalg::backend_list< linalg::CpuReferenceBackend > backend_selector_type
Definition generated_storage.hpp:20
static constexpr auto backend_selector() noexcept -> backend_selector_type
Return the host reference fallback used when no concrete operand selects a backend.
Definition generated_storage.hpp:23
Compact mdspan handle identifying a base offset in a generated value sequence.
Definition generated_accessor.hpp:22
Concepts for tensor-level objects that resolve mdspan kernel operands.