Skip to content

Commit

Permalink
Special case maximum/minimum for cached fill vectors (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty authored Nov 27, 2020
1 parent 8ccc422 commit d54f863
Show file tree
Hide file tree
Showing 3 changed files with 38 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 = "0.19.2"
version = "0.19.3"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
23 changes: 23 additions & 0 deletions src/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,26 @@ copy(a::CachedArray) = CachedArray(copy(a.data), a.array, a.datasize)
copy(a::Adjoint{<:Any,<:CachedArray}) = copy(parent(a))'
copy(a::Transpose{<:Any,<:CachedArray}) = transpose(copy(parent(a)))

###
# special maximum/minimum
# TODO: when view returns a Fill this can be generalised
###


function maximum(a::CachedVector{<:Any,<:Any,<:AbstractFill})
data = cacheddata(a)
if length(data) < length(a)
max(maximum(data), getindex_value(a.array))
else
maximum(data)
end
end

function minimum(a::CachedVector{<:Any,<:Any,<:AbstractFill})
data = cacheddata(a)
if length(data) < length(a)
min(minimum(data), getindex_value(a.array))
else
minimum(data)
end
end
14 changes: 14 additions & 0 deletions test/cachetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,18 @@ import LazyArrays: CachedArray, CachedMatrix, CachedVector, PaddedLayout, Cached
@test zero!(a) a
@test a.datasize == (0,)
end

@testset "minimum/maximum" begin
c = cache(Fill(2,4));
c[1] = 1;
@test maximum(c) == 2
@test minimum(c) == 1
c[1] = 3;
@test maximum(c) == 3
@test minimum(c) == 2
c[1:4] .= 1;
@test maximum(c) == 1
c[1:4] .= 3;
@test minimum(c) == 3
end
end

2 comments on commit d54f863

@dlfivefifty
Copy link
Member Author

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/25411

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 v0.19.3 -m "<description of version>" d54f863768f3dc30da82f15b86c73701ca2947e1
git push origin v0.19.3

Please sign in to comment.