Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

star1327p
Copy link
Contributor

Improve math format in accumulate
https://numpy.org/devdocs/dev/internals.code-explanations.html

Closed #29696 and reopened a new PR.

@jorenham
Copy link
Member

jorenham commented Sep 11, 2025

current:

image

this PR:

image

I can't say I like the alignment here. I think it'd be better without the \quads

@jorenham
Copy link
Member

jorenham commented Sep 11, 2025

How about something like this?

$$o_k = \begin{cases} & i[0] & \text{if } k=0 \\\ & i[k] \text{ <op> }o_{k-1} & \text{if } k=1,\ldots, N \text{.} \end{cases}$$

@star1327p
Copy link
Contributor Author

@jorenham Thank you for the suggestion! I have made the changes, and hope this works!

@mattip
Copy link
Member

mattip commented Sep 12, 2025

Close/reopen to retry failed CI setup

@mattip mattip closed this Sep 12, 2025
@mattip mattip reopened this Sep 12, 2025
Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

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

I think your original motivation was to simply move the i[0] inwards a bit on the first line. Maybe for a first PR that is all you should try to do, and not change other things.

@mattip
Copy link
Member

mattip commented Sep 14, 2025

I see @jorenham's suggestion above also mixes subscripting and bracket-indexing. Sorry to step on his toes.

@star1327p
Copy link
Contributor Author

@mattip Okay, I have applied the original changes in #29696. This time I remember to add [skip actions][skip azp][skip cirrus] in the commit to save CI resources. Hope this works!

@jorenham
Copy link
Member

jorenham commented Sep 14, 2025

I see @jorenham's suggestion above also mixes subscripting and bracket-indexing. Sorry to step on his toes.

I figured that since it's a mathematical formulation, then the $=$ sign means "equals" and not "(re)assignment", so it'd require an index. E.g. if you write $a = a + 1$ that would imply that $a - a = 1$ and therefore $0 = 1$.
I agree that without an index it's probably clearer to most readers, but then this mathematical formulation might not be the best fit, and we should probably use pseudocode instead.

@mattip
Copy link
Member

mattip commented Sep 14, 2025

Pseudocode is probably a better fit indeed. The formulations here do not accurately reflect the true C code, which uses op.identity. In ufunc.reduce and ufunc.accumulate there is a more accurate description of the functionality. The thing to make clear here is the way the same loops are used internally, only the step for the output is different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants