Skip to content

Commit f94a11b

Browse files
committed
Use Base.CartesianIndex.
1 parent f10d175 commit f94a11b

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/device/indexing.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ end
9090
"""
9191
cartesianidx(A, ctxsym = :ctx)
9292
93-
Like [`@linearidx(A, ctxsym = :ctx)`](@ref), but returns an N-dimensional `NTuple{ndim(A), Int}` as index
93+
Like [`@linearidx(A, ctxsym = :ctx)`](@ref), but returns a N-dimensional `CartesianIndex`.
9494
"""
9595
macro cartesianidx(A, ctxsym = :ctx)
9696
quote
9797
x = $(esc(A))
98-
i2 = @linearidx(x, $(esc(ctxsym)))
99-
gpu_ind2sub(x, i2)
98+
i = @linearidx(x, $(esc(ctxsym)))
99+
CartesianIndices(x)[i]
100100
end
101101
end

src/host/linalg.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ function LinearAlgebra.transpose!(At::AbstractGPUArray{T, 2}, A::AbstractGPUArra
99
At
1010
end
1111

12-
function genperm(I::NTuple{N}, perm::NTuple{N}) where N
13-
ntuple(d-> (@inbounds return I[perm[d]]), Val(N))
12+
function genperm(I::CartesianIndex{N}, perm::NTuple{N}) where N
13+
CartesianIndex(ntuple(d-> (@inbounds return I[perm[d]]), Val(N)))
1414
end
1515

1616
function LinearAlgebra.permutedims!(dest::AbstractGPUArray, src::AbstractGPUArray, perm) where N
1717
perm isa Tuple || (perm = Tuple(perm))
1818
gpu_call(dest, src, perm) do ctx, dest, src, perm
1919
I = @cartesianidx src ctx
20-
@inbounds dest[genperm(I, perm)...] = src[I...]
20+
@inbounds dest[genperm(I, perm)] = src[I]
2121
return
2222
end
2323
return dest

src/host/math.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Base.clamp!
33
function Base.clamp!(A::AbstractGPUArray, low, high)
44
function kernel(state, A, low, high)
55
I = @cartesianidx A state
6-
A[I...] = clamp(A[I...], low, high)
6+
A[I] = clamp(A[I], low, high)
77
return
88
end
99
gpu_call(kernel, A, low, high)

0 commit comments

Comments
 (0)