Skip to content

Commit 5fb7d62

Browse files
authored
allowscalar (#217)
1 parent 931ec33 commit 5fb7d62

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/scalar.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
# Manual control over scalar indexing
2-
const ALLOW_SCALAR = Ref{Bool}(true)
2+
const ALLOWSCALAR = Ref{Bool}(true)
33

44
"""
5-
allow_scalar(x::Bool)
5+
allowscalar(x::Bool)
66
77
Specify if a disk array can do scalar indexing, (with all `Int` arguments).
88
9-
Setting `allow_scalar(false)` can help identify the cause of poor performance.
9+
Setting `allowscalar(false)` can help identify the cause of poor performance.
1010
"""
11-
allow_scalar(x::Bool) = ALLOW_SCALAR[] = x
11+
allowscalar(x::Bool) = ALLOWSCALAR[] = x
1212

1313
"""
14-
can_scalar()
14+
canscalar()
1515
16-
Check if DiskArrays is set to allow scalar indexing, with [`allow_scalar`](@ref).
16+
Check if DiskArrays is set to allow scalar indexing, with [`allowscalar`](@ref).
1717
1818
Returns a `Bool`.
1919
"""
20-
can_scalar() = ALLOW_SCALAR[]
20+
canscalar() = ALLOWSCALAR[]
2121

22-
function _scalar_error()
23-
return error(
24-
"Scalar indexing with `Int` is very slow, and currently is disallowed. Run DiskArrays.allow_scalar(true) to allow",
25-
)
26-
end
22+
@deprecate allow_scalar allowscalar
23+
@deprecate can_scalar canscalar
2724

2825
# Checks if an index is scalar at all, and then if scalar indexing is allowed.
2926
# Syntax as for `checkbounds`.
3027
checkscalar(::Type{Bool}, I::Tuple) = checkscalar(Bool, I...)
3128
checkscalar(::Type{Bool}, I...) = !all(map(i -> i isa Int, I)) || can_scalar()
3229
checkscalar(I::Tuple) = checkscalar(I...)
3330
checkscalar(I...) = checkscalar(Bool, I...) || _scalar_error()
31+
32+
function _scalar_error()
33+
return error(
34+
"Scalar indexing with `Int` is very slow, and currently is disallowed. Run DiskArrays.allowscalar(true) to allow",
35+
)
36+
end

test/runtests.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ if VERSION >= v"1.9.0"
1919
Aqua.test_deps_compat(DiskArrays)
2020
end
2121

22-
@testset "allow_scalar" begin
23-
DiskArrays.allow_scalar(false)
22+
@testset "allowscalar" begin
23+
DiskArrays.allowscalar(false)
2424
@test DiskArrays.can_scalar() == false
2525
@test DiskArrays.checkscalar(Bool, 1, 2, 3) == false
2626
@test DiskArrays.checkscalar(Bool, 1, 2:5, :) == true
27-
DiskArrays.allow_scalar(true)
27+
DiskArrays.allowscalar(true)
2828
@test DiskArrays.can_scalar() == true
2929
@test DiskArrays.checkscalar(Bool, 1, 2, 3) == true
3030
@test DiskArrays.checkscalar(Bool, :, 2:5, 3) == true
@@ -72,11 +72,11 @@ function test_getindex(a)
7272
# Test that readblock was called exactly onces for every getindex
7373
@test a[2:2:4, 1:2:5] == [2 10 18; 4 12 20]
7474
@test a[[1, 3, 4], [1, 3], 1] == [1 9; 3 11; 4 12]
75-
@testset "allow_scalar" begin
76-
DiskArrays.allow_scalar(false)
75+
@testset "allowscalar" begin
76+
DiskArrays.allowscalar(false)
7777
@test_throws ErrorException a[2, 3, 1]
7878
@test_throws ErrorException a[5]
79-
DiskArrays.allow_scalar(true)
79+
DiskArrays.allowscalar(true)
8080
@test a[2, 3, 1] == 10
8181
@test a[5] == 5
8282
end

0 commit comments

Comments
 (0)