Skip to content

Commit

Permalink
make fitspline ext, avoid loading Interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Sep 22, 2023
1 parent 07d4c46 commit 9d8dfe7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '^1.6'
- '1.9'
- '^1.9'
os:
- ubuntu-latest
- macOS-latest
Expand Down
10 changes: 8 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

[weakdeps]
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"

[extensions]
SplineFitExt = "Interpolations"

[compat]
Interpolations = "0.12, 0.13, 0.14"
LsqFit = "0.11, 0.12, 0.13"
Parameters = "0.12"
TestItems = "0.1"
julia = "1"
julia = "1.9"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"

[targets]
test = ["Test","TestItemRunner"]
test = ["Test", "TestItemRunner", "Interpolations"]
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ julia> fit = fitexp(x,y,n=3)
## Splines
Use the `fitspline` function:
The fitting of splines requires the use of the `Interpolations` package
(this explicit requirement was introduced in version 0.6 of `EasyFit`,
and depends on `julia >= 1.9`).
To use the `fitspline` function, do:
```julia
julia> using EasyFit, Interpolations

julia> fit = fitspline(x,y)

Expand Down
22 changes: 15 additions & 7 deletions src/fitspline.jl → ext/SplineFitExt.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# requires Iterpolations
module SplineFitExt

using TestItems
using Interpolations
import EasyFit: Fit, fitspline, Options, checkdata

#
# Spline
#

struct Spline{T} <: Fit{T}
x::Vector{T}
y::Vector{T}
end

"""
fitspline(x,y)`
fitspline(x,y)
Computes a spline.
Expand Down Expand Up @@ -47,20 +53,20 @@ function (fit::Spline)(x::Real)
end

function Base.show(io::IO, fit::Spline)
println(io,
println(io,chomp(
"""
-------- Spline fit ---------------------------
x spline: x = [$(fit.x[1]), $(fit.x[2]), ...]
y spline: y = [$(fit.y[1]), $(fit.y[2]), ...]
-----------------------------------------------"""
)
-----------------------------------------------
"""
))
end

export fitspline

@testitem "spline" begin
using Interpolations

x = rand(10)
y = rand(10)
Expand All @@ -75,3 +81,5 @@ export fitspline

end

end # module

8 changes: 6 additions & 2 deletions src/EasyFit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module EasyFit
using TestItems
using Statistics
using LsqFit
using Interpolations
using Parameters

# supertype for all fits, to help on dispatch of common methods
Expand All @@ -24,8 +23,13 @@ include("./fitlinear.jl")
include("./fitquadratic.jl")
include("./fitcubic.jl")
include("./fitexponential.jl")
include("./fitspline.jl")
include("./movingaverage.jl")
include("./fitdensity.jl")

# fitspline is defined in ext/SplineFitExt.jl
export fitspline
function fitspline(args...)
error("Load first the `Interpolations` package to use the `fitspline` function.")
end

end

0 comments on commit 9d8dfe7

Please sign in to comment.