-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
hvncat
: Better handling of 0- and 1-length dims/shape args
#41197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1b35e95
b25b530
ec59c12
a80a522
e73244c
c5f3497
c724b93
cc6cd7e
af6b44c
a8d71bc
b4cfd43
632ef9b
a8c5d6e
cd55f21
415fe84
be7d439
e114402
aa80b40
77c078d
19530be
52166b3
046752c
f730a60
bc53fc7
264f3bc
b565092
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1342,6 +1342,7 @@ end | |
end | ||
end | ||
|
||
using Base: typed_hvncat | ||
@testset "hvncat" begin | ||
a = fill(1, (2,3,2,4,5)) | ||
b = fill(2, (1,1,2,4,5)) | ||
|
@@ -1389,7 +1390,68 @@ end | |
@test [v v;;; fill(v, 1, 2)] == fill(v, 1, 2, 2) | ||
end | ||
|
||
@test_throws BoundsError hvncat(((1, 2), (3,)), false, zeros(Int, 0, 0, 0), 7, 8) | ||
# 0-dimension behaviors | ||
# exactly one argument, placed in an array | ||
# if already an array, copy, with type conversion as necessary | ||
@test_throws ArgumentError hvncat(0) | ||
@test hvncat(0, 1) == fill(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to allow this? Passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
hvncat(3, ...) == hvncat((1, 1, n), ...).
hvncat(2, ...) == hvncat((1, n), ...)
hvncat(1, ...) == hvncat((n,), ...)
hvncat(0, ...) == hvncat((), ....) That does mean, though, I could actually consolidate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I guess the way to understand it is that it refers to the number of dimensions of the block array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, and it's the special case where there is only one dimension involved: |
||
@test hvncat(0, [1]) == [1] | ||
@test_throws ArgumentError hvncat(0, 1, 1) | ||
@test_throws ArgumentError typed_hvncat(Float64, 0) | ||
@test typed_hvncat(Float64, 0, 1) == fill(1.0) | ||
@test typed_hvncat(Float64, 0, [1]) == Float64[1.0] | ||
@test_throws ArgumentError typed_hvncat(Float64, 0, 1, 1) | ||
@test_throws ArgumentError hvncat((), true) == [] | ||
@test hvncat((), true, 1) == fill(1) | ||
@test hvncat((), true, [1]) == [1] | ||
@test_throws ArgumentError hvncat((), true, 1, 1) | ||
@test_throws ArgumentError typed_hvncat(Float64, (), true) == Float64[] | ||
@test typed_hvncat(Float64, (), true, 1) == fill(1.0) | ||
@test typed_hvncat(Float64, (), true, [1]) == [1.0] | ||
@test_throws ArgumentError typed_hvncat(Float64, (), true, 1, 1) | ||
|
||
# 1-dimension behaviors | ||
# int form | ||
@test hvncat(1) == [] | ||
@test hvncat(1, 1) == [1] | ||
@test hvncat(1, [1]) == [1] | ||
@test hvncat(1, [1 2; 3 4]) == [1 2; 3 4] | ||
@test hvncat(1, 1, 1) == [1 ; 1] | ||
@test typed_hvncat(Float64, 1) == Float64[] | ||
@test typed_hvncat(Float64, 1, 1) == Float64[1.0] | ||
@test typed_hvncat(Float64, 1, [1]) == Float64[1.0] | ||
@test typed_hvncat(Float64, 1, 1, 1) == Float64[1.0 ; 1.0] | ||
# dims form | ||
@test_throws ArgumentError hvncat((1,), true) | ||
@test hvncat((2,), true, 1, 1) == [1; 1] | ||
@test hvncat((2,), true, [1], [1]) == [1; 1] | ||
@test_throws ArgumentError hvncat((2,), true, 1) | ||
@test typed_hvncat(Float64, (2,), true, 1, 1) == Float64[1.0; 1.0] | ||
@test typed_hvncat(Float64, (2,), true, [1], [1]) == Float64[1.0; 1.0] | ||
@test_throws ArgumentError typed_hvncat(Float64, (2,), true, 1) | ||
# row_first has no effect with just one dimension of the dims form | ||
@test hvncat((2,), false, 1, 1) == [1; 1] | ||
@test typed_hvncat(Float64, (2,), false, 1, 1) == Float64[1.0; 1.0] | ||
# shape form | ||
@test hvncat(((2,),), true, 1, 1) == [1 1] | ||
@test hvncat(((2,),), true, [1], [1]) == [1 1] | ||
@test_throws ArgumentError hvncat(((2,),), true, 1) | ||
@test hvncat(((2,),), false, 1, 1) == [1; 1] | ||
@test hvncat(((2,),), false, [1], [1]) == [1; 1] | ||
@test typed_hvncat(Float64, ((2,),), true, 1, 1) == Float64[1.0 1.0] | ||
@test typed_hvncat(Float64, ((2,),), true, [1], [1]) == Float64[1.0 1.0] | ||
@test_throws ArgumentError typed_hvncat(Float64, ((2,),), true, 1) | ||
@test typed_hvncat(Float64, ((2,),), false, 1, 1) == Float64[1.0; 1.0] | ||
@test typed_hvncat(Float64, ((2,),), false, [1], [1]) == Float64[1.0; 1.0] | ||
|
||
# zero-value behaviors for int form above dimension zero | ||
# e.g. [;;], [;;;], though that isn't valid syntax | ||
@test [] == hvncat(1) isa Array{Any, 1} | ||
@test Array{Any, 2}(undef, 0, 0) == hvncat(2) isa Array{Any, 2} | ||
@test Array{Any, 3}(undef, 0, 0, 0) == hvncat(3) isa Array{Any, 3} | ||
@test Int[] == typed_hvncat(Int, 1) isa Array{Int, 1} | ||
@test Array{Int, 2}(undef, 0, 0) == typed_hvncat(Int, 2) isa Array{Int, 2} | ||
@test Array{Int, 3}(undef, 0, 0, 0) == typed_hvncat(Int, 3) isa Array{Int, 3} | ||
end | ||
|
||
@testset "keepat!" begin | ||
|
Uh oh!
There was an error while loading. Please reload this page.