@@ -273,33 +273,47 @@ end
273273 end
274274end
275275
276+ struct WithIteratorsKeys{T,N} <: AbstractArray{T,N}
277+ data:: Array{T,N}
278+ end
279+ Base. size (a:: WithIteratorsKeys ) = size (a. data)
280+ Base. getindex (a:: WithIteratorsKeys , inds... ) = a. data[inds... ]
281+ struct IteratorsKeys{T,A<: AbstractArray{T} }
282+ iter:: A
283+ IteratorsKeys (iter) = new {eltype(iter),typeof(iter)} (iter)
284+ end
285+ Base. iterate (a:: IteratorsKeys , state... ) = Base. iterate (a. data, state... )
286+ Base. keys (a:: WithIteratorsKeys ) = IteratorsKeys (keys (a. data))
287+
276288# findmin/findmax function arguments: output type inference
277289@testset " findmin/findmax output type inference" begin
278- A = [" 1" " 22" ; " 333" " 4444" ]
279- for (tup, rval, rind) in [((1 ,), [1 2 ], [CartesianIndex (1 , 1 ) CartesianIndex (1 , 2 )]),
280- ((2 ,), reshape ([1 , 3 ], 2 , 1 ), reshape ([CartesianIndex (1 , 1 ), CartesianIndex (2 , 1 )], 2 , 1 )),
281- ((1 ,2 ), fill (1 ,1 ,1 ), fill (CartesianIndex (1 ,1 ),1 ,1 ))]
282- rval′, rind′ = findmin (length, A, dims= tup)
283- @test (rval, rind) == (rval′, rind′)
284- @test typeof (rval′) == Matrix{Int}
285- end
286- for (tup, rval, rind) in [((1 ,), [3 4 ], [CartesianIndex (2 , 1 ) CartesianIndex (2 , 2 )]),
287- ((2 ,), reshape ([2 , 4 ], 2 , 1 ), reshape ([CartesianIndex (1 , 2 ), CartesianIndex (2 , 2 )], 2 , 1 )),
288- ((1 ,2 ), fill (4 ,1 ,1 ), fill (CartesianIndex (2 ,2 ),1 ,1 ))]
289- rval′, rind′ = findmax (length, A, dims= tup)
290- @test (rval, rind) == (rval′, rind′)
291- @test typeof (rval) == Matrix{Int}
292- end
293- B = [1.5 1.0 ; 5.5 6.0 ]
294- for (tup, rval, rind) in [((1 ,), [3 // 2 1 // 1 ], [CartesianIndex (1 , 1 ) CartesianIndex (1 , 2 )]),
295- ((2 ,), reshape ([1 // 1 , 11 // 2 ], 2 , 1 ), reshape ([CartesianIndex (1 , 2 ), CartesianIndex (2 , 1 )], 2 , 1 )),
296- ((1 ,2 ), fill (1 // 1 ,1 ,1 ), fill (CartesianIndex (1 ,2 ),1 ,1 ))]
297- rval′, rind′ = findmin (Rational, B, dims= tup)
298- @test (rval, rind) == (rval′, rind′)
299- @test typeof (rval) == Matrix{Rational{Int}}
300- rval′, rind′ = findmin (Rational ∘ abs ∘ complex, B, dims= tup)
301- @test (rval, rind) == (rval′, rind′)
302- @test typeof (rval) == Matrix{Rational{Int}}
290+ for wrapper in (identity, WithIteratorsKeys)
291+ A = wrapper ([" 1" " 22" ; " 333" " 4444" ])
292+ for (tup, rval, rind) in [((1 ,), [1 2 ], [CartesianIndex (1 , 1 ) CartesianIndex (1 , 2 )]),
293+ ((2 ,), reshape ([1 , 3 ], 2 , 1 ), reshape ([CartesianIndex (1 , 1 ), CartesianIndex (2 , 1 )], 2 , 1 )),
294+ ((1 ,2 ), fill (1 ,1 ,1 ), fill (CartesianIndex (1 ,1 ),1 ,1 ))]
295+ rval′, rind′ = @inferred findmin (length, A, dims= tup)
296+ @test (rval, rind) == (rval′, rind′)
297+ @test typeof (rval′) == Matrix{Int}
298+ end
299+ for (tup, rval, rind) in [((1 ,), [3 4 ], [CartesianIndex (2 , 1 ) CartesianIndex (2 , 2 )]),
300+ ((2 ,), reshape ([2 , 4 ], 2 , 1 ), reshape ([CartesianIndex (1 , 2 ), CartesianIndex (2 , 2 )], 2 , 1 )),
301+ ((1 ,2 ), fill (4 ,1 ,1 ), fill (CartesianIndex (2 ,2 ),1 ,1 ))]
302+ rval′, rind′ = @inferred findmax (length, A, dims= tup)
303+ @test (rval, rind) == (rval′, rind′)
304+ @test typeof (rval) == Matrix{Int}
305+ end
306+ B = wrapper ([1.5 1.0 ; 5.5 6.0 ])
307+ for (tup, rval, rind) in [((1 ,), [3 // 2 1 // 1 ], [CartesianIndex (1 , 1 ) CartesianIndex (1 , 2 )]),
308+ ((2 ,), reshape ([1 // 1 , 11 // 2 ], 2 , 1 ), reshape ([CartesianIndex (1 , 2 ), CartesianIndex (2 , 1 )], 2 , 1 )),
309+ ((1 ,2 ), fill (1 // 1 ,1 ,1 ), fill (CartesianIndex (1 ,2 ),1 ,1 ))]
310+ rval′, rind′ = @inferred findmin (Rational, B, dims= tup)
311+ @test (rval, rind) == (rval′, rind′)
312+ @test typeof (rval) == Matrix{Rational{Int}}
313+ rval′, rind′ = @inferred findmin (Rational ∘ abs ∘ complex, B, dims= tup)
314+ @test (rval, rind) == (rval′, rind′)
315+ @test typeof (rval) == Matrix{Rational{Int}}
316+ end
303317 end
304318end
305319
0 commit comments