-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,36 @@ | ||
# Manual control over scalar indexing | ||
const ALLOW_SCALAR = Ref{Bool}(true) | ||
const ALLOWSCALAR = Ref{Bool}(true) | ||
|
||
""" | ||
allow_scalar(x::Bool) | ||
allowscalar(x::Bool) | ||
Specify if a disk array can do scalar indexing, (with all `Int` arguments). | ||
Setting `allow_scalar(false)` can help identify the cause of poor performance. | ||
Setting `allowscalar(false)` can help identify the cause of poor performance. | ||
""" | ||
allow_scalar(x::Bool) = ALLOW_SCALAR[] = x | ||
allowscalar(x::Bool) = ALLOWSCALAR[] = x | ||
|
||
""" | ||
can_scalar() | ||
canscalar() | ||
Check if DiskArrays is set to allow scalar indexing, with [`allow_scalar`](@ref). | ||
Check if DiskArrays is set to allow scalar indexing, with [`allowscalar`](@ref). | ||
Returns a `Bool`. | ||
""" | ||
can_scalar() = ALLOW_SCALAR[] | ||
canscalar() = ALLOWSCALAR[] | ||
|
||
function _scalar_error() | ||
return error( | ||
"Scalar indexing with `Int` is very slow, and currently is disallowed. Run DiskArrays.allow_scalar(true) to allow", | ||
) | ||
end | ||
@deprecate allow_scalar allowscalar | ||
@deprecate can_scalar canscalar | ||
|
||
# Checks if an index is scalar at all, and then if scalar indexing is allowed. | ||
# Syntax as for `checkbounds`. | ||
checkscalar(::Type{Bool}, I::Tuple) = checkscalar(Bool, I...) | ||
checkscalar(::Type{Bool}, I...) = !all(map(i -> i isa Int, I)) || can_scalar() | ||
checkscalar(I::Tuple) = checkscalar(I...) | ||
checkscalar(I...) = checkscalar(Bool, I...) || _scalar_error() | ||
|
||
function _scalar_error() | ||
return error( | ||
"Scalar indexing with `Int` is very slow, and currently is disallowed. Run DiskArrays.allowscalar(true) to allow", | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters