Skip to content

Commit f69ac2a

Browse files
authored
Prepare for removal of FillArrays._copy_oftype (#148)
* Prepare for removal of `FillArrays._copy_oftype` * Remove branch * Add tests * Update Project.toml
1 parent 67f5c08 commit f69ac2a

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ArrayLayouts"
22
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "1.0.9"
4+
version = "1.0.10"
55

66
[deps]
77
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"

src/ArrayLayouts.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using LinearAlgebra.BLAS: BlasFloat, BlasReal, BlasComplex
2525

2626
AdjointQtype{T} = isdefined(LinearAlgebra, :AdjointQ) ? LinearAlgebra.AdjointQ{T} : Adjoint{T,<:AbstractQ}
2727

28-
using FillArrays: AbstractFill, getindex_value, axes_print_matrix_row, _copy_oftype
28+
using FillArrays: AbstractFill, getindex_value, axes_print_matrix_row
2929

3030
using Base: require_one_based_indexing
3131

@@ -52,6 +52,9 @@ else
5252
const CNoPivot = NoPivot
5353
end
5454

55+
# Originally defined in FillArrays
56+
_copy_oftype(A::AbstractArray, ::Type{S}) where {S} = eltype(A) == S ? copy(A) : AbstractArray{S}(A)
57+
_copy_oftype(A::AbstractRange, ::Type{S}) where {S} = eltype(A) == S ? copy(A) : map(S, A)
5558

5659
struct ApplyBroadcastStyle <: BroadcastStyle end
5760
@inline function copyto!(dest::AbstractArray, bc::Broadcasted{ApplyBroadcastStyle})

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ArrayLayouts: MemoryLayout, @_layoutlmul, triangulardata
33

44
Random.seed!(0)
55

6+
include("test_utils.jl")
67
include("test_layouts.jl")
78
include("test_muladd.jl")
89
include("test_ldiv.jl")

test/test_utils.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using ArrayLayouts, LinearAlgebra, FillArrays, Test
2+
3+
@testset "_copy_oftype" begin
4+
# Copied from original implementation in FillArrays
5+
@testset "FillArrays" begin
6+
m = Eye(10)
7+
D = Diagonal(Fill(2,10))
8+
9+
@test ArrayLayouts._copy_oftype(m, eltype(m)) m
10+
@test ArrayLayouts._copy_oftype(m, Int) Eye{Int}(10)
11+
@test ArrayLayouts._copy_oftype(D, eltype(D)) D
12+
@test ArrayLayouts._copy_oftype(D, Float64) Diagonal(Fill(2.0,10))
13+
14+
# test that _copy_oftype does, in fact, copy the array
15+
D2 = Diagonal([1,1])
16+
@test ArrayLayouts._copy_oftype(D2, Float64) isa Diagonal{Float64}
17+
@test ArrayLayouts._copy_oftype(D2, eltype(D2)) == D2
18+
@test ArrayLayouts._copy_oftype(D2, eltype(D2)) !== D2
19+
end
20+
21+
@testset "general" begin
22+
for T in (Float32, Float64)
23+
u = T(1):T(10)
24+
v = collect(u)
25+
for S in (Float32, Float64)
26+
# Usually an actual copy
27+
@test ArrayLayouts._copy_oftype(u, S) isa AbstractRange{S}
28+
@test ArrayLayouts._copy_oftype(u, S) == u
29+
@test (ArrayLayouts._copy_oftype(u, S) === u) === (T === S && copy(u) === u)
30+
31+
# Always an actual copy
32+
@test ArrayLayouts._copy_oftype(v, S) isa Array{S}
33+
@test ArrayLayouts._copy_oftype(v, S) == v
34+
@test ArrayLayouts._copy_oftype(v, S) !== v
35+
end
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)