Vexatos / CircularArrays.jl

Multi-dimensional arrays with fixed size and circular indexing.
MIT License
38 stars 12 forks source link

export CircularMatrix #25

Closed terasakisatoshi closed 9 months ago

terasakisatoshi commented 10 months ago

It would be nice to export CircularMatrix.

Ref https://github.com/Vexatos/CircularArrays.jl/pull/23

terasakisatoshi commented 10 months ago

Should I update @testset "matrix" in runtests.jl? If so, here is my suggestion:

diff --git a/src/CircularArrays.jl b/src/CircularArrays.jl
index c6036f5..a08cce9 100644
--- a/src/CircularArrays.jl
+++ b/src/CircularArrays.jl
@@ -3,7 +3,7 @@ Arrays with fixed size and circular indexing.
 """
 module CircularArrays

-export CircularArray, CircularVector
+export CircularArray, CircularVector, CircularMatrix

 """
     CircularArray{T, N, A} <: AbstractArray{T, N}
@@ -106,6 +106,13 @@ Create a `CircularVector` wrapping the array `data`.
 """
 CircularVector(data::AbstractArray{T, 1}) where T = CircularVector{T}(data)

+"""
+    CircularMatrix(data)
+
+Create a `CircularMatrix` wrapping the array `data`.
+"""
+CircularMatrix(data::AbstractArray{T, 2}) where T = CircularMatrix{T}(data)
+
 """
     CircularVector(def, size)

@@ -113,6 +120,13 @@ Create a `CircularVector` of size `size` filled with value `def`.
 """
 CircularVector(def::T, size::Int) where T = CircularVector{T}(fill(def, size))

+"""
+    CircularMatrix(def, size)
+
+Create a `CircularMatrix` of size `size` filled with value `def`.
+"""
+CircularMatrix(def::T, size::NTuple{2, Integer}) where T = CircularMatrix{T}(fill(def, size))
+
 Base.empty(::CircularVector{T}, ::Type{U}=T) where {T,U} = CircularVector{U}(U[])

 function Base.deleteat!(a::CircularVector, i::Integer)
diff --git a/test/runtests.jl b/test/runtests.jl
index 4102294..baa1632 100644
--- a/test/runtests.jl
+++ b/test/runtests.jl
@@ -150,7 +150,7 @@ end

 @testset "matrix" begin
     b_arr = [2 4 6 8; 10 12 14 16; 18 20 22 24]
-    a1 = CircularArray(b_arr)
+    a1 = CircularMatrix(b_arr)
     @test size(a1) == (3, 4)
     @test parent(a1) == b_arr

@@ -179,21 +179,25 @@ end

     @test !isa(a1, CircularVector)
     @test !isa(a1, AbstractVector)
+    @test isa(a1, AbstractMatrix)
     @test isa(a1, AbstractArray)

     @test size(reshape(a1, (2, 2, 3))) == (2, 2, 3)

-    a2 = CircularArray(4, (2, 3))
+    a2 = CircularMatrix(4, (2, 3))
+    @test isa(a2, CircularMatrix{Int})
     @test isa(a2, CircularArray{Int, 2})

     a3 = @inferred(a2 .+ 1)
+    @test a3 isa CircularMatrix{Int64}
     @test a3 isa CircularArray{Int64, 2}
     @test a3 == CircularArray(5, (2, 3))

     @testset "doubly circular" begin
-        a = CircularArray(b_arr)
-        da = CircularArray(a)
+        a = CircularMatrix(b_arr)
+        da = CircularMatrix(a)

+        @test da isa CircularMatrix
         @test all(a[i, j] == da[i, j] for i in -8:8, j in -8:8)
         @test all(a[i] == da[i] for i in -50:50)
     end
codecov[bot] commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (a81ebe9) 100.00% compared to head (3e3e454) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #25 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 1 1 Lines 48 50 +2 ========================================= + Hits 48 50 +2 ``` | [Flag](https://app.codecov.io/gh/Vexatos/CircularArrays.jl/pull/25/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vexatos) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/Vexatos/CircularArrays.jl/pull/25/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vexatos) | `100.00% <100.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Vexatos#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Vexatos commented 10 months ago

Good catch, I forgot to have that exported. Adjusting the tests to use the new alias is probably a good idea, please add those to the PR and I'll merge.