Repository: invenia/NamedDims.jl
Pull request #38 (2019-06-05 19:07:38)

Add Strided Array Interface
Because right now StridedArray is a  Union and thus not extensible
(see https://github.com/JuliaLang/julia/pull/30432)
you don't need to implement `strides` explictly for all new strided array types,
which we can assume (and then be proven wrong with later method errors) 
that our wrapped type is.

This is needed for some BLAS stuff called by Distributions.jl

codecov[bot]: # [Codecov](https://codecov.io/gh/invenia/NamedDims.jl/pull/38?src=pr&el=h1) Report
> Merging [#38](https://codecov.io/gh/invenia/NamedDims.jl/pull/38?src=pr&el=desc) into [master](https://codecov.io/gh/invenia/NamedDims.jl/commit/0e74fec43ef969b99118deabff84758644097167?src=pr&el=desc) will **increase** coverage by `0.25%`.
> The diff coverage is `75%`.

[![Impacted file tree graph](https://codecov.io/gh/invenia/NamedDims.jl/pull/38/graphs/tree.svg?width=650&token=M5MW3xa0xM&height=150&src=pr)](https://codecov.io/gh/invenia/NamedDims.jl/pull/38?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #38      +/-   ##
==========================================
+ Coverage    83.5%   83.75%   +0.25%     
==========================================
  Files           8        8              
  Lines         194      197       +3     
==========================================
+ Hits          162      165       +3     
  Misses         32       32
```


| [Impacted Files](https://codecov.io/gh/invenia/NamedDims.jl/pull/38?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/functions.jl](https://codecov.io/gh/invenia/NamedDims.jl/pull/38/diff?src=pr&el=tree#diff-c3JjL2Z1bmN0aW9ucy5qbA==) | `92.85% <0%> (ø)` | :arrow_up: |
| [src/wrapper\_array.jl](https://codecov.io/gh/invenia/NamedDims.jl/pull/38/diff?src=pr&el=tree#diff-c3JjL3dyYXBwZXJfYXJyYXkuamw=) | `88.09% <100%> (+0.91%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/invenia/NamedDims.jl/pull/38?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/invenia/NamedDims.jl/pull/38?src=pr&el=footer). Last update [0e74fec...f60f12e](https://codecov.io/gh/invenia/NamedDims.jl/pull/38?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

oxinabox: I wanted this again today.
I should come back to this PR

Patch:
diff --git a/Project.toml b/Project.toml
index 5e8227c..ad8fba6 100644
--- a/Project.toml
+++ b/Project.toml
@@ -1,7 +1,7 @@
 name = "NamedDims"
 uuid = "356022a1-0364-5f58-8944-0da4b18d706f"
 authors = ["Invenia Technical Computing Corporation"]
-version = "0.2.16"
+version = "0.2.17"
 
 [deps]
 LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
diff --git a/src/wrapper_array.jl b/src/wrapper_array.jl
index 49d6ae9..3c5340e 100644
--- a/src/wrapper_array.jl
+++ b/src/wrapper_array.jl
@@ -106,6 +106,13 @@ function Base.similar(
     return similar(a, eltype, dims)
 end
 
+#####################################
+# Strided Array interface
+Base.stride(a::NamedDimsArray, k::Symbol) = stride(parent(a), dim(a, k))
+Base.stride(a::NamedDimsArray, k::Integer) = stride(parent(a), k)
+Base.strides(a::NamedDimsArray) = strides(parent(a))
+
+
 ###############################
 # kwargs indexing
 


Test patch:
diff --git a/test/wrapper_array.jl b/test/wrapper_array.jl
index 60ef4f4..991baac 100644
--- a/test/wrapper_array.jl
+++ b/test/wrapper_array.jl
@@ -147,6 +147,12 @@ end
     end
 end
 
+@testset "Strided Array Interface" begin
+    x = ones(3, 5)
+    nda = NamedDimsArray{(:a, :b)}(x)
+    @test strides(nda) == (1, 3) == strides(x)
+    @test stride(nda, :b) == 3 == stride(nda, 2) == stride(x, 2)
+end
 
 const cnda = NamedDimsArray([10 20; 30 40], (:x, :y))
 @testset "allocations: wrapper" begin