# DenseArray vs. Strided

**URL:** <https://discourse.julialang.org/t/densearray-vs-strided/102127>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 26, 2023, 5:31pm UTC](https://discourse.julialang.org/t/densearray-vs-strided/102127 "2023-07-26T17:31:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![orenbenkiki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orenbenkiki/32/5578_2.png) [@orenbenkiki](https://discourse.julialang.org/u/orenbenkiki)\
**Post date:** [July 26, 2023, 5:31pm UTC](https://discourse.julialang.org/t/densearray-vs-strided/102127/1 "2023-07-26T17:31:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 26, 2023, 8:35pm UTC](https://discourse.julialang.org/t/densearray-vs-strided/102127/2 "2023-07-26T20:35:16Z")

</div>

> [@orenbenkiki](#):
>
> Julia doesn’t have anything like the “Striped” concept above.

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`](https://github.com/JuliaLang/julia/blob/c43e5a10be27b7f93b5368875aa1d2596b4d4947/stdlib/LinearAlgebra/src/LinearAlgebra.jl#L185-L221)) in order to verify that a `StridedArray` is compatible with LAPACK/BLAS (which requires contiguous columns).

---

<div class="post-metadata">

**Author:** ![orenbenkiki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orenbenkiki/32/5578_2.png) [@orenbenkiki](https://discourse.julialang.org/u/orenbenkiki)\
**Post date:** [July 27, 2023, 4:52am UTC](https://discourse.julialang.org/t/densearray-vs-strided/102127/3 "2023-07-27T04:52:57Z")

</div>

Thanks!

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?
