KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > vectorJep > function > MUMinus


1 /* @author rich
2  * Created on 27-Jul-2003
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.vectorJep.function;
9 import org.lsmp.djep.vectorJep.*;
10 import org.lsmp.djep.vectorJep.values.*;
11 import org.nfunk.jep.*;
12 import org.nfunk.jep.function.UMinus;
13 /**
14  * An extension of the Subtract command to allow it to add MVector's and Matrix's.
15  * @author Rich Morris
16  * Created on 27-Jul-2003
17  */

18 public class MUMinus extends UMinus implements UnaryOperatorI {
19
20     public Dimensions calcDim(Dimensions ldim)
21     {
22         return ldim;
23     }
24
25     /** calculates the value.
26      * @param res - results will be stored in this object
27      * @param lhs - lhs value
28      * @param rhs - rhs value
29      * @return res
30      */

31     public MatrixValueI calcValue(MatrixValueI res,MatrixValueI lhs) throws ParseException
32     {
33         int len = res.getNumEles();
34         for(int i=0;i<len;++i)
35             res.setEle(i,super.umin(lhs.getEle(i)));
36         return res;
37     }
38
39
40     /**
41      * Negate an objects.
42      */

43     
44     public Object JavaDoc umin(Object JavaDoc param1) throws ParseException
45     {
46         if(param1 instanceof MVector)
47             return umin((MVector) param1);
48         if(param1 instanceof Matrix)
49             return umin((Matrix) param1);
50         else
51             return super.umin(param1);
52     }
53     
54     /** negate a vector. */
55     public MVector umin(MVector lhs) throws ParseException
56     {
57         MVector res = new MVector(lhs.getNumEles());
58         return (MVector) calcValue(res,lhs);
59     }
60
61     /** negate a matrix. */
62     public Matrix umin(Matrix lhs) throws ParseException
63     {
64         Matrix res = new Matrix(lhs.getNumRows(),lhs.getNumCols());
65         return (Matrix) calcValue(res,lhs);
66     }
67
68     /** negate a tensor. */
69     public Tensor umin(Tensor lhs) throws ParseException
70     {
71         Tensor res = new Tensor(lhs);
72         return (Tensor) calcValue(res,lhs);
73     }
74 }
75
Popular Tags