Mercurial > hg > jslab
view src/samer/maths/MatrixTimesVector.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
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; } } }