Skip to content

Commit 7d105da

Browse files
split allocs checks
1 parent 500b89f commit 7d105da

File tree

7 files changed

+117
-63
lines changed

7 files changed

+117
-63
lines changed

.github/workflows/Tests.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
branches:
66
- master
7+
- 'release-'
78
paths-ignore:
89
- 'docs/**'
910
push:
@@ -13,19 +14,26 @@ on:
1314
- 'docs/**'
1415

1516
concurrency:
17+
# Skip intermediate builds: always, but for the master branch.
18+
# Cancel intermediate builds: always, but for the master branch.
1619
group: ${{ github.workflow }}-${{ github.ref }}
17-
cancel-in-progress: ${{ github.ref_name != github.event.repository.default_branch || github.ref != 'refs/tags/v*' }}
20+
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
1821

1922
jobs:
2023
tests:
2124
name: "Tests"
2225
strategy:
26+
fail-fast: false
2327
matrix:
2428
version:
2529
- "1"
2630
- "lts"
2731
- "pre"
32+
group:
33+
- Core
34+
- Downstream
2835
uses: "SciML/.github/.github/workflows/tests.yml@v1"
2936
with:
3037
julia-version: "${{ matrix.version }}"
38+
group: "${{ matrix.group }}"
3139
secrets: "inherit"

src/basic.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,9 @@ end
625625
# In-place: w is destination, v is action vector, u is update vector
626626
function (L::AddedOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
627627
update_coefficients!(L, u, p, t; kwargs...)
628-
L.ops[1](w, v, u, p, t; kwargs...)
629-
for i in 2:length(L.ops)
630-
if !iszero(L.ops[i])
631-
L.ops[i](w, v, u, p, t, 1.0, 1.0; kwargs...)
628+
for op in L.ops
629+
if !iszero(op)
630+
op(w, v, u, p, t, 1.0, 1.0; kwargs...)
632631
end
633632
end
634633
w

src/matrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function Base.conj(L::MatrixOperator)
164164
accepted_kwargs = NoKwargFilter())
165165
end
166166

167-
has_adjoint(A::MatrixOperator) = has_adjoint(A.A)
167+
has_adjoint(L::MatrixOperator) = has_adjoint(L.A)
168168
getops(L::MatrixOperator) = (L.A,)
169169
function isconstant(L::MatrixOperator)
170170
update_func_isconstant(L.update_func) & update_func_isconstant(L.update_func!)

test/basic.jl

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,6 @@ end
203203
@test ldiv!(op, w) * D) \ v
204204
end
205205

206-
function apply_op!(H, du, u, p, t)
207-
H(du, u, p, t)
208-
return nothing
209-
end
210-
211-
test_apply_noalloc(H, du, u, p, t) = @test_broken (@allocations apply_op!(H, du, u, p, t)) == 0
212-
213206
@testset "AddedOperator" begin
214207
A = rand(N, N) |> MatrixOperator
215208
B = rand(N, N) |> MatrixOperator
@@ -284,25 +277,6 @@ test_apply_noalloc(H, du, u, p, t) = @test_broken (@allocations apply_op!(H, du,
284277
@test !isa(op, AddedOperator)
285278
end
286279

287-
# Allocations Tests with new interface
288-
289-
# Define a function to test allocations with the new interface
290-
function apply_op_new!(H, du, v, u, p, t)
291-
H(du, v, u, p, t)
292-
return nothing
293-
end
294-
295-
if VERSION >= v"1.11"
296-
test_apply_noalloc_new(H, du, v, u, p, t) = @test (@allocations apply_op_new!(H, du, v, u, p, t)) == 0
297-
298-
@allocations apply_op_new!(op, w, v, u, p, t) # warmup
299-
test_apply_noalloc_new(op, w, v, u, p, t)
300-
301-
## Original allocations test
302-
@allocations apply_op!(op, v, u, p, t) # warmup
303-
test_apply_noalloc(op, v, u, p, t)
304-
end
305-
306280
## Time-Dependent Coefficients
307281

308282
for T in (Float32, Float64, ComplexF32, ComplexF64)
@@ -331,20 +305,6 @@ test_apply_noalloc(H, du, u, p, t) = @test_broken (@allocations apply_op!(H, du,
331305
du = similar(u)
332306
p == 0.1,)
333307
t = 0.1
334-
335-
if VERSION >= v"1.11"
336-
# Test allocations with original interface
337-
@allocations apply_op!(H_sparse, du, u, p, t) # warmup
338-
@allocations apply_op!(H_dense, du, u, p, t) # warmup
339-
test_apply_noalloc(H_sparse, du, u, p, t)
340-
test_apply_noalloc(H_dense, du, u, p, t)
341-
342-
# Test allocations with new interface
343-
@allocations apply_op_new!(H_sparse, du, v, u, p, t) # warmup
344-
@allocations apply_op_new!(H_dense, du, v, u, p, t) # warmup
345-
test_apply_noalloc_new(H_sparse, du, v, u, p, t)
346-
test_apply_noalloc_new(H_dense, du, v, u, p, t)
347-
end
348308
end
349309
end
350310

test/downstream/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
3+
4+
[compat]
5+
AllocCheck = "0.2.2"

test/downstream/alloccheck.jl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using SciMLOperators, AllocCheck, Random, SparseArrays, Test
2+
using SciMLOperators: IdentityOperator,
3+
NullOperator,
4+
ScaledOperator,
5+
AddedOperator
6+
Random.seed!(0)
7+
N = 8
8+
K = 12
9+
A = rand(N, N) |> MatrixOperator
10+
B = rand(N, N) |> MatrixOperator
11+
C = rand(N, N) |> MatrixOperator
12+
α = rand()
13+
β = rand()
14+
u = rand(N, K) # Update vector
15+
v = rand(N, K) # Action vector
16+
w = zeros(N, K) # Output vector
17+
p = ()
18+
t = 0
19+
op = AddedOperator(A, B)
20+
21+
# Define a function to test allocations with the new interface
22+
@check_allocs ignore_throw = true function apply_op!(H, w, v, u, p, t)
23+
H(w, v, u, p, t)
24+
return nothing
25+
end
26+
27+
if VERSION >= v"1.11"
28+
apply_op!(op, w, v, u, p, t)
29+
else
30+
@test_throws AllocCheckFailure apply_op!(op, w, v, u, p, t)
31+
end
32+
33+
for T in (Float32, Float64, ComplexF32, ComplexF64)
34+
N = 100
35+
A1_sparse = MatrixOperator(sprand(T, N, N, 5 / N))
36+
A2_sparse = MatrixOperator(sprand(T, N, N, 5 / N))
37+
A3_sparse = MatrixOperator(sprand(T, N, N, 5 / N))
38+
39+
A1_dense = MatrixOperator(rand(T, N, N))
40+
A2_dense = MatrixOperator(rand(T, N, N))
41+
A3_dense = MatrixOperator(rand(T, N, N))
42+
43+
coeff1(a, u, p, t) = sin(p.ω * t)
44+
coeff2(a, u, p, t) = cos(p.ω * t)
45+
coeff3(a, u, p, t) = sin(p.ω * t) * cos(p.ω * t)
46+
47+
c1 = ScalarOperator(rand(T), coeff1)
48+
c2 = ScalarOperator(rand(T), coeff2)
49+
c3 = ScalarOperator(rand(T), coeff3)
50+
51+
H_sparse = c1 * A1_sparse + c2 * A2_sparse + c3 * A3_sparse
52+
H_dense = c1 * A1_dense + c2 * A2_dense + c3 * A3_dense
53+
54+
u = rand(T, N)
55+
v = rand(T, N)
56+
w = similar(u)
57+
p == 0.1,)
58+
t = 0.1
59+
60+
# Test allocations with original interface
61+
if VERSION >= v"1.11"
62+
apply_op!(H_sparse, w, v, u, p, t)
63+
apply_op!(H_dense, w, v, u, p, t)
64+
else
65+
@test_throws AllocCheckFailure apply_op!(H_sparse, w, v, u, p, t)
66+
@test_throws AllocCheckFailure apply_op!(H_dense, w, v, u, p, t)
67+
end
68+
end

test/runtests.jl

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
using SafeTestsets, Test
2+
const GROUP = get(ENV, "GROUP", "All")
3+
4+
function activate_downstream_env()
5+
Pkg.activate("downstream")
6+
Pkg.develop(PackageSpec(path = dirname(@__DIR__)))
7+
Pkg.instantiate()
8+
end
29

310
@time begin
411
@testset "SciMLOperators" begin
5-
@time @safetestset "Scalar Operators" begin
6-
include("scalar.jl")
7-
end
8-
@time @safetestset "Basic Operators" begin
9-
include("basic.jl")
10-
end
11-
@time @safetestset "Matrix Operators" begin
12-
include("matrix.jl")
13-
end
14-
@time @safetestset "Function Operator" begin
15-
include("func.jl")
16-
end
17-
@time @safetestset "Full tests" begin
18-
include("total.jl")
19-
end
20-
@time @safetestset "Zygote.jl" begin
21-
include("zygote.jl")
12+
if GROUP == "All" || GROUP == "Core"
13+
@time @safetestset "Scalar Operators" begin
14+
include("scalar.jl")
15+
end
16+
@time @safetestset "Basic Operators" begin
17+
include("basic.jl")
18+
end
19+
@time @safetestset "Matrix Operators" begin
20+
include("matrix.jl")
21+
end
22+
@time @safetestset "Function Operator" begin
23+
include("func.jl")
24+
end
25+
@time @safetestset "Full tests" begin
26+
include("total.jl")
27+
end
28+
@time @safetestset "Zygote.jl" begin
29+
include("zygote.jl")
30+
end
31+
elseif GROUP == "All" || GROUP == "Downstream"
32+
activate_downstream_env()
33+
@time @safetestset "AllocCheck" begin
34+
include("downstream/alloccheck.jl")
35+
end
2236
end
2337
end
2438
end

0 commit comments

Comments
 (0)