-
Notifications
You must be signed in to change notification settings - Fork 197
Numpy sum imap #579
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: master
Are you sure you want to change the base?
Numpy sum imap #579
Changes from all commits
c24a3e8
7580301
f95dfd7
34b28f1
bcd0d3b
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 |
|---|---|---|
|
|
@@ -51,6 +51,9 @@ namespace pythonic | |
| using const_iterator = xrange_iterator; | ||
| using reverse_iterator = xrange_riterator; | ||
| using const_reverse_iterator = xrange_riterator; | ||
| using dtype = value_type; | ||
| static constexpr bool is_vectorizable = false; | ||
|
Owner
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. could be true in the future |
||
| static constexpr size_t value = 1; | ||
|
|
||
| long _begin; | ||
| long _end; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,7 +95,8 @@ namespace pythonic | |
| template <typename Operator, typename List0> | ||
| ifilter<Operator, List0>::ifilter(Operator _op, List0 const &_seq) | ||
| : utils::iterator_reminder<false, List0>(_seq), | ||
| iterator(_op, this->value), end_iter(npos(), _op, this->value) | ||
| iterator(_op, utils::iterator_reminder<false, List0>::value), | ||
|
Owner
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. instead of true/false you could use two different empty structures with explicit names, that would make the review easier
Owner
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. ok it's not your code/fault :-) still a good idea if you're brave enough ;-)
Collaborator
Author
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. haha indeed I was the one introducing this struct :) but not in this commit. |
||
| end_iter(npos(), _op, utils::iterator_reminder<false, List0>::value) | ||
| { | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |
| from pythran.intrinsic import ClassWithReadOnceConstructor | ||
| from pythran.intrinsic import ConstFunctionIntr, FunctionIntr, UpdateEffect | ||
| from pythran.intrinsic import ConstMethodIntr, MethodIntr, AttributeIntr | ||
| from pythran.intrinsic import ReadEffect, ConstantIntr | ||
| from pythran.intrinsic import ReadEffect, ConstantIntr, ReadOnceEffect | ||
| from pythran.intrinsic import ReadOnceFunctionIntr, ConstExceptionIntr | ||
| from pythran.types.conversion import PYTYPE_TO_CTYPE_TABLE | ||
| from pythran import range as prange | ||
|
|
@@ -626,7 +626,8 @@ def update_effects(self, node): | |
| "std_": ConstMethodIntr(args=('a', 'axis', 'dtype'), | ||
| defaults=(None, None)), | ||
| "subtract": ConstFunctionIntr(), | ||
| "sum": ConstMethodIntr(), | ||
| "sum": ConstMethodIntr(argument_effects=(ReadOnceEffect(), | ||
|
Owner
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. why twice?
Collaborator
Author
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. Because of the array value and axis value (the only arguments we support for sum) |
||
| ReadOnceEffect())), | ||
| "swapaxes": ConstMethodIntr(), | ||
| "take": ConstMethodIntr(), | ||
| "tan": ConstFunctionIntr(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,37 @@ def test_sum10_(self): | |
| def test_sum11_(self): | ||
| self.run_test("def np_sum11_(a): import numpy as np ; return np.sum(a+a,2)", numpy.arange(12).reshape(2,3,2), np_sum11_=[numpy.array([[[int]]])]) | ||
|
|
||
| def test_sum_imap(self): | ||
| self.run_test(""" | ||
| def np_sum_imap(a): | ||
| import numpy as np | ||
| from itertools import imap | ||
| return np.sum(imap(lambda x: x + 2, a)) | ||
| """, range(10), np_sum_imap=[[int]]) | ||
|
|
||
| def test_sum_ifilter(self): | ||
| self.run_test(""" | ||
| def np_sum_ifilter(a): | ||
| import numpy as np | ||
| from itertools import ifilter | ||
| return np.sum(ifilter(lambda x: x % 2, a)) | ||
| """, range(10), np_sum_ifilter=[[int]]) | ||
|
|
||
| def test_sum_izip(self): | ||
| self.run_test(""" | ||
| def np_sum_izip(a): | ||
| import numpy as np | ||
| from itertools import izip | ||
| return np.sum(izip(a, a)) | ||
| """, range(10), np_sum_izip=[[int]]) | ||
|
|
||
| def test_sum_xrange(self): | ||
| self.run_test(""" | ||
| def np_sum_xrange(a): | ||
| import numpy as np | ||
| return np.sum(xrange(a)) | ||
|
Owner
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. BTW I add the case of arange being used instead of range, we could make arange lazy :-)
Collaborator
Author
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. Is it OK to keep this "not same as Pythoné i(map/filter/zip) as numpy_expr behavior? |
||
| """, 10, np_sum_xrange=[int]) | ||
|
|
||
| def test_prod_(self): | ||
| """ Check prod function for numpy array. """ | ||
| self.run_test(""" | ||
|
|
||
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.
why?
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 we don't want to overwrite the value if it is explicitly set