forked from JuliaSmoothOptimizers/LinearOperators.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimedOperators.jl
More file actions
64 lines (57 loc) · 1.64 KB
/
TimedOperators.jl
File metadata and controls
64 lines (57 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using TimerOutputs
export TimedLinearOperator
mutable struct TimedLinearOperator{T, OP <: AbstractLinearOperator{T}, F, Ft, Fct} <:
AbstractLinearOperator{T}
timer::TimerOutput
const op::OP
const prod!::F
const tprod!::Ft
const ctprod!::Fct
end
TimedLinearOperator{T}(
timer::TimerOutput,
op::AbstractLinearOperator{T},
prod!::F,
tprod!::Ft,
ctprod!::Fct,
) where {T, F, Ft, Fct} =
TimedLinearOperator{T, typeof(op), F, Ft, Fct}(timer, op, prod!, tprod!, ctprod!)
"""
TimedLinearOperator(op)
Creates a linear operator instrumented with timers from TimerOutputs.
"""
function TimedLinearOperator(op::AbstractLinearOperator{T}) where {T}
timer = TimerOutput()
prod!(res, x, α, β) = @timeit timer "prod" mul!(res, op, x, α, β)
tprod!(res, x, α, β) = @timeit timer "tprod" mul!(res, transpose(op),x, α, β)
ctprod!(res, x, α, β) = @timeit timer "ctprod" mul!(res, op', x, α, β)
TimedLinearOperator{T}(timer, op, prod!, tprod!, ctprod!)
end
TimedLinearOperator(op::AdjointLinearOperator) = adjoint(TimedLinearOperator(op.parent))
TimedLinearOperator(op::TransposeLinearOperator) = transpose(TimedLinearOperator(op.parent))
TimedLinearOperator(op::ConjugateLinearOperator) = conj(TimedLinearOperator(op.parent))
for fn ∈ (
:size,
:shape,
:issymmetric,
:ishermitian,
:has_args5,
:isallocated5,
:allocate_vectors_args3!,
:nprod,
:ntprod,
:nctprod,
:storage_type,
:increase_nprod!,
:increase_ntprod!,
:increase_nctprod!,
:reset!,
)
@eval begin
$fn(A::TimedLinearOperator) = $fn(A.op)
end
end
function show(io::IO, op::TimedLinearOperator)
show(io, op.op)
show(io, op.timer)
end