DenseArray vs. Strided

I’m trying to understand the semantics of dense vs. strided arrays in Julia (in the Base array types).

In my mind, there are three types of “regular” matrices:

  • Strided: offset in memory of element (i, j) is (a + b * i + c * j)

  • Striped (for lack of a better term): Strided, but either b or c are equal to the size of the element, that is, each complete stripe (column or row) is contiguous in memory, but there may be a gap between stripes (columns or rows).

  • Dense: Striped, but where there is no gap between stripes (so the whole memory footprint of the array is contiguous).

These concepts apply to higher dimensions - strided and dense are obvious, and for “Striped”, one could say how many dimensions are in a stripe (at least 1 and at most 1 less than the number of dimensions, otherwise the data would be “Dense”).

Julia has DenseArray which is an abstract type which I think maps to the “Dense” concept above.

Julia also has StridedArray which (alas) is a union of concrete types, which seems to map to the “Strided” concept above.

Julia doesn’t have anything like the “Striped” concept above.

Is that a fair summary of the state of affairs?

Not in the type domain. You can check this at runtime by checking stride(x,1) == 1. The LinearAlgebra stdlib uses this (via a convenience function chkstride1) in order to verify that a StridedArray is compatible with LAPACK/BLAS (which requires contiguous columns).


Speaking of testing features outside the type system, is there an easy way to check whether a type supports the strides function other than trying to invoke it and catching the exception? E.g., Transpose{Array{...}} supports strides, but what’s the idiomatic way of testing for this?