samer@0: /* samer@0: * Copyright (c) 2000, 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: import samer.core.*; samer@0: import samer.tools.*; samer@0: import java.util.*; samer@0: samer@0: samer@0: /** samer@0: An agent which allows the creation of vectors and samer@0: matrices, and can also arrange for them to be samer@0: multiplied as part of the current task list samer@0: */ samer@0: samer@0: public class Ops samer@0: { samer@0: public static Task update(final Viewable v) { samer@0: return new AnonymousTask() { public void run() { v.changed(); } }; samer@0: } samer@0: samer@0: public static Task times(VVector out, Matrix A, VVector x) { samer@0: return new MatrixTimesVector(out,A,x); samer@0: } samer@0: samer@0: // copy as much as possible from one vector to another samer@0: public static Task transfer(final Vec in, final Vec out) { samer@0: final int len=Math.min(in.size(),out.size()); samer@0: double src[]=in.array(); samer@0: samer@0: if (src!=null) return new ArrayCopy(src,0,out.array(),0,len); samer@0: else return new IteratorCopy(in,out,len); samer@0: } samer@0: samer@0: // copy a given range from one vector to another samer@0: public static Task transfer( samer@0: final Vec in, int inpos, final Vec out, int outpos, int len) samer@0: { samer@0: return new ArrayCopy(in.array(),inpos,out.array(),outpos,len); samer@0: } samer@0: samer@0: // copy a listed elements to another vector samer@0: public static Task transfer(final Vec in, final Vec out, final int[] elements) { samer@0: return new AnonymousTask() { samer@0: double [] dst=out.array(); samer@0: double [] src=in.array(); samer@0: int N=elements.length; samer@0: public void run() { samer@0: for (int i=0; i