-
Notifications
You must be signed in to change notification settings - Fork 52
Adaptive task count assignation #432
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
Open
gabotechs
wants to merge
1
commit into
gabrielmusat/cost-calculation
Choose a base branch
from
gabrielmusat/dynamic-task-count
base: gabrielmusat/cost-calculation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| use datafusion::common::internal_err; | ||
| use datafusion::error::Result; | ||
| use num_traits::AsPrimitive; | ||
| use std::ops::{AddAssign, DivAssign, MulAssign}; | ||
|
|
||
| /// Converts a slice of type `I` to a `Vec<O>` using `as`-style primitive casting. | ||
| pub(crate) fn vec_cast<I, O>(input: &[I]) -> Vec<O> | ||
| where | ||
| I: AsPrimitive<O>, | ||
| O: Copy + 'static, | ||
| { | ||
| input.iter().map(|v| v.as_()).collect() | ||
| } | ||
|
|
||
| /// Adds each element of `other` into the corresponding element of `one`, converting types via `AsPrimitive`. | ||
| pub(crate) fn element_wise_sum<I, O>(mut one: Vec<I>, other: &[O]) -> Result<Vec<I>> | ||
| where | ||
| I: AddAssign + Copy + 'static, | ||
| O: AsPrimitive<I> + 'static, | ||
| { | ||
| if one.len() != other.len() { | ||
| return internal_err!("Cannot do an element wise sum of two vectors of different lengths"); | ||
| } | ||
| for i in 0..one.len() { | ||
| one[i] += other[i].as_(); | ||
| } | ||
| Ok(one) | ||
| } | ||
|
|
||
| /// Multiplies every element of `one` by the scalar `other`, converting types via `AsPrimitive`. | ||
| pub(crate) fn vec_mul<I, O>(mut one: Vec<I>, other: O) -> Vec<I> | ||
| where | ||
| I: MulAssign + Copy + 'static, | ||
| O: AsPrimitive<I> + 'static, | ||
| { | ||
| for el in one.iter_mut() { | ||
| *el *= other.as_(); | ||
| } | ||
| one | ||
| } | ||
|
|
||
| /// Divides every element of `one` by the scalar `other`, converting types via `AsPrimitive`. | ||
| pub(crate) fn vec_div<I, O>(mut one: Vec<I>, other: O) -> Vec<I> | ||
| where | ||
| I: DivAssign + Copy + 'static, | ||
| O: AsPrimitive<I> + 'static, | ||
| { | ||
| for el in one.iter_mut() { | ||
| *el /= other.as_(); | ||
| } | ||
| one | ||
| } | ||
|
|
||
| /// Reduces a collection of same-length `f32` vectors into a single vector by averaging element-wise. | ||
| /// Empty inner vecs are skipped; returns an empty vec if all inputs are empty. | ||
| pub(crate) fn vec_avg_reduce(vecs: Vec<Vec<f32>>) -> Result<Vec<f32>> { | ||
| let sample_count = vecs.len(); | ||
| let mut iter = vecs.into_iter(); | ||
| let mut acc = loop { | ||
| let Some(v) = iter.next() else { | ||
| return Ok(vec![]); | ||
| }; | ||
| if !v.is_empty() { | ||
| break v; | ||
| } | ||
| }; | ||
| for v in iter { | ||
| if v.is_empty() { | ||
| continue; | ||
| } else if acc.len() != v.len() { | ||
| return internal_err!( | ||
| "vec_avg_reduce: length mismatch — first vec has {} elements, got {}", | ||
| acc.len(), | ||
| v.len() | ||
| ); | ||
| } | ||
| acc = element_wise_sum(acc, &v)?; | ||
| } | ||
| Ok(vec_div(acc, sample_count as f32)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would an extension trait make sense here to make all of these methods?
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 thought about that, but the conclusion was that it was not worth it as that does not save much code, and these are not typically used during method chaining that is where extension traits really help.
It's also nice to make it explicit for readers that these are not
stdmethods.