# HG changeset patch # User jwe # Date 825813833 0 # Node ID 5668c00f9c7ac457e705a264c01c64d8db144f16 # Parent 413f6a81868f119647afabe81b841a45c7f61f4c [project @ 1996-03-03 00:40:53 by jwe] diff --git a/liboctave/CmplxLU.cc b/liboctave/CmplxLU.cc --- a/liboctave/CmplxLU.cc +++ b/liboctave/CmplxLU.cc @@ -34,6 +34,15 @@ #include "lo-error.h" #include "mx-inlines.cc" +// Instantiate the base LU class for the types we need. + +#include +#include + +template class base_lu ; + +// Define the constructor for this particular derivation. + extern "C" { int F77_FCN (zgesv, ZGESV) (const int&, const int&, Complex*, @@ -54,12 +63,11 @@ int n = a_nr; - Array ipvt (n); - + ipvt.resize (n); int *pipvt = ipvt.fortran_vec (); - ComplexMatrix A_fact = a; - Complex *tmp_data = A_fact.fortran_vec (); + a_fact = a; + Complex *tmp_data = a_fact.fortran_vec (); int info = 0; Complex *dummy = 0; @@ -69,43 +77,7 @@ if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in zgesv"); else - { - Array pvt (n); - - for (int i = 0; i < n; i++) - { - ipvt.elem (i) -= 1; - pvt.elem (i) = i; - } - - for (int i = 0; i < n - 1; i++) - { - int k = ipvt.elem (i); - - if (k != i) - { - int tmp = pvt.elem (k); - pvt.elem (k) = pvt.elem (i); - pvt.elem (i)= tmp; - } - } - - l.resize (n, n, 0.0); - u.resize (n, n, 0.0); - p.resize (n, n, 0.0); - - for (int i = 0; i < n; i++) - { - p.elem (i, pvt.elem (i)) = 1.0; - - l.elem (i, i) = 1.0; - for (int j = 0; j < i; j++) - l.elem (i, j) = A_fact.elem (i, j); - - for (int j = i; j < n; j++) - u.elem (i, j) = A_fact.elem (i, j); - } - } + ipvt -= 1; } /* diff --git a/liboctave/CmplxLU.h b/liboctave/CmplxLU.h --- a/liboctave/CmplxLU.h +++ b/liboctave/CmplxLU.h @@ -28,47 +28,30 @@ #pragma interface #endif -class ostream; - +#include "base-lu.h" #include "dMatrix.h" #include "CMatrix.h" class -ComplexLU +ComplexLU : public base_lu { public: - ComplexLU (void) : l (), u (), p () { } + ComplexLU (void) : base_lu () { } ComplexLU (const ComplexMatrix& a); - ComplexLU (const ComplexLU& a) : l (a.l), u (a.u), p (a.p) { } + ComplexLU (const ComplexLU& a) : base_lu (a) { } ComplexLU& operator = (const ComplexLU& a) { if (this != &a) - { - l = a.l; - u = a.u; - p = a.p; - } + base_lu :: operator = (a); + return *this; } ~ComplexLU (void) { } - - ComplexMatrix L (void) const { return l; } - ComplexMatrix U (void) const { return u; } - - Matrix P (void) const { return p; } - - friend ostream& operator << (ostream& os, const ComplexLU& a); - -private: - - ComplexMatrix l; - ComplexMatrix u; - Matrix p; }; #endif diff --git a/liboctave/MArray.h b/liboctave/MArray.h --- a/liboctave/MArray.h +++ b/liboctave/MArray.h @@ -92,6 +92,10 @@ }; #define INSTANTIATE_MARRAY_FRIENDS(T) \ + template MArray& operator += (MArray& a, const T& s); \ + template MArray& operator -= (MArray& a, const T& s); \ + template MArray& operator += (MArray& a, const MArray& b); \ + template MArray& operator -= (MArray& a, const MArray& b); \ template MArray operator + (const MArray& a, const T& s); \ template MArray operator - (const MArray& a, const T& s); \ template MArray operator * (const MArray& a, const T& s); \ diff --git a/liboctave/MArray2.h b/liboctave/MArray2.h --- a/liboctave/MArray2.h +++ b/liboctave/MArray2.h @@ -91,6 +91,10 @@ }; #define INSTANTIATE_MARRAY2_FRIENDS(T) \ + template MArray2& operator += (MArray2& a, const T& s); \ + template MArray2& operator -= (MArray2& a, const T& s); \ + template MArray2& operator += (MArray2& a, const MArray2& b); \ + template MArray2& operator -= (MArray2& a, const MArray2& b); \ template MArray2 operator + (const MArray2& a, const T& s); \ template MArray2 operator - (const MArray2& a, const T& s); \ template MArray2 operator * (const MArray2& a, const T& s); \ diff --git a/liboctave/MDiagArray2.h b/liboctave/MDiagArray2.h --- a/liboctave/MDiagArray2.h +++ b/liboctave/MDiagArray2.h @@ -102,6 +102,8 @@ }; #define INSTANTIATE_MDIAGARRAY_FRIENDS(T) \ + template MDiagArray2& operator += (MDiagArray2& a, const MDiagArray2& b); \ + template MDiagArray2& operator -= (MDiagArray2& a, const MDiagArray2& b); \ template MDiagArray2 operator * (const MDiagArray2& a, const T& s); \ template MDiagArray2 operator / (const MDiagArray2& a, const T& s); \ template MDiagArray2 operator * (const T& s, const MDiagArray2& a); \ diff --git a/liboctave/dbleLU.cc b/liboctave/dbleLU.cc --- a/liboctave/dbleLU.cc +++ b/liboctave/dbleLU.cc @@ -34,6 +34,15 @@ #include "lo-error.h" #include "mx-inlines.cc" +// Instantiate the base LU class for the types we need. + +#include +#include + +template class base_lu ; + +// Define the constructor for this particular derivation. + extern "C" { int F77_FCN (dgesv, DGESV) (const int&, const int&, double*, @@ -54,11 +63,11 @@ int n = a_nr; - Array ipvt (n); + ipvt.resize (n); int *pipvt = ipvt.fortran_vec (); - Matrix A_fact = a; - double *tmp_data = A_fact.fortran_vec (); + a_fact = a; + double *tmp_data = a_fact.fortran_vec (); int info = 0; double dummy = 0; @@ -68,42 +77,7 @@ if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in dgesv"); else - { - Array pvt (n); - - for (int i = 0; i < n; i++) - { - ipvt.elem (i) -= 1; - pvt.elem (i) = i; - } - - for (int i = 0; i < n - 1; i++) - { - int k = ipvt.elem (i); - if (k != i) - { - int tmp = pvt.elem (k); - pvt.elem (k) = pvt.elem (i); - pvt.elem (i) = tmp; - } - } - - l.resize (n, n, 0.0); - u.resize (n, n, 0.0); - p.resize (n, n, 0.0); - - for (int i = 0; i < n; i++) - { - p.elem (i, pvt.elem (i)) = 1.0; - - l.elem (i, i) = 1.0; - for (int j = 0; j < i; j++) - l.elem (i, j) = A_fact.elem (i, j); - - for (int j = i; j < n; j++) - u.elem (i, j) = A_fact.elem (i, j); - } - } + ipvt -= 1; } /* diff --git a/liboctave/dbleLU.h b/liboctave/dbleLU.h --- a/liboctave/dbleLU.h +++ b/liboctave/dbleLU.h @@ -28,46 +28,29 @@ #pragma interface #endif -class ostream; - +#include "base-lu.h" #include "dMatrix.h" -class LU +class +LU : public base_lu { public: - LU (void) : l (), u (), p () { } + LU (void) : base_lu () { } LU (const Matrix& a); - LU (const LU& a) : l (a.l), u (a.u), p (a.p) { } + LU (const LU& a) : base_lu (a) { } LU& operator = (const LU& a) { if (this != &a) - { - l = a.l; - u = a.u; - p = a.p; - } + base_lu :: operator = (a); + return *this; } ~LU (void) { } - - Matrix L (void) const { return l; } - - Matrix U (void) const { return u; } - - Matrix P (void) const { return p; } - - friend ostream& operator << (ostream& os, const LU& a); - -private: - - Matrix l; - Matrix u; - Matrix p; }; #endif