samer@0: /* samer@0: * Copyright (c) 2002, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.maths; samer@0: samer@0: public class SparseMatrix { samer@0: int max, n; // number of elements samer@0: int[] i, j; // element indices samer@0: double[] x; // element values samer@0: samer@0: public SparseMatrix(String name) {} samer@0: public SparseMatrix(String name, SparseMatrix mask) { samer@0: n=mask.n; samer@0: i=(int[])mask.i.clone(); samer@0: j=(int[])mask.j.clone(); samer@0: x=new double[n]; samer@0: } samer@0: samer@0: /** allocate space for E elements and remove all elements */ samer@0: public void allocate(int E) { samer@0: this.max=E; n=0; samer@0: i=new int[E]; samer@0: j=new int[E]; samer@0: x=new double[E]; samer@0: } samer@0: samer@0: /** add a new element to list. (Must be room for it) */ samer@0: public void addElement( int i, int j, double x) { samer@0: this.i[n]=i; samer@0: this.j[n]=j; samer@0: this.x[n]=x; samer@0: n++; samer@0: } samer@0: samer@0: public void times(double [] out, double [] in) { samer@0: Mathx.zero(out); samer@0: for (int k=0; k