Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
packed_matrix.hpp
Go to the documentation of this file.
1#pragma once
2
9#include <concepts>
10#include <cstddef>
11#include <span>
14
15namespace uni20::linalg
16{
17namespace packed_detail
18{
19template <class Span> auto pack(Span const& span, Precision p, bool read = true)
20{
21 using S = typename Span::value_type;
22 DenseMatrix<S> result(uninitialized, span.extent(0), span.extent(1), p);
23 if (read)
24 for (std::size_t j = 0; j < std::size_t(span.extent(1)); ++j)
25 for (std::size_t i = 0; i < std::size_t(span.extent(0)); ++i)
26 result[i, j] = scalar_at_precision<S>(S(span[i, j]), p);
27 return result;
28}
29template <class Tensor> auto values(Tensor& tensor)
30{
31 return std::span(tensor.storage().data(), tensor.storage().size());
32}
33template <class Tensor, class Span> void unpack(Tensor const& source, Span& target)
34{
35 for (std::size_t j = 0; j < std::size_t(target.extent(1)); ++j)
36 for (std::size_t i = 0; i < std::size_t(target.extent(0)); ++i)
37 target[i, j] = source[i, j];
38}
39} // namespace packed_detail
40
41} // namespace uni20::linalg
Exact arithmetic or an explicit binary working precision.
Definition core/precision.hpp:13
General-purpose owning tensor with immediate or deferred mdspan metadata.
Definition basic_tensor.hpp:109
storage_type & storage() noexcept
Access the owned storage container.
Definition basic_tensor.hpp:542
void unpack(Tensor const &source, Span &target)
Definition packed_matrix.hpp:33
auto values(Tensor &tensor)
Definition packed_matrix.hpp:29
Definition linalg/async.hpp:28
Definition data_table.cpp:8
constexpr uninitialized_t uninitialized
Explicit allocation tag for overwrite outputs and scratch space.
Definition common/initialization.hpp:22
std::size_t span
Definition presentation.cpp:2017
General-purpose owning tensors with runtime extents.