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

◆ diagnose()

std::string MayaFlux::Kakshya::TensorSpec::diagnose ( ) const
nodiscard

Empty when the spec is self-consistent, otherwise the reason it is not.

Definition at line 135 of file TensorSpec.cpp.

136{
137 const std::string label = name.empty() ? std::string("tensor") : "tensor '" + name + "'";
138
139 if (dtype.bits == 0 || dtype.lanes == 0)
140 return label + ": element type has zero width";
141 if (static_cast<uint8_t>(dtype.kind) > static_cast<uint8_t>(TensorDTypeKind::BCOMPLEX))
142 return label + ": unknown element type kind";
143 if (!element_count())
144 return label + ": element count overflows";
145 if (!strides.empty() && strides.size() != shape.size())
146 return label + ": strides rank " + std::to_string(strides.size())
147 + " differs from shape rank " + std::to_string(shape.size());
148 if (!axes.empty() && axes.size() != shape.size())
149 return label + ": axes rank " + std::to_string(axes.size())
150 + " differs from shape rank " + std::to_string(shape.size());
151 if (dtype.is_sub_byte() && !is_contiguous())
152 return label + ": " + dtype.name() + " is sub-byte and must be contiguous";
153 if (!byte_range())
154 return label + ": layout addresses memory outside its storage";
155
156 if (quantization) {
157 const auto& q = *quantization;
158 if (q.scale.empty())
159 return label + ": quantization has no scale";
160 const size_t expected = q.axis ? (*q.axis < shape.size() ? shape[*q.axis] : 0) : 1;
161 if (q.axis && *q.axis >= shape.size())
162 return label + ": quantization axis " + std::to_string(*q.axis) + " is out of range";
163 if (q.scale.size() != expected)
164 return label + ": quantization has " + std::to_string(q.scale.size())
165 + " scales, expected " + std::to_string(expected);
166 if (!q.zero_point.empty() && q.zero_point.size() != q.scale.size())
167 return label + ": quantization zero points differ in length from scales";
168 }
169
170 return {};
171}
std::vector< DataDimension > axes
std::optional< uint64_t > element_count() const noexcept
Product of the shape, or std::nullopt on overflow.
std::optional< std::pair< uint64_t, uint64_t > > byte_range() const noexcept
Storage bytes [first, last) the spec addresses, from storage start.
bool is_contiguous() const noexcept
Whether elements are laid out densely in C order.
std::optional< TensorQuantization > quantization
std::vector< int64_t > strides
std::vector< uint64_t > shape

References axes, MayaFlux::Kakshya::BCOMPLEX, byte_range(), dtype, element_count(), is_contiguous(), name, quantization, shape, and strides.

Referenced by MayaFlux::Kakshya::diagnose_conversion(), is_valid(), MayaFlux::IO::SafetensorsReader::open(), and MayaFlux::IO::Detail::parse_npy_header().

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