Skip to content

Commit

Permalink
Use axes instead of length (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat authored Apr 16, 2024
1 parent 8c3b69f commit e918f95
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/Test/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,21 @@ function sum_test(matrix)
@test_rewrite sum(matrix)
if matrix isa AbstractMatrix
@test_rewrite sum([
2matrix[i, j] for i in 1:size(matrix, 1), j in 1:size(matrix, 2)
2matrix[i, j] for i in axes(matrix, 1), j in axes(matrix, 2)
])
@test_rewrite sum(
2matrix[i, j] for i in 1:size(matrix, 1), j in 1:size(matrix, 2)
2matrix[i, j] for i in axes(matrix, 1), j in axes(matrix, 2)
)
end
end

function sum_multiplication_test(matrix)
if matrix isa AbstractMatrix
@test_rewrite sum([
2matrix[i, j]^2 for i in 1:size(matrix, 1), j in 1:size(matrix, 2)
2matrix[i, j]^2 for i in axes(matrix, 1), j in axes(matrix, 2)
])
@test_rewrite sum(
2matrix[i, j]^2 for i in 1:size(matrix, 1), j in 1:size(matrix, 2)
2matrix[i, j]^2 for i in axes(matrix, 1), j in axes(matrix, 2)
)
end
end
Expand All @@ -344,7 +344,7 @@ function transpose_test(x)
# If the element type does not support multiplication, e.g.
# JuMP or MOI quadratic functions, then we should skip these tests.
if x isa AbstractMatrix && _is_supported(*, eltype(x), eltype(x))
y = [x[i, j] for j in 1:size(x, 2), i in 1:size(x, 1)]
y = [x[i, j] for j in axes(x, 2), i in axes(x, 1)]
@test MA.isequal_canonical(x', y)
@test MA.isequal_canonical(copy(transpose(x)), y)
if size(x, 1) == size(x, 2)
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ end
# `eltype` of `B` might be different form the `eltype` of `A`.
function Matrix(A::LinearAlgebra.Symmetric{<:AbstractMutable})
B = LinearAlgebra.copytri!(convert(Matrix, copy(A.data)), A.uplo)
for i in 1:size(A, 1)
for i in axes(A, 1)
# `B[i, i]` is used instead of `A[i, i]` on Julia v1.1 hence the need
# to overwrite it for `AbstractMutable`.
B[i, i] = LinearAlgebra.symmetric(
Expand All @@ -561,7 +561,7 @@ end

function Matrix(A::LinearAlgebra.Hermitian{<:AbstractMutable})
B = LinearAlgebra.copytri!(convert(Matrix, copy(A.data)), A.uplo, true)
for i in 1:size(A, 1)
for i in axes(A, 1)
# `B[i, i]` is used instead of `A[i, i]` on Julia v1.1 hence the need
# to overwrite it for `AbstractMutable`.
B[i, i] = LinearAlgebra.hermitian(
Expand Down
14 changes: 7 additions & 7 deletions src/implementations/SparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function operate!(
A = parent(adjA)
A_nonzeros = SparseArrays.nonzeros(A)
A_rowvals = SparseArrays.rowvals(A)
for k in 1:size(ret, 2)
for k in axes(ret, 2)
for col in 1:A.n
cur = ret[col, k]
for j in SparseArrays.nzrange(A, col)
Expand All @@ -108,8 +108,8 @@ function operate!(
_dim_check(ret, A, B)
A_nonzeros = SparseArrays.nonzeros(A)
A_rowvals = SparseArrays.rowvals(A)
for col in 1:size(A, 2)
for k in 1:size(ret, 2)
for col in axes(A, 2)
for k in axes(ret, 2)
αxj = *(B[col, k], α...)
for j in SparseArrays.nzrange(A, col)
ret[A_rowvals[j], k] =
Expand All @@ -130,8 +130,8 @@ function operate!(
_dim_check(ret, A, B)
rowval = SparseArrays.rowvals(B)
B_nonzeros = SparseArrays.nonzeros(B)
for multivec_row in 1:size(A, 1)
for col in 1:size(B, 2)
for multivec_row in axes(A, 1)
for col in axes(B, 2)
cur = ret[multivec_row, col]
for k in SparseArrays.nzrange(B, col)
cur = operate!!(
Expand Down Expand Up @@ -159,11 +159,11 @@ function operate!(
B = parent(adjB)
B_rowvals = SparseArrays.rowvals(B)
B_nonzeros = SparseArrays.nonzeros(B)
for B_col in 1:size(B, 2), k in SparseArrays.nzrange(B, B_col)
for B_col in axes(B, 2), k in SparseArrays.nzrange(B, B_col)
B_row = B_rowvals[k]
B_val = _mirror_transpose_or_adjoint(B_nonzeros[k], adjB)
αB_val = *(B_val, α...)
for A_row in 1:size(A, 1)
for A_row in axes(A, 1)
ret[A_row, B_row] =
operate!!(add_mul, ret[A_row, B_row], A[A_row, B_col], αB_val)
end
Expand Down

0 comments on commit e918f95

Please sign in to comment.