Skip to content

Commit cfbdfa7

Browse files
Add code quality tests
1 parent 6bbe457 commit cfbdfa7

File tree

3 files changed

+406
-17
lines changed

3 files changed

+406
-17
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ These guidelines give AI coding agents the minimum project-specific context to b
1818
- Build docs locally: `make docs`.
1919
- Doctests: Any code block in docstrings marked for execution must pass CI doctest phase.
2020
- Format code: `make format`.
21+
- Always check in which directory you are running commands. Change directory to the repo root if needed.
2122

2223
## 4. Coding Conventions
2324
- Public API: add docstrings starting with a concise one-line summary, then details (Documenter picks them up).

src/vector.jl

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ function LinearAlgebra.normalize(V::DeviceSparseVector, p::Real = 2)
111111
end
112112

113113
function LinearAlgebra.dot(x::DeviceSparseVector, y::DenseVector)
114-
length(x) == length(y) ||
115-
throw(DimensionMismatch("Vector x has a length $(length(x)) but y has a length $n"))
114+
length(x) == length(y) || throw(
115+
DimensionMismatch(
116+
"Vector x has a length $(length(x)) but y has a length $(length(y))",
117+
),
118+
)
116119

117120
T = Base.promote_eltype(x, y)
118121

@@ -161,19 +164,6 @@ function _prep_sparsevec_copy_dest!(A::DeviceSparseVector, lB, nnzB)
161164
resize!(nonzeros(A), nnzB)
162165
resize!(nonzeroinds(A), nnzB)
163166
else
164-
nnzA = nnz(A)
165-
166-
lastmodindA = searchsortedlast(nonzeroinds(A), lB)
167-
if lastmodindA >= nnzB
168-
# A will have fewer non-zero elements; unmodified elements are kept at the end.
169-
deleteat!(nonzeroinds(A), (nnzB+1):lastmodindA)
170-
deleteat!(nonzeros(A), (nnzB+1):lastmodindA)
171-
else
172-
# A will have more non-zero elements; unmodified elements are kept at the end.
173-
resize!(nonzeroinds(A), nnzB + nnzA - lastmodindA)
174-
resize!(nonzeros(A), nnzB + nnzA - lastmodindA)
175-
copyto!(nonzeroinds(A), nnzB+1, nonzeroinds(A), lastmodindA+1, nnzA-lastmodindA)
176-
copyto!(nonzeros(A), nnzB+1, nonzeros(A), lastmodindA+1, nnzA-lastmodindA)
177-
end
167+
throw(ArgumentError("Cannot copy to a sparse vector of different length"))
178168
end
179169
end

0 commit comments

Comments
 (0)