@@ -8097,13 +8097,33 @@ min (const SparseComplexMatrix& a, const SparseComplexMatrix& b,
80978097 else
80988098 {
80998099 if (a_nr == 0 && (b_nr == 0 || b_nr == 1 ))
8100- r.resize (a_nr, std::max (a_nc, b_nc));
8100+ {
8101+ if (a_nc == 1 || b_nc == 1 || a_nc == b_nc)
8102+ r.resize (a_nr, std::max (a_nc, b_nc));
8103+ else
8104+ octave::err_nonconformant (" min" , a_nr, a_nc, b_nr, b_nc);
8105+ }
81018106 else if (a_nc == 0 && (b_nc == 0 || b_nc == 1 ))
8102- r.resize (std::max (a_nr, b_nr), a_nc);
8107+ {
8108+ if (a_nr == 1 || b_nr == 1 || a_nr == b_nr)
8109+ r.resize (std::max (a_nr, b_nr), a_nc);
8110+ else
8111+ octave::err_nonconformant (" min" , a_nr, a_nc, b_nr, b_nc);
8112+ }
81038113 else if (b_nr == 0 && (a_nr == 0 || a_nr == 1 ))
8104- r.resize (b_nr, std::max (a_nc, b_nc));
8114+ {
8115+ if (b_nc == 1 || a_nc == 1 || b_nc == a_nc)
8116+ r.resize (b_nr, std::max (a_nc, b_nc));
8117+ else
8118+ octave::err_nonconformant (" min" , a_nr, a_nc, b_nr, b_nc);
8119+ }
81058120 else if (b_nc == 0 && (a_nc == 0 || a_nc == 1 ))
8106- r.resize (std::max (a_nr, b_nr), b_nc);
8121+ {
8122+ if (b_nr == 1 || a_nr == 1 || b_nr == a_nr)
8123+ r.resize (std::max (a_nr, b_nr), b_nc);
8124+ else
8125+ octave::err_nonconformant (" min" , a_nr, a_nc, b_nr, b_nc);
8126+ }
81078127 else
81088128 octave::err_nonconformant (" min" , a_nr, a_nc, b_nr, b_nc);
81098129 }
@@ -8271,13 +8291,33 @@ max (const SparseComplexMatrix& a, const SparseComplexMatrix& b,
82718291 else
82728292 {
82738293 if (a_nr == 0 && (b_nr == 0 || b_nr == 1 ))
8274- r.resize (a_nr, std::max (a_nc, b_nc));
8294+ {
8295+ if (a_nc == 1 || b_nc == 1 || a_nc == b_nc)
8296+ r.resize (a_nr, std::max (a_nc, b_nc));
8297+ else
8298+ octave::err_nonconformant (" max" , a_nr, a_nc, b_nr, b_nc);
8299+ }
82758300 else if (a_nc == 0 && (b_nc == 0 || b_nc == 1 ))
8276- r.resize (std::max (a_nr, b_nr), a_nc);
8301+ {
8302+ if (a_nr == 1 || b_nr == 1 || a_nr == b_nr)
8303+ r.resize (std::max (a_nr, b_nr), a_nc);
8304+ else
8305+ octave::err_nonconformant (" max" , a_nr, a_nc, b_nr, b_nc);
8306+ }
82778307 else if (b_nr == 0 && (a_nr == 0 || a_nr == 1 ))
8278- r.resize (b_nr, std::max (a_nc, b_nc));
8308+ {
8309+ if (b_nc == 1 || a_nc == 1 || b_nc == a_nc)
8310+ r.resize (b_nr, std::max (a_nc, b_nc));
8311+ else
8312+ octave::err_nonconformant (" max" , a_nr, a_nc, b_nr, b_nc);
8313+ }
82798314 else if (b_nc == 0 && (a_nc == 0 || a_nc == 1 ))
8280- r.resize (std::max (a_nr, b_nr), b_nc);
8315+ {
8316+ if (b_nr == 1 || a_nr == 1 || b_nr == a_nr)
8317+ r.resize (std::max (a_nr, b_nr), b_nc);
8318+ else
8319+ octave::err_nonconformant (" max" , a_nr, a_nc, b_nr, b_nc);
8320+ }
82818321 else
82828322 octave::err_nonconformant (" max" , a_nr, a_nc, b_nr, b_nc);
82838323 }
@@ -8287,17 +8327,59 @@ max (const SparseComplexMatrix& a, const SparseComplexMatrix& b,
82878327
82888328/*
82898329
8330+ ## Testing broadcasting of empty matrices with min/max functions
8331+ %!assert (min (sparse (zeros (0,1)), sparse ([1, 2, 3, 4i])), sparse (zeros (0,4)))
8332+ %!error min (sparse (zeros (0,2)), sparse ([1, 2, 3, 4i]))
8333+ %!assert (max (sparse (zeros (0,1)), sparse ([1, 2, 3, 4i])), sparse (zeros (0,4)))
8334+ %!error max (sparse (zeros (0,2)), sparse ([1, 2, 3, 4i]))
8335+ %!assert (min (sparse (zeros (1,0)), sparse ([1; 2; 3; 4i])), sparse (zeros (4,0)))
8336+ %!error min (sparse (zeros (2,0)), sparse ([1; 2; 3; 4i]))
8337+ %!assert (max (sparse (zeros (1,0)), sparse ([1; 2; 3; 4i])), sparse (zeros (4,0)))
8338+ %!error max (sparse (zeros (2,0)), sparse ([1; 2; 3; 4i]))
8339+
82908340## Testing broadcasting of empty matrices with math operators.
82918341## This has been fixed in MSparse.cc and Sparse-op-defs.h
82928342%!assert (sparse (zeros (0,1)) + sparse ([1, 2, 3, 4i]), sparse (zeros (0,4)))
8343+ %!error <operator \+: nonconformant arguments \(op1 is 0x2, op2 is 1x4\)> ...
8344+ %! sparse (zeros (0,2)) + sparse ([1, 2, 3, 4i])
82938345%!assert (sparse (zeros (0,1)) - sparse ([1, 2, 3, 4i]), sparse (zeros (0,4)))
8346+ %!error <operator -: nonconformant arguments \(op1 is 0x2, op2 is 1x4\)> ...
8347+ %! sparse (zeros (0,2)) - sparse ([1, 2, 3, 4i])
82948348%!assert (sparse (zeros (0,1)) * sparse ([1, 2, 3, 4i]), sparse (zeros (0,4)))
8349+ %!error <operator \*: nonconformant arguments \(op1 is 0x2, op2 is 1x4\)> ...
8350+ %! sparse (zeros (0,2)) * sparse ([1, 2, 3, 4i])
8351+ %!assert (sparse (zeros (0,1)) .* sparse ([1, 2, 3, 4i]), sparse (zeros (0,4)))
8352+ %!error <product: nonconformant arguments \(op1 is 0x2, op2 is 1x4\)> ...
8353+ %! sparse (zeros (0,2)) .* sparse ([1, 2, 3, 4i])
82958354%!assert (sparse (zeros (0,1)) ./ sparse ([1, 2, 3, 4i]), sparse (zeros (0,4)))
8355+ %!error <quotient: nonconformant arguments \(op1 is 0x2, op2 is 1x4\)> ...
8356+ %! sparse (zeros (0,2)) ./ sparse ([1, 2, 3, 4i])
82968357%!test
82978358%! a = sparse (zeros (0,1));
82988359%! assert (a += sparse ([1, 2, 3, 4i]), sparse (zeros (0,4)))
82998360%! assert (a -= sparse ([1, 2, 3, 4i]), sparse (zeros (0,4)))
83008361
8362+ %!assert (sparse (zeros (1,0)) + sparse ([1; 2; 3; 4i]), sparse (zeros (4,0)))
8363+ %!error <operator \+: nonconformant arguments \(op1 is 2x0, op2 is 4x1\)> ...
8364+ %! sparse (zeros (2,0)) + sparse ([1; 2; 3; 4i])
8365+ %!assert (sparse (zeros (1,0)) - sparse ([1; 2; 3; 4i]), sparse (zeros (4,0)))
8366+ %!error <operator -: nonconformant arguments \(op1 is 2x0, op2 is 4x1\)> ...
8367+ %! sparse (zeros (2,0)) - sparse ([1; 2; 3; 4i])
8368+ %!error <operator \*: nonconformant arguments \(op1 is 1x0, op2 is 4x1\)>
8369+ %! sparse (zeros (1,0)) * sparse ([1; 2; 3; 4i])
8370+ %!error <operator \*: nonconformant arguments \(op1 is 2x0, op2 is 4x1\)> ...
8371+ %! sparse (zeros (2,0)) * sparse ([1; 2; 3; 4i])
8372+ %!assert (sparse (zeros (1,0)) .* sparse ([1; 2; 3; 4i]), sparse (zeros (4,0)))
8373+ %!error <product: nonconformant arguments \(op1 is 2x0, op2 is 4x1\)> ...
8374+ %! sparse (zeros (2,0)) .* sparse ([1; 2; 3; 4i])
8375+ %!assert (sparse (zeros (1,0)) ./ sparse ([1; 2; 3; 4i]), sparse (zeros (4,0)));
8376+ %!error <quotient: nonconformant arguments \(op1 is 2x0, op2 is 4x1\)> ...
8377+ %! sparse (zeros (2,0)) ./ sparse ([1; 2; 3; 4i])
8378+ %!test
8379+ %! a = sparse (zeros (1,0));
8380+ %! assert (a += sparse ([1; 2; 3; 4i]), sparse (zeros (4,0)))
8381+ %! assert (a -= sparse ([1; 2; 3; 4i]), sparse (zeros (4,0)))
8382+
83018383*/
83028384
83038385SPARSE_SMS_CMP_OPS (SparseComplexMatrix, Complex)
0 commit comments