KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > matrixJep > function > MList


1 /*****************************************************************************
2
3 JEP - Java Math Expression Parser 2.3.0
4       October 3 2004
5       (c) Copyright 2004, Nathan Funk and Richard Morris
6       See LICENSE.txt for license information.
7
8 *****************************************************************************/

9
10 package org.lsmp.djep.matrixJep.function;
11
12 import org.nfunk.jep.*;
13 import org.lsmp.djep.vectorJep.values.*;
14 import org.lsmp.djep.vectorJep.function.*;
15 import org.lsmp.djep.matrixJep.nodeTypes.*;
16 import org.lsmp.djep.xjep.*;
17 //import org.lsmp.djep.matrixJep.nodeTypes.*;
18

19 /**
20  * A enhanced version of list, allows matricies and tensors.
21  *
22  * @author Rich Morris
23  * Created on 27-Nov-2003
24  */

25 public class MList extends VList
26     implements PrintVisitor.PrintRulesI,NaryOperatorI
27 {
28     public MList()
29     {
30         numberOfParameters = -1;
31     }
32
33     public MatrixValueI calcValue(MatrixValueI res,
34         MatrixValueI inputs[]) throws ParseException
35     {
36         int eleSize = inputs[0].getNumEles();
37         for(int i=0;i<inputs.length;++i)
38         {
39             for(int j=0;j<eleSize;++j)
40             {
41                 res.setEle(i*eleSize+j,inputs[i].getEle(j));
42             }
43         }
44         return res;
45     }
46     
47     
48     int curEle;
49     /** recursive procedure to print the tensor with lots of brackets. **/
50     protected void bufferAppend(MatrixNodeI node,PrintVisitor pv,int currank) throws ParseException
51     {
52         pv.append("[");
53         if(currank+1 >= node.getDim().rank())
54         {
55             // bottom of tree
56
for(int i=0;i<node.getDim().getIthDim(currank);++i)
57             {
58                 if(i!=0) pv.append(",");
59                 node.jjtGetChild(curEle++).jjtAccept(pv,null);
60             }
61         }
62         else
63         {
64             // not bottom of tree
65
for(int i=0;i<node.getDim().getIthDim(currank);++i)
66             {
67                 if(i!=0) pv.append(",");
68                 bufferAppend(node,pv,currank+1);
69             }
70         }
71         pv.append("]");
72     }
73
74     /**
75      * Used to print the TensorNode with all its children.
76      * Method implements PrintVisitor.PrintRulesI.
77      */

78     public void append(Node node,PrintVisitor pv) throws ParseException
79     {
80         curEle = 0;
81         bufferAppend((MatrixNodeI) node,pv,0);
82     }
83
84 }
85
Popular Tags