diff libinterp/operators/op-scm-m.cc @ 29845:2ef9080ca017

allow more mixed-type assignments to work for sparse matrices (bug #60859) This change allows indexed assignment to work when the LHS is a sparse matrix (real or complex) and the RHS is a single precision scalar or matrix (real or complex). * ov-base-sparse.h, ov-base-sparse.cc (octave_base_sparse<T>::assign): Declare RHS as a template type separate from the type of the sparse array itself. Move implementation to header file so that instantiation will work automatically. * Sparse.cc, Sparse.h (Sparse<T>::assign): Provide versions for scalar RHS. * op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc: Use DEFNDASSIGNOP_FN to define functions for assignment. Define and install mixed-type assignment operations for float and float complex scalar and array assignments to complex and double sparse arrays. * test/sparse-assign.tst: New tests. * test/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Wed, 30 Jun 2021 17:52:03 -0400
parents 7854d5752dd2
children b260322f6730
line wrap: on
line diff
--- a/libinterp/operators/op-scm-m.cc	Thu Jul 01 15:28:17 2021 +0200
+++ b/libinterp/operators/op-scm-m.cc	Wed Jun 30 17:52:03 2021 -0400
@@ -31,6 +31,7 @@
 #include "ov.h"
 #include "ov-typeinfo.h"
 #include "ov-re-mat.h"
+#include "ov-flt-re-mat.h"
 #include "ov-cx-mat.h"
 #include "ops.h"
 #include "xdiv.h"
@@ -131,16 +132,8 @@
          (v1.sparse_complex_matrix_value ().concat (tmp, ra_idx));
 }
 
-DEFASSIGNOP (assign, sparse_complex_matrix, matrix)
-{
-  octave_sparse_complex_matrix& v1
-    = dynamic_cast<octave_sparse_complex_matrix&> (a1);
-  const octave_matrix& v2 = dynamic_cast<const octave_matrix&> (a2);
-
-  SparseComplexMatrix tmp (v2.complex_matrix_value ());
-  v1.assign (idx, tmp);
-  return octave_value ();
-}
+DEFNDASSIGNOP_FN (assign, sparse_complex_matrix, matrix, complex_matrix, assign);
+DEFNDASSIGNOP_FN (sgl_assign, sparse_complex_matrix, float_matrix, complex_matrix, assign);
 
 void
 install_scm_m_ops (octave::type_info& ti)
@@ -175,4 +168,6 @@
 
   INSTALL_ASSIGNOP_TI (ti, op_asn_eq, octave_sparse_complex_matrix, octave_matrix,
                        assign);
+  INSTALL_ASSIGNOP_TI (ti, op_asn_eq, octave_sparse_complex_matrix, octave_float_matrix,
+                       sgl_assign);
 }