MATRIX: Fix multiplication of empty matrices.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 18 Mar 2023 19:22:42 +0000 (12:22 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 18 Mar 2023 19:25:32 +0000 (12:25 -0700)
This crashed due to an assertion failure in blas before.
Thanks to Youngseok Choi for reporting the bug.

src/language/commands/matrix.c
tests/language/commands/matrix.at

index f34e24edda0abd417e4b76766e098d5a35be0c89..9076476ed7a10379bedf3b5785f3b1ef1fd6501e 100644 (file)
@@ -3336,7 +3336,8 @@ matrix_expr_evaluate_mul_mat (const struct matrix_expr *e,
     }
 
   gsl_matrix *c = gsl_matrix_alloc (a->size1, b->size2);
-  gsl_blas_dgemm (CblasNoTrans, CblasNoTrans, 1.0, a, b, 0.0, c);
+  if (a->size1 && b->size2)
+    gsl_blas_dgemm (CblasNoTrans, CblasNoTrans, 1.0, a, b, 0.0, c);
   return c;
 }
 
index 8412468ac9722a2de485329e4604c0626f1d9f27..9ebd23671f8939a1d826c9cc2817845a7780175d 100644 (file)
@@ -9,6 +9,9 @@ COMPUTE b={a; 1; 2; 3}.
 PRINT b.
 COMPUTE c={a, 1, 2, 3}.
 PRINT c.
+/* Multiplication of empty matrices previously assert-failed in blas.
+COMPUTE d = a * a.
+PRINT d.
 END MATRIX.
 ])
 AT_CHECK([pspp matrix.sps], [0], [dnl
@@ -21,6 +24,8 @@ b
 
 c
   1  2  3
+
+d
 ])
 AT_CLEANUP