From 621e9580cfc3fe47a9055cb384f00d08a1137fc1 Mon Sep 17 00:00:00 2001 From: fred Date: Sat, 12 Oct 1996 11:43:27 +0000 Subject: [PATCH] lilypond-0.0.3 --- choleski.cc | 95 -------------------- choleski.hh | 46 ---------- dstream.cc | 108 ----------------------- dstream.hh | 37 -------- main.cc | 51 +++++++---- matrix.cc | 281 ------------------------------------------------------------ matrix.hh | 141 ------------------------------ real.hh | 25 ------ smat.cc | 187 ---------------------------------------- smat.hh | 93 -------------------- template.cc | 26 ------ vector.cc | 41 --------- vector.hh | 106 ----------------------- vsmat.hh | 141 ------------------------------ 14 files changed, 33 insertions(+), 1345 deletions(-) delete mode 100644 choleski.cc delete mode 100644 choleski.hh delete mode 100644 dstream.cc delete mode 100644 dstream.hh delete mode 100644 matrix.cc delete mode 100644 matrix.hh delete mode 100644 real.hh delete mode 100644 smat.cc delete mode 100644 smat.hh delete mode 100644 template.cc delete mode 100644 vector.cc delete mode 100644 vector.hh delete mode 100644 vsmat.hh diff --git a/choleski.cc b/choleski.cc deleted file mode 100644 index 2d8c68aa66..0000000000 --- a/choleski.cc +++ /dev/null @@ -1,95 +0,0 @@ -#include "choleski.hh" - -Vector -Choleski_decomposition::solve(Vector rhs)const -{ - int n= rhs.dim(); - assert(n == L.dim()); - Vector y(n); - - // forward substitution - for (int i=0; i < n; i++) { - Real sum(0.0); - for (int j=0; j < i; j++) - sum += y(j) * L(i,j); - y(i) = (rhs(i) - sum)/L(i,i); - } - for (int i=0; i < n; i++) { - assert(D(i)); - y(i) /= D(i); - } - - // backward subst - Vector x(n); - for (int i=n-1; i >= 0; i--) { - Real sum(0.0); - for (int j=i+1; j < n; j++) - sum += L(j,i)*x(j); - x(i) = (y(i) - sum)/L(i,i); - } - return x; -} - -/* - Standard matrix algorithm. - */ - -Choleski_decomposition::Choleski_decomposition(Matrix P) - : L(P.dim()), D(P.dim()) -{ - int n = P.dim(); - assert((P-P.transposed()).norm() < EPS); - L.unit(); - for (int k= 0; k < n; k++) { - for (int j = 0; j < k; j++){ - Real sum(0.0); - for (int l=0; l < j; l++) - sum += L(k,l)*L(j,l)*D(l); - L(k,j) = (P(k,j) - sum)/D(j); - } - Real sum=0.0; - - for (int l=0; l < k; l++) - sum += sqr(L(k,l))*D(l); - Real d = P(k,k) - sum; - D(k) = d; - } - -#ifdef NDEBUG - assert((original()-P).norm() < EPS); -#endif -} - -Matrix -Choleski_decomposition::original() const -{ - Matrix T(L.dim()); - T.set_diag(D); - return L*T*L.transposed(); -} - -Matrix -Choleski_decomposition::inverse() const -{ - int n=L.dim(); - Matrix invm(n); - Vector e_i(n); - for (int i = 0; i < n; i++) { - e_i.set_unit(i); - Vector inv(solve(e_i)); - for (int j = 0 ; j - -#include "dstream.hh" -#include "string.hh" -#include "textdb.hh" - - -/* - should use Regexp library. - */ -static String -strip_pretty(String pret) -{ - String cl(pret.left(pret.pos('(')-1)); - int l = cl.lastPos(' '); - cl = cl.right(cl.len() -l); - return cl; -} - -static String -strip_member(String pret) -{ - String cl(pret.left(pret.lastPos(':')-2)); - return cl; -} - -Dstream& -Dstream::identify_as(String name) -{ - String mem(strip_pretty(name)); - String cl(strip_member(mem)); - - if(!silent.elt_query(cl)) - silent[cl] = false; - local_silence = silent[cl]; - if (classname != cl && !local_silence) { - classname=cl; - *os << "[" << classname << ":]"; - } - return *this; -} - -void -Dstream::switch_output(String name,bool b) -{ - silent[name] = b; -} - -/// -Dstream & -Dstream::operator<<(String s) -{ - if (local_silence) - return *this; - - for (const char *cp = s ; *cp; cp++) - switch(*cp) - { - case '{': - case '[': - case '(': indentlvl += INDTAB; - *os << *cp; - break; - - case ')': - case ']': - case '}': - indentlvl -= INDTAB; - *os << *cp ; - - if (indentlvl<0) indentlvl = 0; - break; - - case '\n': - *os << '\n' << String (' ', indentlvl) << flush; - break; - default: - *os << *cp; - break; - } - return *this; -} - -/** only output possibility. Delegates all conversion to String class. - */ - -Dstream::Dstream(ostream &r, const char * cfg_nm ) -{ - os = &r; - indentlvl = 0; - - const char * fn =cfg_nm ? cfg_nm : ".dstreamrc"; - { - ifstream ifs(fn); // can't open - if (!ifs) - return; - } - cerr << "(" << fn; - Text_db cfg(fn); - while (! cfg.eof()){ - Text_record r( cfg++); - assert(r.sz() == 2); - silent[r[0]] = r[1].to_bool(); - } - cerr <<")"; -} - - diff --git a/dstream.hh b/dstream.hh deleted file mode 100644 index 24673695f2..0000000000 --- a/dstream.hh +++ /dev/null @@ -1,37 +0,0 @@ -// debug_stream - -#ifndef DSTREAM_HH -#define DSTREAM_HH - -#include "string.hh" -#include "assoc.hh" - -const char eol= '\n'; - -/// debug stream -class Dstream -{ - ostream *os; - int indentlvl; - Assoc silent; - bool local_silence; - String classname; - /// indent of each level - const INDTAB = 3; - -public: - Dstream(ostream &r, const char * = 0); - Dstream &identify_as(String s); - void switch_output(String s,bool); - Dstream &operator << (String s); -}; - /** - a class for providing debug output of nested structures, - with indents according to \{\}()[]. - - Using identify_as() one can turn on and off specific messages. Init - for these can be given in a rc file - - */ -#endif - diff --git a/main.cc b/main.cc index 3758840ac6..2145331565 100644 --- a/main.cc +++ b/main.cc @@ -1,26 +1,41 @@ #include +#include #include "lgetopt.hh" #include "misc.hh" -#include "debug.hh" -#include "score.hh" -#include "globvars.hh" +#include "string.hh" +#include "main.hh" extern void parse_file(String s); -Score *the_score =0; long_option_init theopts[] = { - 1, "debug", 'd', 1, "output", 'o', + 0, "warranty", 'w', 0,0,0 }; -String outfn="lelie.uit"; - -void -set_output(String s) +void notice() { - outfn = s; + cout << + "LilyPond, a music typesetter. +Copyright (C) 1996 by + Han-Wen Nienhuys + + + This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License version 2 +as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + + You should have received a copy (refer to the file COPYING) of the +GNU General Public License along with this program; if not, write to +the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, +USA. +" } int @@ -28,16 +43,16 @@ main (int argc, char **argv) { Getopt_long oparser(argc, argv,theopts); - cout << get_version() - << "copyright 1996 Han-Wen Nienhuys\n"; + cout << get_version(); while (long_option_init * opt = oparser()) { switch ( opt->shortname){ - case 'd': - set_debug(oparser.optarg); - break; case 'o': - set_output(oparser.optarg); + set_default_output(oparser.optarg); + break; + case 'w': + notice(); + exit(0); break; default: assert(false); @@ -49,6 +64,6 @@ main (int argc, char **argv) if (!arg) arg = ""; parse_file(arg); - the_score->process(); - the_score->output(outfn); + do_scores(); + exit (0); } diff --git a/matrix.cc b/matrix.cc deleted file mode 100644 index ab59a87308..0000000000 --- a/matrix.cc +++ /dev/null @@ -1,281 +0,0 @@ -#include "matrix.hh" -#include "string.hh" - - -Real -Matrix::norm() const -{ - Real r =0.0; - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - r += sqr(dat->elem(i,j)); - return sqrt(r); -} - -//inline -Real -Matrix::operator()(int i,int j) const -{ - assert(i >= 0 && j >= 0); - assert(i < rows() && j < cols()); - return dat->elem(i,j); -} - -//inline -Real & -Matrix::operator()(int i, int j) -{ - assert(i >= 0 && j >= 0); - assert(i < rows() && j < cols()); - return dat->elem(i,j); -} - -void -Matrix::fill(Real r) -{ - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - dat->elem(i,j)=r; -} - -void -Matrix::set_diag(Real r) -{ - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - dat->elem(i,j)=(i==j) ? r: 0.0; -} - -void -Matrix::set_diag(Vector d) -{ - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - dat->elem(i,j)=(i==j) ? d(i): 0.0; -} - -void -Matrix::operator+=(const Matrix&m) -{ - assert(m.cols() == cols()); - assert(m.rows() == rows()); - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - dat->elem(i,j) += m(i,j); -} - -void -Matrix::operator-=(const Matrix&m) -{ - assert(m.cols() == cols()); - assert(m.rows() == rows()); - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - dat->elem(i,j) -= m(i,j); -} - - -void -Matrix::operator*=(Real a) -{ - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - dat->elem(i,j) *= a; -} - -void -Matrix::operator=(const Matrix&m) -{ - if (&m == this) - return ; - delete dat; - dat = m.dat->clone(); -} - -Matrix::Matrix(const Matrix &m) -{ - m.OK(); - - dat = m.dat->clone(); -} - - -Matrix::Matrix(int n, int m) -{ - dat = virtual_smat::get_full(n,m); - fill(0); -} - -Matrix::Matrix(int n) -{ - dat = virtual_smat::get_full(n,n); - fill(0); -} - -Matrix::Matrix(Vector v, Vector w) -{ - dat = virtual_smat::get_full(v.dim(), w.dim()); - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - dat->elem(i,j)=v(i)*w(j); -} - - -Vector -Matrix::row(int k) const -{ - int n=cols(); - - - Vector v(n); - for(int i=0; i < n; i++) - v(i)=dat->elem(k,i); - - return v; -} - -Vector -Matrix::col(int k) const -{ - int n=rows(); - Vector v(n); - for(int i=0; i < n; i++) - v(i)=dat->elem(i,k); - return v; -} - -Vector -Matrix::left_multiply(const Vector& v) const -{ - Vector dest(v.dim()); - assert(dat->cols()==v.dim()); - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - dest(i)+= dat->elem(j,i)*v(j); - return dest; -} - -Vector -Matrix::operator *(const Vector& v) const -{ - Vector dest(rows()); - assert(dat->cols()==v.dim()); - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) - dest(i)+= dat->elem(i,j)*v(j); - return dest; -} - -Matrix -operator /(Matrix const& m1,Real a) -{ - Matrix m(m1); - m /= a; - return m; -} - -void -Matrix::transpose() // delegate to storage? -{ - for (int i=0, j=0; dat->mult_ok(i,j); dat->mult_next(i,j)) { - if (i >= j) - continue; - Real r=dat->elem(i,j); - dat->elem(i,j) = dat->elem(j,i); - dat->elem(j,i)=r; - } -} - -Matrix -Matrix::operator-() const -{ - OK(); - Matrix m(*this); - m*=-1.0; - return m; -} - -Matrix -Matrix::transposed() const -{ - Matrix m(*this); - m.transpose(); - return m; -} - - -/* should do something smarter: bandmatrix * bandmatrix is also banded matrix. */ -Matrix -operator *(const Matrix &m1, const Matrix &m2) -{ - Matrix result(m1.rows(), m2.cols()); - result.set_product(m1,m2); - return result; -} - -void -Matrix::set_product(const Matrix &m1, const Matrix &m2) -{ - assert(m1.cols()==m2.rows()); - assert(cols()==m2.cols() && rows()==m1.rows()); - - for (int i=0, j=0; dat->mult_ok(i,j); - dat->mult_next(i,j)) { - Real r=0.0; - for (int k = 0; k < m1.cols(); k++) - r += m1(i,k)*m2(k,j); - dat->elem(i,j)=r; - } -} - -void -Matrix::insert_row(Vector v, int k) -{ - assert(v.dim()==cols()); - dat->insert_row(k); - for (int j=0; j < cols(); j++) - dat->elem(k,j)=v(j); -} - - -void -Matrix::swap_columns(int c1, int c2) -{ - assert(c1>=0&& c1 < cols()&&c2 < cols() && c2 >=0); - for (int i=0; i< rows(); i++) { - Real r=dat->elem(i,c1); - dat->elem(i,c1) = dat->elem(i,c2); - dat->elem(i,c2)=r; - } -} - -void -Matrix::swap_rows(int c1, int c2) -{ - assert(c1>=0&& c1 < rows()&&c2 < rows() && c2 >=0); - for (int i=0; i< cols(); i++) { - Real r=dat->elem(c1,i); - dat->elem(c1,i) = dat->elem(c2,i); - dat->elem(c2,i)=r; - } -} - - -int -Matrix::dim() const -{ - assert(cols() == rows()); - return rows(); -} - -Matrix::operator String() const -{ - String s("matrix {\n"); - for (int i=0; i< rows(); i++){ - for (int j = 0; j < cols(); j++) { - s+= String(dat->elem(i,j), "%6f "); - } - s+="\n"; - } - s+="}\n"; - return s; -} - - - -#include "debug.hh" -void -Matrix::print() const -{ - mtor << *this; -} diff --git a/matrix.hh b/matrix.hh deleted file mode 100644 index e092a5fbe6..0000000000 --- a/matrix.hh +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef MATRIX_HH -#define MATRIX_HH - - -#include "vsmat.hh" -#include "vector.hh" - -/// a Real matrix -class Matrix { - virtual_smat *dat; - -public: - void OK() const { dat->OK(); } - int cols() const { return dat->cols(); } - int rows() const { return dat->rows(); } - - /// return the size of a matrix - int dim() const; - /** - PRE - the matrix needs to be square. - */ - - // Matrix() { dat = 0; } - ~Matrix() { delete dat; } - - /// set entries to r - void fill(Real r); - - /// set diagonal to d - void set_diag(Real d); - - void set_diag(Vector d); - /// set unit matrix - void unit() { set_diag(1.0); } - - void operator+=(const Matrix&m); - void operator-=(const Matrix&m); - void operator*=(Real a); - void operator/=(Real a) { (*this) *= 1/a; } - - /// add a row - void insert_row(Vector v,int k); - /** - add a row to the matrix before row k - - PRE - v.dim() == cols() - 0 <= k <= rows() - */ - /// - void delete_row(int k) { dat->delete_row(k); } - /** - delete a row from this matrix. - - PRE - 0 <= k < rows(); - */ - void delete_column(int k) { dat->delete_column(k); } - /// - Matrix(int n); - /** - square n matrix, initialised to null - */ - /// - Matrix(int n, int m); - /** - n x m matrix, init to 0 - */ - Matrix(const Matrix &m); - - /// dyadic product: v * w.transpose - Matrix(Vector v, Vector w); - void operator=(const Matrix&m); - - /// access an element - Real operator()(int i,int j) const; - - /// access an element - Real &operator()(int i, int j); - - /// Matrix multiply with vec (from right) - Vector operator *(const Vector &v) const; - - /// set this to m1*m2. - void set_product(const Matrix &m1, const Matrix &m2); - - - Vector left_multiply(Vector const &) const; - - Matrix operator-() const; - - /// transpose this. - void transpose(); - - /// return a transposed copy. - Matrix transposed() const ; - - Real norm() const; - /// swap - void swap_columns(int c1, int c2); - /** - PRE - 0 <= c1,c2 < cols() - */ - - /// swap - void swap_rows(int c1, int c2); - /** - PRE - 0 <= c1,c2 < rows() - */ - - - Vector row(int ) const; - Vector col(int) const; - - operator String() const; - void print() const; -}; - -/** This is a class for a nonsquare block of #Real#s. The - implementation of sparse matrices is done in the appropriate #smat# - class. Matrix only does the mathematical actions (adding, - multiplying, etc.) - - - TODO - implement ref counting? */ - - -inline Vector -operator *(Vector &v, const Matrix& m) { return m.left_multiply(v); } -Matrix operator *(const Matrix& m1,const Matrix &m2); -Matrix operator /(const Matrix &m1,Real a); -inline Matrix operator -(Matrix m1,const Matrix m2) -{ - m1 -= m2; - return m1; -} -#endif diff --git a/real.hh b/real.hh deleted file mode 100644 index 1f2187c8c1..0000000000 --- a/real.hh +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef REAL_HH -#define REAL_HH -typedef double Real; -inline Real sqr(Real x){ - return x*x; -} -inline Real MIN(Real x, Real y) { - return (x < y)? x : y; -} - -inline Real MAX(Real x, Real y) { - return (x > y) ? x : y; -} - -inline Real ABS(Real x) -{ - return (x>0)? x:-x; -} -inline -int sgn(Real x) { - if (!x)return 0; - return (x > 0) ?1: -1; -} - -#endif diff --git a/smat.cc b/smat.cc deleted file mode 100644 index 3830fd6825..0000000000 --- a/smat.cc +++ /dev/null @@ -1,187 +0,0 @@ -#include "smat.hh" - -void -Full_storage::operator=(Full_storage const &fs) -{ - resize(fs.h, fs.w); - OK(); - fs.OK(); - for (int i=0; i= h && maxw >= w); - assert(h >= 0 && w >= 0); - assert(els||!maxh); - if (maxh>0) { // access outer elts. - Real *r = els[maxh -1]; - if (maxw>0) { - assert(r); - Real s = r[maxw -1]; - s = sin(s); - } - } -} -void -Full_storage::resize_cols(int newh) -{ - if (newh <= maxh) { - h=newh; - return; - } - - Real ** newa=new Real*[newh]; - int j=0; - for (; j < h; j++) - newa[j] = els[j]; - for (; j < newh; j++) - newa[j] = new Real[maxw]; - delete[] els; - els=newa; - - h = maxh = newh; -} - -void -Full_storage::resize_rows(int neww) -{ - if (neww <= maxw) { - w=neww; - return; - } - for (int i=0; i < maxh ; i++) { - Real* newa=new Real[neww]; - for (int k=0; k < w; k++) - newa[k] = els[i][k]; - - delete[] els[i]; - els[i] = newa; - } - w = maxw = neww; -} - -Full_storage::~Full_storage() { - for (int i=0; i < maxh; i++) - delete [] els[i]; - delete[] els; -} - -void -Full_storage::resize(int rows, int cols) -{ - OK(); - resize_cols(rows); - resize_rows(cols); - -} - - -bool -Full_storage::mult_ok(int i, int j) const -{ - return valid(i,j); -} - -bool -Full_storage::trans_ok(int i, int j) const -{ - return valid(i,j); -} - - -void -Full_storage::trans_next(int &i, int &j) const -{ - assert(trans_ok(i,j)); - i++; - if (i >= h) { - i=0; - j ++; - } -} - -void -Full_storage::mult_next(int &i, int &j) const -{ - assert(mult_ok(i,j)); - j++; - if (j >= w) { - j=0; - i++; - } -} - -void -Full_storage::delete_column(int k) -{ - assert(0 <= k &&k k ; i--) - for (int j=0; j -Full_storage::row(int n) const -{ - svec r; - for (int j = 0; j < w; j++) - r.add(els[n][j]); - return r; -} - -svec -Full_storage::column(int n) const -{ - - svec r; - for (int i = 0; i=0 && i < h) - && (j < w && j >=0); - } - - - void resize_rows(int); - void resize_cols(int); - -public: - virtual int rows() const { - return h; - } - virtual int cols() const { - return w; - } - - - virtual void set_size(int i, int j) - { - resize(i,j); //this could be more efficient. - } - - virtual void set_size(int i) { - set_size(i,i); - } - virtual void resize(int i, int j); - virtual void resize(int i) { - resize(i,i); - } - - virtual Real& elem(int i,int j) { - assert(valid(i,j)); - return els[i][j]; - } - virtual const Real& elem(int i, int j) const { - assert(valid(i,j)); - return els[i][j]; - } - virtual svec row(int i) const; - virtual svec column(int j) const; - - Full_storage() { - init(); - } - Full_storage(int i, int j) { - init(); - set_size(i,j); - } - Full_storage(Full_storage&); - Full_storage(int i) { - init(); - set_size(i); - } - void OK() const; - void operator=(Full_storage const &); - - virtual void insert_row(int k); - virtual void delete_row(int k); - virtual void delete_column(int k); - - - ~Full_storage(); - virtual bool mult_ok(int i, int j)const; - virtual void mult_next(int &i, int &j) const ; - virtual bool trans_ok(int i, int j) const; - virtual void trans_next(int &i, int &j) const; - virtual virtual_smat * clone(); -}; - -#endif diff --git a/template.cc b/template.cc deleted file mode 100644 index f0260b5edc..0000000000 --- a/template.cc +++ /dev/null @@ -1,26 +0,0 @@ -#include "line.hh" - -#include "list.hh" -#include "cols.hh" -#include "item.hh" -#include "request.hh" -#include "score.hh" -#include "command.hh" -#include "staff.hh" - -#include "list.cc" -#include "cursor.cc" - - -PL_instantiate(Line_of_score); -PL_instantiate(Line_of_staff); -PL_instantiate(Item); -PL_instantiate(Spanner); -PL_instantiate(PStaff); -PL_instantiate(Idealspacing); -PL_instantiate(PCol); -PL_instantiate(Command); -PL_instantiate(Request); -PL_instantiate(Score_column); - - diff --git a/vector.cc b/vector.cc deleted file mode 100644 index be2423250d..0000000000 --- a/vector.cc +++ /dev/null @@ -1,41 +0,0 @@ -#include "debug.hh" -#include "vector.hh" -#include "string.hh" - -Vector::Vector(const Vector&n) - :dat(n.dat) - // this makes GCC 272 barf -{ - //dat = n.dat; -} - -Vector::operator String() const -{ - int i=0; - String s("vector ["); - for (; i < dim(); i++) { - s += String(dat[i], "%6f") + ' '; - } - s+="]"; - return s; -} - - -void -Vector::print() const -{ - mtor << *this<<'\n'; -} - -Vector -Vector::operator-() const -{ - Vector v(*this); v*=-1; return v; -} - -void -Vector::set_unit(int j) -{ - fill(0.0); - dat[j] = 1.0; -} diff --git a/vector.hh b/vector.hh deleted file mode 100644 index 5be792c54b..0000000000 --- a/vector.hh +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef VECTOR_HH -#define VECTOR_HH - -#include "glob.hh" -#include "vray.hh" - -/// a row of numbers -class Vector { - svec dat; -public: - void OK() const { dat.OK();} - int dim() const { return dat.sz(); } - Vector() { } - Vector(const Vector&n); - Vector(int n) { - dat.set_size(n); - fill(0); - } - void insert(Real v, int i) { - dat.insert(v,i); - } - void del(int i) { dat.del(i); } - operator String() const; - void fill(Real r) { - for (int i=0; i < dim(); i++) - dat[i] =r; - } - - void operator +=(Vector v) { - assert(v.dim() == dim()); - for (int i=0; i < dim(); i++) - dat[i] += v.dat[i]; - } - - void operator /=(Real a) { - (*this) *= 1/a; - } - - void operator *=(Real a) { - for (int i=0; i < dim(); i++) - dat[i] *= a; - } - - void operator -=(Vector v) { - assert(v.dim() == dim()); - for (int i=0; i < dim(); i++) - dat[i] -= v(i); - } - - Real &operator()(int i) { return dat[i]; } - Real operator()(int i) const { return dat[i]; } - Real elem(int i) { return dat[i]; } - Real operator *(Vector v) const { - Real ip=0; - assert(v.dim() == dim()); - for (int i=0; i < dim(); i++) - ip += dat[i] *v(i); - return ip; - } - Vector operator-() const; - Real norm() { - return sqrt(norm_sq() ); - } - Real norm_sq() { - return ((*this) * (*this)); - } - operator svec () { return dat; } - void print() const; - /// set to j-th element of unit-base - void set_unit(int j) ; -}; -/** - a vector. Storage is handled in svec, Vector only does the mathematics. - */ - -inline Vector -operator+(Vector a, Vector const &b) { - a += b; - return a; -} - -inline Vector -operator-(Vector a, Vector const &b) { - a -= b; - return a; -} - -inline Vector -operator*(Vector v, Real a) { - v *= a; - return v; -} - -inline Vector -operator*( Real a,Vector v) { - v *= a; - return v; -} - -inline Vector -operator/(Vector v,Real a) { - v *= 1/a; - return v; -} - -#endif diff --git a/vsmat.hh b/vsmat.hh deleted file mode 100644 index 4e1ea797b6..0000000000 --- a/vsmat.hh +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef VSMAT_HH -#define VSMAT_HH -#include "vray.hh" -#include "real.hh" -/// a matrix storage baseclass. -class virtual_smat { - - -public: - /// check invariants - virtual void OK() const=0; - - /// height of matrix - virtual int rows() const = 0; - - /// width of matrix - virtual int cols() const = 0; - - /// set the size. contents lost - virtual void set_size(int i, int j) = 0; - /** - PRE - i >=0, j>=0 - */ - - /// set the size to square dimen. contents lost - virtual void set_size(int i) = 0; - /** - PRE - i>=0 - */ - /// set the size to i - virtual void resize(int i, int j) = 0; - /** - - keep contents. If enlarged contents unspecified - - PRE - i>=0, j>=0 - - */ - - /// set the size to square dimen. contents kept - virtual void resize(int i) = 0; - /** - Keep contents. If enlarged contents are unspecified - - PRE - i>=0 - */ - - /// access an element - virtual Real& elem(int i,int j) = 0; - /** - access an element. - - Generate an errormessage, if this happens - in the 0-part of a sparse matrix. - */ - - /// access a element, no modify - virtual const Real& elem(int i, int j) const = 0; - -#if 1 - virtual svec row(int i) const = 0; - virtual svec column(int j) const = 0; -#endif - - /// add a row - virtual void insert_row(int k)=0; - /** - add a row to the matrix before row k. Contents - of added row are unspecified - - 0 <= k <= rows() - */ - - /// delete a row - virtual void delete_row(int k)=0; - /** - delete a row from this matrix. - - PRE - 0 <= k < rows(); - */ - virtual void delete_column(int k)=0; - virtual ~virtual_smat() { } - virtual virtual_smat *clone()=0; - - - /// is there a next? - virtual bool mult_ok(int i, int j) const=0; - /** - at end of matrix? when doing loop - - for(i=0; i