|
298 | 298 | @test evalpoly(1+im, [2,]) == 2 |
299 | 299 | end |
300 | 300 |
|
| 301 | +# https://github.com/JuliaLang/julia/pull/35298 |
| 302 | +begin |
| 303 | + # A custom linear slow sparse-like array that relies upon Dict for its storage |
| 304 | + struct TSlow{T,N} <: AbstractArray{T,N} |
| 305 | + data::Dict{NTuple{N,Int}, T} |
| 306 | + dims::NTuple{N,Int} |
| 307 | + end |
| 308 | + TSlow(::Type{T}, dims::Int...) where {T} = TSlow(T, dims) |
| 309 | + TSlow(::Type{T}, dims::NTuple{N,Int}) where {T,N} = TSlow{T,N}(Dict{NTuple{N,Int}, T}(), dims) |
| 310 | + |
| 311 | + TSlow{T,N}(X::TSlow{T,N}) where {T,N } = X |
| 312 | + TSlow( X::AbstractArray{T,N}) where {T,N } = TSlow{T,N}(X) |
| 313 | + TSlow{T }(X::AbstractArray{_,N}) where {T,N,_} = TSlow{T,N}(X) |
| 314 | + TSlow{T,N}(X::AbstractArray ) where {T,N } = begin |
| 315 | + A = TSlow(T, size(X)) |
| 316 | + for I in CartesianIndices(X) |
| 317 | + A[Tuple(I)...] = X[Tuple(I)...] |
| 318 | + end |
| 319 | + A |
| 320 | + end |
| 321 | + Base.size(A::TSlow) = A.dims |
| 322 | + Base.similar(A::TSlow, ::Type{T}, dims::Dims) where {T} = TSlow(T, dims) |
| 323 | + Base.IndexStyle(::Type{A}) where {A<:TSlow} = IndexCartesian() |
| 324 | + Base.getindex(A::TSlow{T,N}, i::Vararg{Int,N}) where {T,N} = get(A.data, i, zero(T)) |
| 325 | + Base.setindex!(A::TSlow{T,N}, v, i::Vararg{Int,N}) where {T,N} = (A.data[i] = v) |
| 326 | +end |
| 327 | + |
| 328 | +# https://github.com/JuliaLang/julia/pull/35304 |
| 329 | +@testset "similar(PermutedDimsArray)" begin |
| 330 | + x = PermutedDimsArray([1 2; 3 4], (2, 1)) |
| 331 | + @test similar(x, 3,3) isa Array |
| 332 | + z = TSlow([1 2; 3 4]) |
| 333 | + x_slow = PermutedDimsArray(z, (2, 1)) |
| 334 | + @test similar(x_slow, 3,3) isa TSlow |
| 335 | +end |
| 336 | + |
301 | 337 | # https://github.com/JuliaLang/julia/pull/34548 |
302 | 338 | @testset "@NamedTuple" begin |
303 | 339 | @test (@NamedTuple {a::Int, b::String}) === NamedTuple{(:a, :b),Tuple{Int,String}} === |
|
0 commit comments