comparison liboctave/array/Sparse.cc @ 32045:f18da620ab4d stable

Fix floating point exception when Sparse array reshaped to 0x0 (bug #64080) * Sparse.cc (reshape): Test for empty matrix (number of rows or columns equal to 0) and immediately return constructed, but unfilled, empty sparse matrix. * data.cc (Freshape): Add BIST test for bug #64080.
author Rik <rik@octave.org>
date Thu, 20 Apr 2023 18:58:57 -0700
parents 597f3ee61a48
children 39700c1ea93e
comparison
equal deleted inserted replaced
32033:1824e0ee4088 32045:f18da620ab4d
871 octave_idx_type new_nr = dims2 (0); 871 octave_idx_type new_nr = dims2 (0);
872 octave_idx_type new_nc = dims2 (1); 872 octave_idx_type new_nc = dims2 (1);
873 octave_idx_type old_nr = rows (); 873 octave_idx_type old_nr = rows ();
874 octave_idx_type old_nc = cols (); 874 octave_idx_type old_nc = cols ();
875 retval = Sparse<T, Alloc> (new_nr, new_nc, new_nnz); 875 retval = Sparse<T, Alloc> (new_nr, new_nc, new_nnz);
876 // Special case for empty matrices (bug #64080)
877 if (new_nr == 0 || new_nc == 0)
878 return retval;
876 879
877 octave_idx_type kk = 0; 880 octave_idx_type kk = 0;
878 retval.xcidx (0) = 0; 881 retval.xcidx (0) = 0;
879 // Quotient and remainder of i * old_nr divided by new_nr. 882 // Quotient and remainder of i * old_nr divided by new_nr.
880 // Track them individually to avoid overflow (bug #42850). 883 // Track them individually to avoid overflow (bug #42850).