Skip to content
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

Numpy sum imap #579

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

pbrunet
Copy link
Collaborator

@pbrunet pbrunet commented Jun 7, 2016

WIP : I have to add some tests and do the itertools to numpy_expr transformation for others iterators like ifilter

super(ConstMethodIntr, self).__init__(
*combiners,
argument_effects=(ReadEffect(),) * 12, **kwargs)
*combiners, **kwargs)

Choose a reason for hiding this comment

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

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because we don't want to overwrite the value if it is explicitly set

@pbrunet
Copy link
Collaborator Author

pbrunet commented Jun 27, 2016

There is an issue with this PR as numpy.sum on generator return the same generator. Reason is that numpy expression are not Lazy in numpy as numpy need to know the size of the generator to allocate memory. For this reason, replacing list with generator will never work on numpy functions. Of course, we may still want to replace some numpy call on list to numpy call to generator to avoid memory allocation.

I see 2 solution:

  1. The filter-> ifilter transformation is perform after others (so after constant folding) and we accept to have non complient python at this stage. It could be done
  2. We may add an attributes to builtin like ReadOnlyNDArray and in this case, the filter can be transform to -> numpy.fromiter(ifilter(...)) but it supports only 1D array (which is most of the cases but not all) and we don't have the size information which may be required to create a numpy_expr.

Any better idea? Or should I just leave this PR as it can't be really applied?

@serge-sans-paille
Copy link
Owner

On Mon, Jun 27, 2016 at 12:55:06PM -0700, pbrunet wrote:

There is an issue with this PR as numpy.sum on generator return the same generator. Reason is that numpy expression are not Lazy in numpy as numpy need to know the size of the generator to allocate memory. For this reason, replacing list with generator will never work on numpy functions. Of course, we may still want to replace some numpy call on list to numpy call to generator to avoid memory allocation.

I see 2 solution:

  1. The filter-> ifilter transformation is perform after others (so after constant folding) and we accept to have non complient python at this stage. It could be done
  2. We may add an attributes to builtin like ReadOnlyNDArray and in this case, the filter can be transform to -> numpy.fromiter(ifilter(...)) but it supports only 1D array (which is most of the cases but not all) and we don't have the size information which may be required to create a numpy_expr.

Isn't this similar to saying that if we have a 1D array, we cann turn
numpy.sum into sum? Eitherway, we have no way to know at compile time
the dimension of an array. This looks dommed to me and I'b better say «
do nothing ». Do yiu have a test case that exhibits a ral use for this
one?

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