Mercurial > hg > jslab
view src/samer/maths/MatrixTimesVector.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line source
/* * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.maths; import samer.tools.*; public class MatrixTimesVector extends VectorFunctionOfVector implements SafeTask { int m, n; double [][] a; double [] x, y, arow; public MatrixTimesVector( Vec out, Matrix matrix, Vec in) { this(out.array(),matrix,in.array()); } public MatrixTimesVector(Matrix matrix) { n = matrix.getRowDimension(); m = matrix.getColumnDimension(); a = matrix.getArray(); } public MatrixTimesVector( double [] out, Matrix matrix) { n = matrix.getRowDimension(); m = matrix.getColumnDimension(); a = matrix.getArray(); y = out; } public MatrixTimesVector( double [] out, Matrix matrix, double [] in) { n = matrix.getRowDimension(); m = matrix.getColumnDimension(); a = matrix.getArray(); x = in; y = out; } public void dispose() {} public void starting() {} public void stopping() {} public void run() { for (int i=0; i<n; i++) { double t=0; arow=a[i]; for (int j=0; j<m; j++) t+=arow[j]*x[j]; y[i]=t; } } public void apply(double [] x, double [] y) { for (int i=0; i<n; i++) { double t=0; arow=a[i]; for (int j=0; j<m; j++) t+=arow[j]*x[j]; y[i]=t; } } }