Skip to content

Commit

Permalink
chore: format files
Browse files Browse the repository at this point in the history
  • Loading branch information
sathvikbhagavan committed Oct 20, 2023
1 parent cf3fc49 commit cafe775
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
4 changes: 2 additions & 2 deletions ext/DataInterpolationsOptimExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ function _interpolate(A::CurvefitCache{<:AbstractVector{<:Number}},
end

function get_show(interp::CurvefitCache)
return "Curvefit" * " with $(length(interp.t)) points, using $(nameof(typeof(interp.alg)))\n"
return "Curvefit" *
" with $(length(interp.t)) points, using $(nameof(typeof(interp.alg)))\n"
end


end # module
3 changes: 2 additions & 1 deletion ext/DataInterpolationsRegularizationToolsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ function DataInterpolations._interpolate(A::RegularizationSmooth{
end

function DataInterpolations.get_show(interp::RegularizationSmooth)
return "RegularizationSmooth" * " with $(length(interp.t)) points, with regularization coefficient $(interp.λ)\n"
return "RegularizationSmooth" *
" with $(length(interp.t)) points, with regularization coefficient $(interp.λ)\n"
end

end # module
28 changes: 13 additions & 15 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ function get_show(interp::AbstractInterpolation)
return string(nameof(typeof(interp))) * " with $(length(interp.t)) points\n"
end

function get_data(u::AbstractVector)
function get_data(u::AbstractVector)
return u
end

function get_data(u::AbstractVector{<:AbstractVector})
function get_data(u::AbstractVector{<:AbstractVector})
return reduce(hcat, u)'

Check warning on line 19 in src/show.jl

View check run for this annotation

Codecov / codecov/patch

src/show.jl#L18-L19

Added lines #L18 - L19 were not covered by tests
end

function get_data(u::AbstractMatrix)
function get_data(u::AbstractMatrix)
return u'

Check warning on line 23 in src/show.jl

View check run for this annotation

Codecov / codecov/patch

src/show.jl#L22-L23

Added lines #L22 - L23 were not covered by tests
end

Expand All @@ -38,28 +38,26 @@ end
###################### Specific Dispatches ######################

function get_show(interp::QuadraticInterpolation)
return string(nameof(typeof(interp))) * " with $(length(interp.t)) points, $(interp.mode) mode\n"
return string(nameof(typeof(interp))) *
" with $(length(interp.t)) points, $(interp.mode) mode\n"
end

function get_show(interp::LagrangeInterpolation)
return string(nameof(typeof(interp))) * " with $(length(interp.t)) points, with order $(interp.n)\n"
return string(nameof(typeof(interp))) *
" with $(length(interp.t)) points, with order $(interp.n)\n"
end

function get_show(interp::ConstantInterpolation)
return string(nameof(typeof(interp))) * " with $(length(interp.t)) points, in $(interp.dir) direction\n"
return string(nameof(typeof(interp))) *
" with $(length(interp.t)) points, in $(interp.dir) direction\n"
end

function get_show(interp::BSplineInterpolation)
return string(nameof(typeof(interp))) * " with $(length(interp.t)) points, with degree $(interp.d)\n"
return string(nameof(typeof(interp))) *
" with $(length(interp.t)) points, with degree $(interp.d)\n"
end

function get_show(interp::BSplineApprox)
return string(nameof(typeof(interp))) * " with $(length(interp.t)) points, with degree $(interp.d), number of control points $(interp.h)\n"
return string(nameof(typeof(interp))) *
" with $(length(interp.t)) points, with degree $(interp.d), number of control points $(interp.h)\n"
end







26 changes: 17 additions & 9 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ x = [1.0, 2.0, 3.0, 4.0, 5.0]
@testset "Generic Cases" begin
function test_show_line(A)
@testset "$(nameof(typeof(A)))" begin
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)), "$(nameof(typeof(A))) with $(length(A.t)) points\n")
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)),
"$(nameof(typeof(A))) with $(length(A.t)) points\n")
end
end
methods = [
Expand All @@ -22,23 +23,28 @@ end
@testset "Specific Cases" begin
@testset "QuadraticInterpolation" begin
A = QuadraticInterpolation(x, t)
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)), "QuadraticInterpolation with 5 points, Forward mode\n")
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)),
"QuadraticInterpolation with 5 points, Forward mode\n")
end
@testset "LagrangeInterpolation" begin
A = LagrangeInterpolation(x, t)
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)), "LagrangeInterpolation with 5 points, with order 4\n")
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)),
"LagrangeInterpolation with 5 points, with order 4\n")
end
@testset "ConstantInterpolation" begin
A = ConstantInterpolation(x, t)
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)), "ConstantInterpolation with 5 points, in left direction\n")
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)),
"ConstantInterpolation with 5 points, in left direction\n")
end
@testset "BSplineInterpolation" begin
A = BSplineInterpolation(x, t, 3, :Uniform, :Uniform)
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)), "BSplineInterpolation with 5 points, with degree 3\n")
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)),
"BSplineInterpolation with 5 points, with degree 3\n")
end
@testset "BSplineApprox" begin
A = BSplineApprox(x, t, 2, 4, :Uniform, :Uniform)
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)), "BSplineApprox with 5 points, with degree 2, number of control points 4\n")
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)),
"BSplineApprox with 5 points, with degree 2, number of control points 4\n")
end
end

Expand All @@ -49,7 +55,8 @@ end
u = model(t, [1.0, 2.0]) + 0.01 * randn(rng, length(t))
p0 = [0.5, 0.5]
A = Curvefit(u, t, model, p0, LBFGS())
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)), "Curvefit with 40 points, using LBFGS\n")
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)),
"Curvefit with 40 points, using LBFGS\n")
end

@testset "RegularizationSmooth" begin
Expand All @@ -71,5 +78,6 @@ end
tₒ = t[idx]
uₒ = u[idx]
A = RegularizationSmooth(uₒ, tₒ; alg = :fixed)
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)), "RegularizationSmooth with 15 points, with regularization coefficient 1.0\n")
end
@test startswith(sprint(io -> show(io, MIME"text/plain"(), A)),
"RegularizationSmooth with 15 points, with regularization coefficient 1.0\n")
end

0 comments on commit cafe775

Please sign in to comment.