-
Notifications
You must be signed in to change notification settings - Fork 31
Cache SizeInfo on ReduceNode
#481
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ | |
| #include <utility> | ||
|
|
||
| #include "../functional_.hpp" | ||
| #include "dwave-optimization/array.hpp" | ||
| #include "dwave-optimization/state.hpp" | ||
|
|
||
| namespace dwave::optimization { | ||
|
|
||
|
|
@@ -281,7 +283,7 @@ class ReduceNodeData : public NodeStateData { | |
| if (flags_[index] == ReductionFlag::unchanged) { | ||
| reductions_diff_.emplace_back(index, reductions_[index]); | ||
| } | ||
| flags_[index] = ReductionFlag::invalid; | ||
| flags_[index] = ReductionFlag::invalid; | ||
| return; | ||
| } | ||
| reduction = std::move(inverse.value()); | ||
|
|
@@ -581,6 +583,19 @@ ValuesInfo values_info(const Array* array_ptr, std::span<const ssize_t> axes, | |
| return bounds; | ||
| } | ||
|
|
||
| SizeInfo reducenode_calculate_sizeinfo(const Array* node_ptr, const Array* array_ptr, | ||
| std::span<const ssize_t> axes) { | ||
| // Node is statically sized. Note: If node_shape = {}, product(node_shape) = 1. | ||
| if (!node_ptr->dynamic()) return SizeInfo(product(node_ptr->shape())); | ||
| assert(node_ptr->shape().size() && node_ptr->shape().front() == -1); | ||
|
|
||
| // Node is dynamically sized but predecessor is always empty. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a bit more detail here, something like "this means we can't easily make any deductions about the resulting size as it likely depends on predecessors of the input array" (assuming that's correct). |
||
| if (array_ptr->size() == 0) return SizeInfo(node_ptr); | ||
|
|
||
| // Node size is derived from its predecessor's size. | ||
| return array_ptr->sizeinfo() / product(keep_axes(array_ptr->shape(), axes)); | ||
| } | ||
|
|
||
| template <class BinaryOp> | ||
| ReduceNode<BinaryOp>::ReduceNode(ArrayNode* array_ptr) : ReduceNode(array_ptr, {}) {} | ||
|
|
||
|
|
@@ -591,7 +606,8 @@ ReduceNode<BinaryOp>::ReduceNode(ArrayNode* array_ptr, std::span<const ssize_t> | |
| initial(initial), | ||
| array_ptr_(array_ptr), | ||
| axes_(normalize_axes(array_ptr, axes)), | ||
| values_info_(values_info<BinaryOp>(array_ptr_, axes_, initial)) { | ||
| values_info_(values_info<BinaryOp>(array_ptr_, axes_, initial)), | ||
| sizeinfo_(reducenode_calculate_sizeinfo(this, array_ptr_, axes_)) { | ||
| add_predecessor(array_ptr); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,5 @@ | ||||||
| --- | ||||||
| features: | ||||||
| - | | ||||||
| The symbol: `All`, `Any`, `Max`, `Min`, `Prod`, and `Sum` can infer | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| their size from their predecessor's size. | ||||||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Because of #399?
Uh oh!
There was an error while loading. Please reload this page.
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.
If so, shouldn't the
!above be anot?