Skip to content

Commit

Permalink
Add == for Zeros-backed CachedArrays (#328)
Browse files Browse the repository at this point in the history
* Add == for CacheArrays

* Test

* rm extra using

* Add better tests, fix definition for unequal axes

* Fix namespace

* Move the test to a better file
  • Loading branch information
DanielVandH authored Jul 4, 2024
1 parent 9c335fb commit a7df659
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "LazyArrays"
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
version = "2.1.2"
version = "2.1.3"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
8 changes: 8 additions & 0 deletions src/padded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ function ==(A::CachedVector{<:Any,<:Any,<:Zeros}, B::CachedVector{<:Any,<:Any,<:
view(A.data,OneTo(n)) == view(B.data,OneTo(n))
end

function ==(A::CachedArray{<:Any,<:Any,<:Any,<:Zeros}, B::CachedArray{<:Any,<:Any,<:Any,<:Zeros})
size(A) == size(B) || return false
m = max(A.datasize[1], B.datasize[1])
n = max(A.datasize[2], B.datasize[2])
resizedata!(A, m, n); resizedata!(B, m, n)
view(A.data, OneTo(m), OneTo(n)) == view(B.data, OneTo(m), OneTo(n))
end

function copyto!_layout(::PaddedColumns, ::PaddedColumns, dest::AbstractVector, src::AbstractVector)
length(src) length(dest) || throw(BoundsError())
src_data = paddeddata(src)
Expand Down
30 changes: 30 additions & 0 deletions test/cachetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LazyArrays: CachedArray, CachedMatrix, CachedVector, PaddedLayout, Cached

include("infinitearrays.jl")
using .InfiniteArrays
using .InfiniteArrays: OneToInf
using Infinities

@testset "Cache" begin
Expand Down Expand Up @@ -456,6 +457,35 @@ using Infinities
view(a, 2:ℵ₀) .= 0.0;
@test a[1:5] == zeros(5)
end


@testset "Issue #327" begin
A = cache(Zeros((1:5, OneToInf())))
B = cache(Zeros((1:5, OneToInf())))
@test A == B
A[2, 7] = 2.0
@test A B
B[2, 7] = 2.0
@test A == B

A = cache(Zeros((OneToInf(), 1:7)))
B = cache(Zeros((OneToInf(), 1:10)))
@test A B
B = cache(Zeros((OneToInf(), 1:7)))
@test A == B
B[2, 2] = 1.0
@test A B
A[2, 2] = 1.0
@test A == B

A = cache(Zeros((OneToInf(), OneToInf())))
B = cache(Zeros((OneToInf(), OneToInf())))
@test A == B
A[5, 7] = 3.4
@test A B
B[5, 7] = 3.4
@test A == B
end
end

end # module
3 changes: 3 additions & 0 deletions test/paddedtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import ArrayLayouts: OnesLayout
import Base: setindex
using LinearAlgebra

include("infinitearrays.jl")
using .InfiniteArrays: OneToInf

# padded block arrays have padded data that is also padded. This is to test this
struct PaddedPadded <: LayoutVector{Int} end

Expand Down

2 comments on commit a7df659

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/110396

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.1.3 -m "<description of version>" a7df6599a7153fc662680fc61e7393a3b19e0e84
git push origin v2.1.3

Please sign in to comment.