Empty when the spec is self-consistent, otherwise the reason it is not.
136{
137 const std::string label =
name.empty() ? std::string(
"tensor") :
"tensor '" +
name +
"'";
138
140 return label + ": element type has zero width";
142 return label + ": unknown element type kind";
144 return label + ": element count overflows";
146 return label +
": strides rank " + std::to_string(
strides.size())
147 +
" differs from shape rank " + std::to_string(
shape.size());
149 return label +
": axes rank " + std::to_string(
axes.size())
150 +
" differs from shape rank " + std::to_string(
shape.size());
152 return label +
": " +
dtype.name() +
" is sub-byte and must be contiguous";
154 return label + ": layout addresses memory outside its storage";
155
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