MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::interface::ContiguousVector Concept Reference

True when a vector type's storage is CONTIGUOUS – data()[i] IS element i. More...

#include <dispatch_traits.hpp>

Concept definition

template<typename V>
(!requires(const V& v) { v.stride(); } ||
requires { requires V::stride() == 1; })
True when a vector type's storage is CONTIGUOUS – data()[i] IS element i.
Definition dispatch_traits.hpp:138
constexpr bool host_resident_v
Whether host code, and so every dispatch target in this header, may read M's elements.
Definition dispatch_traits.hpp:60

Detailed Description

True when a vector type's storage is CONTIGUOUS – data()[i] IS element i.

Every fast path below hands data() to a kernel that walks it with unit stride, so this is a precondition of dispatching there at all. Asking only for data() and size() did not establish it: vec::strided_vector_ref supplies both while storing element i at data()[i * stride()], so it was accepted by BlasDenseVector and every operation gated on it read the wrong elements and returned a confident wrong answer. Measured on a stride-2 view: dot_real gave 14 where the answer is 44. A column of a row-major matrix is exactly such a view, which is the case that makes this worth catching.

A type qualifies when it either has no stride notion at all – data() and size() are then the whole layout, which is what these concepts always assumed – or pins its stride to 1 at COMPILE time, as vec::dense_vector does with static constexpr size_type stride() { return 1; }.

A runtime stride cannot qualify: strided_vector_ref::stride() is an instance value, so no concept can admit only its unit-stride objects. Those types take the generic element-wise loop instead, which indexes through operator() and is correct for any stride. That costs a stride-1 strided_vector_ref its fast path – the right side to err on, and recoverable later with a runtime stride() == 1 check at the call sites if it ever measures.