-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove A.tprod #151
Remove A.tprod #151
Conversation
I don't understand. Could you give an example? |
This example shows that we don't allocate with the new transpose linear operator. using LinearOperators
n = 10^4
A = rand(n, n)
x = rand(n)
y = rand(n)
op = PreallocatedLinearOperator(A)
function test1(op, x, y, p=10)
opᵀ = op'
for i = 1:p
p = op * x
q = opᵀ * y
end
end
function test2(op, x, y, p=10)
for i = 1:p
p = op * x
q = op.tprod(y)
end
end
test1(op, x, y) # warm up
@allocated test1(op, x, y)
test2(op, x, y) # warm up
@allocated test2(op, x, y)
m = 100
A2 = rand(m, n)
op2 = PreallocatedLinearOperator(A2)
x2 = rand(n)
y2 = rand(m)
test1(op2, x2, y2) # warm up
@allocated test1(op2, x2, y2)
test2(op2, x2, y2) # warm up
@allocated test2(op2, x2, y2) |
And this example shows that something else is allocated whereas I only changed using LinearOperators, Printf, LinearAlgebra, SparseArrays
include("aux.jl")
include("crmr1.jl")
include("crmr2.jl")
L = get_div_grad(32, 32, 32)
n = size(L, 1)
m = div(n, 2)
A = PreallocatedLinearOperator(L) # Dimension n x n
Au = PreallocatedLinearOperator(L[1:m,:]) # Dimension m x n
Ao = PreallocatedLinearOperator(L[:,1:m]) # Dimension n x m
b = ones(n) # Dimension n
c = ones(m) # Dimension m
crmr1(Au, c) # warmup
@allocated crmr1(Au, c)
crmr2(Au, c) # warmup
@allocated crmr2(Au, c) |
According to the new TimedLinearOperators, there is no extra allocation: julia> op = TimedLinearOperator(A);
julia> crmr1(op, b);
julia> op.timer
──────────────────────────────────────────────────────────────────
Time Allocations
────────────────────── ───────────────────────
Tot / % measured: 7.02s / 3.72% 974KiB / 0.71%
Section ncalls time %tot avg alloc %tot avg
──────────────────────────────────────────────────────────────────
prod 441 139ms 53.1% 315μs 0.00B 0.00% 0.00B
tprod 442 123ms 46.9% 277μs 6.91KiB 100% 16.0B
──────────────────────────────────────────────────────────────────
julia> op = TimedLinearOperator(A);
julia> crmr2(op, b);
julia> op.timer
──────────────────────────────────────────────────────────────────
Time Allocations
────────────────────── ───────────────────────
Tot / % measured: 7.22s / 3.40% 16.5MiB / 0.04%
Section ncalls time %tot avg alloc %tot avg
──────────────────────────────────────────────────────────────────
prod 441 130ms 53.1% 295μs 0.00B 0.00% 0.00B
ctprod 442 115ms 46.9% 260μs 6.91KiB 100% 16.0B
────────────────────────────────────────────────────────────────── If I change julia> op = TimedLinearOperator(A);
julia> crmr2(op, b);
julia> op.timer
──────────────────────────────────────────────────────────────────
Time Allocations
────────────────────── ───────────────────────
Tot / % measured: 88.8s / 0.29% 18.3MiB / 0.04%
Section ncalls time %tot avg alloc %tot avg
──────────────────────────────────────────────────────────────────
prod 441 135ms 52.8% 307μs 0.00B 0.00% 0.00B
tprod 442 121ms 47.2% 273μs 6.91KiB 100% 16.0B
────────────────────────────────────────────────────────────────── I do observe the same extra allocations as you do with |
3677dc7
to
51433a3
Compare
51433a3
to
f9f1d45
Compare
I rebased my pull request. We should be able to use |
Project.toml
Outdated
@@ -11,5 +11,5 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | |||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | |||
|
|||
[compat] | |||
LinearOperators = "0.5.2, 0.6" | |||
LinearOperators = "≥ 0.7.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use LinearOperators = "0.7.1, 1"
, so it has an upper limit also.
f9f1d45
to
ace45b8
Compare
🤞 |
Codecov Report
@@ Coverage Diff @@
## master #151 +/- ##
==========================================
+ Coverage 97.15% 97.16% +0.01%
==========================================
Files 26 26
Lines 2146 2155 +9
==========================================
+ Hits 2085 2094 +9
Misses 61 61
Continue to review full report at Codecov.
|
Wow, Travis / Appveyor tests time has been reduced by a factor 4 with our recent updates of |
The type annotations must be doing something right. |
🤘 |
close #135
I remove
A.tprod
but I don't understand something.In the
REPL
with the following code :Nothing is allocated when I compute
A3 * x
(cost of compilation of*
method) whereasAᵀ * x
seems to be recompiled inside methods even if the method was compiled before.And
Aᵀ = A'
is not allocating if the function has been "warm up"...