-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add sum without dims * add sum; dims=1 * support for dims = 2 and error handling * fix for empty matrices and added unit tests * style * make improvements * add test_sum.jl to runtests.jl * fix method dispatch issue in a way that mimics Base.sum * update unit tests, reduce memory allocation, improve style * update unit tests, add sum!, move to AbstractBandedMatrix.jl * revert tests to \approx * make improvements in AbstractBandedMatrix.jl * test special cases of sum! * add some tests and avoid CI failure --------- Co-authored-by: Sheehan Olver <[email protected]>
- Loading branch information
1 parent
47c15ab
commit ea616cc
Showing
6 changed files
with
104 additions
and
2 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module TestSum | ||
|
||
using Test, BandedMatrices, Random | ||
|
||
Random.seed!(0) | ||
r = brand(rand(1:10_000),rand(1:10_000),rand(-20:100),rand(-20:100)) | ||
empty_r = brand(rand(1:1_000),rand(1:1_000),rand(1:100),rand(-200:-101)) | ||
n,m = size(empty_r) | ||
matr = Matrix(r) | ||
@testset "sum" begin | ||
@test sum(empty_r) == 0 | ||
@test sum(empty_r; dims = 2) == zeros(n,1) | ||
@test sum(empty_r; dims = 1) == zeros(1,m) | ||
|
||
@test sum(r) ≈ sum(matr) rtol = 1e-10 | ||
@test sum(r; dims=2) ≈ sum(matr; dims=2) rtol = 1e-10 | ||
@test sum(r; dims=1) ≈ sum(matr; dims=1) rtol = 1e-10 | ||
@test sum(r; dims=3) == r | ||
@test_throws ArgumentError sum(r; dims=0) | ||
|
||
v = [1.0] | ||
sum!(v, r) | ||
@test v == sum!(v, Matrix(r)) | ||
n2, m2 = size(r) | ||
v = ones(n2) | ||
@test sum!(v, r) == sum!(v, Matrix(r)) | ||
V = zeros(1,m2) | ||
@test sum!(V, r) === V ≈ sum!(zeros(1,m2), Matrix(r)) | ||
V = zeros(n2,m2) | ||
@test sum!(V, r) === V == r | ||
@test_throws DimensionMismatch sum!(zeros(Float64, n2 + 1, m2 + 1), r) | ||
end | ||
|
||
end |