-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Chain reduce #4232
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
Chain reduce #4232
Conversation
Sync the remote fork with upstream and pull to local branch
Search for |
I added How it works with Python 3:
How it works with this implementation:
|
The solution was to implement |
@Snowapril you may be interested in this |
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.
Looks good! I left a few suggestions about style and locks.
vm/src/stdlib/itertools.rs
Outdated
match source { | ||
Some(source) => match active { | ||
Some(active) => { | ||
Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone(), (source, active)))) | ||
} | ||
None => Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone(), (source,)))), | ||
}, | ||
None => Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone()))), | ||
} |
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.
match source { | |
Some(source) => match active { | |
Some(active) => { | |
Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone(), (source, active)))) | |
} | |
None => Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone(), (source,)))), | |
}, | |
None => Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone()))), | |
} | |
let empty_tuple = vm.ctx.empty_tuple.clone(); | |
let reduced = match source { | |
Some(source) => match active { | |
Some(active) => vm.new_tuple((cls, empty_tuple, (source, active))), | |
None => vm.new_tuple((cls, empty_tuple, (source,))), | |
}, | |
None => vm.new_tuple((cls, empty_tuple)), | |
}; | |
Ok(reduced) |
vm/src/stdlib/itertools.rs
Outdated
*zelf.source.write() = source.to_owned().try_into_value(vm)?; | ||
*zelf.active.write() = active.to_owned().try_into_value(vm)?; |
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.
To avoid unpleasure broken synchronization, locking both and writing will be better.
*zelf.source.write() = source.to_owned().try_into_value(vm)?; | |
*zelf.active.write() = active.to_owned().try_into_value(vm)?; | |
let mut source_lock = zelf.source.write(); | |
let mut active_lock = zelf.active.write(); | |
*source_lock = source.to_owned().try_into_value(vm)?; | |
*active_lock = active.to_owned().try_into_value(vm)?; |
Thank you for contributing! |
Hello!
I tried to implement the
reduce
method forPyItertoolsChain
(issue #3611) but got stuck. I used the CPython implementation as a reference. The implementation seems to work just fine with simple arrays etc. but fails thetest_chain_reducible
test. Any suggestions on why?The error message: