Mercurial > hg > octave-terminal
changeset 1992:5668c00f9c7a
[project @ 1996-03-03 00:40:53 by jwe]
author | jwe |
---|---|
date | Sun, 03 Mar 1996 00:43:53 +0000 |
parents | 413f6a81868f |
children | 1b57120c997b |
files | liboctave/CmplxLU.cc liboctave/CmplxLU.h liboctave/MArray.h liboctave/MArray2.h liboctave/MDiagArray2.h liboctave/dbleLU.cc liboctave/dbleLU.h |
diffstat | 7 files changed, 49 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- 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 <base-lu.h> +#include <base-lu.cc> + +template class base_lu <ComplexMatrix, Matrix>; + +// 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<int> 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<int> 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; } /*
--- 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 <ComplexMatrix, Matrix> { public: - ComplexLU (void) : l (), u (), p () { } + ComplexLU (void) : base_lu <ComplexMatrix, Matrix> () { } ComplexLU (const ComplexMatrix& a); - ComplexLU (const ComplexLU& a) : l (a.l), u (a.u), p (a.p) { } + ComplexLU (const ComplexLU& a) : base_lu <ComplexMatrix, Matrix> (a) { } ComplexLU& operator = (const ComplexLU& a) { if (this != &a) - { - l = a.l; - u = a.u; - p = a.p; - } + base_lu <ComplexMatrix, Matrix> :: 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
--- a/liboctave/MArray.h +++ b/liboctave/MArray.h @@ -92,6 +92,10 @@ }; #define INSTANTIATE_MARRAY_FRIENDS(T) \ + template MArray<T>& operator += (MArray<T>& a, const T& s); \ + template MArray<T>& operator -= (MArray<T>& a, const T& s); \ + template MArray<T>& operator += (MArray<T>& a, const MArray<T>& b); \ + template MArray<T>& operator -= (MArray<T>& a, const MArray<T>& b); \ template MArray<T> operator + (const MArray<T>& a, const T& s); \ template MArray<T> operator - (const MArray<T>& a, const T& s); \ template MArray<T> operator * (const MArray<T>& a, const T& s); \
--- a/liboctave/MArray2.h +++ b/liboctave/MArray2.h @@ -91,6 +91,10 @@ }; #define INSTANTIATE_MARRAY2_FRIENDS(T) \ + template MArray2<T>& operator += (MArray2<T>& a, const T& s); \ + template MArray2<T>& operator -= (MArray2<T>& a, const T& s); \ + template MArray2<T>& operator += (MArray2<T>& a, const MArray2<T>& b); \ + template MArray2<T>& operator -= (MArray2<T>& a, const MArray2<T>& b); \ template MArray2<T> operator + (const MArray2<T>& a, const T& s); \ template MArray2<T> operator - (const MArray2<T>& a, const T& s); \ template MArray2<T> operator * (const MArray2<T>& a, const T& s); \
--- a/liboctave/MDiagArray2.h +++ b/liboctave/MDiagArray2.h @@ -102,6 +102,8 @@ }; #define INSTANTIATE_MDIAGARRAY_FRIENDS(T) \ + template MDiagArray2<T>& operator += (MDiagArray2<T>& a, const MDiagArray2<T>& b); \ + template MDiagArray2<T>& operator -= (MDiagArray2<T>& a, const MDiagArray2<T>& b); \ template MDiagArray2<T> operator * (const MDiagArray2<T>& a, const T& s); \ template MDiagArray2<T> operator / (const MDiagArray2<T>& a, const T& s); \ template MDiagArray2<T> operator * (const T& s, const MDiagArray2<T>& a); \
--- 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 <base-lu.h> +#include <base-lu.cc> + +template class base_lu <Matrix, Matrix>; + +// 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<int> 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<int> 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; } /*
--- 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 <Matrix, Matrix> { public: - LU (void) : l (), u (), p () { } + LU (void) : base_lu <Matrix, Matrix> () { } LU (const Matrix& a); - LU (const LU& a) : l (a.l), u (a.u), p (a.p) { } + LU (const LU& a) : base_lu <Matrix, Matrix> (a) { } LU& operator = (const LU& a) { if (this != &a) - { - l = a.l; - u = a.u; - p = a.p; - } + base_lu <Matrix, Matrix> :: 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