rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
strided_layout.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include "dynamic_subscript.hpp"
6#include "../numerical/numerical_type.hpp"
7#include "../span.hpp"
8#include "../platform/attributes.hpp"
9#include "../platform/dynamic_shared_object.h"
10
11#include <memory>
12#include <functional>
13#include <cstddef>
14
15namespace rexlib
16{
17
18class strided_layout_implementation;
19
21{
22public:
23 REXLIB_API strided_layout() noexcept;
27
29 strided_layout& operator=(const strided_layout &other) noexcept;
31 strided_layout& operator=(strided_layout &&other) noexcept;
32
33
40 std::size_t hash() const noexcept;
41
48 std::size_t get_rank() const noexcept;
49
56 void get_extents(std::vector<std::size_t> &extents) const;
57
65
73
81
89
99
111
119
131
142 std::ptrdiff_t axis1 = -1,
143 std::ptrdiff_t axis2 = -2
144 ) const;
145
158 std::ptrdiff_t axis1 = -1,
159 std::ptrdiff_t axis2 = -2
160 ) const;
161
169
185
196
204 static
206
208 static
209 strided_layout make_custom_layout(
210 span<const std::size_t> extents,
212 std::ptrdiff_t offset = 0
213 );
214
215 // Defined out of line: it compares the implementations, and the
216 // implementation type is incomplete here.
219
220 friend bool
222 {
223 return !(lhs == rhs);
224 }
225
226private:
227 // Copy-on-write implementation
228 std::shared_ptr<const strided_layout_implementation> m_implementation;
229
230 explicit
232 std::shared_ptr<const strided_layout_implementation> impl
233 ) noexcept;
234 explicit
236};
237
238} // namespace rexlib
239
240namespace std
241{
242
243template<>
244struct hash<rexlib::strided_layout>
245{
246 std::size_t operator()(
247 const rexlib::strided_layout &layout
248 ) const noexcept
249 {
250 return layout.hash();
251 }
252};
253
254} // namespace std
#define REXLIB_NODISCARD
Indicates that the return value should be used.
Definition attributes.hpp:76
Container for multidimensional numeric data.
Definition array.hpp:31
Class describing a runtime defined subscript.
Definition dynamic_subscript.hpp:30
Represents a non-owning area of contiguous memory.
Definition span.hpp:99
Definition strided_layout.hpp:21
std::ptrdiff_t get_offset() const noexcept
Get the offset of the data.
REXLIB_NODISCARD strided_layout squeeze() const
Remove insignificant axes of the layout.
std::size_t hash() const noexcept
Obtain a hash of the layout.
REXLIB_NODISCARD strided_layout transpose() const
Reverse the order of the axes.
REXLIB_NODISCARD strided_layout apply_subscripts(span< const dynamic_subscript > subscripts) const
Apply a set of dynamic subscripts to this layout.
static strided_layout make_contiguous_layout(span< const std::size_t > extents)
Create a contiguous layout from the provided extents.
REXLIB_NODISCARD strided_layout broadcast_to(span< const std::size_t > extents) const
Perform a broadcast of the layout to match the provided extents.
REXLIB_NODISCARD strided_layout matrix_transpose(std::ptrdiff_t axis1=-1, std::ptrdiff_t axis2=-2) const
Swap two axes in the layout.
REXLIB_NODISCARD strided_layout permute(span< const std::size_t > order) const
Permute the order of the axes.
void get_extents(std::vector< std::size_t > &extents) const
Get the extents of the layout.
std::size_t get_rank() const noexcept
Get the number of axis in the layout.
const strided_layout_implementation & get_implementation() const noexcept
Get the implementation of this layout.
std::size_t compute_element_count() const noexcept
Computes the number of elements referenced by the layout.
void get_strides(std::vector< std::ptrdiff_t > &strides) const
Get the strides of the layout.
bool extents_equal(span< const std::size_t > extents) const noexcept
Check if this layout has a specific shape.
REXLIB_NODISCARD strided_layout matrix_diagonal(std::ptrdiff_t axis1=-1, std::ptrdiff_t axis2=-2) const
Obtains a layout view to the matrix diagonal defined by two axes.
std::size_t compute_storage_requirement() const noexcept
Computes the minimum storage size (in elements) for this layout.
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10