File tree Expand file tree Collapse file tree 1 file changed +21
-11
lines changed Expand file tree Collapse file tree 1 file changed +21
-11
lines changed Original file line number Diff line number Diff line change 1
- # mechanism to disallow indexing
1
+ # mechanism to disallow scalar operations
2
2
3
- const _allowscalar = Ref (true )
3
+ const scalar_allowed = Ref (true )
4
+ const scalar_warned = Ref (false )
4
5
5
- allowscalar (flag = true ) = (_allowscalar[] = flag)
6
+ function allowscalar (flag = true )
7
+ scalar_allowed[] = flag
8
+ scalar_warned[] = false
9
+ return
10
+ end
6
11
7
12
function assertscalar (op = " operation" )
8
- _allowscalar[] || error (" $op is disallowed" )
9
- return
13
+ if ! scalar_allowed[]
14
+ error (" $op is disallowed" )
15
+ elseif ! scalar_warned[]
16
+ @warn " Performing scalar operations on GPU arrays: This is very slow, consider disallowing these operations with `allowscalar(false)`"
17
+ scalar_warned[] = true
18
+ end
19
+ return
10
20
end
11
21
12
22
macro allowscalar (ex)
13
23
quote
14
- local prev = _allowscalar []
15
- _allowscalar [] = true
24
+ local prev = scalar_allowed []
25
+ scalar_allowed [] = true
16
26
local ret = $ (esc (ex))
17
- _allowscalar [] = prev
27
+ scalar_allowed [] = prev
18
28
ret
19
29
end
20
30
end
21
31
22
32
macro disallowscalar (ex)
23
33
quote
24
- local prev = _allowscalar []
25
- _allowscalar [] = false
34
+ local prev = scalar_allowed []
35
+ scalar_allowed [] = false
26
36
local ret = $ (esc (ex))
27
- _allowscalar [] = prev
37
+ scalar_allowed [] = prev
28
38
ret
29
39
end
30
40
end
You can’t perform that action at this time.
0 commit comments