Skip to content

Commit 8fa0b60

Browse files
authored
imag for operators (#841)
* imag for operators * implement conj * Move real/imag to ApproxFunBase
1 parent 89673a2 commit 8fa0b60

File tree

4 files changed

+15
-37
lines changed

4 files changed

+15
-37
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFun"
22
uuid = "28f2ccd6-bb30-5033-b560-165f7b14dc2f"
3-
version = "0.13.10"
3+
version = "0.13.11"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -20,7 +20,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2020

2121
[compat]
2222
AbstractFFTs = "1.0"
23-
ApproxFunBase = "0.7"
23+
ApproxFunBase = "0.7.29"
2424
ApproxFunBaseTest = "0.1"
2525
ApproxFunFourier = "0.3"
2626
ApproxFunOrthogonalPolynomials = "0.5"

src/ApproxFun.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import FFTW: plan_r2r!, fftwNumber, REDFT10, REDFT01, REDFT00, RODFT00, R2HC, HC
6060

6161
import Base: values, convert, getindex, setindex!, *, +, -, ==, <, <=, >, |, !, !=, eltype, iterate,
6262
>=, /, ^, \, , transpose, size, tail, broadcast, broadcast!, copyto!, copy, to_index, (:),
63-
similar, map, vcat, hcat, hvcat, show, summary, stride, sum, cumsum, sign, imag, conj, inv,
63+
similar, map, vcat, hcat, hvcat, show, summary, stride, sum, cumsum, sign, conj, inv,
6464
complex, reverse, exp, sqrt, abs, abs2, sign, issubset, values, in, first, last, rand, intersect, setdiff,
6565
isless, union, angle, join, isnan, isapprox, isempty, sort, merge, promote_rule,
6666
minimum, maximum, extrema, argmax, argmin, findmax, findmin, isfinite,

src/Extras/ReImSpace.jl

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1 @@
1-
2-
3-
4-
## just takes realpart of operator
5-
struct ReOperator{O,T} <: Operator{T}
6-
op::O
7-
end
8-
9-
ReOperator(op)=ReOperator{typeof(op),Float64}(op)
10-
convert(::Type{Operator{T}},R::ReOperator) where {T} = ReOperator{typeof(R.op),T}(R.op)
11-
12-
@wrapperstructure ReOperator
13-
@wrapperspaces ReOperator
14-
15-
16-
17-
18-
19-
getindex(RI::ReOperator{O,T},k::Integer,j::Integer) where {O,T} =
20-
convert(T,real(RI.op[k,j]))
21-
22-
choosedomainspace(R::ReOperator,sp::Space) = choosedomainspace(R.op,sp)
23-
for OP in (:promotedomainspace,:promoterangespace)
24-
@eval begin
25-
$OP(R::ReOperator,sp::UnsetSpace) = ReOperator($OP(R.op,sp))
26-
$OP(R::ReOperator,sp::Space) = ReOperator($OP(R.op,sp))
27-
end
28-
end
29-
30-
31-
32-
# TODO: can't do this because UnsetSpace might change type
33-
#real{T<:Real}(op::Operator{T})=op
34-
real(op::Operator) = ReOperator(op)
1+
real(op::Operator) = ApproxFunBase.real(op)

test/ExtrasTest.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,15 @@ using DualNumbers
136136
@test cumsum(d).J*Fun() Fun(x -> (x^2-1)/2)
137137
@test cumsum(d*d).J*Fun(1) cumsum(2d).f Fun(x -> x^2-1)
138138
end
139+
140+
@testset "real-imag" begin
141+
A = (3 + 2im) * I : Chebyshev()
142+
@test real(A)[1:4, 1:4] == diagm(0=>fill(3,4))
143+
@test imag(A)[1:4, 1:4] == diagm(0=>fill(2,4))
144+
@test conj(A)[1:4, 1:4] == conj(A[1:4, 1:4])
145+
A = (3 - 2im) * I : Chebyshev()
146+
@test real(A)[1:4, 1:4] == diagm(0=>fill(3,4))
147+
@test imag(A)[1:4, 1:4] == diagm(0=>fill(-2,4))
148+
@test conj(A)[1:4, 1:4] == conj(A[1:4, 1:4])
149+
end
139150
end

0 commit comments

Comments
 (0)