Skip to content

Commit 831bf1d

Browse files
authored
Make spaces callable (#369)
* Make spaces callable * offset by one * Add test
1 parent 70cd5d2 commit 831bf1d

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

src/Space.jl

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ export Space, domainspace, rangespace, maxspace,Space,conversion_type, transform
33

44

55

6-
# Space maps the Domain to the type R
7-
# For example, we have
8-
# Chebyshev{Interval{Float64}} <: Space{Interval{Float64},Float64}
9-
# Laurent{PeriodicSegment{Float64}} <: Space{PeriodicSegment{Float64},ComplexF64}
10-
# Fourier{Circle{ComplexF64}} <: Space{Circle{ComplexF64},Float64}
11-
# Note for now Space doesn't contain any information about the coefficients
6+
"""
7+
Space{D<:Domain, R}
8+
9+
Abstract supertype of various spaces in which a `Fun` may be defined, where `R` represents
10+
the type of the basis functions over the domain. Space maps the `Domain` to the type `R`.
11+
12+
For example, we have
13+
* `Chebyshev{Interval{Float64}} <: Space{Interval{Float64},Float64}`
14+
* `Laurent{PeriodicSegment{Float64}} <: Space{PeriodicSegment{Float64},ComplexF64}`
15+
* `Fourier{Circle{ComplexF64}} <: Space{Circle{ComplexF64},Float64}`
1216
17+
!!! note
18+
For now, `Space` doesn't contain any information about the coefficients
19+
"""
1320
abstract type Space{D,R} end
1421

1522

@@ -661,3 +668,33 @@ spacescompatible(::SequenceSpace,::SequenceSpace) = true
661668
## Boundary
662669

663670
boundary(S::Space) = boundary(domain(S))
671+
672+
"""
673+
(s::Space)(n::Integer)
674+
675+
Return a `Fun` with the coefficients being a sparse representation of
676+
`[zeros(n); 1]`. The result is primarily meant to be evaluated at
677+
a specific point.
678+
679+
For orthogonal polynomial spaces, the result will usually represent the `n`-th
680+
basis function.
681+
682+
# Examples
683+
```jldoctest
684+
julia> Chebyshev()(2)
685+
Fun(Chebyshev(), [0.0, 0.0, 1.0])
686+
```
687+
"""
688+
(s::Space)(n::Integer) = basisfunction(s, n+1)
689+
"""
690+
(s::Space)(n::Integer, points...)
691+
692+
Evaluate `s(n)(points...)`
693+
694+
# Examples
695+
```jldoctest
696+
julia> Chebyshev()(1, 0.5)
697+
0.5
698+
```
699+
"""
700+
(s::Space)(n::Integer, args...) = s(n)(args...)

test/SpacesTest.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ using LinearAlgebra
185185
@test B isa Operator{ComplexF64}
186186
@test ComplexF64.(Ainv[1:4, 1:4]) == B[1:4, 1:4]
187187
end
188+
189+
@testset "call spaces" begin
190+
@test PointSpace(1:4)(3, 4) == 1
191+
end
188192
end
189193

190194
@testset "DiracSpace" begin

0 commit comments

Comments
 (0)