8000 ENH: perform inplace operations if one operand is a temporary by juliantaylor · Pull Request #4322 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: perform inplace operations if one operand is a temporary #4322

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

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add m2.ref_cnt == 1 eliding for associative operations
implementation not good, just improve checking for issues in testsuite
  • Loading branch information
juliantaylor committed Aug 6, 2014
commit be38f5833b39092ef7aadacf7ffb546bdf7011cb
15 changes: 15 additions & 0 deletions numpy/core/src/multiarray/number.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ array_add(PyArrayObject *m1, PyObject *m2)
if (can_elide_temp(m1, m2)) {
return array_inplace_add(m1, m2);
}
else if (can_elide_temp(m2, m1)) {
return array_inplace_add(m2, m1);
}
else {
return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);
}
Expand All @@ -408,6 +411,9 @@ array_multiply(PyArrayObject *m1, PyObject *m2)
if (can_elide_temp(m1, m2)) {
return array_inplace_multiply(m1, m2);
}
else if (can_elide_temp(m2, m1)) {
return array_inplace_multiply(m2, m1);
}
return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);
}

Expand Down Expand Up @@ -639,6 +645,9 @@ array_bitwise_and(PyArrayObject *m1, PyObject *m2)
if (can_elide_temp(m1, m2)) {
return array_inplace_bitwise_and(m1, m2);
}
else if (can_elide_temp(m2, m1)) {
return array_inplace_bitwise_and(m2, m1);
}
return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);
}

Expand All @@ -649,6 +658,9 @@ array_bitwise_or(PyArrayObject *m1, PyObject *m2)
if 71F7 (can_elide_temp(m1, m2)) {
return array_inplace_bitwise_or(m1, m2);
}
else if (can_elide_temp(m2, m1)) {
return array_inplace_bitwise_or(m2, m1);
}
return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);
}

Expand All @@ -659,6 +671,9 @@ array_bitwise_xor(PyArrayObject *m1, PyObject *m2)
if (can_elide_temp(m1, m2)) {
return array_inplace_bitwise_xor(m1, m2);
}
else if (can_elide_temp(m2, m1)) {
return array_inplace_bitwise_xor(m2, m1);
}
return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);
}

Expand Down
0