Skip to content

Commit 737f61a

Browse files
authored
always allow scalar indexing for zero dimensional (#250)
* always allow scalar indexing for zero dimensional * test zero dim scalar
1 parent 6b2fa78 commit 737f61a

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/scalar.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ canscalar() = ALLOWSCALAR[]
2424

2525
# Checks if an index is scalar at all, and then if scalar indexing is allowed.
2626
# Syntax as for `checkbounds`.
27+
checkscalar(::Type{Bool}) = true # Handle 0 dimensional
2728
checkscalar(::Type{Bool}, I::Tuple) = checkscalar(Bool, I...)
2829
checkscalar(::Type{Bool}, I...) = !all(map(i -> i isa Int, I)) || canscalar()
2930
checkscalar(I::Tuple) = checkscalar(I...)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ end
2222
@testset "allowscalar" begin
2323
DiskArrays.allowscalar(false)
2424
@test DiskArrays.canscalar() == false
25+
@test DiskArrays.checkscalar(Bool) == true # Always allowed for zero dimensional
2526
@test DiskArrays.checkscalar(Bool, 1, 2, 3) == false
2627
@test DiskArrays.checkscalar(Bool, 1, 2:5, :) == true
2728
DiskArrays.allowscalar(true)
2829
@test DiskArrays.canscalar() == true
30+
@test DiskArrays.checkscalar(Bool) == true
2931
@test DiskArrays.checkscalar(Bool, 1, 2, 3) == true
3032
@test DiskArrays.checkscalar(Bool, :, 2:5, 3) == true
3133
a = AccessCountDiskArray(reshape(1:24, 2, 3, 4), chunksize=(2, 2, 2))

0 commit comments

Comments
 (0)