| 1127 | |
| 1128 | |
| 1129 | static int |
| 1130 | set_shape_mismatch_exception(PyArrayMultiIterObject *mit, int i1, int i2) |
| 1131 | { |
| 1132 | PyObject *shape1, *shape2, *msg; |
| 1133 | |
| 1134 | shape1 = PyObject_GetAttrString((PyObject *) mit->iters[i1]->ao, "shape"); |
| 1135 | if (shape1 == NULL) { |
| 1136 | return -1; |
| 1137 | } |
| 1138 | shape2 = PyObject_GetAttrString((PyObject *) mit->iters[i2]->ao, "shape"); |
| 1139 | if (shape2 == NULL) { |
| 1140 | Py_DECREF(shape1); |
| 1141 | return -1; |
| 1142 | } |
| 1143 | msg = PyUnicode_FromFormat("shape mismatch: objects cannot be broadcast " |
| 1144 | "to a single shape. Mismatch is between arg %d " |
| 1145 | "with shape %S and arg %d with shape %S.", |
| 1146 | i1, shape1, i2, shape2); |
| 1147 | Py_DECREF(shape1); |
| 1148 | Py_DECREF(shape2); |
| 1149 | if (msg == NULL) { |
| 1150 | return -1; |
| 1151 | } |
| 1152 | PyErr_SetObject(PyExc_ValueError, msg); |
| 1153 | Py_DECREF(msg); |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | /* Adjust dimensionality and strides for index object iterators |
| 1158 | --- i.e. broadcast |