Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/MappedArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ end
eltypes(A::AbstractArray) = Tuple{eltype(A)}
@Base.pure eltypes(A::Tuple{Vararg{<:AbstractArray}}) = Tuple{(eltype.(A))...}

Base.unaliascopy(x::ReadonlyMappedArray) = mappedarray(x.f, Base.unaliascopy(x.data))
Base.unaliascopy(x::MappedArray) = mappedarray(x.f, x.finv, Base.unaliascopy(x.data))
Base.unaliascopy(x::ReadonlyMultiMappedArray) = mappedarray(x.f, Base.unaliascopy.(x.data)...)
Base.unaliascopy(x::MultiMappedArray) = mappedarray(x.f, x.finv, Base.unaliascopy.(x.data)...)

## Deprecations
@deprecate mappedarray(f_finv::Tuple{Any,Any}, args::AbstractArray...) mappedarray(f_finv[1], f_finv[2], args...)

Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ using FixedPointNumbers, OffsetArrays, ColorTypes
@test isa(eachindex(b), AbstractUnitRange)
b = mappedarray(sqrt, s)
@test isa(eachindex(b), CartesianIndices)
c = Base.unaliascopy(b)
@test c == b
@test c !== b
end

@testset "MappedArray" begin
Expand All @@ -43,6 +46,10 @@ end
c = @inferred(mappedarray(sqrt, x->x*x, s))
@test isa(eachindex(c), CartesianIndices)

d = Base.unaliascopy(c)
@test c == d
@test c !== d

sb = similar(b)
@test isa(sb, Array{Float64})
@test size(sb) == size(b)
Expand Down Expand Up @@ -106,6 +113,10 @@ end
@test M == a + b
@test @inferred(M[1]) === 11.0f0
@test @inferred(M[CartesianIndex(1, 1)]) === 11.0f0

d = Base.unaliascopy(b)
@test d == b
@test d !== b

c = view(reshape(1:9, 3, 3), 1:2, :)
M = @inferred(mappedarray(+, c, b))
Expand Down Expand Up @@ -155,6 +166,10 @@ end
@test M[1,1] === RGB{N0f8}(0.1, 0.8, 0)
@test_throws ErrorException("indexed assignment fails for a reshaped range; consider calling collect") M[1,2] = RGB(0.25, 0.35, 0)

d = Base.unaliascopy(M)
@test d == M
@test d !== M

a = reshape(0.1:0.1:0.6, 3, 2)
@test_throws DimensionMismatch mappedarray(f, finv, a, b, c)
end
Expand Down