MCPcopy Create free account
hub / github.com/numpy/numpy / dot_alignment_error

Function dot_alignment_error

numpy/core/src/multiarray/common.c:248–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246
247
248NPY_NO_EXPORT void
249dot_alignment_error(PyArrayObject *a, int i, PyArrayObject *b, int j)
250{
251 PyObject *errmsg = NULL, *format = NULL, *fmt_args = NULL,
252 *i_obj = NULL, *j_obj = NULL,
253 *shape1 = NULL, *shape2 = NULL,
254 *shape1_i = NULL, *shape2_j = NULL;
255
256 format = PyUnicode_FromString("shapes %s and %s not aligned:"
257 " %d (dim %d) != %d (dim %d)");
258
259 shape1 = convert_shape_to_string(PyArray_NDIM(a), PyArray_DIMS(a), "");
260 shape2 = convert_shape_to_string(PyArray_NDIM(b), PyArray_DIMS(b), "");
261
262 i_obj = PyLong_FromLong(i);
263 j_obj = PyLong_FromLong(j);
264
265 shape1_i = PyLong_FromSsize_t(PyArray_DIM(a, i));
266 shape2_j = PyLong_FromSsize_t(PyArray_DIM(b, j));
267
268 if (!format || !shape1 || !shape2 || !i_obj || !j_obj ||
269 !shape1_i || !shape2_j) {
270 goto end;
271 }
272
273 fmt_args = PyTuple_Pack(6, shape1, shape2,
274 shape1_i, i_obj, shape2_j, j_obj);
275 if (fmt_args == NULL) {
276 goto end;
277 }
278
279 errmsg = PyUnicode_Format(format, fmt_args);
280 if (errmsg != NULL) {
281 PyErr_SetObject(PyExc_ValueError, errmsg);
282 }
283 else {
284 PyErr_SetString(PyExc_ValueError, "shapes are not aligned");
285 }
286
287end:
288 Py_XDECREF(errmsg);
289 Py_XDECREF(fmt_args);
290 Py_XDECREF(format);
291 Py_XDECREF(i_obj);
292 Py_XDECREF(j_obj);
293 Py_XDECREF(shape1);
294 Py_XDECREF(shape2);
295 Py_XDECREF(shape1_i);
296 Py_XDECREF(shape2_j);
297}
298
299/**
300 * unpack tuple of dtype->fields (descr, offset, title[not-needed])

Callers 2

PyArray_MatrixProduct2Function · 0.85
cblas_matrixproductFunction · 0.85

Calls 4

convert_shape_to_stringFunction · 0.85
PyArray_NDIMFunction · 0.85
PyArray_DIMSFunction · 0.85
PyArray_DIMFunction · 0.85

Tested by

no test coverage detected