comparison liboctave/fDiagMatrix.cc @ 9698:7c6d5d8c8d37

fix diag*diag multiplication
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 06 Oct 2009 08:43:01 +0200
parents a9b37bae1802
children f80c566bc751
comparison
equal deleted inserted replaced
9697:51c17bd18563 9698:7c6d5d8c8d37
336 336
337 octave_idx_type b_nr = b.rows (); 337 octave_idx_type b_nr = b.rows ();
338 octave_idx_type b_nc = b.cols (); 338 octave_idx_type b_nc = b.cols ();
339 339
340 if (a_nc != b_nr) 340 if (a_nc != b_nr)
341 { 341 gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc);
342 gripe_nonconformant ("operaotr *", a_nr, a_nc, b_nr, b_nc);
343 return FloatDiagMatrix ();
344 }
345
346 if (a_nr == 0 || a_nc == 0 || b_nc == 0)
347 return FloatDiagMatrix (a_nr, a_nc, 0.0);
348 342
349 FloatDiagMatrix c (a_nr, b_nc); 343 FloatDiagMatrix c (a_nr, b_nc);
350 344
351 octave_idx_type len = a_nr < b_nc ? a_nr : b_nc; 345 octave_idx_type len = c.length (), lenm = len < a_nc ? len : a_nc;
352 346
353 for (octave_idx_type i = 0; i < len; i++) 347 for (octave_idx_type i = 0; i < lenm; i++)
354 { 348 c.dgxelem (i) = a.dgelem (i) * b.dgelem (i);
355 float a_element = a.elem (i, i); 349 for (octave_idx_type i = lenm; i < len; i++)
356 float b_element = b.elem (i, i); 350 c.dgxelem (i) = 0.0f;
357
358 c.elem (i, i) = a_element * b_element;
359 }
360 351
361 return c; 352 return c;
362 } 353 }
363 354
364 // other operations 355 // other operations