diff options
author | Pauli Virtanen <pav@iki.fi> | 2013-10-12 22:57:22 +0300 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2013-10-12 23:07:01 +0300 |
commit | 984854aa605b5b4d5afe630e1879aa83845b11fb (patch) | |
tree | 324e8b43ae7968caf9a636dc7d88b99f232cc455 /numpy/linalg/umath_linalg.c.src | |
parent | c9ed04a5a72fa488a203a7c82cc73f390c3afe8b (diff) | |
download | numpy-984854aa605b5b4d5afe630e1879aa83845b11fb.tar.gz |
BUG: linalg: don't tell BLAS to use zero strides
At least OSX Accelerate fails for this case.
Diffstat (limited to 'numpy/linalg/umath_linalg.c.src')
-rw-r--r-- | numpy/linalg/umath_linalg.c.src | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/numpy/linalg/umath_linalg.c.src b/numpy/linalg/umath_linalg.c.src index 3c2b316e2..b38038fc2 100644 --- a/numpy/linalg/umath_linalg.c.src +++ b/numpy/linalg/umath_linalg.c.src @@ -812,24 +812,32 @@ linearize_@TYPE@_matrix(void *dst_in, @typ@ *dst = (@typ@ *) dst_in; if (dst) { - int i; + int i, j; @typ@* rv = dst; fortran_int columns = (fortran_int)data->columns; fortran_int column_strides = (fortran_int)(data->column_strides/sizeof(@typ@)); fortran_int one = 1; for (i=0; i< data->rows; i++) { - if (column_strides >= 0) { + if (column_strides > 0) { FNAME(@copy@)(&columns, (void*)src, &column_strides, (void*)dst, &one); } - else { + else if (column_strides < 0) { FNAME(@copy@)(&columns, (void*)((@typ@*)src + (columns-1)*column_strides), &column_strides, (void*)dst, &one); } + else { + /* Zero stride has undefined behavior in some BLAS + implementations (e.g. OSX Accelerate), so do it + manually */ + for (j = 0; j < columns; ++j) { + memcpy((@typ@*)dst + j, (@typ@*)src, sizeof(@typ@)); + } + } src += data->row_strides/sizeof(@typ@); dst += data->columns; } @@ -855,17 +863,25 @@ delinearize_@TYPE@_matrix(void *dst_in, (fortran_int)(data->column_strides/sizeof(@typ@)); fortran_int one = 1; for (i=0; i < data->rows; i++) { - if (column_strides >= 0) { + if (column_strides > 0) { FNAME(@copy@)(&columns, (void*)src, &one, (void*)dst, &column_strides); } - else { + else if (column_strides < 0) { FNAME(@copy@)(&columns, (void*)src, &one, (void*)((@typ@*)dst + (columns-1)*column_strides), &column_strides); } + else { + /* Zero stride has undefined behavior in some BLAS + implementations (e.g. OSX Accelerate), so do it + manually */ + if (columns > 0) { + memcpy((@typ@*)dst, (@typ@*)src + (columns-1), sizeof(@typ@)); + } + } src += data->columns; dst += data->row_strides/sizeof(@typ@); } |