Mercurial > hg > octave-avbm
changeset 378:e04b38065c55
[project @ 1994-03-03 20:41:35 by jwe]
author | jwe |
---|---|
date | Thu, 03 Mar 1994 20:41:41 +0000 |
parents | 1d3dbdfd0d19 |
children | 80b85cc1c082 |
files | liboctave/DiagMatrix.cc liboctave/Matrix.h |
diffstat | 2 files changed, 171 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/DiagMatrix.cc +++ b/liboctave/DiagMatrix.cc @@ -1,7 +1,7 @@ // DiagMatrix manipulations. -*- C++ -*- /* -Copyright (C) 1992, 1993 John W. Eaton +Copyright (C) 1992, 1993, 1994 John W. Eaton This file is part of Octave. @@ -533,6 +533,45 @@ // diagonal matrix by diagonal matrix -> diagonal matrix operations +DiagMatrix +operator * (const DiagMatrix& a, const DiagMatrix& b) +{ + int nr_a = a.rows (); + int nc_a = a.cols (); + int nr_b = b.rows (); + int nc_b = b.cols (); + if (nc_a != nr_b) + { + (*current_liboctave_error_handler) + ("nonconformant matrix multiplication attempted"); + return DiagMatrix (); + } + + if (nr_a == 0 || nc_a == 0 || nc_b == 0) + return DiagMatrix (nr_a, nc_a, 0.0); + + DiagMatrix c (nr_a, nc_b); + + int len = nr_a < nc_b ? nr_a : nc_b; + + for (int i = 0; i < len; i++) + { + double a_element = a.elem (i, i); + double b_element = b.elem (i, i); + + if (a_element == 0.0 || b_element == 0.0) + c.elem (i, i) = 0.0; + else if (a_element == 1.0) + c.elem (i, i) = b_element; + else if (b_element == 1.0) + c.elem (i, i) = a_element; + else + c.elem (i, i) = a_element * b_element; + } + + return c; +} + ComplexDiagMatrix operator + (const DiagMatrix& m, const ComplexDiagMatrix& a) { @@ -571,6 +610,45 @@ } ComplexDiagMatrix +operator * (const DiagMatrix& a, const ComplexDiagMatrix& b) +{ + int nr_a = a.rows (); + int nc_a = a.cols (); + int nr_b = b.rows (); + int nc_b = b.cols (); + if (nc_a != nr_b) + { + (*current_liboctave_error_handler) + ("nonconformant matrix multiplication attempted"); + return ComplexDiagMatrix (); + } + + if (nr_a == 0 || nc_a == 0 || nc_b == 0) + return ComplexDiagMatrix (nr_a, nc_a, 0.0); + + ComplexDiagMatrix c (nr_a, nc_b); + + int len = nr_a < nc_b ? nr_a : nc_b; + + for (int i = 0; i < len; i++) + { + double a_element = a.elem (i, i); + Complex b_element = b.elem (i, i); + + if (a_element == 0.0 || b_element == 0.0) + c.elem (i, i) = 0.0; + else if (a_element == 1.0) + c.elem (i, i) = b_element; + else if (b_element == 1.0) + c.elem (i, i) = a_element; + else + c.elem (i, i) = a_element * b_element; + } + + return c; +} + +ComplexDiagMatrix product (const DiagMatrix& m, const ComplexDiagMatrix& a) { int nr = m.rows (); @@ -1568,6 +1646,45 @@ // diagonal matrix by diagonal matrix -> diagonal matrix operations ComplexDiagMatrix +operator * (const ComplexDiagMatrix& a, const ComplexDiagMatrix& b) +{ + int nr_a = a.rows (); + int nc_a = a.cols (); + int nr_b = b.rows (); + int nc_b = b.cols (); + if (nc_a != nr_b) + { + (*current_liboctave_error_handler) + ("nonconformant matrix multiplication attempted"); + return ComplexDiagMatrix (); + } + + if (nr_a == 0 || nc_a == 0 || nc_b == 0) + return ComplexDiagMatrix (nr_a, nc_a, 0.0); + + ComplexDiagMatrix c (nr_a, nc_b); + + int len = nr_a < nc_b ? nr_a : nc_b; + + for (int i = 0; i < len; i++) + { + Complex a_element = a.elem (i, i); + Complex b_element = b.elem (i, i); + + if (a_element == 0.0 || b_element == 0.0) + c.elem (i, i) = 0.0; + else if (a_element == 1.0) + c.elem (i, i) = b_element; + else if (b_element == 1.0) + c.elem (i, i) = a_element; + else + c.elem (i, i) = a_element * b_element; + } + + return c; +} + +ComplexDiagMatrix operator + (const ComplexDiagMatrix& m, const DiagMatrix& a) { int nr = m.rows (); @@ -1605,6 +1722,45 @@ } ComplexDiagMatrix +operator * (const ComplexDiagMatrix& a, const DiagMatrix& b) +{ + int nr_a = a.rows (); + int nc_a = a.cols (); + int nr_b = b.rows (); + int nc_b = b.cols (); + if (nc_a != nr_b) + { + (*current_liboctave_error_handler) + ("nonconformant matrix multiplication attempted"); + return ComplexDiagMatrix (); + } + + if (nr_a == 0 || nc_a == 0 || nc_b == 0) + return ComplexDiagMatrix (nr_a, nc_a, 0.0); + + ComplexDiagMatrix c (nr_a, nc_b); + + int len = nr_a < nc_b ? nr_a : nc_b; + + for (int i = 0; i < len; i++) + { + Complex a_element = a.elem (i, i); + double b_element = b.elem (i, i); + + if (a_element == 0.0 || b_element == 0.0) + c.elem (i, i) = 0.0; + else if (a_element == 1.0) + c.elem (i, i) = b_element; + else if (b_element == 1.0) + c.elem (i, i) = a_element; + else + c.elem (i, i) = a_element * b_element; + } + + return c; +} + +ComplexDiagMatrix product (const ComplexDiagMatrix& m, const DiagMatrix& a) { int nr = m.rows ();
--- a/liboctave/Matrix.h +++ b/liboctave/Matrix.h @@ -396,6 +396,7 @@ // i/o friend ostream& operator << (ostream& os, const ColumnVector& a); + friend ostream& operator >> (ostream& is, ColumnVector& a); #define KLUDGE_VECTORS #define TYPE double @@ -508,6 +509,7 @@ // i/o friend ostream& operator << (ostream& os, const RowVector& a); + friend ostream& operator >> (ostream& is, RowVector& a); #define KLUDGE_VECTORS #define TYPE double @@ -618,10 +620,15 @@ // diagonal matrix by diagonal matrix -> diagonal matrix operations + friend DiagMatrix operator * (const DiagMatrix& a, + const DiagMatrix& b); + friend ComplexDiagMatrix operator + (const DiagMatrix& a, const ComplexDiagMatrix& b); friend ComplexDiagMatrix operator - (const DiagMatrix& a, const ComplexDiagMatrix& b); + friend ComplexDiagMatrix operator * (const DiagMatrix& a, + const ComplexDiagMatrix& b); friend ComplexDiagMatrix product (const DiagMatrix& a, const ComplexDiagMatrix& b); @@ -1018,6 +1025,7 @@ // i/o friend ostream& operator << (ostream& os, const ComplexColumnVector& a); + friend ostream& operator >> (ostream& is, ComplexColumnVector& a); #define KLUDGE_VECTORS #define TYPE Complex @@ -1144,6 +1152,7 @@ // i/o friend ostream& operator << (ostream& os, const ComplexRowVector& a); + friend ostream& operator >> (ostream& is, ComplexRowVector& a); #define KLUDGE_VECTORS #define TYPE Complex @@ -1277,10 +1286,15 @@ // diagonal matrix by diagonal matrix -> diagonal matrix operations + friend ComplexDiagMatrix operator * (const ComplexDiagMatrix& a, + const ComplexDiagMatrix& b); + friend ComplexDiagMatrix operator + (const ComplexDiagMatrix& a, const DiagMatrix& b); friend ComplexDiagMatrix operator - (const ComplexDiagMatrix& a, const DiagMatrix& b); + friend ComplexDiagMatrix operator * (const ComplexDiagMatrix& a, + const DiagMatrix& b); friend ComplexDiagMatrix product (const ComplexDiagMatrix& a, const DiagMatrix& b);