-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DataIntegralProblem
#491
Conversation
Codecov Report
@@ Coverage Diff @@
## master #491 +/- ##
===========================================
- Coverage 57.27% 33.30% -23.98%
===========================================
Files 50 50
Lines 3703 3681 -22
===========================================
- Hits 2121 1226 -895
- Misses 1582 2455 +873
... and 32 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
x
and dim
field to IntegralProblem
Also added 2 constructors: function IntegralProblem(f, x::AbstractVector{<:Number}, args...; kwargs...)
IntegralProblem{isinplace(f, 3)}(f, x, args...; kwargs...)
end
function IntegralProblem(y::AbstractArray, x::AbstractVector{<:Number}, args...; dim::Int=1, kwargs...)
IntegralProblem{false}(y, x, args...; dim=Val(dim), kwargs...)
end The first for integrating a callable |
Oops, there was a small mistake, |
There are still method ambiguities, but I don't know how to get rid of them... |
If I may comment on this pr, I think adding a separate
I hope this is useful feedback and I am happy to see a pr like this because I think this feature would be very useful. |
Feedback is always welcome of course. |
Separate it for the reasons @lxvm mentioned. When I last reviewed this PR it was separated to have a separate Indeed overlapping them doesn't make sense because their dispatches need to be separate, along with most of their data, so it's not quite clear what would be gained by keeping them together. The AD passes indeed need to be very different too, so I do not understand why it would be part of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should split to a separate IntegralDataProblem
like originally discussed.
The reason I merged them into the same struct was because, for the case
There needed to be an x-field in IntegralProblem anyway. And so I thought that it therefore wasnt necessary to split the two. I hadnt considered the AD angle. In hindsight
So I will revert the changes (apart from the added tests) when I have time, reintroducing the DataIntegralProblem. |
Thanks for the explanation! I'll wait for the revert to re-review. |
x
and dim
field to IntegralProblem
DataIntegralProblem
Do you prefer IntegralDataProblem or DataIntegralProblem? The last one sounds slightly better to me, but I'm not a native English speaker. Anyway, it should be ready for review now. |
Perhaps |
I like it. |
👍 on SampledIntegralProblem |
src/problems/basic_problems.jl
Outdated
It is assumed that the values of `y` along dimension `dim` | ||
correspond to the integrand evaluated at sampling points `x` | ||
- x: Sampling points, must be a subtype of `AbstractVector`. | ||
- dim: Dimension along which to integrate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to leave it up to the user? I think that just adds more work in the implementation without a tangible benefit. dimension should always be the last one as other wise you'll have a performance hit from column major, so we should just stick to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree, with both (1) that the last dim is always faster, and (2) even if it were that we should force all users to use that.
- Here is a simple example:
function trapz(y, dim)
solve(SampledIntegralProblem(y, axes(y,dim); dim=dim),
TrapezoidalRule())
end
y = rand(5, 100000)
julia> @btime trapz(trapz($y,2), 1)
1.165 ms (8 allocations: 400 bytes)
u: 200010.59503616963
julia> @btime trapz(trapz($y,1), 1)
395.000 μs (9 allocations: 781.59 KiB)
u: 200010.59503616992
while there are better ways to do a two-dimensional trapezoidal rule of course.
- Doing numeric integration over some array isn't always the performance bottleneck of the algorithm. Typically, generating the data in the first place (by some experiment perhaps) takes more time. It would be annoying to force users to stick to a certain data layout to be able to do integration over it if it is just a small part of their workflow. This is also why other packages implement this feature, see SciPy or Trapz.jl for example.
Having said that, you are of course right that the last dimension is typically faster and should be the default, so I'll change that.
I'm a bit weary on the |
See this issue.