-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfd_operators.jl
61 lines (52 loc) · 2.38 KB
/
fd_operators.jl
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
# * Scalar operators
function similar(ADB::MulQuasiArray{<:Any,2,
<:Tuple{<:AdjointBasisOrRestricted{<:AbstractFiniteDifferences},
<:QuasiDiagonal,
<:BasisOrRestricted{<:AbstractFiniteDifferences}}}, ::Type{T}=eltype(ADB)) where T
Ac,D,B = ADB.args
A = parent(Ac)
parent(A) == parent(B) ||
throw(ArgumentError("Cannot multiply functions on different grids"))
Ai,Bi = indices(A,2), indices(B,2)
if Ai == Bi
Diagonal(Vector{T}(undef, length(Ai)))
else
m,n = length(Ai),length(Bi)
offset = Ai[1]-Bi[1]
BandedMatrix{T}(undef, (m,n), (-offset,offset))
end
end
function copyto!(dest::Diagonal{T}, ADB::MulQuasiArray{<:Any,2,
<:Tuple{<:AdjointBasisOrRestricted{<:AbstractFiniteDifferences},
<:QuasiDiagonal,
<:BasisOrRestricted{<:AbstractFiniteDifferences}}}) where T
axes(dest) == axes(ADB) || throw(DimensionMismatch("axes must be same"))
Ac,D,B = ADB.args
A = parent(Ac)
parent(A) == parent(B) ||
throw(ArgumentError("Cannot multiply functions on different grids"))
for (i,d) in enumerate(locs(B))
dest.diag[i] = D.diag[d]
end
dest
end
function copyto!(dest::BandedMatrix{T}, ADB::MulQuasiArray{<:Any,2,
<:Tuple{<:AdjointBasisOrRestricted{<:AbstractFiniteDifferences},
<:QuasiDiagonal,
<:BasisOrRestricted{<:AbstractFiniteDifferences}}}) where T
axes(dest) == axes(ADB) || throw(DimensionMismatch("axes must be same"))
Ac,D,B = ADB.args
A = parent(Ac)
parent(A) == parent(B) ||
throw(ArgumentError("Cannot multiply functions on different grids"))
for (i,d) in enumerate(locs(B))
dest.data[i] = D.diag[d]
end
dest
end
@simplify function *(Ac::AdjointBasisOrRestricted{<:AbstractFiniteDifferences},
D::QuasiDiagonal,
B::BasisOrRestricted{<:AbstractFiniteDifferences})
M = ApplyQuasiArray(*, Ac, D, B)
copyto!(similar(M), M)
end