Index: lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java diff -u lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java:1.6 lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java:1.7 --- lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java:1.6 Thu Oct 20 20:58:04 2005 +++ lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java Fri Jan 13 16:55:30 2006 @@ -23,20 +23,23 @@ * Created: 29 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * - * Mise a jour: $Date: 2005/10/20 20:58:04 $ + * Mise a jour: $Date: 2006/01/13 16:55:30 $ * par : $Author: bpoussin $ */ package org.codelutin.math.matrix; -import org.codelutin.util.ArrayUtil; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.apache.commons.collections.primitives.ArrayIntList; +import org.apache.commons.lang.math.NumberUtils; +import org.codelutin.util.ArrayUtil; + public abstract class AbstractMatrixND implements MatrixND { // AbstractMatrixND abstract public MatrixIterator iterator(); @@ -269,6 +272,54 @@ result.append("\n]\n"); return result.toString(); } + + public List toList() { + List result = new ArrayList(); + // [3,2,5,4] + for(MatrixIterator i=iterator(); i.next();){ + int [] coord = i.getCoordinates(); + double value = i.getValue(); + List tmp = result; + for(int dim=0; dim - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * - * Mise a jour: $Date: 2005/10/20 20:58:04 $ + * Mise a jour: $Date: 2006/01/13 16:55:30 $ * par : $Author: bpoussin $ */ package org.codelutin.math.matrix; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.io.IOException; +import java.io.StreamTokenizer; import java.io.StringReader; import java.io.StringWriter; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; import java.util.NoSuchElementException; import org.codelutin.xml.XMLEncoderDecoder; -public class MatrixHelper { // MatrixHelper +public class MatrixHelper { + + /** + * Logger for this class + */ + private static final Log log = LogFactory.getLog(MatrixHelper.class); + // MatrixHelper static { XMLEncoderDecoder.registerType(MatrixND.class, new MatrixXMLDelegator()); } + + /** + * Permet de relire une chaine du type [[[1, 2], [3, 4]],[[3, 5], [1, 4]]] + * @param s la chaine representant les listes de liste + * @return une liste de liste ... de Double + */ + static public List convertStringToList(String s) { + List result = null; + Stack stack = new Stack(); + double value = 0; + StreamTokenizer tok = new StreamTokenizer(new StringReader(s)); + try { + int v = tok.nextToken(); + while (v != StreamTokenizer.TT_EOF) { + if (v == '[') { + stack.push(new ArrayList()); + } else if (v == ']'){ + List current = stack.pop(); + if (stack.empty()) { + result = current; + } else { + stack.peek().add(current); + } + } else if (v == StreamTokenizer.TT_NUMBER) { + value = tok.nval; + stack.peek().add(value); + } + v = tok.nextToken(); + } + } catch (IOException eee) { + if (log.isWarnEnabled()) { + log.warn("Read from String this exception must be never throw", eee); + } + } + return result; + } + /** * permet de donner une représentation String d'un tableau de coordonnées * @param coordinates les coordonnées Index: lutinmatrix/src/java/org/codelutin/math/matrix/MatrixND.java diff -u lutinmatrix/src/java/org/codelutin/math/matrix/MatrixND.java:1.5 lutinmatrix/src/java/org/codelutin/math/matrix/MatrixND.java:1.6 --- lutinmatrix/src/java/org/codelutin/math/matrix/MatrixND.java:1.5 Thu Oct 20 20:58:04 2005 +++ lutinmatrix/src/java/org/codelutin/math/matrix/MatrixND.java Fri Jan 13 16:55:30 2006 @@ -23,9 +23,9 @@ * Created: 29 oct. 2004 * * @author Benjamin Poussin -* @version $Revision: 1.5 $ +* @version $Revision: 1.6 $ * -* Mise a jour: $Date: 2005/10/20 20:58:04 $ +* Mise a jour: $Date: 2006/01/13 16:55:30 $ * par : $Author: bpoussin $ */ @@ -474,6 +474,19 @@ * Multiplication d'une matrice par un scalaire */ public MatrixND divs(final double d); + + /** + * Donne la matrice sous forme de List de list ... de double + * @return + */ + public List toList(); + + /** + * Permet de charger une matrice a partir d'une representation List + * @param list la matrice sous forme de List de list ... de double + */ + public void fromList(List list); + // /** // * Multiplication d'une vecteur [i] avec une matrice [i,j], // * le resultat est result[i,j]=matrice[i,j]*vecteur[i]