Skip to content

Conversation

@devmotion
Copy link
Member

@devmotion devmotion commented Feb 7, 2025

Related to #389, this PR optimizes cumulative_integral by returning nothing for non-numeric types. The PR also improves allocations for numeric types a bit.

Fixes #385.

On the master branch:

julia> A = ConstantInterpolation([3.1, 2.5, 4.7], [0.0, 0.25, 0.75])

julia> DataInterpolations.cumulative_integral(A, false)
Float64[]

julia> DataInterpolations.cumulative_integral(A, true)
2-element Vector{Float64}:
 0.775
 2.025

julia> f(A, cache_parameters) = @allocations DataInterpolations.cumulative_integral(A, cache_parameters)

julia> f(A, false)
1

julia> f(A, true)
8

julia> using Unitful

julia> A = ConstantInterpolation(rand(5)u"m", (1:5)u"s");

julia> DataInterpolations.integral(A, 4u"s")
ERROR: ArgumentError: zero(Quantity{Float64}) not defined.
...

With this PR:

julia> A = ConstantInterpolation([3.1, 2.5, 4.7], [0.0, 0.25, 0.75])

julia> DataInterpolations.cumulative_integral(A, false)
Float64[]

julia> DataInterpolations.cumulative_integral(A, true)
2-element Vector{Float64}:
 0.775
 2.025

julia> f(A, cache_parameters) = @allocations DataInterpolations.cumulative_integral(A, cache_parameters)
f (generic function with 2 methods)

julia> f(A, false)
1

julia> f(A, true)
2

julia> using Unitful

julia> A = ConstantInterpolation(rand(5)u"m", (1:5)u"s");

julia> DataInterpolations.integral(A, 4u"s")
1.549774483763152 m s

@ChrisRackauckas ChrisRackauckas merged commit 5391a3c into master Feb 7, 2025
15 of 16 checks passed
@ChrisRackauckas ChrisRackauckas deleted the dw/cumulative_integral branch February 7, 2025 14:31
@Ickaser
Copy link
Contributor

Ickaser commented Feb 8, 2025

Awesome, thanks @devmotion !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrals with incorrect dimensions for Unitful input

4 participants