Index: lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java diff -u lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java:1.13 lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java:1.14 --- lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java:1.13 Tue Jun 6 07:32:22 2006 +++ lutinmatrix/src/java/org/codelutin/math/matrix/AbstractMatrixND.java Fri Aug 11 09:29:48 2006 @@ -23,10 +23,10 @@ * Created: 29 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.13 $ + * @version $Revision: 1.14 $ * - * Mise a jour: $Date: 2006/06/06 07:32:22 $ - * par : $Author: ruchaud $ + * Mise a jour: $Date: 2006/08/11 09:29:48 $ + * par : $Author: bpoussin $ */ package org.codelutin.math.matrix; @@ -112,6 +112,22 @@ } } + /* (non-Javadoc) + * @see org.codelutin.math.matrix.MatrixND#copy() + */ + public MatrixND copy() { + MatrixND result = getFactory().create(this); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#clone() + */ + @Override + protected Object clone() throws CloneNotSupportedException { + return copy(); + } + /** * Retourne la factory utilisée pour créer cette matrice, la factory * peut-être réutilisé pour créer d'autre matrice si besoin. @@ -400,10 +416,12 @@ // et que origin est 0 // on doit pouvoir optimiser en appeler une methode paste // sur BasicMatrix qui l'appel sur le vector - for(MatrixIterator mi=mat.iterator(); mi.next();){ - int [] coordinates = ArrayUtil.sum(origin, mi.getCoordinates()); - if(isValidCoordinates(coordinates)){ - setValue(coordinates, mi.getValue()); + if (mat != null) { + for(MatrixIterator mi=mat.iterator(); mi.next();){ + int [] coordinates = ArrayUtil.sum(origin, mi.getCoordinates()); + if(isValidCoordinates(coordinates)){ + setValue(coordinates, mi.getValue()); + } } } return this; @@ -415,10 +433,12 @@ * dimension n'est pas trouvé, alors il est passé */ public MatrixND pasteSemantics(MatrixND mat){ - for(MatrixIterator mi=mat.iterator(); mi.next();){ - Object [] sems = mi.getSemanticsCoordinates(); - if(isValidCoordinates(sems)){ - setValue(sems, mi.getValue()); + if (mat != null) { + for(MatrixIterator mi=mat.iterator(); mi.next();){ + Object [] sems = mi.getSemanticsCoordinates(); + if(isValidCoordinates(sems)){ + setValue(sems, mi.getValue()); + } } } return this; Index: lutinmatrix/src/java/org/codelutin/math/matrix/BasicMatrix.java diff -u lutinmatrix/src/java/org/codelutin/math/matrix/BasicMatrix.java:1.5 lutinmatrix/src/java/org/codelutin/math/matrix/BasicMatrix.java:1.6 --- lutinmatrix/src/java/org/codelutin/math/matrix/BasicMatrix.java:1.5 Mon May 22 12:39:07 2006 +++ lutinmatrix/src/java/org/codelutin/math/matrix/BasicMatrix.java Fri Aug 11 09:29:48 2006 @@ -23,9 +23,9 @@ * Created: 27 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ * - * Mise a jour: $Date: 2006/05/22 12:39:07 $ + * Mise a jour: $Date: 2006/08/11 09:29:48 $ * par : $Author: bpoussin $ */ @@ -226,7 +226,7 @@ result = (0 <= pos[i]) && (pos[i] < dim[i]); } if(! result){ - throw new NoSuchElementException("L'élément demandé n'existe pas dans la matrice."); + throw new NoSuchElementException("L'élément demandé " + Arrays.toString(pos) + " n'existe pas dans la matrice " + Arrays.toString(dim)); } } Index: lutinmatrix/src/java/org/codelutin/math/matrix/MatrixDecoder.java diff -u lutinmatrix/src/java/org/codelutin/math/matrix/MatrixDecoder.java:1.2 lutinmatrix/src/java/org/codelutin/math/matrix/MatrixDecoder.java:1.3 --- lutinmatrix/src/java/org/codelutin/math/matrix/MatrixDecoder.java:1.2 Mon Jan 23 13:50:05 2006 +++ lutinmatrix/src/java/org/codelutin/math/matrix/MatrixDecoder.java Fri Aug 11 09:29:48 2006 @@ -23,9 +23,9 @@ * Created: 21 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Mise a jour: $Date: 2006/01/23 13:50:05 $ + * Mise a jour: $Date: 2006/08/11 09:29:48 $ * par : $Author: bpoussin $ */ @@ -81,9 +81,6 @@ Element root = doc.getRootElement(); if("matrix".equals(root.getName())){ - // recuperation du type de matrice - String type = root.attributeValue("type"); - Class clazz = Class.forName(type); // recuperation des dimensions de la matrice String [] dimensions = root.attributeValue("dimensions").split(","); Index: lutinmatrix/src/java/org/codelutin/math/matrix/MatrixHelper.java diff -u lutinmatrix/src/java/org/codelutin/math/matrix/MatrixHelper.java:1.8 lutinmatrix/src/java/org/codelutin/math/matrix/MatrixHelper.java:1.9 --- lutinmatrix/src/java/org/codelutin/math/matrix/MatrixHelper.java:1.8 Mon Jan 23 13:50:05 2006 +++ lutinmatrix/src/java/org/codelutin/math/matrix/MatrixHelper.java Fri Aug 11 09:29:48 2006 @@ -23,9 +23,9 @@ * Created: 28 oct. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * - * Mise a jour: $Date: 2006/01/23 13:50:05 $ + * Mise a jour: $Date: 2006/08/11 09:29:48 $ * par : $Author: bpoussin $ */ @@ -57,6 +57,25 @@ XMLEncoderDecoder.registerType(MatrixND.class, new MatrixXMLDelegator()); } + /** + * Convert Matrix to identity matrix must have 2 dimensions. If dimension + * haven't same length, then the small dimension is used. + * @param mat + * @return + */ + static public MatrixND convertToId(MatrixND mat) { + int size = mat.getDim(0); + if (size > mat.getDim(1)) { + size = mat.getDim(1); + } + + fill(mat, 0); + + for(int i=0; i -* @version $Revision: 1.9 $ +* @version $Revision: 1.10 $ * -* Mise a jour: $Date: 2006/06/01 17:38:56 $ -* par : $Author: ruchaud $ +* Mise a jour: $Date: 2006/08/11 09:29:48 $ +* par : $Author: bpoussin $ */ package org.codelutin.math.matrix; @@ -222,11 +222,12 @@ public void setValue(Object x, Object y, Object z, double d); public void setValue(Object x, Object y, Object z, Object t, double d); -// /** -// * Copy la matrice pour pouvoir la modifier sans perdre les -// * donnees initiales. -// */ -// public MatrixND copy(); + /** + * Copy la matrice pour pouvoir la modifier sans perdre les + * donnees initiales. + */ + public MatrixND copy(); + // public String toString(); // /** Index: lutinmatrix/src/java/org/codelutin/math/matrix/MatrixXMLDelegator.java diff -u lutinmatrix/src/java/org/codelutin/math/matrix/MatrixXMLDelegator.java:1.4 lutinmatrix/src/java/org/codelutin/math/matrix/MatrixXMLDelegator.java:1.5 --- lutinmatrix/src/java/org/codelutin/math/matrix/MatrixXMLDelegator.java:1.4 Thu Oct 27 12:28:10 2005 +++ lutinmatrix/src/java/org/codelutin/math/matrix/MatrixXMLDelegator.java Fri Aug 11 09:29:48 2006 @@ -23,14 +23,15 @@ * Created: 5 nov. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Mise a jour: $Date: 2005/10/27 12:28:10 $ + * Mise a jour: $Date: 2006/08/11 09:29:48 $ * par : $Author: bpoussin $ */ package org.codelutin.math.matrix; +import java.io.Writer; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -53,6 +54,11 @@ return CURRENT_VERSION; } + public Element encodeVersion(XMLEncoderDecoder ed, Object o, Writer writer){ + // FIXME write directly in writer to optimise memory usage + return encodeVersion(ed, o); + } + public Element encodeVersion(XMLEncoderDecoder ed, Object o){ MatrixND matrix = (MatrixND)o;