Skip to content
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

Mince should return an iterator #431

Closed
dpsanders opened this issue Dec 24, 2020 · 6 comments · Fixed by #593
Closed

Mince should return an iterator #431

dpsanders opened this issue Dec 24, 2020 · 6 comments · Fixed by #593

Comments

@dpsanders
Copy link
Member

For efficiency

@lbenet
Copy link
Member

lbenet commented May 28, 2021

I find this is a good proposal!

Do you have some specific idea how to implement this? mince is implemented here for Intervals (note that and nodes is a range), and here for IntervalBoxes.

@dpsanders
Copy link
Member Author

dpsanders commented May 30, 2021

I think it's just a question of replacing the array comprehension by a generator expression, i.e. replacing square brackets with parentheses:

        function mince(x::Interval, n)
             nodes = range(x.lo, x.hi, length = n+1)
             return (Interval(nodes[i], nodes[i+1]) for i in 1:length(nodes)-1)
         end

@lbenet
Copy link
Member

lbenet commented May 30, 2021

I've open #467, which improves performance (broadcasting!), but returns a vector...

@OlivierHnt
Copy link
Member

Is this still a wanted feature?

@edtrelo
Copy link

edtrelo commented Aug 29, 2023

@dpsanders what about using a new structure that relies on ranges? @lbenet and I have been discussing this issue and we think it would be useful to have an implementation of the getindex method, that proposed structure would enable us to achive such task.

@OlivierHnt
Copy link
Member

OlivierHnt commented Sep 5, 2023

I still wonder why this is so bad for mince to allocate a vector, since this is fairly cheap. Unless of course mince is used in a loop. Then perhaps an in-place version mince! should be implemented, instead of resorting to some new structure / generators.
On master

julia> @btime mince($interval(1, 2), $10_000);
  9.917 μs (2 allocations: 156.30 KiB)

edtrelo added a commit to edtrelo/IntervalArithmetic.jl that referenced this issue Sep 29, 2023
@OlivierHnt OlivierHnt mentioned this issue Dec 1, 2023
1 task
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 a pull request may close this issue.

4 participants