MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ byte_range()

std::optional< std::pair< uint64_t, uint64_t > > MayaFlux::Kakshya::TensorSpec::byte_range ( ) const
nodiscardnoexcept

Storage bytes [first, last) the spec addresses, from storage start.

Returns
Range, or std::nullopt for overflow or a negative start.

Definition at line 88 of file TensorSpec.cpp.

89{
90 const auto count = element_count();
91 if (!count)
92 return std::nullopt;
93 if (*count == 0)
94 return std::pair<uint64_t, uint64_t> { byte_offset, byte_offset };
95
96 if (dtype.is_sub_byte()) {
97 const auto bytes = dtype.storage_bytes(*count);
98 if (!bytes || *bytes > std::numeric_limits<uint64_t>::max() - byte_offset)
99 return std::nullopt;
100 return std::pair<uint64_t, uint64_t> { byte_offset, byte_offset + *bytes };
101 }
102
103 const auto resolved = resolved_strides();
104 uint64_t low = 0;
105 uint64_t high = 0;
106 for (size_t i = 0; i < shape.size(); ++i) {
107 if (shape[i] <= 1)
108 continue;
109 const int64_t stride = resolved[i];
110 const uint64_t magnitude = stride < 0 ? static_cast<uint64_t>(-(stride + 1)) + 1 : static_cast<uint64_t>(stride);
111 uint64_t reach = 0;
112 if (!magnitude_times(shape[i] - 1, magnitude, reach))
113 return std::nullopt;
114 uint64_t& side = stride < 0 ? low : high;
115 if (reach > max_signed - side)
116 return std::nullopt;
117 side += reach;
118 }
119
120 const uint64_t element = dtype.element_bytes();
121 uint64_t low_bytes = 0;
122 uint64_t high_bytes = 0;
123 if (!magnitude_times(low, element, low_bytes) || !magnitude_times(high, element, high_bytes))
124 return std::nullopt;
125 if (low_bytes > byte_offset)
126 return std::nullopt;
127
128 const uint64_t first = byte_offset - low_bytes;
129 const uint64_t extent = high_bytes + low_bytes + element;
130 if (extent < element || extent > std::numeric_limits<uint64_t>::max() - first)
131 return std::nullopt;
132 return std::pair<uint64_t, uint64_t> { first, first + extent };
133}
std::vector< double > count(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Sample count per window (as double for pipeline uniformity).
Definition Analysis.cpp:506
std::optional< uint64_t > element_count() const noexcept
Product of the shape, or std::nullopt on overflow.
std::vector< uint64_t > shape
std::vector< int64_t > resolved_strides() const
Element strides, with C order filled in when none are stored.

References byte_offset, dtype, element_count(), resolved_strides(), and shape.

Referenced by diagnose().

Here is the call graph for this function:
Here is the caller graph for this function: