Skip to content

Commit d24fd64

Browse files
authored
add OneHotVector (#179)
* add OneHotVector * don't test against SingularIntegralEquations for now * add basis * fix test * remove unnecessary test * don't export basis * coefficients returns Vector * rename basis to basisfunction
1 parent da2d24d commit d24fd64

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

.github/workflows/downstream.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
- {repo: ApproxFunOrthogonalPolynomials.jl, group: JuliaApproximation}
2424
- {repo: ApproxFunFourier.jl, group: JuliaApproximation}
2525
- {repo: ApproxFunSingularities.jl, group: JuliaApproximation}
26-
- {repo: SingularIntegralEquations.jl, group: JuliaApproximation}
2726

2827
steps:
2928
- uses: actions/checkout@v2

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.6.17"
3+
version = "0.6.18"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/ApproxFunBase.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ strictconvert(T::Type, x) = convert(T, x)::T
107107

108108
include("LinearAlgebra/LinearAlgebra.jl")
109109
include("Fun.jl")
110+
include("onehotvector.jl")
110111
include("Domains/Domains.jl")
111112
include("Multivariate/Multivariate.jl")
112113
include("Operators/Operator.jl")

src/Fun.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function coefficients(f::Fun,msp::Space)
4545
#zero can always be converted
4646
fc = f.coefficients
4747
if ncoefficients(f) == 0 || (ncoefficients(f) == 1 && fc[1] == 0)
48-
fc
48+
convert(Vector, fc)
4949
else
5050
coefficients(fc, space(f), msp)
5151
end

src/onehotvector.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct OneHotVector{T} <: AbstractVector{T}
2+
n :: Int
3+
len :: Int
4+
end
5+
OneHotVector(n, len = n) = OneHotVector{Float64}(n, len)
6+
Base.size(v::OneHotVector) = (v.len,)
7+
Base.length(v::OneHotVector) = v.len
8+
function Base.getindex(v::OneHotVector{T}, i::Int) where {T}
9+
i == v.n ? one(T) : zero(T)
10+
end
11+
basisfunction(sp, k) = Fun(sp, OneHotVector(k))

test/SpacesTest.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ using BandedMatrices: rowrange, colrange, BandedMatrix
320320
f3 = Fun(space(f), Float64[1:4;])
321321
@test newvals(f2) values(f3)
322322
@test values(f2) values(f3)
323+
324+
@testset "OneHotVector" begin
325+
for n in [1, 3, 10_000]
326+
f = Fun(Chebyshev(), [zeros(n-1); 1])
327+
g = ApproxFunBase.basisfunction(Chebyshev(), n)
328+
@test f == g
329+
@test f(0.5) == g(0.5)
330+
end
331+
end
323332
end
324333

325334
@testset "multiplication of Funs" begin

0 commit comments

Comments
 (0)