Skip to content

Cache SizeInfo on ReduceNode#481

Open
fastbodin wants to merge 1 commit intodwavesystems:mainfrom
fastbodin:enhancement/reducenode_cache_sizeinfo
Open

Cache SizeInfo on ReduceNode#481
fastbodin wants to merge 1 commit intodwavesystems:mainfrom
fastbodin:enhancement/reducenode_cache_sizeinfo

Conversation

@fastbodin
Copy link
Contributor

ReduceNode can now infer when its size is a function of its predecessor's size.

@fastbodin fastbodin force-pushed the enhancement/reducenode_cache_sizeinfo branch from cab78f1 to c47e836 Compare February 24, 2026 02:41
@fastbodin
Copy link
Contributor Author

fastbodin commented Feb 24, 2026

Should add a python test to confirm behaviour similar to https://github.com/dwavesystems/dwave-optimization/blob/main/tests/test_symbols.py#L567-L579 <- Done

`ReduceNode` (and therefore the symbols: `All`, `Any`, `Max`, `Min`,
`Prod`, and `Sum`) can infer size from predecessor's size.
@fastbodin fastbodin force-pushed the enhancement/reducenode_cache_sizeinfo branch from c47e836 to c5d2e0f Compare February 24, 2026 17:15
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert(node_ptr->shape().size() && node_ptr->shape().front() == -1);
assert(node_ptr->shape().size() and node_ptr->shape().front() == -1);

Copy link
Contributor Author

@fastbodin fastbodin Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of #399?

Copy link
Contributor Author

@fastbodin fastbodin Feb 26, 2026

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 a not?

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.
Copy link
Member

Choose a reason for hiding this comment

The 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).

---
features:
- |
The symbol: `All`, `Any`, `Max`, `Min`, `Prod`, and `Sum` can infer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The symbol: `All`, `Any`, `Max`, `Min`, `Prod`, and `Sum` can infer
The symbols `All`, `Any`, `Max`, `Min`, `Prod`, and `Sum` can infer

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 this pull request may close these issues.

2 participants