Skip to content

Commit

Permalink
Fix ReferenceError
Browse files Browse the repository at this point in the history
  • Loading branch information
Hood committed Apr 16, 2021
1 parent 0e30a22 commit e6fe5e1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
31 changes: 28 additions & 3 deletions packages/numpy/patches/0001-temp.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
From 406f26be6c693603f266d58220ac28b388f2a93a Mon Sep 17 00:00:00 2001
From f24c0d34b632f7005b6787bdbaca73a2bae03d54 Mon Sep 17 00:00:00 2001
From: Hood <hood@mit.edu>
Date: Thu, 15 Apr 2021 21:14:55 -0700
Subject: [PATCH] temp

---
numpy/core/src/multiarray/iterators.c | 35 ++++-----------------------
1 file changed, 5 insertions(+), 30 deletions(-)
numpy/core/src/multiarray/conversion_utils.c | 5 +--
numpy/core/src/multiarray/iterators.c | 35 +++-----------------
2 files changed, 8 insertions(+), 32 deletions(-)

diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index 52cb58726..5467f4d78 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -955,9 +955,9 @@ PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals)
return -1;
}

- vals[i] = PyArray_PyIntAsIntp(op);
+ npy_intp x = PyArray_PyIntAsIntp(op);
Py_DECREF(op);
- if(vals[i] == -1) {
+ if(x == -1) {
err = PyErr_Occurred();
if (err &&
PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) {
@@ -968,6 +968,7 @@ PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals)
return -1;
}
}
+ vals[i] = x;
}
}
return nd;
diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c
index 9da811f69..f723c7646 100644
--- a/numpy/core/src/multiarray/iterators.c
Expand Down
26 changes: 13 additions & 13 deletions src/core/PyArray_Broadcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,49 @@ EM_JS_NUM(int, PyArray_Broadcast_part1, (void* mit), {
let it;
let it_ptr;

let numiter = _HEAP32[(mit + 8) / 4];
let numiter = HEAP32[(mit + 8) / 4];
/* Discover the broadcast number of dimensions */
nd = 0;
for (i = 0; i < numiter; i++) {
// nd = PyArray_MAX(nd, PyArray_NDIM(mit->iters[i]->ao));
let it = _HEAP32[(mit + 152 + 4 * i) / 4];
let it = HEAP32[(mit + 152 + 4 * i) / 4];
// Look up ao
let it_ao = _HEAP32[(res + 660) / 4];
let it_ao = HEAP32[(res + 660) / 4];
// look up NDIM
let it_ao_ndim = _HEAP32[(res + 12) / 4];
let it_ao_ndim = HEAP32[(res + 12) / 4];
nd = (res > nd) ? res : nd;
}
// mit->nd = nd;
_HEAP32[(mit + 20) / 4] = nd;
HEAP32[(mit + 20) / 4] = nd;

/* Discover the broadcast shape in each dimension */
// for (i = 0; i < nd; i++) {
// mit->dimensions[i] = 1;
// }
_HEAP32.subarray((mit + 24) / 4, (mit + 24 + nd) / 4).fill(1);
HEAP32.subarray((mit + 24) / 4, (mit + 24 + nd) / 4).fill(1);

for (j = 0; j < numiter; j++) {
// it = mit->iters[i];
it = _HEAP32[(mit + 4 * j + 152) / 4];
it = HEAP32[(mit + 4 * j + 152) / 4];
for (i = 0; i < nd; i++) {
/* This prepends 1 to shapes not already equal to nd */
// k = i + PyArray_NDIM(it->ao) - nd;
let it_ao = _HEAP32[(it + 660) / 4];
let it_ao_ndim = _HEAP32[(ao + 12) / 4];
let it_ao = HEAP32[(it + 660) / 4];
let it_ao_ndim = HEAP32[(ao + 12) / 4];
let k = i + it_ao_ndim - nd;
if (k >= 0) {
// tmp = PyArray_DIMS(it->ao)[k];
let it_dims = _HEAP32[(it_ao + 16) / 4];
let it_dims_k = _HEAP32[(it_dims + 4 * k) / 4];
let it_dims = HEAP32[(it_ao + 16) / 4];
let it_dims_k = HEAP32[(it_dims + 4 * k) / 4];
if (it_dims_k == 1) {
continue;
}
// &mit->dimensions[i];
let mit_dim_i_addr = mit + 4 * i + 24;
// let tmp2 = mit->dimensions[i];
let mit_dim_i = _HEAP32[mit_dim_i_addr / 4];
let mit_dim_i = HEAP32[mit_dim_i_addr / 4];
if (mit_dim_i == = 1) {
_HEAP32[mit_dim_i_addr / 4] = it_dims_k;
HEAP32[mit_dim_i_addr / 4] = it_dims_k;
} else if (mit_dim_i != = it_dims_k) {
_set_shape_mismatch_err();
return -1;
Expand Down

0 comments on commit e6fe5e1

Please sign in to comment.