diff src/OPERATORS/op-sm-scm.cc @ 6221:8e0f1eda266b

[project @ 2007-01-03 17:23:33 by jwe]
author jwe
date Wed, 03 Jan 2007 17:23:34 +0000
parents 6b9cec830d72
children 93c65f2a5668
line wrap: on
line diff
--- a/src/OPERATORS/op-sm-scm.cc	Sat Dec 30 17:29:35 2006 +0000
+++ b/src/OPERATORS/op-sm-scm.cc	Wed Jan 03 17:23:34 2007 +0000
@@ -47,12 +47,25 @@
 DEFBINOP (div, sparse_matrix, sparse_complex_matrix)
 {
   CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_sparse_complex_matrix&);
-  MatrixType typ = v2.matrix_type ();
-  SparseComplexMatrix ret = xdiv (v1.sparse_matrix_value (), 
+
+  if (v2.rows() == 1 && v2.columns() == 1)
+    {
+      Complex d = v2.complex_value ();
+
+      if (d == 0.0)
+	gripe_divide_by_zero ();
+
+      return octave_value (v1.sparse_matrix_value () / d);
+    }
+  else
+    {
+      MatrixType typ = v2.matrix_type ();
+      SparseComplexMatrix ret = xdiv (v1.sparse_matrix_value (), 
 				  v2.sparse_complex_matrix_value (), typ);
   
-  v2.matrix_type (typ);
-  return ret;
+      v2.matrix_type (typ);
+      return ret;
+    }
 }
 
 DEFBINOPX (pow, sparse_matrix, sparse_complex_matrix)
@@ -64,13 +77,27 @@
 DEFBINOP (ldiv, sparse_matrix, sparse_complex_matrix)
 {
   CAST_BINOP_ARGS (const octave_sparse_matrix&, const octave_sparse_complex_matrix&);
-  MatrixType typ = v1.matrix_type ();
+
+  if (v1.rows() == 1 && v1.columns() == 1)
+    {
+      double d = v1.scalar_value ();
+
+      if (d == 0.0)
+	gripe_divide_by_zero ();
 
-  SparseComplexMatrix ret = xleftdiv (v1.sparse_matrix_value (), 
-				      v2.sparse_complex_matrix_value (), typ);
+      return octave_value (v2.sparse_complex_matrix_value () / d);
+    }
+  else
+    {
+      MatrixType typ = v1.matrix_type ();
 
-  v1.matrix_type (typ);
-  return ret;
+      SparseComplexMatrix ret = 
+	xleftdiv (v1.sparse_matrix_value (), 
+		  v2.sparse_complex_matrix_value (), typ);
+
+      v1.matrix_type (typ);
+      return ret;
+    }
 }
 
 DEFBINOP_FN (lt, sparse_matrix, sparse_complex_matrix, mx_el_lt)