package jsci.maths.matrices;

import jsci.GlobalSettings;
import jsci.maths.DimensionException;
import jsci.maths.Mapping;
import jsci.maths.vectors.AbstractDoubleVector;
import jsci.maths.vectors.DoubleVector;

/**
* The DoubleSparseMatrix class provides an object for encapsulating sparse matrices.
* Uses compressed row storage.
* @version 1.2
* @author Mark Hale
*/
public final class DoubleSparseMatrix extends AbstractDoubleMatrix {
        /**
        * Matrix elements.
        */
        private double elements[];
        /**
        * Sparse indexing data.
        * Contains the column positions of each element,
        * e.g. colPos[n] is the column position
        * of the nth element.
        */
        private int colPos[];
        /**
        * Sparse indexing data.
        * Contains the indices of the start of each row,
        * e.g. rows[i] is the index
        * where the ith row starts.
        */
        private int rows[];
        /**
        * Constructs an empty matrix.
        * @param rowCount the number of rows
        * @param colCount the number of columns
        */
        public DoubleSparseMatrix(final int rowCount, final int colCount) {
                super(rowCount, colCount);
                elements=new double[0];
                colPos=new int[0];
                rows=new int[numRows+1];
        }
        /**
        * Constructs a matrix from an array.
        * @param array an assigned value
        */
        public DoubleSparseMatrix(final double array[][]) {
                super(array.length,array[0].length);
                rows=new int[numRows+1];
                int n=0;
                for(int i=0;iGlobalSettings.ZERO_TOL)
                                        n++;
                        }
                }
                elements=new double[n];
                colPos=new int[n];
                n=0;
                for(int i=0;iGlobalSettings.ZERO_TOL) {
                                        elements[n]=array[i][j];
                                        colPos[n]=j;
                                        n++;
                                }
                        }
                }
                rows[numRows]=n;
        }
        /**
        * Compares two double sparse matrices for equality.
        * @param m a double matrix
        */
        public boolean equals(AbstractDoubleMatrix m, double tol) {
                if(numRows==m.numRows && numCols==m.numCols) {
                        if(m instanceof DoubleSparseMatrix) {
                                return this.equals((DoubleSparseMatrix)m);
                        } else {
        			double sumSqr = 0;
                                for(int i=0;i=0 && i=0 && j=0 && i=0 && jinfinity-norm.
        */
        public double infNorm() {
                double result=0.0,tmpResult;
                for(int i=0;iresult)
                                result=tmpResult;
                }
                return result;
        }
        /**
        * Returns the Frobenius (l2) norm.
        */
        public double frobeniusNorm() {
                double result=0.0;
                for(int i=0;i 

Ads help maintain this website.