Nuiton-matrix-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- 560 discussions
[Lutinmatrix-commits] r125 - in lutinmatrix/trunk/src: main/java/org/codelutin/math/matrix test/java/org/codelutin/math/matrix
by chatellier@users.labs.libre-entreprise.org 04 Mar '09
by chatellier@users.labs.libre-entreprise.org 04 Mar '09
04 Mar '09
Author: chatellier
Date: 2009-03-04 10:29:44 +0000 (Wed, 04 Mar 2009)
New Revision: 125
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java
Log:
Specials chars on columns names \"
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java 2009-03-04 09:44:40 UTC (rev 124)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java 2009-03-04 10:29:44 UTC (rev 125)
@@ -25,6 +25,7 @@
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtilsBean;
+import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codelutin.util.StringUtil;
@@ -166,7 +167,7 @@
String result = "[";
String sep = "";
for (int i = 0; i < dimNamesArray.length; i++) {
- result += sep + '"' + dimNamesArray[i] + '"';
+ result += sep + '"' + StringEscapeUtils.escapeJava(dimNamesArray[i]) + '"';
sep = ", ";
}
result += "]";
@@ -188,7 +189,9 @@
for (int i = 0; i < result.length; i++) {
result[i] = result[i].trim();
if (result[i].startsWith("\"") && result[i].endsWith("\"")) {
- result[i] = result[i].substring(1, result[i].length() - 1); // remove " and "
+ String resultString = result[i].substring(1, result[i].length() - 1);// remove " and "
+ resultString = StringEscapeUtils.unescapeJava(resultString);
+ result[i] = resultString;
}
}
return result;
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java 2009-03-04 09:44:40 UTC (rev 124)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java 2009-03-04 10:29:44 UTC (rev 125)
@@ -142,5 +142,39 @@
Assert.assertEquals(2.345, matrix.getValue(1, 1), 0);
Assert.assertEquals(-8.321, matrix.getValue(1, 4), 0);
}
+
+ @Test
+ public void testMatrixNamesSpecialChars() {
+
+ MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
+ mat1.setValue(0, 0, 0, -1.0E-7);
+ mat1.setValue(1, 1, 0, 2);
+ mat1.setValue(2, 1, 0, 5.0E-7);
+ mat1.setDimensionNames(new String[]{"col \"1\", \"2\"","col \"3\", \"4\""});
+ String rep = stringEncoder.getMatrixAsString(mat1);
+
+ System.out.println(rep);
+
+ Assert.assertTrue("Null() semantics missing", rep.indexOf("null()") > 0);
+ Assert.assertTrue("Dimentation missing", rep.indexOf("3, 2, 1") > 0);
+ Assert.assertTrue("Data missing", rep.indexOf("[2.0]") > 0);
+ Assert.assertTrue("Wrong string encoding", rep.indexOf("\"col \\\"1\\\", \\\"2\\\"\", \"col \\\"3\\\", \\\"4\\\"\", \"\"") > 0);
+ }
+
+ @Test
+ public void testMatrixFromNamesSpecialChars() {
+ String representation = "[,[3, 2, 1],[\"col \\\"1\\\", \\\"2\\\"\", \"col \\\"3\\\", \\\"4\\\"\", \"\"],[[null(), null(), null()], [null(), null()], [null()]],[[[-1.0E-7], [0.0]], [[0.0], [2.0]], [[0.0], [5.0E-7]]]]";
+
+ MatrixND matrix = stringEncoder.getMatrixFromString(representation);
+
+ Assert.assertEquals(3, matrix.getDim()[0]);
+ Assert.assertEquals(2, matrix.getDim()[1]);
+ Assert.assertEquals(1, matrix.getDim()[2]);
+ Assert.assertEquals(-1.0E-7, matrix.getValue(0, 0, 0), 0);
+ Assert.assertEquals(2, matrix.getValue(1, 1, 0), 0);
+ Assert.assertEquals(5.0E-7, matrix.getValue(2, 1, 0), 0);
+ Assert.assertEquals("col \"1\", \"2\"", matrix.getDimensionNames()[0]);
+ Assert.assertEquals("col \"3\", \"4\"", matrix.getDimensionNames()[1]);
+ }
} // MatrixHelperTest
1
0
[Lutinmatrix-commits] r124 - lutinmatrix/trunk
by chatellier@users.labs.libre-entreprise.org 04 Mar '09
by chatellier@users.labs.libre-entreprise.org 04 Mar '09
04 Mar '09
Author: chatellier
Date: 2009-03-04 09:44:40 +0000 (Wed, 04 Mar 2009)
New Revision: 124
Modified:
lutinmatrix/trunk/pom.xml
Log:
Add beanutils dep.
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-03-04 09:42:17 UTC (rev 123)
+++ lutinmatrix/trunk/pom.xml 2009-03-04 09:44:40 UTC (rev 124)
@@ -31,6 +31,13 @@
<version>2.4</version>
<scope>compile</scope>
</dependency>
+
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.8.0</version>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>commons-primitives</groupId>
1
0
[Lutinmatrix-commits] r123 - in lutinmatrix/trunk: . src/main/java/org/codelutin/math/matrix src/test/java/org/codelutin/math/matrix
by chatellier@users.labs.libre-entreprise.org 04 Mar '09
by chatellier@users.labs.libre-entreprise.org 04 Mar '09
04 Mar '09
Author: chatellier
Date: 2009-03-04 09:42:17 +0000 (Wed, 04 Mar 2009)
New Revision: 123
Added:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java
Modified:
lutinmatrix/trunk/pom.xml
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java
Log:
Add matrix to string/from string convertion
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/pom.xml 2009-03-04 09:42:17 UTC (rev 123)
@@ -117,8 +117,19 @@
</plugin>
</plugins>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>cobertura-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
-
<!-- ************************************************************* -->
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -198,11 +198,33 @@
return name;
}
- public void setDimensionName(String[] names) {
+ public String[] getDimensionNames() {
+ return dimNames;
+ }
+
+ public void setDimensionNames(String[] names) {
for (int i = 0; names != null && i < names.length; i++) {
setDimensionName(i, names[i]);
}
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @deprecated Use #getDimensionNames()
+ */
+ public String[] getDimensionName() {
+ return getDimensionNames();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @deprecated Use #setDimensionName(String[])
+ */
+ public void setDimensionName(String[] names) {
+ setDimensionNames(names);
+ }
public void setDimensionName(int dim, String name) {
dimNames[dim] = name;
@@ -212,10 +234,6 @@
return dimNames[dim];
}
- public String[] getDimensionName() {
- return dimNames;
- }
-
public double getMaxOccurence() {
// on creer un tableau dans cette classe, car on ne sait pas sur quelle
// implantation on s'appuie. Mais dans les sous classes, si on a deja
@@ -513,7 +531,7 @@
// creation du resultat
MatrixND result = getFactory().create(getName(), semantics,
- getDimensionName());
+ getDimensionNames());
for (int i = 0; i < result.getDim(dim); i++) {
MatrixND temp = getSubMatrix(dim, i * step, step);
@@ -541,7 +559,7 @@
// creation du resultat
MatrixND result = getFactory().create(getName(), semantics,
- getDimensionName());
+ getDimensionNames());
MatrixND sub1 = this.getSubMatrix(dim, 0, start);
MatrixND sub2 = this.getSubMatrix(dim, start, nb).sumOverDim(dim);
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -35,165 +35,185 @@
*/
public class MatrixFactory { // MatrixFactory
- /*
- * following code in only an exception generator since lutinxml in not used
- * anymore :) static {
- * // on essai d'enregistrer le converter XML try { // Il faut le faire par
- * pur introspection sinon l'exception // NoClassDefFoundError est levé
- * avant d'entrer dans le constructeur // static :( Class converterClass =
- * Class .forName("org.codelutin.math.matrix.MatrixNDXMLConverter"); Object
- * converter = converterClass.newInstance();
- *
- * Class converterFactoryClass = Class
- * .forName("org.codelutin.xml.XMLConverterFactory"); Method m =
- * converterFactoryClass.getMethod("addConverter", Class.class, Class
- * .forName("org.codelutin.xml.XMLConverter")); m.invoke(null,
- * MatrixND.class, converter);
- * // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class, //
- * new MatrixNDXMLConverter()); log.info("Converter XML pour MatrixND
- * ajoute");
- * // on essai d'enregistrer le converter JDBC // le JDBC depend du XML try {
- * converterClass = Class
- * .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter"); converter =
- * converterClass.newInstance();
- *
- * converterFactoryClass = Class
- * .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
- * m = converterFactoryClass .getMethod( "addConverter", Class.class,
- * Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
- * m.invoke(null, MatrixND.class, converter);
- * // Class converterClass = //
- * org.codelutin.math.matrix.MatrixNDJDBCConverter(); //
- * JDBCTransformerFactory // .addConverter(MatrixND.class, new
- * MatrixNDJDBCConverter()); log.info("Converter JDBC pour MatrixND
- * ajoute"); } catch (Throwable eee) { log .info("librairie topia non
- * presente. Import/Export JDBC impossible"); log.debug("L'exception etait",
- * eee); }
- * } catch (Throwable eee) { log .info("librairie lutinxml non presente.
- * Import/Export XML impossible"); log.debug("L'exception etait", eee); }
- * }
- */
+ /* following code in only an exception generator since
+ * lutinxml in not used anymore :)
+ static {
- /** Valeur par defaut si aucun type de Vector n'est donné */
- protected static Class defaultVectorClass = DoubleBigVector.class;
+ // on essai d'enregistrer le converter XML
+ try {
+ // Il faut le faire par pur introspection sinon l'exception
+ // NoClassDefFoundError est levé avant d'entrer dans le constructeur
+ // static :(
+ Class converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
+ Object converter = converterClass.newInstance();
- protected Class vectorClass = null;
+ Class converterFactoryClass = Class
+ .forName("org.codelutin.xml.XMLConverterFactory");
+ Method m = converterFactoryClass.getMethod("addConverter",
+ Class.class, Class
+ .forName("org.codelutin.xml.XMLConverter"));
+ m.invoke(null, MatrixND.class, converter);
- protected MatrixFactory(Class vectorClass) {
- this.vectorClass = vectorClass;
- }
+ // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
+ // new MatrixNDXMLConverter());
+ log.info("Converter XML pour MatrixND ajoute");
- public static void setDefaultVectorClass(Class vectorClass) {
- defaultVectorClass = vectorClass;
- }
+ // on essai d'enregistrer le converter JDBC
+ // le JDBC depend du XML
+ try {
+ converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
+ converter = converterClass.newInstance();
- public static Class getDefaultVectorClass() {
- return defaultVectorClass;
- }
+ converterFactoryClass = Class
+ .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
+ m = converterFactoryClass
+ .getMethod(
+ "addConverter",
+ Class.class,
+ Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
+ m.invoke(null, MatrixND.class, converter);
- /**
- * Retourne une factory utilisant vectorClass comme classe de base a
- * l'implantation des matrices
- */
- public static MatrixFactory getInstance(Class vectorClass) {
- return new MatrixFactory(vectorClass);
- }
+ // Class converterClass =
+ // org.codelutin.math.matrix.MatrixNDJDBCConverter();
+ // JDBCTransformerFactory
+ // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
+ log.info("Converter JDBC pour MatrixND ajoute");
+ } catch (Throwable eee) {
+ log
+ .info("librairie topia non presente. Import/Export JDBC impossible");
+ log.debug("L'exception etait", eee);
+ }
- /**
- * Utilise par defaut {@link FloatBigVector}
- */
- public static MatrixFactory getInstance() {
- return getInstance(defaultVectorClass);
- }
+ } catch (Throwable eee) {
+ log
+ .info("librairie lutinxml non presente. Import/Export XML impossible");
+ log.debug("L'exception etait", eee);
+ }
- public MatrixND create(int[] dim) {
- return new MatrixNDImpl(this, dim);
- }
+ }*/
- /**
- * Convert a double array into matrix.
- *
- * @param values
- * The values to fill the matrix
- * @param dim
- * An array representing the dimensions of the matrix
- * @return a 2D matrix filled with the values, null if the dimension is more
- * than 2
- */
- public MatrixND create(double[] values, int[] dim) {
+ /** Valeur par defaut si aucun type de Vector n'est donné */
+ protected static Class defaultVectorClass = DoubleBigVector.class;
- if (dim.length > 2) {
- return null;
- }
- MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
+ protected Class vectorClass = null;
- if (dim.length == 2) {
- for (int i = 0; i < dim[0]; i++) {
- for (int j = 0; j < dim[1]; j++) {
- int[] coordinates = { i, j };
- matrix.setValue(coordinates, values[i * dim[1] + j]);
- }
- }
- }
- if (dim.length == 1) {
- for (int i = 0; i < dim[0]; i++) {
- int[] coordinates = { i };
- matrix.setValue(coordinates, values[i]);
- }
- }
+ protected MatrixFactory(Class vectorClass) {
+ this.vectorClass = vectorClass;
+ }
- return matrix;
- }
+ public static void setDefaultVectorClass(Class vectorClass) {
+ defaultVectorClass = vectorClass;
+ }
- public MatrixND create(List[] semantics) {
- return new MatrixNDImpl(this, semantics);
- }
+ public static Class getDefaultVectorClass() {
+ return defaultVectorClass;
+ }
- public MatrixND create(String name, int[] dim) {
- return new MatrixNDImpl(this, name, dim);
- }
+ /**
+ * Retourne une factory utilisant vectorClass comme classe de base a
+ * l'implantation des matrices
+ */
+ public static MatrixFactory getInstance(Class vectorClass) {
+ return new MatrixFactory(vectorClass);
+ }
- public MatrixND create(String name, int[] dim, String[] dimNames) {
- return new MatrixNDImpl(this, name, dim, dimNames);
- }
+ /**
+ * Utilise par defaut {@link FloatBigVector}
+ */
+ public static MatrixFactory getInstance() {
+ return getInstance(defaultVectorClass);
+ }
- public MatrixND create(String name, List[] semantics) {
- return new MatrixNDImpl(this, name, semantics);
- }
+ public MatrixND create(int[] dim) {
+ return new MatrixNDImpl(this, dim);
+ }
- public MatrixND create(String name, List[] semantics, String[] dimNames) {
- return new MatrixNDImpl(this, name, semantics, dimNames);
- }
+ /**
+ * Convert a double array into matrix.
+ *
+ * @param values
+ * The values to fill the matrix
+ * @param dim
+ * An array representing the dimensions of the matrix
+ * @return a 2D matrix filled with the values, null if the dimension is more
+ * than 2
+ */
+ public MatrixND create(double[] values, int[] dim) {
- public MatrixND create(MatrixND matrix) {
- return new MatrixNDImpl(this, matrix);
- }
+ if (dim.length > 2) {
+ return null;
+ }
+ MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
- /**
- * Crée une nouvelle matrice identité. Une matrice identité est une matrice
- * à 2 dimensions dont tous les éléments de la diagonal vaut 1
- *
- * @param size
- * la taille de la matrice
- * @return une nouvelle matrice identité
- */
- public MatrixND matrixId(int size) {
- MatrixND result = create(new int[] { size, size });
- for (int i = 0; i < size; i++) {
- result.setValue(i, i, 1);
- }
- return result;
- }
+ if (dim.length == 2) {
+ for (int i = 0; i < dim[0]; i++) {
+ for (int j = 0; j < dim[1]; j++) {
+ int[] coordinates = { i, j };
+ matrix.setValue(coordinates, values[i * dim[1] + j]);
+ }
+ }
+ }
+ if (dim.length == 1) {
+ for (int i = 0; i < dim[0]; i++) {
+ int[] coordinates = { i };
+ matrix.setValue(coordinates, values[i]);
+ }
+ }
- protected Vector createVector(int length) {
- try {
- Constructor c = vectorClass
- .getConstructor(new Class[] { Integer.TYPE });
- return (Vector) c.newInstance(new Object[] { length });
- } catch (Exception eee) {
- throw new RuntimeException("Can't create vector", eee);
- }
- }
+ return matrix;
+ }
+ public MatrixND create(List[] semantics) {
+ return new MatrixNDImpl(this, semantics);
+ }
+
+ public MatrixND create(String name, int[] dim) {
+ return new MatrixNDImpl(this, name, dim);
+ }
+
+ public MatrixND create(String name, int[] dim, String[] dimNames) {
+ return new MatrixNDImpl(this, name, dim, dimNames);
+ }
+
+ public MatrixND create(String name, List[] semantics) {
+ return new MatrixNDImpl(this, name, semantics);
+ }
+
+ public MatrixND create(String name, List[] semantics, String[] dimNames) {
+ return new MatrixNDImpl(this, name, semantics, dimNames);
+ }
+
+ public MatrixND create(MatrixND matrix) {
+ return new MatrixNDImpl(this, matrix);
+ }
+
+ /**
+ * Crée une nouvelle matrice identité. Une matrice identité est une matrice
+ * à 2 dimensions dont tous les éléments de la diagonal vaut 1
+ *
+ * @param size
+ * la taille de la matrice
+ * @return une nouvelle matrice identité
+ */
+ public MatrixND matrixId(int size) {
+ MatrixND result = create(new int[] { size, size });
+ for (int i = 0; i < size; i++) {
+ result.setValue(i, i, 1);
+ }
+ return result;
+ }
+
+ protected Vector createVector(int length) {
+ try {
+ Constructor c = vectorClass
+ .getConstructor(new Class[] { Integer.TYPE });
+ return (Vector) c.newInstance(new Object[] { length });
+ } catch (Exception eee) {
+ throw new RuntimeException("Can't create vector", eee);
+ }
+ }
+
} // MatrixFactory
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -28,7 +28,7 @@
import org.apache.commons.logging.LogFactory;
/**
- * MatrixHelper.
+ * Contains usefull methods to get information on matrix.
*
* Created: 28 oct. 2004
*
@@ -40,6 +40,9 @@
*/
public class MatrixHelper { // MatrixHelper
+ /** Class logger */
+ private static Log log = LogFactory.getLog(MatrixHelper.class);
+
/**
* Convert Matrix to identity matrix must have 2 dimensions. If dimension
* haven't same length, then the small dimension is used.
@@ -253,21 +256,6 @@
return mat;
}
- // /**
- // * Crée une nouvelle matrice identité. Une matrice identité est une
- // * matrice à 2 dimensions dont tous les éléments de la diagonale
- // * valent 1
- // * @param size la taille de la matrice
- // * @return une nouvelle matrice identité
- // */
- // static public MatrixND matrixId(int size){
- // MatrixND result = new MatrixNDImpl(new int[]{size, size});
- // for(int i=0; i<size; i++){
- // result.setValue(i, i , 1);
- // }
- // return result;
- // }
-
/**
* Retourne la valeur la plus courrement rencontrer dans un tableau. si
* plusieurs valeurs ont le même nombre d'occurence la plus petite valeur
@@ -335,21 +323,4 @@
return result;
}
- // static public String encodeToXML(MatrixND mat){
- // StringWriter out = new StringWriter();
- // XMLEncoderDecoder.getInstance().encode(out, mat);
- // return out.toString();
- // }
- //
- // static public MatrixND decodeFromXML(String xml){
- // try{
- // return (MatrixND)XMLEncoderDecoder.getInstance().decode(new
- // StringReader(xml));
- // }catch(Exception eee){
- // throw new MatrixException("Erreur durant le decodage de la matrice",
- // eee);
- // }
- // }
-
} // MatrixHelper
-
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -15,8 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-
package org.codelutin.math.matrix;
import java.io.IOException;
@@ -39,13 +37,20 @@
public interface MatrixND extends Serializable, Cloneable { // MatrixND
/**
- * Retourne la factory qui a permit de creer la matrice
+ * Retourne la factory qui a permit de creer la matrice.
+ *
+ * @return la {@link MatrixFactory}
+ *
+ * @see MatrixFactory
*/
public MatrixFactory getFactory();
/**
- * Donne toutes les semantiques de la matrice Si la matrice n'a pas de
- * semantique retourne null
+ * Donne toutes les semantiques de la matrice.
+ *
+ * Si la matrice n'a pas de semantique retourne null.
+ *
+ * @return la liste des semantics
*/
public List[] getSemantics();
@@ -65,6 +70,8 @@
/**
* Permet de donner un nom à la matrice.
+ *
+ * @param name name to set
*/
public void setName(String name);
@@ -77,10 +84,39 @@
/**
* Permet de mettre des noms aux différentes dimension.
+ *
+ * @deprecated (since 1.0.3) Use #setDimensionNames(String[])
*/
public void setDimensionName(String[] names);
/**
+ * Permet de mettre des noms aux différentes dimension.
+ *
+ * @param names names to set
+ *
+ * @since 1.0.3
+ */
+ public void setDimensionNames(String[] names);
+
+ /**
+ * Permet de recuperer les noms des dimension.
+ *
+ * @return tableau des noms de dimension.
+ *
+ * @deprecated (since 1.0.3) Use #getDimensionNames()
+ */
+ public String[] getDimensionName();
+
+ /**
+ * Permet de recuperer les noms des dimension.
+ *
+ * @return tableau des noms de dimension.
+ *
+ * @since 1.0.3
+ */
+ public String[] getDimensionNames();
+
+ /**
* Permet de mettre un nom à une dimension.
*
* @param dim la dimension dont on veut changer le nom
@@ -97,8 +133,6 @@
*/
public String getDimensionName(int dim);
- public String[] getDimensionName();
-
/**
* Retourne la valeur la plus courrement rencontrer dans un tableau. si
* plusieurs valeurs ont le même nombre d'occurence la plus petite valeur
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -72,7 +72,7 @@
protected MatrixNDImpl(MatrixFactory factory, MatrixND matrix) {
super(factory, matrix.getName(), matrix.getSemantics(), matrix
- .getDimensionName());
+ .getDimensionNames());
this.matrix = new BasicMatrix(factory, dim);
this.paste(matrix);
}
Added: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java (rev 0)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixStringEncoder.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -0,0 +1,342 @@
+/* *##% lutinmatrix
+ * Copyright (C) 2004 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.math.matrix;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.beanutils.ConvertUtilsBean;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.util.StringUtil;
+
+/**
+ * Convert matrix into {@link String} and inverse.
+ *
+ * Method from this class are non "static" to be overriden.
+ *
+ * Created: 04 mar. 2009
+ *
+ * @author chatellier
+ * @version $Revision: 120 $
+ *
+ * Mise a jour: $Date: 2009-03-03 11:19:18 +0100 (mar. 03 mars 2009) $
+ * par : $Author: chatellier $
+ */
+public class MatrixStringEncoder { // MatrixStringEncoder
+
+ /** Class logger */
+ private static Log log = LogFactory.getLog(MatrixStringEncoder.class);
+
+ /**
+ * Convert a matrix in string representation.
+ *
+ * String representation is composed in (ordered) :
+ * - name
+ * - dim
+ * - dimNames
+ * - semantics
+ * - data
+ *
+ * @param matrix matrix to convert
+ * @return a {@link String} representation
+ */
+ public String getMatrixAsString(MatrixND matrix) {
+ StringBuffer representationBuffer = new StringBuffer();
+ representationBuffer.append("["); // top level
+ representationBuffer.append(matrix.getName());
+ representationBuffer.append(",");
+ representationBuffer.append(getDimToString(matrix.getDim()));
+ representationBuffer.append(",");
+ representationBuffer.append(getDimensionNamesToString(matrix
+ .getDimensionNames()));
+ representationBuffer.append(",");
+ representationBuffer
+ .append(getSemanticsToString(matrix.getSemantics()));
+ representationBuffer.append(",");
+ representationBuffer.append(matrix.toList().toString());
+ representationBuffer.append("]"); // top level
+ return representationBuffer.toString();
+ }
+
+ /**
+ * Parse string as matrix representation.
+ *
+ * str must be in following format :
+ * - [name,dim,dimNames,semantics,data]
+ * @param str
+ * @return
+ */
+ public MatrixND getMatrixFromString(String str) {
+
+ MatrixND matrix = null;
+
+ // composed of 5 groups
+ Pattern matrixPattern = Pattern
+ .compile("^\\[(.*),(\\[.*\\]),(\\[.*\\]),(\\[.*\\]),(\\[.*\\])\\]$");
+ Matcher matcher = matrixPattern.matcher(str);
+
+ if (matcher.find()) {
+ String name = matcher.group(1);
+ String dimString = matcher.group(2);
+ String dimNamesString = matcher.group(3);
+ String semanticsString = matcher.group(4);
+ String dataString = matcher.group(5);
+
+ int[] dim = getDimFromString(dimString);
+ String[] dimNames = getDimensionNamesFromString(dimNamesString);
+ List<Object>[] semantics = getSemanticsFromString(semanticsString);
+
+ matrix = MatrixFactory.getInstance().create(name, semantics,
+ dimNames);
+ List<Object> data = MatrixHelper.convertStringToList(dataString);
+ matrix.fromList(data);
+ } else {
+ throw new IllegalArgumentException("Can't parse \"" + str
+ + "\" as string");
+ }
+
+ return matrix;
+ }
+
+ /**
+ * Matrix dim to string.
+ *
+ * @param dimArray dim to convert.
+ * @return a {@link String} representation
+ */
+ public String getDimToString(int[] dimArray) {
+ String result = "[";
+ String sep = "";
+ for (int i = 0; i < dimArray.length; i++) {
+ result += sep + dimArray[i];
+ sep = ", ";
+ }
+ result += "]";
+ return result;
+ }
+
+ /**
+ * String to matrix dim.
+ *
+ * @param str string to parse
+ * @return dim array
+ */
+ public int[] getDimFromString(String str) {
+ String localStr = str.trim();
+ if (localStr.startsWith("[") && localStr.endsWith("]")) {
+ localStr = localStr.substring(1, localStr.length() - 1); // remove [ and ]
+ }
+ String[] dimAsString = StringUtil.split(localStr, ",");
+ int[] result = new int[dimAsString.length];
+ int i = 0;
+ for (String dim : dimAsString) {
+ int val = Integer.parseInt(dim.trim());
+ result[i++] = val;
+ }
+ return result;
+ }
+
+ /**
+ * Dim names to string.
+ *
+ * @param dimNamesArray dim array to convert
+ * @return a {@link String} representation
+ */
+ public String getDimensionNamesToString(String[] dimNamesArray) {
+ String result = "[";
+ String sep = "";
+ for (int i = 0; i < dimNamesArray.length; i++) {
+ result += sep + '"' + dimNamesArray[i] + '"';
+ sep = ", ";
+ }
+ result += "]";
+ return result;
+ }
+
+ /**
+ * String to dim names array.
+ *
+ * @param str string to parse
+ * @return a {@link String} representation
+ */
+ public String[] getDimensionNamesFromString(String str) {
+ String localStr = str.trim();
+ if (localStr.startsWith("[") && localStr.endsWith("]")) {
+ localStr = localStr.substring(1, localStr.length() - 1); // remove [ and ]
+ }
+ String[] result = StringUtil.split(localStr, ",");
+ for (int i = 0; i < result.length; i++) {
+ result[i] = result[i].trim();
+ if (result[i].startsWith("\"") && result[i].endsWith("\"")) {
+ result[i] = result[i].substring(1, result[i].length() - 1); // remove " and "
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Semantics array to string.
+ *
+ * @param semanticsArray semantics arrayy
+ * @return string names array
+ */
+ public String getSemanticsToString(List<Object>[] semanticsArray) {
+ StringBuffer result = new StringBuffer("[");
+ for (int i = 0; i < semanticsArray.length; i++) {
+ result.append("[");
+ List<Object> semantics = semanticsArray[i];
+ for (Iterator<Object> it = semantics.iterator(); it.hasNext();) {
+ appendString(result, it.next());
+ if (it.hasNext()) {
+ result.append(", ");
+ }
+ }
+ result.append("]");
+ if ((i + 1) < semanticsArray.length) {
+ result.append(", ");
+ }
+ }
+ return result.append("]").toString();
+ }
+
+ /**
+ * String to samantics.
+ *
+ * @param str la chaine representant la semantique
+ * @return
+ */
+ public List<Object>[] getSemanticsFromString(String str) {
+ String localStr = str.trim();
+ if (localStr.startsWith("[") && localStr.endsWith("]")) {
+ localStr = localStr.substring(1, localStr.length() - 1); // remove [ and ]
+ }
+ String[] sems = StringUtil.split(localStr, ",");
+
+ List<Object>[] result = new List[sems.length];
+
+ for (int i = 0; i < sems.length; i++) {
+ result[i] = splitObjects(sems[i]);
+ }
+
+ return result;
+ }
+
+ /**
+ * Recréé chaque object de la chaine de caractere et l'ajoute dans une liste
+ * la chaine est de la forme.
+ *
+ * [null(), java.lang.String("toto"), ...]
+ *
+ * @param str la chaine representant
+ */
+ public List<Object> splitObjects(String str) {
+ List<Object> result = new LinkedList<Object>();
+ String localStr = str.trim();
+ if (localStr.startsWith("[") && localStr.endsWith("]")) {
+ localStr = localStr.substring(1, localStr.length() - 1);
+ }
+ String[] elems = StringUtil.split(localStr, ",");
+ for (String elem : elems) {
+ elem = elem.trim();
+ int openbrace = elem.indexOf('(');
+ String objectType = elem.substring(0, openbrace);
+ String objectString = elem.substring(openbrace + 1,
+ elem.length() - 1);
+
+ if ("null".equals(objectType)) {
+ result.add(null);
+ } else {
+ ConvertUtilsBean converter = getConverter();
+ Object o;
+ try {
+ o = converter.convert(objectString, Class
+ .forName(objectType));
+ } catch (Exception e) {
+ // if can't create objet, put String representation as semantics
+ o = objectType + "(" + objectString + ")";
+ if (log.isWarnEnabled()) {
+ log
+ .warn("Continuing but can't convert object in matrix from String: '"
+ + o + "'");
+ }
+ if (log.isDebugEnabled()) {
+ log.debug(
+ "Continuing but can't convert object in matrix from String: '"
+ + o + "'", e);
+ }
+ }
+ result.add(o);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Append object type and value.
+ *
+ * qualifiedName(value)
+ * java.lang.String(test)
+ * java.lang.Double(4.5)
+ *
+ * @param buffer buffer to append to
+ * @param o object to put on buffer
+ * @return buffer
+ */
+ public StringBuffer appendString(StringBuffer buffer, Object o) {
+ if (o == null) {
+ buffer.append("null()");
+ } else {
+ String qualifiedName = getQualifiedName(o);
+ buffer.append(qualifiedName).append("(");
+ ConvertUtilsBean converter = getConverter();
+ buffer.append(converter.convert(o));
+ buffer.append(")");
+ }
+ return buffer;
+ }
+
+ /**
+ * Get object qualified name.
+ *
+ * Can't be overridden to put another impl.
+ *
+ * @param o object to get qulified name
+ * @return object qualified class name
+ */
+ public String getQualifiedName(Object o) {
+ String qualifiedName = o.getClass().getName();
+ return qualifiedName;
+ }
+
+ /**
+ * Get commons-beanutils bean converter.
+ * @return a {@link ConvertUtilsBean}
+ */
+ public ConvertUtilsBean getConverter() {
+ BeanUtilsBean instance = BeanUtilsBean.getInstance();
+ ConvertUtilsBean cub = instance.getConvertUtils();
+ return cub;
+ }
+
+} // MatrixStringEncoder
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -46,7 +46,7 @@
public SubMatrix(MatrixND matrix, int dim, int start, int nb) {
super(matrix.getFactory(), matrix.getName(), matrix.getSemantics(),
- matrix.getDimensionName());
+ matrix.getDimensionNames());
this.matrix = matrix;
converter = new ShiftConverter(dim, start, nb);
@@ -56,7 +56,7 @@
public SubMatrix(MatrixND matrix, int dim, int[] elem) {
super(matrix.getFactory(), matrix.getName(), matrix.getSemantics(),
- matrix.getDimensionName());
+ matrix.getDimensionNames());
this.matrix = matrix;
converter = new MappingConverter(dim, elem);
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-03 14:01:27 UTC (rev 122)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -39,49 +39,51 @@
/** to use log facility, just put in your code: log.info(\"...\"); */
private static Log log = LogFactory.getLog(MatrixHelperTest.class);
-
- public MatrixFactory getFactory() throws Exception {
+
+ public MatrixFactory getFactory() {
return MatrixFactory.getInstance();
}
@Test
- public void testCoordinatesToString() throws Exception {
- Assert.assertEquals("1", MatrixHelper.coordinatesToString(new int[] { 1 }));
- Assert.assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[] { 2,
- 3, 4, 5 }));
- Assert.assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[] {
- 2, 3, 4, 5, 234 }));
+ public void testCoordinatesToString() {
+ Assert.assertEquals("1", MatrixHelper
+ .coordinatesToString(new int[] { 1 }));
+ Assert.assertEquals("2,3,4,5", MatrixHelper
+ .coordinatesToString(new int[] { 2, 3, 4, 5 }));
+ Assert.assertEquals("2,3,4,5,234", MatrixHelper
+ .coordinatesToString(new int[] { 2, 3, 4, 5, 234 }));
Assert.assertEquals("a", MatrixHelper
.coordinatesToString(new String[] { "a" }));
- Assert.assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[] {
- "a", "b", "n", "m" }));
+ Assert.assertEquals("a,b,n,m", MatrixHelper
+ .coordinatesToString(new String[] { "a", "b", "n", "m" }));
Assert.assertEquals("a,b,f,e,aze",
MatrixHelper.coordinatesToString(new String[] { "a", "b", "f",
"e", "aze" }));
}
@Test
- public void testSameDimension() throws Exception {
- Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1 }, new int[] { 1 }));
- Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 }, new int[] {
- 1, 2 }));
+ public void testSameDimension() {
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1 },
+ new int[] { 1 }));
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 },
+ new int[] { 1, 2 }));
Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 324, 3 },
new int[] { 1, 324, 3 }));
}
@Test
- public void testDimensionToSemantics() throws Exception {
+ public void testDimensionToSemantics() {
// TODO faire un test pour dimensionToSemantics
}
@Test
- public void testSemanticsToDimension() throws Exception {
+ public void testSemanticsToDimension() {
// TODO faire un test pour semanticsToDimension
}
@Test
- public void testFill() throws Exception {
+ public void testFill() {
MatrixND mat = getFactory().create(new int[] { 3, 3 });
MatrixHelper.fill(mat, 4);
@@ -89,9 +91,10 @@
}
@Test
- public void testMatrixId() throws Exception {
+ public void testMatrixId() {
MatrixND mat = getFactory().matrixId(4);
- Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat.getDim()));
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat
+ .getDim()));
Assert.assertEquals(0, mat.getValue(1, 2), 0);
Assert.assertEquals(1, mat.getValue(0, 0), 0);
Assert.assertEquals(1, mat.getValue(1, 1), 0);
@@ -100,7 +103,7 @@
}
@Test
- public void testToList() throws Exception {
+ public void testToList() {
MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
mat1.setValue(0, 0, 0, -1.0E-7);
mat1.setValue(1, 1, 0, 2);
@@ -118,7 +121,7 @@
}
@Test
- public void testMaxOccurence() throws Exception {
+ public void testMaxOccurence() {
double[] val = new double[5];
Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
@@ -154,7 +157,7 @@
val = new double[0];
try {
MatrixHelper.maxOccurence(val);
- Assert.fail("AN exception must be thrown");
+ Assert.fail("An exception must be thrown");
} catch (IllegalArgumentException e) {
if (log.isDebugEnabled()) {
log.debug("Exception normally thrown", e);
@@ -162,6 +165,6 @@
}
}
-
+
} // MatrixHelperTest
Added: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java (rev 0)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixStringEncoderTest.java 2009-03-04 09:42:17 UTC (rev 123)
@@ -0,0 +1,146 @@
+/* *##% lutinmatrix
+ * Copyright (C) 2004 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
+
+package org.codelutin.math.matrix;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * MatrixHelperTest.
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision: 120 $
+ *
+ * Mise a jour: $Date: 2009-03-03 11:19:18 +0100 (mar. 03 mars 2009) $
+ * par : $Author: chatellier $
+ */
+public class MatrixStringEncoderTest { // MatrixHelperTest
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(MatrixStringEncoderTest.class);
+
+ protected MatrixStringEncoder stringEncoder;
+
+ @Before
+ public void setUp() {
+ stringEncoder = new MatrixStringEncoder();
+ }
+
+ public MatrixFactory getFactory() {
+ return MatrixFactory.getInstance();
+ }
+
+ @Test
+ public void testMatrixStringRepresentation() {
+
+ MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
+ mat1.setValue(0, 0, 0, -1.0E-7);
+ mat1.setValue(1, 1, 0, 2);
+ mat1.setValue(2, 1, 0, 5.0E-7);
+
+ String rep = stringEncoder.getMatrixAsString(mat1);
+
+ System.out.println(rep);
+
+ Assert.assertTrue("Null() semantics missing", rep.indexOf("null()") > 0);
+ Assert.assertTrue("Dimentation missing", rep.indexOf("3, 2, 1") > 0);
+ Assert.assertTrue("Data missing", rep.indexOf("[2.0]") > 0);
+ }
+
+ @Test
+ public void testMatrixFromString() {
+ String representation = "[,[3, 2, 1],[\"\", \"\", \"\"],[[null(), null(), null()], [null(), null()], [null()]],[[[-1.0E-7], [0.0]], [[0.0], [2.0]], [[0.0], [5.0E-7]]]]";
+
+ MatrixND matrix = stringEncoder.getMatrixFromString(representation);
+
+ Assert.assertEquals(3, matrix.getDim()[0]);
+ Assert.assertEquals(2, matrix.getDim()[1]);
+ Assert.assertEquals(1, matrix.getDim()[2]);
+ Assert.assertEquals(-1.0E-7, matrix.getValue(0, 0, 0), 0);
+ Assert.assertEquals(2, matrix.getValue(1, 1, 0), 0);
+ Assert.assertEquals(5.0E-7, matrix.getValue(2, 1, 0), 0);
+ }
+
+ @Test
+ public void testMatrixStringRepresentationWithMoreInfos() {
+
+ MatrixND mat1 = getFactory().create(new int[] { 2, 5 });
+ mat1.setName("StringRepresentationWithMoreInfos");
+ mat1.setValue(0, 0, -2);
+ mat1.setValue(1, 1, 2.345);
+ mat1.setValue(1, 4, -8.321);
+
+ List<Serializable> sem0 = new ArrayList<Serializable>();
+ sem0.add(new String("test"));
+ sem0.add(new Double(3.453));
+ mat1.setSemantics(0, sem0);
+ List<Serializable> sem1 = new ArrayList<Serializable>();
+ sem1.add(new Integer(7));
+ sem1.add(new Character('e'));
+ sem1.add(Byte.valueOf("1"));
+ sem1.add(Short.valueOf("3"));
+ sem1.add(new Integer(12));
+ mat1.setSemantics(1, sem1);
+
+ mat1.setDimensionNames(new String[] {"col1", "col2"});
+
+ String rep = stringEncoder.getMatrixAsString(mat1);
+
+ System.out.println(rep);
+
+ Assert.assertTrue("java.lang.String semantics missing", rep.indexOf("java.lang.String") > 0);
+ Assert.assertTrue("Dimentation missing", rep.indexOf("[2, 5]") > 0);
+ Assert.assertTrue("Data missing", rep.indexOf("[0.0, 2.345, 0.0, 0.0, -8.321]") > 0);
+ Assert.assertTrue("Columns name missing", rep.indexOf("[\"col1\", \"col2\"]") > 0);
+ Assert.assertTrue("Name missing", rep.indexOf("StringRepresentationWithMoreInfos") > 0);
+
+ }
+
+ @Test
+ public void testMatrixFromStringWithMoreInfos() {
+ String representation = "[StringRepresentationWithMoreInfos,[2, 5],[\"col1\", \"col2\"],[[java.lang.String(test), java.lang.Double(3.453)], [java.lang.Integer(7), java.lang.Character(e), java.lang.Byte(1), java.lang.Short(3), java.lang.Integer(12)]],[[-2.0, 0.0, 0.0, 0.0, 0.0], [0.0, 2.345, 0.0, 0.0, -8.321]]]";
+
+ MatrixND matrix = stringEncoder.getMatrixFromString(representation);
+
+ Assert.assertEquals("StringRepresentationWithMoreInfos", matrix.getName());
+ Assert.assertEquals(2, matrix.getDim()[0]);
+ Assert.assertEquals(5, matrix.getDim()[1]);
+ Assert.assertEquals("col1", matrix.getDimensionNames()[0]);
+ Assert.assertEquals("col2", matrix.getDimensionNames()[1]);
+ Assert.assertEquals("test", matrix.getSemantics(0).get(0));
+ Assert.assertEquals(3.453, matrix.getSemantics(0).get(1));
+ Assert.assertEquals(7, matrix.getSemantics(1).get(0));
+ Assert.assertEquals('e', matrix.getSemantics(1).get(1));
+ Assert.assertEquals(Byte.valueOf("1"), matrix.getSemantics(1).get(2));
+ Assert.assertEquals(Short.valueOf("3"), matrix.getSemantics(1).get(3));
+ Assert.assertEquals(12, matrix.getSemantics(1).get(4));
+ Assert.assertEquals(-2, matrix.getValue(0, 0), 0);
+ Assert.assertEquals(2.345, matrix.getValue(1, 1), 0);
+ Assert.assertEquals(-8.321, matrix.getValue(1, 4), 0);
+ }
+} // MatrixHelperTest
+
1
0
[Lutinmatrix-commits] r122 - in lutinmatrix/trunk/src: main/java/org/codelutin/math/matrix test/java/org/codelutin/math/matrix
by jcouteau@users.labs.libre-entreprise.org 03 Mar '09
by jcouteau@users.labs.libre-entreprise.org 03 Mar '09
03 Mar '09
Author: jcouteau
Date: 2009-03-03 14:01:27 +0000 (Tue, 03 Mar 2009)
New Revision: 122
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
Log:
Correct bug on asymmetrical matrices.
Add tests.
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 10:26:11 UTC (rev 121)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 14:01:27 UTC (rev 122)
@@ -26,190 +26,174 @@
* representation interne des matrices de facon simple.
* <p>
* Created: 11 octobre 2005 20:15:20 CEST
- *
+ *
* @author Benjamin POUSSIN <poussin(a)codelutin.com>
* @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
+ *
+ * Last update: $Date$ by :
+ * $Author$
*/
public class MatrixFactory { // MatrixFactory
- /* following code in only an exception generator since
- * lutinxml in not used anymore :)
- static {
+ /*
+ * following code in only an exception generator since lutinxml in not used
+ * anymore :) static {
+ * // on essai d'enregistrer le converter XML try { // Il faut le faire par
+ * pur introspection sinon l'exception // NoClassDefFoundError est levé
+ * avant d'entrer dans le constructeur // static :( Class converterClass =
+ * Class .forName("org.codelutin.math.matrix.MatrixNDXMLConverter"); Object
+ * converter = converterClass.newInstance();
+ *
+ * Class converterFactoryClass = Class
+ * .forName("org.codelutin.xml.XMLConverterFactory"); Method m =
+ * converterFactoryClass.getMethod("addConverter", Class.class, Class
+ * .forName("org.codelutin.xml.XMLConverter")); m.invoke(null,
+ * MatrixND.class, converter);
+ * // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class, //
+ * new MatrixNDXMLConverter()); log.info("Converter XML pour MatrixND
+ * ajoute");
+ * // on essai d'enregistrer le converter JDBC // le JDBC depend du XML try {
+ * converterClass = Class
+ * .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter"); converter =
+ * converterClass.newInstance();
+ *
+ * converterFactoryClass = Class
+ * .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
+ * m = converterFactoryClass .getMethod( "addConverter", Class.class,
+ * Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
+ * m.invoke(null, MatrixND.class, converter);
+ * // Class converterClass = //
+ * org.codelutin.math.matrix.MatrixNDJDBCConverter(); //
+ * JDBCTransformerFactory // .addConverter(MatrixND.class, new
+ * MatrixNDJDBCConverter()); log.info("Converter JDBC pour MatrixND
+ * ajoute"); } catch (Throwable eee) { log .info("librairie topia non
+ * presente. Import/Export JDBC impossible"); log.debug("L'exception etait",
+ * eee); }
+ * } catch (Throwable eee) { log .info("librairie lutinxml non presente.
+ * Import/Export XML impossible"); log.debug("L'exception etait", eee); }
+ * }
+ */
- // on essai d'enregistrer le converter XML
- try {
- // Il faut le faire par pur introspection sinon l'exception
- // NoClassDefFoundError est levé avant d'entrer dans le constructeur
- // static :(
- Class converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
- Object converter = converterClass.newInstance();
+ /** Valeur par defaut si aucun type de Vector n'est donné */
+ protected static Class defaultVectorClass = DoubleBigVector.class;
- Class converterFactoryClass = Class
- .forName("org.codelutin.xml.XMLConverterFactory");
- Method m = converterFactoryClass.getMethod("addConverter",
- Class.class, Class
- .forName("org.codelutin.xml.XMLConverter"));
- m.invoke(null, MatrixND.class, converter);
+ protected Class vectorClass = null;
- // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
- // new MatrixNDXMLConverter());
- log.info("Converter XML pour MatrixND ajoute");
+ protected MatrixFactory(Class vectorClass) {
+ this.vectorClass = vectorClass;
+ }
- // on essai d'enregistrer le converter JDBC
- // le JDBC depend du XML
- try {
- converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
- converter = converterClass.newInstance();
+ public static void setDefaultVectorClass(Class vectorClass) {
+ defaultVectorClass = vectorClass;
+ }
- converterFactoryClass = Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
- m = converterFactoryClass
- .getMethod(
- "addConverter",
- Class.class,
- Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
- m.invoke(null, MatrixND.class, converter);
+ public static Class getDefaultVectorClass() {
+ return defaultVectorClass;
+ }
- // Class converterClass =
- // org.codelutin.math.matrix.MatrixNDJDBCConverter();
- // JDBCTransformerFactory
- // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
- log.info("Converter JDBC pour MatrixND ajoute");
- } catch (Throwable eee) {
- log
- .info("librairie topia non presente. Import/Export JDBC impossible");
- log.debug("L'exception etait", eee);
- }
+ /**
+ * Retourne une factory utilisant vectorClass comme classe de base a
+ * l'implantation des matrices
+ */
+ public static MatrixFactory getInstance(Class vectorClass) {
+ return new MatrixFactory(vectorClass);
+ }
- } catch (Throwable eee) {
- log
- .info("librairie lutinxml non presente. Import/Export XML impossible");
- log.debug("L'exception etait", eee);
- }
+ /**
+ * Utilise par defaut {@link FloatBigVector}
+ */
+ public static MatrixFactory getInstance() {
+ return getInstance(defaultVectorClass);
+ }
- }*/
+ public MatrixND create(int[] dim) {
+ return new MatrixNDImpl(this, dim);
+ }
- /** Valeur par defaut si aucun type de Vector n'est donné */
- protected static Class defaultVectorClass = DoubleBigVector.class;
+ /**
+ * Convert a double array into matrix.
+ *
+ * @param values
+ * The values to fill the matrix
+ * @param dim
+ * An array representing the dimensions of the matrix
+ * @return a 2D matrix filled with the values, null if the dimension is more
+ * than 2
+ */
+ public MatrixND create(double[] values, int[] dim) {
- protected Class vectorClass = null;
+ if (dim.length > 2) {
+ return null;
+ }
+ MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
- protected MatrixFactory(Class vectorClass) {
- this.vectorClass = vectorClass;
- }
+ if (dim.length == 2) {
+ for (int i = 0; i < dim[0]; i++) {
+ for (int j = 0; j < dim[1]; j++) {
+ int[] coordinates = { i, j };
+ matrix.setValue(coordinates, values[i * dim[1] + j]);
+ }
+ }
+ }
+ if (dim.length == 1) {
+ for (int i = 0; i < dim[0]; i++) {
+ int[] coordinates = { i };
+ matrix.setValue(coordinates, values[i]);
+ }
+ }
- public static void setDefaultVectorClass(Class vectorClass) {
- defaultVectorClass = vectorClass;
- }
+ return matrix;
+ }
- public static Class getDefaultVectorClass() {
- return defaultVectorClass;
- }
+ public MatrixND create(List[] semantics) {
+ return new MatrixNDImpl(this, semantics);
+ }
- /**
- * Retourne une factory utilisant vectorClass comme classe de base a
- * l'implantation des matrices
- */
- public static MatrixFactory getInstance(Class vectorClass) {
- return new MatrixFactory(vectorClass);
- }
+ public MatrixND create(String name, int[] dim) {
+ return new MatrixNDImpl(this, name, dim);
+ }
- /**
- * Utilise par defaut {@link FloatBigVector}
- */
- public static MatrixFactory getInstance() {
- return getInstance(defaultVectorClass);
- }
+ public MatrixND create(String name, int[] dim, String[] dimNames) {
+ return new MatrixNDImpl(this, name, dim, dimNames);
+ }
- public MatrixND create(int[] dim) {
- return new MatrixNDImpl(this, dim);
- }
+ public MatrixND create(String name, List[] semantics) {
+ return new MatrixNDImpl(this, name, semantics);
+ }
- /**
- * Convert a double array into matrix.
- *
- * @param values The values to fill the matrix
- * @param dim An array representing the dimensions of the matrix
- * @return a 2D matrix filled with the values, null if the dimension is more than 2
- */
- public MatrixND create(double[] values, int[] dim) {
+ public MatrixND create(String name, List[] semantics, String[] dimNames) {
+ return new MatrixNDImpl(this, name, semantics, dimNames);
+ }
- if (dim.length > 2) {
- return null;
- }
- MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
+ public MatrixND create(MatrixND matrix) {
+ return new MatrixNDImpl(this, matrix);
+ }
- if (dim.length == 2) {
- for (int i = 0; i < dim[0]; i++) {
- for (int j = 0; j < dim[1]; j++) {
- int[] coordinates = { i, j };
- matrix.setValue(coordinates, values[i * dim[0] + j]);
- }
- }
- }
- if (dim.length == 1) {
- for (int i = 0; i < dim[0]; i++) {
- int[] coordinates = { i };
- matrix.setValue(coordinates, values[i]);
- }
- }
+ /**
+ * Crée une nouvelle matrice identité. Une matrice identité est une matrice
+ * à 2 dimensions dont tous les éléments de la diagonal vaut 1
+ *
+ * @param size
+ * la taille de la matrice
+ * @return une nouvelle matrice identité
+ */
+ public MatrixND matrixId(int size) {
+ MatrixND result = create(new int[] { size, size });
+ for (int i = 0; i < size; i++) {
+ result.setValue(i, i, 1);
+ }
+ return result;
+ }
- return matrix;
- }
+ protected Vector createVector(int length) {
+ try {
+ Constructor c = vectorClass
+ .getConstructor(new Class[] { Integer.TYPE });
+ return (Vector) c.newInstance(new Object[] { length });
+ } catch (Exception eee) {
+ throw new RuntimeException("Can't create vector", eee);
+ }
+ }
- public MatrixND create(List[] semantics) {
- return new MatrixNDImpl(this, semantics);
- }
-
- public MatrixND create(String name, int[] dim) {
- return new MatrixNDImpl(this, name, dim);
- }
-
- public MatrixND create(String name, int[] dim, String[] dimNames) {
- return new MatrixNDImpl(this, name, dim, dimNames);
- }
-
- public MatrixND create(String name, List[] semantics) {
- return new MatrixNDImpl(this, name, semantics);
- }
-
- public MatrixND create(String name, List[] semantics, String[] dimNames) {
- return new MatrixNDImpl(this, name, semantics, dimNames);
- }
-
- public MatrixND create(MatrixND matrix) {
- return new MatrixNDImpl(this, matrix);
- }
-
- /**
- * Crée une nouvelle matrice identité. Une matrice identité est une matrice
- * à 2 dimensions dont tous les éléments de la diagonal vaut 1
- *
- * @param size la taille de la matrice
- * @return une nouvelle matrice identité
- */
- public MatrixND matrixId(int size) {
- MatrixND result = create(new int[] { size, size });
- for (int i = 0; i < size; i++) {
- result.setValue(i, i, 1);
- }
- return result;
- }
-
- protected Vector createVector(int length) {
- try {
- Constructor c = vectorClass
- .getConstructor(new Class[] { Integer.TYPE });
- return (Vector) c.newInstance(new Object[] { length });
- } catch (Exception eee) {
- throw new RuntimeException("Can't create vector", eee);
- }
- }
-
} // MatrixFactory
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 10:26:11 UTC (rev 121)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 14:01:27 UTC (rev 122)
@@ -543,7 +543,33 @@
Assert.assertEquals(7, (int) mat.getValue(new int[] { 2, 0 }));
Assert.assertEquals(8, (int) mat.getValue(new int[] { 2, 1 }));
Assert.assertEquals(9, (int) mat.getValue(new int[] { 2, 2 }));
+
+ mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6},
+ new int[] { 2, 3 });
+ Assert.assertEquals(2, mat.getDim().length);
+ Assert.assertEquals(2, mat.getDim(0));
+ Assert.assertEquals(3, mat.getDim(1));
+ Assert.assertEquals(1, (int) mat.getValue(new int[] { 0, 0 }));
+ Assert.assertEquals(2, (int) mat.getValue(new int[] { 0, 1 }));
+ Assert.assertEquals(3, (int) mat.getValue(new int[] { 0, 2 }));
+ Assert.assertEquals(4, (int) mat.getValue(new int[] { 1, 0 }));
+ Assert.assertEquals(5, (int) mat.getValue(new int[] { 1, 1 }));
+ Assert.assertEquals(6, (int) mat.getValue(new int[] { 1, 2 }));
+
+ mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6},
+ new int[] { 3, 2 });
+
+ Assert.assertEquals(2, mat.getDim().length);
+ Assert.assertEquals(3, mat.getDim(0));
+ Assert.assertEquals(2, mat.getDim(1));
+ Assert.assertEquals(1, (int) mat.getValue(new int[] { 0, 0 }));
+ Assert.assertEquals(2, (int) mat.getValue(new int[] { 0, 1 }));
+ Assert.assertEquals(3, (int) mat.getValue(new int[] { 1, 0 }));
+ Assert.assertEquals(4, (int) mat.getValue(new int[] { 1, 1 }));
+ Assert.assertEquals(5, (int) mat.getValue(new int[] { 2, 0 }));
+ Assert.assertEquals(6, (int) mat.getValue(new int[] { 2, 1 }));
+
mat = getFactory().create(new double[] { 1, 2, 3 }, new int[] { 3 });
Assert.assertEquals(1, mat.getDim().length);
Assert.assertEquals(3, mat.getDim(0));
1
0
[Lutinmatrix-commits] r121 - lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix
by chatellier@users.labs.libre-entreprise.org 03 Mar '09
by chatellier@users.labs.libre-entreprise.org 03 Mar '09
03 Mar '09
Author: chatellier
Date: 2009-03-03 10:26:11 +0000 (Tue, 03 Mar 2009)
New Revision: 121
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
Log:
Improve code style
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 10:19:18 UTC (rev 120)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 10:26:11 UTC (rev 121)
@@ -75,7 +75,7 @@
/**
* Separateur CSV par défaut le point virgule.
*/
- public static char CSV_SEPARATOR = ';';
+ public static final char CSV_SEPARATOR = ';';
protected static final Pattern NUMBER = Pattern
.compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *");
1
0
[Lutinmatrix-commits] r120 - in lutinmatrix/trunk: . src/main/java/org/codelutin/math/matrix src/main/java/org/codelutin/math/matrix/gui src/test src/test/java/org/codelutin/math/matrix src/test/java/org/codelutin/math/matrix/gui src/test/resources
by chatellier@users.labs.libre-entreprise.org 03 Mar '09
by chatellier@users.labs.libre-entreprise.org 03 Mar '09
03 Mar '09
Author: chatellier
Date: 2009-03-03 10:19:18 +0000 (Tue, 03 Mar 2009)
New Revision: 120
Added:
lutinmatrix/trunk/src/test/resources/
lutinmatrix/trunk/src/test/resources/log4j.properties
Removed:
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java
Modified:
lutinmatrix/trunk/changelog.txt
lutinmatrix/trunk/pom.xml
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java
Log:
Clean code, move test to junit4.
Remove converter form lutinxml.
Modified: lutinmatrix/trunk/changelog.txt
===================================================================
--- lutinmatrix/trunk/changelog.txt 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/changelog.txt 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,3 +1,8 @@
+ver-1.3 chatellier 2009xxxx
+ * Move test to junit 4
+ * Update copyright
+ * Ajout de la serialisation des matrices
+
ver-1.2 chemit 20090218
* Switch to lutinutil 1.0
* Use lutinproject:3.4
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/pom.xml 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
<modelVersion>4.0.0</modelVersion>
<!-- ************************************************************* -->
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/AbstractMatrixND.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * AbstractMatrixND.java
- *
- * Created: 29 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.io.IOException;
@@ -45,26 +33,53 @@
import org.apache.commons.logging.LogFactory;
import org.codelutin.util.ArrayUtil;
+/**
+ * AbstractMatrixND.
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
public abstract class AbstractMatrixND implements MatrixND { // AbstractMatrixND
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -6838751468730930727L;
+
/** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(AbstractMatrixND.class);
+ private static Log log = LogFactory.getLog(AbstractMatrixND.class);
- abstract public MatrixIterator iterator();
+ public abstract MatrixIterator iterator();
- abstract public double getValue(int[] coordinates);
+ public abstract double getValue(int[] coordinates);
- abstract public void setValue(int[] coordinates, double d);
+ public abstract void setValue(int[] coordinates, double d);
- transient protected DimensionHelper dimHelper = new DimensionHelper();
+ protected transient DimensionHelper dimHelper = new DimensionHelper();
- transient protected MatrixFactory factory = null;
+ protected transient MatrixFactory factory = null;
+
protected String name = "";
+
protected String[] dimNames = null;
+
protected int[] dim = null;
+
protected List[] semantics = null;
+
protected double defaultValue = 0;
+ /**
+ * Separateur CSV par défaut le point virgule.
+ */
+ public static char CSV_SEPARATOR = ';';
+
+ protected static final Pattern NUMBER = Pattern
+ .compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *");
+
protected void init(int[] dim) {
this.dim = new int[dim.length];
System.arraycopy(dim, 0, this.dim, 0, dim.length);
@@ -279,7 +294,7 @@
public double getValue(int x, int y, int z, int t) {
return getValue(dimHelper.get(x, y, z, t));
- };
+ }
public void setValue(Object[] coordinates, double d) {
setValue(
@@ -845,11 +860,6 @@
}
/**
- * Separateur CSV par défaut la virgule
- */
- public static char CSV_SEPARATOR = ';';
-
- /**
* Determine si la matrice supporte l'import et l'export CSV
*
* @return support du CSV
@@ -858,9 +868,6 @@
return getNbDim() <= 2;
}
- Pattern NUMBER = Pattern
- .compile(" *[+-]?[0-9]*\\.?[0-9]+([eE][+-]?[0-9]+)? *");
-
/**
* Import depuis un reader au format CSV des données dans la matrice
*
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrix.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * BasicMatrix.java
- *
- * Created: 27 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.util.Arrays;
@@ -37,6 +25,14 @@
/**
* Objet matrice qui ne permet que le stockage de double dans un matrice à
* autant de dimension que l'on souhaite.
+ *
+ * Created: 27 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
*/
public class BasicMatrix { // BasicMatrix
@@ -46,6 +42,7 @@
protected int[] dimensions = null;
/** La matrice en représentation linéaire */
protected Vector data = null;
+
/**
* tableau de facteur permettant de convertir les coordonnées dans la
* matrice en un indice dans la représentation linéaire de la matrice
@@ -208,8 +205,8 @@
for (int i = 0; i < dim.length; i++) {
if (dim[i] <= 0) {
throw new IllegalArgumentException(I18n._(
- "lutinmatrix.invalid.size", new Integer(i),
- new Integer(dim[i])));
+ "lutinmatrix.invalid.size", Integer.valueOf(i),
+ Integer.valueOf(dim[i])));
}
}
}
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/BasicMatrixIterator.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * BasicMatrixIterator.java
+package org.codelutin.math.matrix;
+
+/**
+ * BasicMatrixIterator.
*
* Created: 28 oct. 2004
*
@@ -26,35 +28,32 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
public interface BasicMatrixIterator { // BasicMatrixIterator
/**
- * Retourne vrai s'il existe un suivant
+ * Retourne vrai s'il existe un suivant.
*
* @return vrai s'il y a un suivant, faux sinon
*/
public boolean hasNext();
/**
- * Passe à l'élément suivant
+ * Passe à l'élément suivant.
*/
public boolean next();
/**
- * Retourne les coordonnés de l'élément
+ * Retourne les coordonnés de l'élément.
*/
public int[] getCoordinates();
/**
- * Retourne la valeur courant pointé par l'iterator
+ * Retourne la valeur courant pointé par l'iterator.
*/
public double getValue();
/**
- * Modifie la valeur courant pointé par l'iterator
+ * Modifie la valeur courant pointé par l'iterator.
*/
public void setValue(double value);
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DimensionHelper.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * DimensionHelper.java
- *
- * Created: 29 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
/**
@@ -36,6 +24,14 @@
* cette classe, par exemple il ne faut pas l'utiliser dans une méthode qui
* appelle une autre methode réutilisant le meme objet, car il sera alors
* modifier alors qu'il ne le faut pas pour la premiere methode appelée.
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
*/
public class DimensionHelper { // DimensionHelper
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleBigVector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,12 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * DoubleBigVector.java
+package org.codelutin.math.matrix;
+
+import java.util.Arrays;
+
+/**
+ * DoubleBigVector.
*
* Created: 6 octobre 2005 02:54:36 CEST
*
@@ -26,11 +30,6 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.util.Arrays;
-
public class DoubleBigVector implements Vector { // DoubleBigVector
protected double data[] = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/DoubleVector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * FloatVector.java
- *
- * Created: 6 octobre 2005 01:29:23 CEST
- *
- * @author Benjamin POUSSIN <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix;
import java.util.Arrays;
@@ -34,10 +22,18 @@
import org.apache.commons.collections.primitives.ArrayDoubleList;
/**
- * Permet de stocker des données à une position lineair et de la redemander
+ * Permet de stocker des données à une position lineaire et de la redemander.
* Cette classe ne gére que les données lineaire. L'avantage de cette classe est
* de ne conserver que les elements differents de la valeur par defaut, ce qui
* minimize la taille du tableau necessaire a conserver les données.
+ *
+ * Created: 6 octobre 2005 01:29:23 CEST
+ *
+ * @author Benjamin POUSSIN <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class DoubleVector implements Vector { // FloatVector
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatBigVector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,12 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * FloatBigVector.java
+package org.codelutin.math.matrix;
+
+import java.util.Arrays;
+
+/**
+ * FloatBigVector.
*
* Created: 6 octobre 2005 02:54:36 CEST
*
@@ -26,11 +30,6 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.util.Arrays;
-
public class FloatBigVector implements Vector { // FloatBigVector
protected float data[] = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/FloatVector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * FloatVector.java
- *
- * Created: 6 octobre 2005 01:29:23 CEST
- *
- * @author Benjamin POUSSIN <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix;
import java.util.Arrays;
@@ -38,6 +26,14 @@
* Cette classe ne gére que les données lineaire. L'avantage de cette classe est
* de ne conserver que les elements differents de la valeur par defaut, ce qui
* minimize la taille du tableau necessaire a conserver les données.
+ *
+ * Created: 6 octobre 2005 01:29:23 CEST
+ *
+ * @author Benjamin POUSSIN <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class FloatVector implements Vector { // FloatVector
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MapFunction.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,11 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MapFunction.java
+package org.codelutin.math.matrix;
+
+/**
+ * Permet de faire un traitement sur des valeurs et d'en retourner
+ * des nouvelles.
*
* Created: 27 oct. 2004
*
@@ -26,9 +29,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
public interface MapFunction { // MapFunction
/**
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixEncoder.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,16 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatriceEncoder.java
+package org.codelutin.math.matrix;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * MatriceEncoder.
*
* Created: 21 oct. 2004
*
@@ -26,15 +34,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
public class MatrixEncoder { // MatriceEncoder
protected Writer out = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixException.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/*##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,216 +15,201 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixFactory.java
- *
- * Created: 11 octobre 2005 20:15:20 CEST
- *
- * @author Benjamin POUSSIN <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
* Cette classe permet de creer des matrices, toutes les creations de matrice
* doivent etre faite a travers cette classe. Cette classe permet de modifier la
* representation interne des matrices de facon simple.
* <p>
- *
+ * Created: 11 octobre 2005 20:15:20 CEST
+ *
+ * @author Benjamin POUSSIN <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class MatrixFactory { // MatrixFactory
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(MatrixFactory.class);
+ /* following code in only an exception generator since
+ * lutinxml in not used anymore :)
+ static {
- static {
- // on essai d'enregistrer le converter XML
- try {
- // Il faut le faire par pur introspection sinon l'exception
- // NoClassDefFoundError est levé avant d'entrer dans le constructeur
- // static :(
- Class converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
- Object converter = converterClass.newInstance();
+ // on essai d'enregistrer le converter XML
+ try {
+ // Il faut le faire par pur introspection sinon l'exception
+ // NoClassDefFoundError est levé avant d'entrer dans le constructeur
+ // static :(
+ Class converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
+ Object converter = converterClass.newInstance();
- Class converterFactoryClass = Class
- .forName("org.codelutin.xml.XMLConverterFactory");
- Method m = converterFactoryClass.getMethod("addConverter",
- Class.class, Class
- .forName("org.codelutin.xml.XMLConverter"));
- m.invoke(null, MatrixND.class, converter);
+ Class converterFactoryClass = Class
+ .forName("org.codelutin.xml.XMLConverterFactory");
+ Method m = converterFactoryClass.getMethod("addConverter",
+ Class.class, Class
+ .forName("org.codelutin.xml.XMLConverter"));
+ m.invoke(null, MatrixND.class, converter);
- // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
- // new MatrixNDXMLConverter());
- log.info("Converter XML pour MatrixND ajoute");
+ // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
+ // new MatrixNDXMLConverter());
+ log.info("Converter XML pour MatrixND ajoute");
- // on essai d'enregistrer le converter JDBC
- // le JDBC depend du XML
- try {
- converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
- converter = converterClass.newInstance();
+ // on essai d'enregistrer le converter JDBC
+ // le JDBC depend du XML
+ try {
+ converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
+ converter = converterClass.newInstance();
- converterFactoryClass = Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
- m = converterFactoryClass
- .getMethod(
- "addConverter",
- Class.class,
- Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
- m.invoke(null, MatrixND.class, converter);
+ converterFactoryClass = Class
+ .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
+ m = converterFactoryClass
+ .getMethod(
+ "addConverter",
+ Class.class,
+ Class.forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
+ m.invoke(null, MatrixND.class, converter);
- // Class converterClass =
- // org.codelutin.math.matrix.MatrixNDJDBCConverter();
- // JDBCTransformerFactory
- // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
- log.info("Converter JDBC pour MatrixND ajoute");
- } catch (Throwable eee) {
- log
- .info("librairie topia non presente. Import/Export JDBC impossible");
- log.debug("L'exception etait", eee);
- }
+ // Class converterClass =
+ // org.codelutin.math.matrix.MatrixNDJDBCConverter();
+ // JDBCTransformerFactory
+ // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
+ log.info("Converter JDBC pour MatrixND ajoute");
+ } catch (Throwable eee) {
+ log
+ .info("librairie topia non presente. Import/Export JDBC impossible");
+ log.debug("L'exception etait", eee);
+ }
- } catch (Throwable eee) {
- log
- .info("librairie lutinxml non presente. Import/Export XML impossible");
- log.debug("L'exception etait", eee);
- }
+ } catch (Throwable eee) {
+ log
+ .info("librairie lutinxml non presente. Import/Export XML impossible");
+ log.debug("L'exception etait", eee);
+ }
- }
+ }*/
- /** Valeur par defaut si aucun type de Vector n'est donné */
- static protected Class defaultVectorClass = DoubleBigVector.class;
+ /** Valeur par defaut si aucun type de Vector n'est donné */
+ protected static Class defaultVectorClass = DoubleBigVector.class;
- protected Class vectorClass = null;
+ protected Class vectorClass = null;
- protected MatrixFactory(Class vectorClass) {
- this.vectorClass = vectorClass;
- }
+ protected MatrixFactory(Class vectorClass) {
+ this.vectorClass = vectorClass;
+ }
- static public void setDefaultVectorClass(Class vectorClass) {
- defaultVectorClass = vectorClass;
- }
+ public static void setDefaultVectorClass(Class vectorClass) {
+ defaultVectorClass = vectorClass;
+ }
- static public Class getDefaultVectorClass() {
- return defaultVectorClass;
- }
+ public static Class getDefaultVectorClass() {
+ return defaultVectorClass;
+ }
- /**
- * Retourne une factory utilisant vectorClass comme classe de base a
- * l'implantation des matrices
- */
- static public MatrixFactory getInstance(Class vectorClass) {
- return new MatrixFactory(vectorClass);
- }
+ /**
+ * Retourne une factory utilisant vectorClass comme classe de base a
+ * l'implantation des matrices
+ */
+ public static MatrixFactory getInstance(Class vectorClass) {
+ return new MatrixFactory(vectorClass);
+ }
- /**
- * Utilise par defaut {@link FloatBigVector}
- */
- static public MatrixFactory getInstance() {
- return getInstance(defaultVectorClass);
- }
+ /**
+ * Utilise par defaut {@link FloatBigVector}
+ */
+ public static MatrixFactory getInstance() {
+ return getInstance(defaultVectorClass);
+ }
- public MatrixND create(int[] dim) {
- return new MatrixNDImpl(this, dim);
- }
+ public MatrixND create(int[] dim) {
+ return new MatrixNDImpl(this, dim);
+ }
- /**
- *
- * @param values
- * The values to fill the matrix
- * @param dim
- * An array representing the dimensions of the matrix
- * @return a 2D matrix filled with the values, null if the dimension is more
- * than 2
- */
+ /**
+ * Convert a double array into matrix.
+ *
+ * @param values The values to fill the matrix
+ * @param dim An array representing the dimensions of the matrix
+ * @return a 2D matrix filled with the values, null if the dimension is more than 2
+ */
+ public MatrixND create(double[] values, int[] dim) {
- public MatrixND create(double[] values, int[] dim) {
+ if (dim.length > 2) {
+ return null;
+ }
+ MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
- if (dim.length > 2) {
- return null;
- }
- MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
+ if (dim.length == 2) {
+ for (int i = 0; i < dim[0]; i++) {
+ for (int j = 0; j < dim[1]; j++) {
+ int[] coordinates = { i, j };
+ matrix.setValue(coordinates, values[i * dim[0] + j]);
+ }
+ }
+ }
+ if (dim.length == 1) {
+ for (int i = 0; i < dim[0]; i++) {
+ int[] coordinates = { i };
+ matrix.setValue(coordinates, values[i]);
+ }
+ }
- if (dim.length == 2) {
- for (int i = 0; i < dim[0]; i++) {
- for (int j = 0; j < dim[1]; j++) {
- int[] coordinates = {i,j};
- matrix.setValue(coordinates, values[i * dim[0] + j]);
- }
- }
- }
- if (dim.length == 1){
- for (int i=0;i<dim[0];i++) {
- int[] coordinates = {i};
- matrix.setValue(coordinates, values[i]);
- }
- }
+ return matrix;
+ }
- return matrix;
- }
+ public MatrixND create(List[] semantics) {
+ return new MatrixNDImpl(this, semantics);
+ }
- public MatrixND create(List[] semantics) {
- return new MatrixNDImpl(this, semantics);
- }
+ public MatrixND create(String name, int[] dim) {
+ return new MatrixNDImpl(this, name, dim);
+ }
- public MatrixND create(String name, int[] dim) {
- return new MatrixNDImpl(this, name, dim);
- }
+ public MatrixND create(String name, int[] dim, String[] dimNames) {
+ return new MatrixNDImpl(this, name, dim, dimNames);
+ }
- public MatrixND create(String name, int[] dim, String[] dimNames) {
- return new MatrixNDImpl(this, name, dim, dimNames);
- }
+ public MatrixND create(String name, List[] semantics) {
+ return new MatrixNDImpl(this, name, semantics);
+ }
- public MatrixND create(String name, List[] semantics) {
- return new MatrixNDImpl(this, name, semantics);
- }
+ public MatrixND create(String name, List[] semantics, String[] dimNames) {
+ return new MatrixNDImpl(this, name, semantics, dimNames);
+ }
- public MatrixND create(String name, List[] semantics, String[] dimNames) {
- return new MatrixNDImpl(this, name, semantics, dimNames);
- }
+ public MatrixND create(MatrixND matrix) {
+ return new MatrixNDImpl(this, matrix);
+ }
- public MatrixND create(MatrixND matrix) {
- return new MatrixNDImpl(this, matrix);
- }
+ /**
+ * Crée une nouvelle matrice identité. Une matrice identité est une matrice
+ * à 2 dimensions dont tous les éléments de la diagonal vaut 1
+ *
+ * @param size la taille de la matrice
+ * @return une nouvelle matrice identité
+ */
+ public MatrixND matrixId(int size) {
+ MatrixND result = create(new int[] { size, size });
+ for (int i = 0; i < size; i++) {
+ result.setValue(i, i, 1);
+ }
+ return result;
+ }
- /**
- * Crée une nouvelle matrice identité. Une matrice identité est une matrice
- * à 2 dimensions dont tous les éléments de la diagonal vaut 1
- *
- * @param size
- * la taille de la matrice
- * @return une nouvelle matrice identité
- */
- public MatrixND matrixId(int size) {
- MatrixND result = create(new int[] { size, size });
- for (int i = 0; i < size; i++) {
- result.setValue(i, i, 1);
- }
- return result;
- }
+ protected Vector createVector(int length) {
+ try {
+ Constructor c = vectorClass
+ .getConstructor(new Class[] { Integer.TYPE });
+ return (Vector) c.newInstance(new Object[] { length });
+ } catch (Exception eee) {
+ throw new RuntimeException("Can't create vector", eee);
+ }
+ }
- protected Vector createVector(int length) {
- try {
- Constructor c = vectorClass
- .getConstructor(new Class[] { Integer.TYPE });
- return (Vector) c.newInstance(new Object[] { length });
- } catch (Exception eee) {
- throw new RuntimeException("Can't create vector", eee);
- }
- }
-
} // MatrixFactory
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixHelper.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixHelper.java
- *
- * Created: 28 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.io.StreamTokenizer;
@@ -39,23 +27,27 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-public class MatrixHelper {
+/**
+ * MatrixHelper.
+ *
+ * Created: 28 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class MatrixHelper { // MatrixHelper
/**
- * Logger for this class
- */
- private static final Log log = LogFactory.getLog(MatrixHelper.class);
-
- // MatrixHelper
-
- /**
* 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) {
+ public static MatrixND convertToId(MatrixND mat) {
int size = mat.getDim(0);
if (size > mat.getDim(1)) {
size = mat.getDim(1);
@@ -72,7 +64,7 @@
/**
* Permet de relire une chaine du type [[[1, 2], [3, 4]],[[3, 5], [1, 4]]]
* <p>
- * Remarque: une premiere implatantion avait ete faite en utilisant
+ * Remarque: une premiere implantantion avait ete faite en utilisant
* {@link StreamTokenizer} mais en fait il y a un bug dedans, il ne sait pas
* parser les chiffres avec un exposant: 5.0E-7 par exemple est lu comme 5.0
* :(
@@ -84,7 +76,7 @@
* @param s la chaine representant les listes de liste
* @return une liste de liste ... de Double
*/
- static public List convertStringToList(String s) {
+ public static List convertStringToList(String s) {
List result = null;
Stack<List> stack = new Stack<List>();
StringBuffer number = new StringBuffer(20); // initial to 20 char
@@ -130,12 +122,12 @@
}
/**
- * permet de donner une repr�sentation String d'un tableau de coordonn�es
+ * permet de donner une représentation String d'un tableau de coordonnées
*
- * @param coordinates les coordonn�es
- * @return la chaine demand�e de la forme 1,3,34,23
+ * @param coordinates les coordonnées
+ * @return la chaine demandée de la forme 1,3,34,23
*/
- static public String coordinatesToString(int[] coordinates) {
+ public static String coordinatesToString(int[] coordinates) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < coordinates.length; i++) {
sb.append(coordinates[i]);
@@ -147,47 +139,48 @@
}
/**
- * permet de donner une repr�sentation String d'un tableau de coordonn�es
+ * permet de donner une représentation String d'un tableau de coordonnées
*
- * @param coordinates les coordonn�es
- * @return la chaine demand�e de la forme "Ob1","Ob2,"Ob3", ... la chaine
- * prise pour l'objet est celle retourn�e par la m�thode toString de
+ * @param coordinates les coordonnées
+ * @return la chaine demandée de la forme "Ob1","Ob2,"Ob3", ... la chaine
+ * prise pour l'objet est celle retournée par la méthode toString de
* l'objet
*/
- static public String coordinatesToString(Object[] coordinates) {
+ public static String coordinatesToString(Object[] coordinates) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < coordinates.length; i++) {
sb.append(coordinates[i]);
- if (i + 1 < coordinates.length)
+ if (i + 1 < coordinates.length) {
sb.append(',');
+ }
}
return sb.toString();
}
/**
- * Permet de savoir si deux dimension sont identique
+ * Permet de savoir si deux dimension sont identiques.
*/
- static public boolean sameDimension(int[] dim1, int[] dim2) {
+ public static boolean sameDimension(int[] dim1, int[] dim2) {
return Arrays.equals(dim1, dim2);
}
/**
- * Permet de convertir des coordonn�es d�fini par des entiers en coordonn�e
+ * Permet de convertir des coordonnées définies par des entiers en coordonnées
* semantique par des objets
*
- * @param semantics la semantique � utilis� pour la conversion
- * @param coordinates les coordonn�es � convertir
- * @return un tableau donnant les coordonn�es sous forme semantique s'il n'y
+ * @param semantics la semantique à utilisé pour la conversion
+ * @param coordinates les coordonnées à convertir
+ * @return un tableau donnant les coordonnées sous forme semantique s'il n'y
* a pas de semantique (liste pleine de null) alors un objet Integer
- * est cr�er pour repr�senter la semantique de la dimension.
+ * est créer pour représenter la semantique de la dimension.
*/
- static public Object[] dimensionToSemantics(List[] semantics,
+ public static Object[] dimensionToSemantics(List[] semantics,
int[] coordinates) {
Object[] result = new Object[coordinates.length];
for (int i = 0; i < result.length; i++) {
result[i] = semantics[i].get(coordinates[i]);
if (result[i] == null) {
- result[i] = new Integer(coordinates[i]);
+ result[i] = Integer.valueOf(coordinates[i]);
}
}
return result;
@@ -204,7 +197,7 @@
* Integer alors la valeur de l'integer est utilisé pour la
* conversion.
*/
- static public int[] semanticsToDimension(List[] semantics,
+ public static int[] semanticsToDimension(List[] semantics,
Object[] coordinates) {
int[] result = new int[coordinates.length];
for (int i = 0; i < coordinates.length; i++) {
@@ -220,12 +213,14 @@
/**
* Permet de retrouver la position d'un objet dans une liste
*
- * @param semantics la semantique � utilis� pour la recherche
+ * @param semantics la semantique à utilisé pour la recherche
* @param dim la dimension dans lequel il faut faire la recherche
- * @param o l'objet � rechercher
- * @return la position de l'objet dans la dimension demand�e
+ * @param o l'objet à rechercher
+ * @return la position de l'objet dans la dimension demandée
+ *
+ * @throws NoSuchElementException If element doesn't exists
*/
- static public int indexOf(List[] semantics, int dim, Object o)
+ public static int indexOf(List[] semantics, int dim, Object o)
throws NoSuchElementException {
if (o instanceof Integer) {
return ((Integer) o).intValue();
@@ -236,20 +231,20 @@
}
if (result == -1) {
throw new NoSuchElementException(
- "L'objet pass� en argument n'a pas �t� retrouve ou la dimension donn�e ne convient pas:"
+ "L'objet passé en argument n'a pas été retrouvé ou la dimension donnée ne convient pas:"
+ o + " in " + semantics[dim]);
}
return result;
}
/**
- * Permet de remplir toute la matrice avec la m�me donn�e
+ * Permet de remplir toute la matrice avec la même donnée
*
- * @param mat la matrice � remplir
+ * @param mat la matrice à remplir
* @param value la valeur de remplissage
- * @return la matrice pass� en param�tre
+ * @return la matrice passé en paramêtre
*/
- static public MatrixND fill(MatrixND mat, final double value) {
+ public static MatrixND fill(MatrixND mat, final double value) {
mat.map(new MapFunction() {
public double apply(double v) {
return value;
@@ -259,11 +254,11 @@
}
// /**
- // * Cr�e une nouvelle matrice identit�. Une matrice identit� est une
- // matrice
- // * � 2 dimensions dont tous les �l�ments de la diagonal vaut 1
+ // * Crée une nouvelle matrice identité. Une matrice identité est une
+ // * matrice à 2 dimensions dont tous les éléments de la diagonale
+ // * valent 1
// * @param size la taille de la matrice
- // * @return une nouvelle matrice identit�
+ // * @return une nouvelle matrice identité
// */
// static public MatrixND matrixId(int size){
// MatrixND result = new MatrixNDImpl(new int[]{size, size});
@@ -275,19 +270,19 @@
/**
* Retourne la valeur la plus courrement rencontrer dans un tableau. si
- * plusieurs valeurs ont le m�me nombre d'occurence la plus petite valeur
- * est retourn�.
+ * plusieurs valeurs ont le même nombre d'occurence la plus petite valeur
+ * est retournée.
*
* @param tab le tableau de valeur
* @return la valeur la plus nombreuse dans le tableau
*/
- static public double maxOccurence(double[] tab) {
+ public static double maxOccurence(double[] tab) {
double[] tmp = new double[tab.length];
System.arraycopy(tab, 0, tmp, 0, tab.length);
return maxOccurence1(tmp);
}
- static public double maxOccurence(float[] tab) {
+ public static double maxOccurence(float[] tab) {
double[] tmp = new double[tab.length];
for (int i = 0; i < tab.length; i++) {
tmp[i] = tab[i];
@@ -297,9 +292,9 @@
/**
* le tableau en entre est trie durant l'execution de la methode, il est
- * donc modifi�
+ * donc modifié
*/
- static protected double maxOccurence1(double[] tmp) {
+ protected static double maxOccurence1(double[] tmp) {
if (tmp.length == 0) {
throw new IllegalArgumentException("Array must be not empty");
}
@@ -313,7 +308,7 @@
int count = 1;
// la valeur la plus rencontrer
double result = tmp[0];
- // la valeur que l'on vient de traiter pr�c�dement
+ // la valeur que l'on vient de traiter précédement
double old = tmp[0];
// la valeur courante lu dans le tableaux
double current = tmp[0];
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIterator.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixIterator.java
+package org.codelutin.math.matrix;
+
+/**
+ * MatrixIterator.
*
* Created: 28 oct. 2004
*
@@ -26,9 +28,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
public interface MatrixIterator extends BasicMatrixIterator { // MatrixIterator
/**
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixIteratorImpl.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,12 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixIteratorImpl.java
+package org.codelutin.math.matrix;
+
+import java.util.List;
+
+/**
+ * MatrixIteratorImpl.
*
* Created: 28 oct. 2004
*
@@ -26,11 +30,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.util.List;
-
public class MatrixIteratorImpl implements MatrixIterator { // MatrixIteratorImpl
protected BasicMatrixIterator iterator = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixND.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,18 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixND.java
+
+
+package org.codelutin.math.matrix;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Serializable;
+import java.io.Writer;
+import java.util.List;
+
+/**
+ * MatrixND.
*
* Created: 29 oct. 2004
*
@@ -26,15 +36,6 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Serializable;
-import java.io.Writer;
-import java.util.List;
-
public interface MatrixND extends Serializable, Cloneable { // MatrixND
/**
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixNDImpl.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,13 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixNDImpl.java
+package org.codelutin.math.matrix;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * MatrixNDImpl.
*
* Created: 29 oct. 2004
*
@@ -26,15 +31,9 @@
* Mise a jour: $Date$
* par : $Author$
*/
-
-package org.codelutin.math.matrix;
-
-import java.util.Arrays;
-import java.util.List;
-
public class MatrixNDImpl extends AbstractMatrixND { // MatrixNDImpl
- /** */
+ /** serialVersionUID. */
private static final long serialVersionUID = 1L;
protected BasicMatrix matrix = null;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SemanticList.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * SemanticList.java
- *
- * Created: 6 sept. 06 17:18:23
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix;
import java.util.AbstractList;
@@ -37,7 +25,15 @@
import java.util.RandomAccess;
/**
+ * SemanticList.
+ *
+ * Created: 6 sept. 06 17:18:23
+ *
* @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class SemanticList<T> extends AbstractList<T> implements RandomAccess {
@@ -49,8 +45,6 @@
}
/*
- * (non-Javadoc)
- *
* @see java.util.AbstractList#get(int)
*/
@Override
@@ -60,8 +54,6 @@
}
/*
- * (non-Javadoc)
- *
* @see java.util.AbstractCollection#size()
*/
@Override
@@ -71,8 +63,6 @@
}
/*
- * (non-Javadoc)
- *
* @see java.util.AbstractList#indexOf(java.lang.Object)
*/
@Override
@@ -89,7 +79,7 @@
/**
* @return
*/
- private Map getIndex() {
+ protected Map getIndex() {
if (index == null) {
index = new HashMap<Object, Integer>();
for (int i = 0; i < datas.size(); i++) {
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/SubMatrix.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/*##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * SubMatrix.java
- *
- * Created: 29 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.io.Serializable;
@@ -39,12 +27,20 @@
* Pour l'instant une sous matrice a obligatoirement le meme nombre de dimension
* que la matrice qu'elle contient. Elle permet juste de reduire le nombre
* d'element d'une dimension.
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
*/
public class SubMatrix extends AbstractMatrixND { // SubMatrix
- /** */
- private static final long serialVersionUID = 1L;
-
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 4092234115185263506L;
+
protected MatrixND matrix = null;
protected DimensionConverter converter = null;
@@ -183,9 +179,10 @@
* La conversion est le mapping d'un element vers un autre element
*/
protected class MappingConverter implements DimensionConverter {
- /** */
- private static final long serialVersionUID = 1L;
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -6367416559713556559L;
+
protected int dim;
protected int[] elem = null;
@@ -203,7 +200,7 @@
return result;
} else {
throw new NoSuchElementException(
- "L'indice est supérieur au nombre d'élement de la sous matrice pour cette dimension.");
+ "L'indice est supérieur au nombre d'élements de la sous matrice pour cette dimension.");
}
}
}
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/Vector.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * Vector.java
+package org.codelutin.math.matrix;
+
+/**
+ * Vector.
*
* Created: 6 octobre 2005 02:51:12 CEST
*
@@ -26,9 +28,6 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix;
-
public interface Vector { // Vector
public double getMaxOccurence();
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEditor.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,6 +1,6 @@
/*
* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -55,10 +55,18 @@
* TODO: Une methode permettant de retourne la sous matrice de la selection que
* la matrice soit reprensentée en lineaire ou non. (avoir un mapping cellule de
* table vers element de matrice
+ *
+ * Created: 29 oct. 2004
+ *
+ * @author Benjamin Poussin <poussin(a)codelutin.com>
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
*/
public class MatrixPanelEditor extends JPanel implements TableModelListener { // MatrixPanelEditor
- /** */
+ /** serialVersionUID */
private static final long serialVersionUID = 2097859265435050946L;
private final static int DEFAULT_WIDTH = 150;
@@ -148,7 +156,7 @@
initDimensionEdit();
}
- JButton bEdit = null;
+ protected JButton bEdit = null;
protected JButton getButtonEdit() {
if (bEdit == null) {
@@ -316,13 +324,6 @@
fireEvent();
}
- /**
- * @deprecated use setMatrix
- */
- public void setMatrice(MatrixND m) throws MatrixException {
- setMatrix(m);
- }
-
public MatrixND getMatrix() {
// if (m == null) {
return m;
@@ -334,13 +335,6 @@
}
/**
- * @deprecated use setMatrix
- */
- public MatrixND getMatrice() {
- return getMatrix();
- }
-
- /**
* Enable the matrix to be edited. By default, the matrix is editable.
*/
public void setEnabled(boolean enabled) {
@@ -367,10 +361,7 @@
}
/*
- * (non-Javadoc)
- *
- * @seejavax.swing.event.TableModelListener#tableChanged(javax.swing.event.
- * TableModelEvent)
+ * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
*/
public void tableChanged(TableModelEvent e) {
fireEvent();
@@ -440,7 +431,6 @@
// final MatrixPanelEditor mp = ed;
frame.addWindowListener(new WindowAdapter() {
-
public void windowClosing(WindowEvent e) {
System.exit(0);
}
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelEvent.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -15,8 +15,14 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixPanelEvent.java
+package org.codelutin.math.matrix.gui;
+
+import java.util.EventObject;
+
+import org.codelutin.math.matrix.MatrixND;
+
+/**
+ * MatrixPanelEvent.
*
* Created: 21 mars 2006 14:53:25
*
@@ -26,20 +32,11 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix.gui;
-
-import java.util.EventObject;
-
-import org.codelutin.math.matrix.MatrixND;
-
-/**
- * @author poussin
- *
- */
-
public class MatrixPanelEvent extends EventObject {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 368165247855055401L;
+
/**
* @param source
*/
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPanelListener.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixPanelListener.java
+package org.codelutin.math.matrix.gui;
+
+/**
+ * MatrixPanelListener.
*
* Created: 21 mars 2006 14:54:05
*
@@ -26,14 +28,6 @@
* Last update: $Date$
* by : $Author$
*/
-
-package org.codelutin.math.matrix.gui;
-
-/**
- * @author poussin
- *
- */
-
public interface MatrixPanelListener {
/**
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixPopupMenu.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixPopupMenu.java
- *
- * Created: 22 mars 2006 12:11:46
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import static org.codelutin.i18n.I18n._;
@@ -61,11 +49,19 @@
/**
* Ajout d'un menu contextuel sur la matrice dans l'editeur
*
+ * Created: 22 mars 2006 12:11:46
+ *
* @author ruchaud
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
public class MatrixPopupMenu extends JPopupMenu {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 3349189688987885915L;
+
private MatrixPanelEditor matrixEditor;
private JFileChooser fileChooser;
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModel.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixTableModel.java
- *
- * Created: 22 mars 2006 12:53:22
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import javax.swing.table.TableCellRenderer;
@@ -35,10 +23,16 @@
import org.codelutin.math.matrix.MatrixND;
/**
+ * MatrixTableModel.
+ *
+ * Created: 22 mars 2006 12:53:22
+ *
* @author poussin
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
-
public interface MatrixTableModel extends TableModel {
public void setMatrix(MatrixND m);
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelLinear.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixTableModelLinear.java
- *
- * Created: 22 mars 2006 12:11:46
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import java.awt.Color;
@@ -49,19 +37,25 @@
import org.codelutin.math.matrix.MatrixND;
/**
+ * MatrixTableModelLinear.
+ *
+ * Created: 22 mars 2006 12:11:46
+ *
* @author poussin
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
-
public class MatrixTableModelLinear extends AbstractTableModel implements
MatrixTableModel {
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory
- .getLog(MatrixTableModelLinear.class);
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -7498520067143762434L;
+ /** Logger for this class. */
+ private static Log log = LogFactory.getLog(MatrixTableModelLinear.class);
+
protected boolean enabled = true;
protected MatrixND m = null;
protected boolean showDefault = false;
@@ -138,8 +132,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.TableModel#getRowCount()
*/
public int getRowCount() {
@@ -147,8 +139,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.TableModel#getColumnCount()
*/
public int getColumnCount() {
@@ -156,8 +146,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
public Object getValueAt(int rowIndex, int columnIndex) {
@@ -171,8 +159,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
*/
@Override
@@ -181,10 +167,7 @@
}
/*
- * (non-Javadoc)
- *
- * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object,
- * int, int)
+ * @see javax.swing.table.AbstractTableModel#setValueAt(java.lang.Object, int, int)
*/
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
@@ -201,8 +184,6 @@
}
/*
- * (non-Javadoc)
- *
* @see javax.swing.table.AbstractTableModel#getColumnName(int)
*/
@Override
@@ -235,6 +216,9 @@
class MatrixCellRenderer extends DefaultTableCellRenderer {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 6537813058357761914L;
+
protected MatrixTableModelLinear model = null;
protected Color bg = null;
protected Color fg = null;
@@ -249,9 +233,6 @@
border = getBorder();
}
- /** */
- private static final long serialVersionUID = 6537813058357761914L;
-
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/gui/MatrixTableModelND.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/*##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,18 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixTableModel.java
- *
- * Created: 21 mars 2006 19:01:27
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import java.awt.Color;
@@ -47,20 +35,23 @@
import org.codelutin.math.matrix.MatrixND;
/**
- * @author poussin
+ * Extension de AbstractTableModel pour definir un TableModel avec une
+ * MatrixND comme support d'information.
*
+ * TODO changer les 'matrice' en 'matrix', s'il y a des methodes public
+ * avec les nom 'matice' les laisser mais les mettres depreciées
+ *
+ * Created: 21 mars 2006 19:01:27
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
+public class MatrixTableModelND extends AbstractTableModel implements MatrixTableModel {
-public/*
- * Extension de AbstractTableModel pour definir un TableModel avec une
- * MatrixND comme support d'information.
- *
- * @todo changer les 'matrice' en 'matrix', s'il y a des methodes public
- * avec les nom 'matice' les laisser mais les mettres depreciées
- */
-class MatrixTableModelND extends AbstractTableModel implements MatrixTableModel {
-
- /** */
+ /** serialVersionUID. */
private static final long serialVersionUID = 983978774901981167L;
protected MatrixND m;
@@ -318,6 +309,9 @@
class MatrixCellRenderer extends DefaultTableCellRenderer {
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 6537813058357761914L;
+
protected MatrixTableModelND model = null;
protected Color bg = null;
protected Color fg = null;
@@ -332,9 +326,6 @@
border = getBorder();
}
- /** */
- private static final long serialVersionUID = 6537813058357761914L;
-
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixBigTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,10 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatriceTest.java
+package org.codelutin.math.matrix;
+
+/**
+ * BasicMatrixBigTest.
*
* Created: 27 oct. 2004
*
@@ -26,14 +28,11 @@
* Mise a jour: $Date$
* par : $Author$
*/
+public class BasicMatrixBigTest extends BasicMatrixTest { // BasicMatrixBigTest
-package org.codelutin.math.matrix;
-
-public class BasicMatrixBigTest extends BasicMatrixTest { // BasicMatrixTest
-
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance(FloatBigVector.class);
}
-} // BasicMatrixTest
+} // BasicMatrixBigTest
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/BasicMatrixTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -15,8 +15,17 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatriceTest.java
+package org.codelutin.math.matrix;
+
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * BasicMatrixTest.
*
* Created: 27 oct. 2004
*
@@ -26,96 +35,89 @@
* Mise a jour: $Date$
* par : $Author$
*/
+public class BasicMatrixTest { // BasicMatrixTest
-package org.codelutin.math.matrix;
-
-import java.util.Arrays;
-import java.util.NoSuchElementException;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.lang.time.DurationFormatUtils;
-
-public class BasicMatrixTest extends TestCase { // BasicMatrixTest
-
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance();
}
+ @Test
public void testNew() throws Exception {
BasicMatrix mat = null;
try {
mat = new BasicMatrix(getFactory(), null);
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (NullPointerException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
try {
mat = new BasicMatrix(getFactory(), new int[] { 0 });
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IllegalArgumentException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
mat = new BasicMatrix(getFactory(), new int[] { 100 });
mat = new BasicMatrix(getFactory(), new int[] { 10, 1 });
- assertEquals(0.0, mat.getMaxOccurence());
+ Assert.assertEquals(0.0, mat.getMaxOccurence(), 0);
mat = new BasicMatrix(getFactory(), new int[] { 10, 10, 10, 10 });
try {
mat = new BasicMatrix(getFactory(), new int[] { -10 });
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IllegalArgumentException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
try {
mat = new BasicMatrix(getFactory(), new int[] { 10, 20, -10, 20 });
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IllegalArgumentException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
}
+ @Test
public void testDimension() throws Exception {
BasicMatrix mat = null;
mat = new BasicMatrix(getFactory(), new int[] { 1, 10, 30, 5 });
- assertEquals(4, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(10, mat.getDim(1));
- assertEquals(30, mat.getDim(2));
- assertEquals(5, mat.getDim(3));
+ Assert.assertEquals(4, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(10, mat.getDim(1));
+ Assert.assertEquals(30, mat.getDim(2));
+ Assert.assertEquals(5, mat.getDim(3));
try {
mat.getDim(-3);
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IndexOutOfBoundsException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
try {
mat.getDim(4);
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (IndexOutOfBoundsException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
}
+ @Test
public void testGetSet() throws Exception {
BasicMatrix mat = null;
// test avec la plus petit BasicMatrix possible
mat = new BasicMatrix(getFactory(), new int[] { 1 });
// test la valeur par defaut doit etre 0
- assertEquals(0, mat.getValue(new int[] { 0 }), 0);
+ Assert.assertEquals(0, mat.getValue(new int[] { 0 }), 0);
mat.setValue(new int[] { 0 }, 30);
- assertEquals(30, mat.getValue(new int[] { 0 }), 0);
+ Assert.assertEquals(30, mat.getValue(new int[] { 0 }), 0);
// acces a un element qui n'existe pas
try {
mat.getValue(new int[] { 1 });
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (NoSuchElementException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
mat = new BasicMatrix(getFactory(), new int[] { 1, 10, 5 });
@@ -134,37 +136,39 @@
mat.setValue(new int[] { 0, 2, 2 }, 22);
mat.setValue(new int[] { 0, 9, 4 }, 98);
mat.setValue(new int[] { 0, 4, 2 }, 97);
- assertEquals(0, mat.getValue(new int[] { 0, 0, 0 }), 0);
- assertEquals(98, mat.getValue(new int[] { 0, 9, 4 }), 0);
- assertEquals(97, mat.getValue(new int[] { 0, 4, 2 }), 0);
+ Assert.assertEquals(0, mat.getValue(new int[] { 0, 0, 0 }), 0);
+ Assert.assertEquals(98, mat.getValue(new int[] { 0, 9, 4 }), 0);
+ Assert.assertEquals(97, mat.getValue(new int[] { 0, 4, 2 }), 0);
// System.out.println(mat.toString());
// acces a un element qui n'existe pas
try {
mat.setValue(new int[] { 0, 9, 5 }, 44);
- assertFalse(true); // on ne doit pas etre ici
+ Assert.assertFalse(true); // on ne doit pas etre ici
} catch (NoSuchElementException eee) {
- assertTrue(true); // mais on doit etre la
+ Assert.assertTrue(true); // mais on doit etre la
}
}
+ @Test
public void testEquals() throws Exception {
BasicMatrix m1 = new BasicMatrix(getFactory(), new int[] { 3, 3, 3, 3 });
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 3, 3, 3, 3 });
- assertEquals(m1, m2);
+ Assert.assertEquals(m1, m2);
m1.setValue(new int[] { 1, 2, 1, 2 }, 123);
m2.setValue(new int[] { 1, 2, 1, 2 }, 123);
- assertEquals(m1, m2);
+ Assert.assertEquals(m1, m2);
m1.setValue(new int[] { 1, 0, 1, 0 }, 321);
- assertFalse(m1.equals(m2));
+ Assert.assertFalse(m1.equals(m2));
}
+ @Test
public void testIterator() throws Exception {
int[][] val27 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 },
@@ -184,7 +188,7 @@
cpt++;
}
- assertEquals(27, cpt);
+ Assert.assertEquals(27, cpt);
cpt = 0;
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 1 });
@@ -194,15 +198,16 @@
cpt++;
}
- assertEquals(1, cpt);
+ Assert.assertEquals(1, cpt);
}
- MapFunction f = new MapFunction() {
+ protected MapFunction f = new MapFunction() {
public double apply(double value) {
return value + 2;
}
};
+ @Test
public void testPerfLineaire() throws Exception {
long time = System.nanoTime();
BasicMatrix m1 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30,
@@ -214,6 +219,7 @@
"s'.'S"));
}
+ @Test
public void testPerfCoordonnee() throws Exception {
long time = System.nanoTime();
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30,
@@ -245,6 +251,7 @@
}
+ @Test
public void testPerfCoordonnee2() throws Exception {
long time = System.nanoTime();
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30,
@@ -276,6 +283,7 @@
}
+ @Test
public void testPerfCoordonnee4() throws Exception {
long time = System.nanoTime();
BasicMatrix m2 = new BasicMatrix(getFactory(), new int[] { 30, 30, 30,
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/FloatVectorTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,15 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * FloatVectorTest.java
+package org.codelutin.math.matrix;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * FloatVectorTest.
*
* Created: 6 octobre 2005 01:54:49 CEST
*
@@ -26,27 +33,26 @@
* Last update: $Date$
* by : $Author$
*/
+public class FloatVectorTest { // FloatVectorTest
-package org.codelutin.math.matrix;
-
-import junit.framework.TestCase;
-
-public class FloatVectorTest extends TestCase { // FloatVectorTest
-
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(FloatVectorTest.class);
+
+ @Test
public void testAll() throws Exception {
FloatVector v = new FloatVector(16);
- assertEquals(0.0, v.getMaxOccurence());
+ Assert.assertEquals(0.0, v.getMaxOccurence(), 0);
v.setValue(0, 1);
- assertEquals(1.0, v.getValue(0));
+ Assert.assertEquals(1.0, v.getValue(0), 0);
v.setValue(15, 16);
- assertEquals(16.0, v.getValue(15));
+ Assert.assertEquals(16.0, v.getValue(15), 0);
- assertEquals(2, v.positionSize);
+ Assert.assertEquals(2, v.positionSize);
v.setValue(0, 0);
- assertEquals(0.0, v.getValue(0));
- assertEquals(1, v.positionSize);
+ Assert.assertEquals(0.0, v.getValue(0), 0);
+ Assert.assertEquals(1, v.positionSize);
v.setValue(0, 4);
v.setValue(1, 4);
@@ -55,27 +61,30 @@
v.setValue(4, 4);
v.setValue(5, 4);
v.setValue(6, 4);
- assertEquals(0.0, v.getMaxOccurence());
+ Assert.assertEquals(0.0, v.getMaxOccurence(), 0);
v.setValue(8, 4);
- assertEquals(4.0, v.getMaxOccurence());
+ Assert.assertEquals(4.0, v.getMaxOccurence(), 0);
v.setValue(0, 0);
- assertEquals(0.0, v.getMaxOccurence());
+ Assert.assertEquals(0.0, v.getMaxOccurence(), 0);
try {
v.getValue(-1);
- assertTrue(false);
- } catch (IllegalArgumentException eee) {
- assertTrue(true);
+ Assert.fail("An exception must be thrown");
+ } catch (IllegalArgumentException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exception normally thrown", e);
+ }
}
try {
v.getValue(20);
- assertTrue(false);
- } catch (IllegalArgumentException eee) {
- assertTrue(true);
+ Assert.fail("An exception must be thrown");
+ } catch (IllegalArgumentException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exception normally thrown", e);
+ }
}
}
} // FloatVectorTest
-
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/ImportExportMatrixTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,6 +1,5 @@
-/*
- * *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+/* *##% lutinmatrix
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -24,26 +23,32 @@
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
/**
- * Test de l'import et export CSV
+ * Test de l'import et export CSV.
*
* @author ruchaud
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
-public class ImportExportMatrixTest extends TestCase {
+public class ImportExportMatrixTest {
- private MatrixND mat1D;
- private MatrixND mat2D;
- private MatrixND mat2DSemantics;
+ protected MatrixND mat1D;
+ protected MatrixND mat2D;
+ protected MatrixND mat2DSemantics;
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance(DoubleVector.class);
}
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
mat1D = new MatrixNDImpl(getFactory(), new int[] { 10 });
mat1D.setValue(new int[] { 0 }, 0);
mat1D.setValue(new int[] { 1 }, 1);
@@ -70,6 +75,7 @@
sem1, sem2 }, new String[] { "dim1", "dim2" });
}
+ @Test
public void testImport() throws IOException {
String test = "5.0E-7;1.0;2.0;3.0;4.0;4.0;4.0;4.0;0.3;0.0\n"
+ "0.0;0.0;7.0;0.0;0.0;2.0;0.0;0.0;4.0;0.0\n"
@@ -77,19 +83,20 @@
StringReader reader = new StringReader(test);
mat2D.importCSV(reader, new int[] { 0, 0 });
- assertEquals(mat2D.getValue(0, 0), 5.0E-7);
- assertEquals(mat2D.getValue(1, 2), 7.0);
- assertEquals(mat2D.getValue(2, 2), 8.0);
- assertEquals(mat2D.getValue(1, 8), 4.0);
+ Assert.assertEquals(mat2D.getValue(0, 0), 5.0E-7, 0);
+ Assert.assertEquals(mat2D.getValue(1, 2), 7.0, 0);
+ Assert.assertEquals(mat2D.getValue(2, 2), 8.0, 0);
+ Assert.assertEquals(mat2D.getValue(1, 8), 4.0, 0);
reader = new StringReader(test);
mat2D.importCSV(reader, new int[] { 1, 1 });
- assertEquals(mat2D.getValue(1, 1), 5.0E-7);
- assertEquals(mat2D.getValue(2, 3), 7.0);
- assertEquals(mat2D.getValue(3, 3), 8.0);
- assertEquals(mat2D.getValue(2, 9), 4.0);
+ Assert.assertEquals(mat2D.getValue(1, 1), 5.0E-7, 0);
+ Assert.assertEquals(mat2D.getValue(2, 3), 7.0, 0);
+ Assert.assertEquals(mat2D.getValue(3, 3), 8.0, 0);
+ Assert.assertEquals(mat2D.getValue(2, 9), 4.0, 0);
}
+ @Test
public void testExport() throws IOException {
testExport(mat1D, false);
testExport(mat2D, false);
@@ -101,7 +108,8 @@
testExport(mat2DSemantics, true);
}
- private void testExport(MatrixND matrixND, boolean withSemantics)
+ @Ignore
+ protected void testExport(MatrixND matrixND, boolean withSemantics)
throws IOException {
StringWriter writer = new StringWriter();
matrixND.exportCSV(writer, withSemantics);
@@ -112,15 +120,16 @@
StringWriter readerToWriter = new StringWriter();
matrixND.exportCSV(readerToWriter, withSemantics);
- assertEquals(writer.toString(), readerToWriter.toString());
+ Assert.assertEquals(writer.toString(), readerToWriter.toString());
}
+ @Test
public void testSupport() throws Exception {
- assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 1 })
+ Assert.assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 1 })
.isSupportedCSV());
- assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 2, 2 })
+ Assert.assertEquals(true, new MatrixNDImpl(getFactory(), new int[] { 2, 2 })
.isSupportedCSV());
- assertEquals(false, new MatrixNDImpl(getFactory(),
+ Assert.assertEquals(false, new MatrixNDImpl(getFactory(),
new int[] { 3, 3, 3 }).isSupportedCSV());
}
}
Deleted: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixEncoderDecoderTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,82 +0,0 @@
-/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-
-/* *
- * MatrixEncoderDecoderTest.java
- *
- * Created: 31 oct. 2004
- *
- * @author Benjamin Poussin <poussin(a)codelutin.com>
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
-package org.codelutin.math.matrix;
-
-import junit.framework.TestCase;
-
-/**
- * FIXME comment test since lutinxml is not used any.
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class MatrixEncoderDecoderTest extends TestCase { // MatrixEncoderDecoderTest
-
- public void testDummy() {
- // dummy test for hudson compilation work, perhaps remove this class if we put something about XML in TODO
- assertTrue(true);
- }
-
- /*
- * public MatrixFactory getFactory() throws Exception { return
- * MatrixFactory.getInstance(); }
- *
- * protected void subtestEncoderDecoder(MatrixND mat) throws Exception { //
- * encodage en XML String xml = MatrixHelper.encodeToXML(mat); // decodage
- * depuis le XML MatrixND mat2 = MatrixHelper.decodeFromXML(xml); //
- * reencodage de la matrice resultat String xml2 =
- * MatrixHelper.encodeToXML(mat2); // on verifie que les 2 matrices sont
- * egals et leur representation // XML aussi assertEquals(mat, mat2);
- * assertEquals(xml, xml2); }
- *
- * public void testEncoderDecoder() throws Exception { List s1 =
- * Arrays.asList(new String[]{"a", "b", "c"}); List s2 = Arrays.asList(new
- * String[]{"e", "f", "g"}); List s3 = Arrays.asList(new String[]{"k", "l",
- * "m"});
- *
- * MatrixND mat = null;
- *
- * mat = getFactory().create("Ma mat", new int[]{3,3,3});
- * subtestEncoderDecoder(mat);
- *
- * mat = getFactory().create("Ma mat", new List[]{s1, s2, s3});
- * subtestEncoderDecoder(mat);
- *
- * // on modifie S1 pour avoir un null au milieu s1.set(1, null); mat =
- * getFactory().create("Ma mat", new List[]{s1, s2, s3}, new
- * String[]{"dim abc", "dim efg", "dim klm"}); mat.setSemantics(1,
- * Collections.nCopies(3, null)); subtestEncoderDecoder(mat); }
- */
-
-} // MatrixEncoderDecoderTest
-
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixHelperTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,8 +15,17 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixHelperTest.java
+package org.codelutin.math.matrix;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * MatrixHelperTest.
*
* Created: 29 oct. 2004
*
@@ -26,68 +35,71 @@
* Mise a jour: $Date$
* par : $Author$
*/
+public class MatrixHelperTest { // MatrixHelperTest
-package org.codelutin.math.matrix;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-public class MatrixHelperTest extends TestCase { // MatrixHelperTest
-
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static Log log = LogFactory.getLog(MatrixHelperTest.class);
+
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance();
}
+ @Test
public void testCoordinatesToString() throws Exception {
- assertEquals("1", MatrixHelper.coordinatesToString(new int[] { 1 }));
- assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[] { 2,
+ Assert.assertEquals("1", MatrixHelper.coordinatesToString(new int[] { 1 }));
+ Assert.assertEquals("2,3,4,5", MatrixHelper.coordinatesToString(new int[] { 2,
3, 4, 5 }));
- assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[] {
+ Assert.assertEquals("2,3,4,5,234", MatrixHelper.coordinatesToString(new int[] {
2, 3, 4, 5, 234 }));
- assertEquals("a", MatrixHelper
+ Assert.assertEquals("a", MatrixHelper
.coordinatesToString(new String[] { "a" }));
- assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[] {
+ Assert.assertEquals("a,b,n,m", MatrixHelper.coordinatesToString(new String[] {
"a", "b", "n", "m" }));
- assertEquals("a,b,f,e,aze",
+ Assert.assertEquals("a,b,f,e,aze",
MatrixHelper.coordinatesToString(new String[] { "a", "b", "f",
"e", "aze" }));
}
+ @Test
public void testSameDimension() throws Exception {
- assertTrue(MatrixHelper.sameDimension(new int[] { 1 }, new int[] { 1 }));
- assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 }, new int[] {
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1 }, new int[] { 1 }));
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 2 }, new int[] {
1, 2 }));
- assertTrue(MatrixHelper.sameDimension(new int[] { 1, 324, 3 },
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 1, 324, 3 },
new int[] { 1, 324, 3 }));
}
+ @Test
public void testDimensionToSemantics() throws Exception {
// TODO faire un test pour dimensionToSemantics
}
+ @Test
public void testSemanticsToDimension() throws Exception {
// TODO faire un test pour semanticsToDimension
}
+ @Test
public void testFill() throws Exception {
MatrixND mat = getFactory().create(new int[] { 3, 3 });
MatrixHelper.fill(mat, 4);
- assertEquals(4, mat.getValue(1, 1), 0);
+ Assert.assertEquals(4, mat.getValue(1, 1), 0);
}
+ @Test
public void testMatrixId() throws Exception {
MatrixND mat = getFactory().matrixId(4);
- assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat.getDim()));
- assertEquals(0, mat.getValue(1, 2), 0);
- assertEquals(1, mat.getValue(0, 0), 0);
- assertEquals(1, mat.getValue(1, 1), 0);
- assertEquals(1, mat.getValue(2, 2), 0);
- assertEquals(1, mat.getValue(3, 3), 0);
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 4, 4 }, mat.getDim()));
+ Assert.assertEquals(0, mat.getValue(1, 2), 0);
+ Assert.assertEquals(1, mat.getValue(0, 0), 0);
+ Assert.assertEquals(1, mat.getValue(1, 1), 0);
+ Assert.assertEquals(1, mat.getValue(2, 2), 0);
+ Assert.assertEquals(1, mat.getValue(3, 3), 0);
}
+ @Test
public void testToList() throws Exception {
MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
mat1.setValue(0, 0, 0, -1.0E-7);
@@ -101,49 +113,52 @@
System.out.println(l);
System.out.println(l2);
- assertEquals(l, l2);
+ Assert.assertEquals(l, l2);
}
+ @Test
public void testMaxOccurence() throws Exception {
double[] val = new double[5];
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[2] = -1;
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[0] = -1;
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[1] = -1;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[4] = -3;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[3] = 3;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val = new double[6];
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[2] = -1;
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[0] = -1;
- assertEquals(0, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(0, MatrixHelper.maxOccurence(val), 0);
val[1] = -1;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[4] = -3;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[3] = -3;
- assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-1, MatrixHelper.maxOccurence(val), 0);
val[5] = -3;
- assertEquals(-3, MatrixHelper.maxOccurence(val), 0);
+ Assert.assertEquals(-3, MatrixHelper.maxOccurence(val), 0);
val = new double[0];
try {
MatrixHelper.maxOccurence(val);
- assertFalse(true); // on ne passe pas ici
- } catch (IllegalArgumentException eee) {
- assertTrue(true); // on passe ici
+ Assert.fail("AN exception must be thrown");
+ } catch (IllegalArgumentException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exception normally thrown", e);
+ }
}
}
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,17 +15,6 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * AppTestCase.java
- *
- * Created: 10 mai 2004
- *
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-
package org.codelutin.math.matrix;
import java.io.IOException;
@@ -36,17 +25,28 @@
import java.util.List;
import java.util.Stack;
-import junit.framework.TestCase;
-
import org.apache.commons.lang.time.DurationFormatUtils;
import org.codelutin.util.StringUtil;
+import org.junit.Assert;
+import org.junit.Test;
-public class MatrixNDTest extends TestCase {
+/* *
+ * AppTestCase.java
+ *
+ * Created: 10 mai 2004
+ *
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class MatrixNDTest {
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance(DoubleVector.class);
}
+ @Test
public void testNew() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -60,10 +60,11 @@
mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 },
new String[] { "dim abc", "dim efg", "dim klm" });
- assertEquals(0.0, mat.getMaxOccurence());
+ Assert.assertEquals(0.0, mat.getMaxOccurence(), 0);
}
+ @Test
public void testSemantique() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -73,18 +74,19 @@
mat = getFactory().create(new int[] { 3, 3, 3 });
- assertTrue(null == mat.getSemantics(1).get(1));
+ Assert.assertNull(mat.getSemantics(1).get(1));
mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 });
// la matrice doit avoir ca propre copie des semantiques
s2.set(1, "pas bon");
- assertEquals("f", mat.getSemantics(1).get(1));
+ Assert.assertEquals("f", mat.getSemantics(1).get(1));
mat.setSemantics(1, s1);
- assertEquals("b", mat.getSemantics(1).get(1));
+ Assert.assertEquals("b", mat.getSemantics(1).get(1));
}
+ @Test
public void testName() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -95,15 +97,16 @@
mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 },
new String[] { "dim abc", "dim efg", "dim klm" });
- assertEquals("Ma mat", mat.getName());
+ Assert.assertEquals("Ma mat", mat.getName());
mat.setName("Renamed");
- assertEquals("Renamed", mat.getName());
+ Assert.assertEquals("Renamed", mat.getName());
- assertEquals("dim abc", mat.getDimensionName(0));
+ Assert.assertEquals("dim abc", mat.getDimensionName(0));
mat.setDimensionName(0, "dim renamed");
- assertEquals("dim renamed", mat.getDimensionName(0));
+ Assert.assertEquals("dim renamed", mat.getDimensionName(0));
}
+ @Test
public void testGetSet() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -115,12 +118,13 @@
new String[] { "dim abc", "dim efg", "dim klm" });
mat.setValue(1, 1, 1, 34);
- assertEquals(34, mat.getValue("b", "f", "l"), 0);
+ Assert.assertEquals(34, mat.getValue("b", "f", "l"), 0);
mat.setValue("a", "f", "m", 22);
- assertEquals(22, mat.getValue(0, 1, 2), 0);
+ Assert.assertEquals(22, mat.getValue(0, 1, 2), 0);
}
+ @Test
public void testIterator() throws Exception {
int[][] val27 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 },
{ 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, { 0, 2, 0 },
@@ -153,13 +157,15 @@
int cpt = 0;
for (MatrixIterator i = mat.iterator(); i.hasNext();) {
i.next();
- assertTrue(Arrays.equals(val27[cpt], i.getCoordinates()));
- assertTrue(Arrays.equals(vals27[cpt], i.getSemanticsCoordinates()));
+ Assert.assertTrue(Arrays.equals(val27[cpt], i.getCoordinates()));
+ Assert.assertTrue(Arrays.equals(vals27[cpt], i
+ .getSemanticsCoordinates()));
cpt++;
}
- assertEquals(27, cpt);
+ Assert.assertEquals(27, cpt);
}
+ @Test
public void testAdd() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -177,11 +183,12 @@
mat1.add(mat2);
- assertEquals(29, mat1.getValue(0, 0, 0), 0);
- assertEquals(29, mat1.getValue(1, 2, 0), 0);
- assertEquals(29, mat1.getValue(2, 2, 2), 0);
+ Assert.assertEquals(29, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(29, mat1.getValue(1, 2, 0), 0);
+ Assert.assertEquals(29, mat1.getValue(2, 2, 2), 0);
}
+ @Test
public void testMinus() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -199,11 +206,12 @@
mat1.minus(mat2);
- assertEquals(-23, mat1.getValue(0, 0, 0), 0);
- assertEquals(-23, mat1.getValue(1, 2, 0), 0);
- assertEquals(-23, mat1.getValue(2, 2, 2), 0);
+ Assert.assertEquals(-23, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(-23, mat1.getValue(1, 2, 0), 0);
+ Assert.assertEquals(-23, mat1.getValue(2, 2, 2), 0);
}
+ @Test
public void testEquals() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -225,9 +233,10 @@
mat1.add(mat2);
- assertEquals(mat1, mat3);
+ Assert.assertEquals(mat1, mat3);
}
+ @Test
public void testsumOverDim() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -242,35 +251,35 @@
mi.setValue(++i);
}
- assertEquals(mat, mat2);
+ Assert.assertEquals(mat, mat2);
mat2 = mat.sumOverDim(1, 0);
- assertEquals(mat, mat2);
+ Assert.assertEquals(mat, mat2);
mat2 = mat.sumOverDim(1, 1);
- assertEquals(mat, mat2);
+ Assert.assertEquals(mat, mat2);
mat2 = mat.sumOverDim(1, 2);
- assertEquals(2, mat2.getDim(1));
- assertEquals(3, mat2.getValue(0, 0), 0);
- assertEquals(7, mat2.getValue(0, 1), 0);
- assertEquals(11, mat2.getValue(1, 0), 0);
- assertEquals(15, mat2.getValue(1, 1), 0);
- assertEquals(19, mat2.getValue(2, 0), 0);
- assertEquals(23, mat2.getValue(2, 1), 0);
- assertEquals(27, mat2.getValue(3, 0), 0);
- assertEquals(31, mat2.getValue(3, 1), 0);
+ Assert.assertEquals(2, mat2.getDim(1));
+ Assert.assertEquals(3, mat2.getValue(0, 0), 0);
+ Assert.assertEquals(7, mat2.getValue(0, 1), 0);
+ Assert.assertEquals(11, mat2.getValue(1, 0), 0);
+ Assert.assertEquals(15, mat2.getValue(1, 1), 0);
+ Assert.assertEquals(19, mat2.getValue(2, 0), 0);
+ Assert.assertEquals(23, mat2.getValue(2, 1), 0);
+ Assert.assertEquals(27, mat2.getValue(3, 0), 0);
+ Assert.assertEquals(31, mat2.getValue(3, 1), 0);
mat2 = mat.sumOverDim(1, 3);
- assertEquals(1, mat2.getDim(1));
- assertEquals(6, mat2.getValue(0, 0), 0);
- assertEquals(18, mat2.getValue(1, 0), 0);
- assertEquals(30, mat2.getValue(2, 0), 0);
- assertEquals(42, mat2.getValue(3, 0), 0);
+ Assert.assertEquals(1, mat2.getDim(1));
+ Assert.assertEquals(6, mat2.getValue(0, 0), 0);
+ Assert.assertEquals(18, mat2.getValue(1, 0), 0);
+ Assert.assertEquals(30, mat2.getValue(2, 0), 0);
+ Assert.assertEquals(42, mat2.getValue(3, 0), 0);
mat2 = mat.sumOverDim(1, 4);
- assertEquals(1, mat2.getDim(1));
- assertEquals(10, mat2.getValue(0, 0), 0);
- assertEquals(26, mat2.getValue(1, 0), 0);
- assertEquals(42, mat2.getValue(2, 0), 0);
- assertEquals(58, mat2.getValue(3, 0), 0);
+ Assert.assertEquals(1, mat2.getDim(1));
+ Assert.assertEquals(10, mat2.getValue(0, 0), 0);
+ Assert.assertEquals(26, mat2.getValue(1, 0), 0);
+ Assert.assertEquals(42, mat2.getValue(2, 0), 0);
+ Assert.assertEquals(58, mat2.getValue(3, 0), 0);
mat = getFactory().create("Ma mat", new List[] { s1, s2, s3 },
new String[] { "dim abc", "dim efg", "dim klm" });
@@ -279,12 +288,12 @@
mat.setValue(0, 0, 0, 2);
mat.setValue(2, 2, 2, 4);
mat = mat.sumOverDim(1);
- assertTrue(MatrixHelper.sameDimension(new int[] { 3, 1, 3 }, mat
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 3, 1, 3 }, mat
.getDim()));
- assertEquals(8, mat.getValue(0, 0, 0), 0);
- assertEquals(9, mat.getValue(2, 0, 1), 0);
- assertEquals(10, mat.getValue(2, 0, 2), 0);
+ Assert.assertEquals(8, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(9, mat.getValue(2, 0, 1), 0);
+ Assert.assertEquals(10, mat.getValue(2, 0, 2), 0);
mat = getFactory().create(new int[] { 6, 6, 6 });
@@ -297,14 +306,15 @@
mat.setValue(0, 5, 0, 5);
mat = mat.sumOverDim(1, 3);
- assertTrue(MatrixHelper.sameDimension(new int[] { 6, 2, 6 }, mat
+ Assert.assertTrue(MatrixHelper.sameDimension(new int[] { 6, 2, 6 }, mat
.getDim()));
- assertEquals(3, mat.getValue(0, 0, 0), 0);
- assertEquals(12, mat.getValue(0, 1, 0), 0);
- assertEquals(9, mat.getValue(1, 1, 5), 0);
- assertEquals(9, mat.getValue(5, 0, 3), 0);
+ Assert.assertEquals(3, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(12, mat.getValue(0, 1, 0), 0);
+ Assert.assertEquals(9, mat.getValue(1, 1, 5), 0);
+ Assert.assertEquals(9, mat.getValue(5, 0, 3), 0);
}
+ @Test
public void testTranspose() throws Exception {
MatrixND mat = null;
@@ -315,10 +325,10 @@
mat.setValue(1, 0, 46);
mat = mat.transpose();
- assertEquals(56, mat.getValue(3, 1), 0);
- assertEquals(34, mat.getValue(2, 0), 0);
- assertEquals(64, mat.getValue(1, 0), 0);
- assertEquals(46, mat.getValue(0, 1), 0);
+ Assert.assertEquals(56, mat.getValue(3, 1), 0);
+ Assert.assertEquals(34, mat.getValue(2, 0), 0);
+ Assert.assertEquals(64, mat.getValue(1, 0), 0);
+ Assert.assertEquals(46, mat.getValue(0, 1), 0);
mat = getFactory().create(new int[] { 4 });
mat.setValue(1, 56);
@@ -327,12 +337,13 @@
mat.setValue(0, 46);
mat = mat.transpose();
- assertEquals(56, mat.getValue(0, 1), 0);
- assertEquals(34, mat.getValue(0, 2), 0);
- assertEquals(64, mat.getValue(0, 3), 0);
- assertEquals(46, mat.getValue(0, 0), 0);
+ Assert.assertEquals(56, mat.getValue(0, 1), 0);
+ Assert.assertEquals(34, mat.getValue(0, 2), 0);
+ Assert.assertEquals(64, mat.getValue(0, 3), 0);
+ Assert.assertEquals(46, mat.getValue(0, 0), 0);
}
+ @Test
public void testMults() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -351,16 +362,17 @@
mat1.mults(3);
mat2.mults(0);
- assertEquals(9, mat1.getValue(0, 0, 0), 0);
- assertEquals(9, mat1.getValue(1, 2, 0), 0);
- assertEquals(0, mat2.getValue(2, 2, 2), 0);
+ Assert.assertEquals(9, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(9, mat1.getValue(1, 2, 0), 0);
+ Assert.assertEquals(0, mat2.getValue(2, 2, 2), 0);
MatrixND mat0 = getFactory().create(new int[] { 4, 4 });
MatrixND matId = getFactory().matrixId(4);
matId.mults(0);
- assertEquals(mat0, matId);
+ Assert.assertEquals(mat0, matId);
}
+ @Test
public void testDivs() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -379,11 +391,12 @@
mat1.divs(3);
mat2.divs(4);
- assertEquals(1, mat1.getValue(0, 0, 0), 0);
- assertEquals(6.5, mat2.getValue(1, 2, 0), 0);
- assertEquals(6.5, mat2.getValue(2, 2, 2), 0);
+ Assert.assertEquals(1, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(6.5, mat2.getValue(1, 2, 0), 0);
+ Assert.assertEquals(6.5, mat2.getValue(2, 2, 2), 0);
}
+ @Test
public void testPaste() throws Exception {
MatrixND mat1 = getFactory().create(new int[] { 6, 7, 8 });
@@ -394,12 +407,13 @@
mat1.paste(new int[] { 3, 0, 4 }, mat2);
- assertEquals(3, mat1.getValue(0, 0, 0), 0);
- assertEquals(26, mat1.getValue(3, 0, 4), 0);
- assertEquals(26, mat1.getValue(4, 1, 5), 0);
- assertEquals(3, mat1.getValue(5, 2, 6), 0);
+ Assert.assertEquals(3, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(26, mat1.getValue(3, 0, 4), 0);
+ Assert.assertEquals(26, mat1.getValue(4, 1, 5), 0);
+ Assert.assertEquals(3, mat1.getValue(5, 2, 6), 0);
}
+ @Test
public void testSumOverDim() throws Exception {
MatrixND mat = null;
@@ -425,9 +439,10 @@
mat = mat.sumOverDim(0, 1, 3);
mat = mat.sumOverDim(0, 2, 2);
- assertTrue(result.equalsValues(mat));
+ Assert.assertTrue(result.equalsValues(mat));
}
+ @Test
public void testReduce() throws Exception {
MatrixND mat = null;
@@ -436,25 +451,25 @@
MatrixHelper.fill(mat, 3);
mat = mat.sumOverDim(1);
- assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
mat = mat.reduce();
- assertEquals(2, mat.getNbDim());
- assertEquals(6, mat.getDim(0));
- assertEquals(8, mat.getDim(1));
- assertEquals(21, mat.getValue(0, 0), 0);
- assertEquals(21, mat.getValue(5, 7), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(6, mat.getDim(0));
+ Assert.assertEquals(8, mat.getDim(1));
+ Assert.assertEquals(21, mat.getValue(0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(5, 7), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 26);
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(0);
- assertEquals(104, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 0, 0), 0);
mat = mat.reduce();
- assertEquals(1, mat.getNbDim());
- assertEquals(2, mat.getDim(0));
- assertEquals(104, mat.getValue(0), 0);
- assertEquals(104, mat.getValue(1), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(2, mat.getDim(0));
+ Assert.assertEquals(104, mat.getValue(0), 0);
+ Assert.assertEquals(104, mat.getValue(1), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 6);
@@ -462,36 +477,36 @@
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(2);
mat = mat.sumOverDim(0);
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
mat = mat.reduce();
- assertEquals(1, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(48, mat.getValue(0), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(48, mat.getValue(0), 0);
mat = getFactory().create(new int[] { 6, 7, 8 });
MatrixHelper.fill(mat, 3);
mat = mat.sumOverDim(1);
- assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
mat = mat.reduce(2);
- assertEquals(2, mat.getNbDim());
- assertEquals(6, mat.getDim(0));
- assertEquals(8, mat.getDim(1));
- assertEquals(21, mat.getValue(0, 0), 0);
- assertEquals(21, mat.getValue(5, 7), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(6, mat.getDim(0));
+ Assert.assertEquals(8, mat.getDim(1));
+ Assert.assertEquals(21, mat.getValue(0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(5, 7), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 26);
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(0);
- assertEquals(104, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 0, 0), 0);
mat = mat.reduce(2);
- assertEquals(2, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(2, mat.getDim(1));
- assertEquals(104, mat.getValue(0, 0), 0);
- assertEquals(104, mat.getValue(0, 1), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(2, mat.getDim(1));
+ Assert.assertEquals(104, mat.getValue(0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 1), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 6);
@@ -499,46 +514,50 @@
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(2);
mat = mat.sumOverDim(0);
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
mat = mat.reduce(5);
- assertEquals(3, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(1, mat.getDim(1));
- assertEquals(1, mat.getDim(2));
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(3, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(1, mat.getDim(1));
+ Assert.assertEquals(1, mat.getDim(2));
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
}
-
+
+ @Test
public void testCreateFromDoubleArray() throws Exception {
- MatrixND mat = null;
-
- mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8,9}, new int[] {3,3});
-
- assertEquals(2,mat.getDim().length);
- assertEquals(3,mat.getDim(0));
- assertEquals(3,mat.getDim(1));
- assertEquals(1,(int)mat.getValue(new int[] {0,0}));
- assertEquals(2,(int)mat.getValue(new int[] {0,1}));
- assertEquals(3,(int)mat.getValue(new int[] {0,2}));
- assertEquals(4,(int)mat.getValue(new int[] {1,0}));
- assertEquals(5,(int)mat.getValue(new int[] {1,1}));
- assertEquals(6,(int)mat.getValue(new int[] {1,2}));
- assertEquals(7,(int)mat.getValue(new int[] {2,0}));
- assertEquals(8,(int)mat.getValue(new int[] {2,1}));
- assertEquals(9,(int)mat.getValue(new int[] {2,2}));
-
- mat = getFactory().create(new double[] {1,2,3}, new int[]{3});
- assertEquals(1,mat.getDim().length);
- assertEquals(3,mat.getDim(0));
- assertEquals(1,(int)mat.getValue(new int[] {0}));
- assertEquals(2,(int)mat.getValue(new int[] {1}));
- assertEquals(3,(int)mat.getValue(new int[] {2}));
-
- mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8}, new int[] {2,2,2});
- assertNull(mat);
-
+ MatrixND mat = null;
+
+ mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
+ new int[] { 3, 3 });
+
+ Assert.assertEquals(2, mat.getDim().length);
+ Assert.assertEquals(3, mat.getDim(0));
+ Assert.assertEquals(3, mat.getDim(1));
+ Assert.assertEquals(1, (int) mat.getValue(new int[] { 0, 0 }));
+ Assert.assertEquals(2, (int) mat.getValue(new int[] { 0, 1 }));
+ Assert.assertEquals(3, (int) mat.getValue(new int[] { 0, 2 }));
+ Assert.assertEquals(4, (int) mat.getValue(new int[] { 1, 0 }));
+ Assert.assertEquals(5, (int) mat.getValue(new int[] { 1, 1 }));
+ Assert.assertEquals(6, (int) mat.getValue(new int[] { 1, 2 }));
+ Assert.assertEquals(7, (int) mat.getValue(new int[] { 2, 0 }));
+ Assert.assertEquals(8, (int) mat.getValue(new int[] { 2, 1 }));
+ Assert.assertEquals(9, (int) mat.getValue(new int[] { 2, 2 }));
+
+ mat = getFactory().create(new double[] { 1, 2, 3 }, new int[] { 3 });
+ Assert.assertEquals(1, mat.getDim().length);
+ Assert.assertEquals(3, mat.getDim(0));
+ Assert.assertEquals(1, (int) mat.getValue(new int[] { 0 }));
+ Assert.assertEquals(2, (int) mat.getValue(new int[] { 1 }));
+ Assert.assertEquals(3, (int) mat.getValue(new int[] { 2 }));
+
+ mat = getFactory().create(new double[] { 1, 2, 3, 4, 5, 6, 7, 8 },
+ new int[] { 2, 2, 2 });
+ Assert.assertNull(mat);
+
}
+ @Test
public void testReduceDims() throws Exception {
MatrixND mat = null;
@@ -547,25 +566,25 @@
MatrixHelper.fill(mat, 3);
mat = mat.sumOverDim(1);
- assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(1);
- assertEquals(2, mat.getNbDim());
- assertEquals(6, mat.getDim(0));
- assertEquals(8, mat.getDim(1));
- assertEquals(21, mat.getValue(0, 0), 0);
- assertEquals(21, mat.getValue(5, 7), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(6, mat.getDim(0));
+ Assert.assertEquals(8, mat.getDim(1));
+ Assert.assertEquals(21, mat.getValue(0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(5, 7), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 26);
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(0);
- assertEquals(104, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(1, 0);
- assertEquals(1, mat.getNbDim());
- assertEquals(2, mat.getDim(0));
- assertEquals(104, mat.getValue(0), 0);
- assertEquals(104, mat.getValue(1), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(2, mat.getDim(0));
+ Assert.assertEquals(104, mat.getValue(0), 0);
+ Assert.assertEquals(104, mat.getValue(1), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 6);
@@ -573,37 +592,37 @@
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(2);
mat = mat.sumOverDim(0);
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(1, 2, 0);
- assertEquals(1, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(48, mat.getValue(0), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(48, mat.getValue(0), 0);
mat = getFactory().create(new int[] { 6, 7, 8 });
MatrixHelper.fill(mat, 3);
mat = mat.sumOverDim(1);
- assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(0);
- assertEquals(3, mat.getNbDim());
- assertEquals(6, mat.getDim(0));
- assertEquals(1, mat.getDim(1));
- assertEquals(8, mat.getDim(2));
- assertEquals(21, mat.getValue(0, 0, 0), 0);
- assertEquals(21, mat.getValue(5, 0, 7), 0);
+ Assert.assertEquals(3, mat.getNbDim());
+ Assert.assertEquals(6, mat.getDim(0));
+ Assert.assertEquals(1, mat.getDim(1));
+ Assert.assertEquals(8, mat.getDim(2));
+ Assert.assertEquals(21, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(21, mat.getValue(5, 0, 7), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 26);
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(0);
- assertEquals(104, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(1);
- assertEquals(2, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(2, mat.getDim(1));
- assertEquals(104, mat.getValue(0, 0), 0);
- assertEquals(104, mat.getValue(0, 1), 0);
+ Assert.assertEquals(2, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(2, mat.getDim(1));
+ Assert.assertEquals(104, mat.getValue(0, 0), 0);
+ Assert.assertEquals(104, mat.getValue(0, 1), 0);
mat = getFactory().create(new int[] { 2, 2, 2 });
MatrixHelper.fill(mat, 6);
@@ -611,14 +630,15 @@
mat = mat.sumOverDim(1);
mat = mat.sumOverDim(2);
mat = mat.sumOverDim(0);
- assertEquals(48, mat.getValue(0, 0, 0), 0);
+ Assert.assertEquals(48, mat.getValue(0, 0, 0), 0);
mat = mat.reduceDims(0, 1, 2);
- assertEquals(1, mat.getNbDim());
- assertEquals(1, mat.getDim(0));
- assertEquals(48, mat.getValue(0), 0);
+ Assert.assertEquals(1, mat.getNbDim());
+ Assert.assertEquals(1, mat.getDim(0));
+ Assert.assertEquals(48, mat.getValue(0), 0);
}
+ @Test
public void testToList() throws Exception {
MatrixND mat1 = getFactory().create(new int[] { 3, 2, 1 });
mat1.setValue(0, 0, 0, 1.0E-7);
@@ -633,7 +653,7 @@
System.out.println(mat1);
System.out.println(mat2);
- assertEquals(mat1, mat2);
+ Assert.assertEquals(mat1, mat2);
String s = String.valueOf(l);
List l2 = convertStringToList2(s);
@@ -645,7 +665,7 @@
System.out.println(l1);
System.out.println(l0); // implatation fausse
- assertEquals(l, l2);
+ Assert.assertEquals(l, l2);
int MAX = 10000;
int dummy = 0;
@@ -677,7 +697,7 @@
/**
* implantation peut performante
*/
- static public List convertStringToList1(String s) {
+ public static List convertStringToList1(String s) {
List result = new ArrayList();
s = s.trim();
if (s.startsWith("[") && s.endsWith("]")) {
@@ -701,7 +721,7 @@
/**
* implantation utilisé actuellement dans MatrixHelper
*/
- static public List convertStringToList2(String s) {
+ public static List convertStringToList2(String s) {
List result = null;
Stack<List> stack = new Stack<List>();
StringBuffer number = new StringBuffer(20); // initial to 20 char
@@ -749,7 +769,7 @@
/**
* implantation fausse pour les nombres 5.0E-7
*/
- static public List convertStringToList0(String s) throws IOException {
+ public static List convertStringToList0(String s) throws IOException {
List result = null;
Stack<List> stack = new Stack<List>();
StringBuffer number = new StringBuffer(20); // initial to 20 char
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/PerfTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,7 +15,15 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
+package org.codelutin.math.matrix;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.junit.Test;
+
+/**
* PerfTest.java
*
* Created: 7 sept. 06 02:28:51
@@ -26,26 +34,12 @@
* Last update: $Date$
* by : $Author$
*/
+public class PerfTest {
-package org.codelutin.math.matrix;
+ protected static final char CMAX = 'j';
+ protected static final int MAX = 10;
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.lang.time.DurationFormatUtils;
-
-/**
- * @author poussin
- *
- */
-
-public class PerfTest extends TestCase {
-
- static char CMAX = 'j';
- static int MAX = 10;
-
+ @Test
public void testDoubleVectorIterator() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -77,6 +71,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleVectorIndex() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -112,6 +107,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleVectorSemantic() throws Exception {
List<String> sem = new ArrayList<String>();
for (char c = 'a'; c <= CMAX; c++) {
@@ -150,6 +146,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleBigVectorIterator() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -181,6 +178,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleBigVectorIndex() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -216,6 +214,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testDoubleBigVectorSemantic() throws Exception {
List<String> sem = new ArrayList<String>();
for (char c = 'a'; c <= CMAX; c++) {
@@ -254,6 +253,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatVectorIterator() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -285,6 +285,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatVectorIndex() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -320,6 +321,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatVectorSemantic() throws Exception {
List<String> sem = new ArrayList<String>();
for (char c = 'a'; c <= CMAX; c++) {
@@ -358,6 +360,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatBigVectorIterator() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -389,6 +392,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatBigVectorIndex() throws Exception {
List sem = new ArrayList();
for (char c = 'a'; c <= CMAX; c++) {
@@ -424,6 +428,7 @@
(timeend - timeinit) / 1000000, "s'.'S"));
}
+ @Test
public void testFloatBigVectorSemantic() throws Exception {
List<String> sem = new ArrayList<String>();
for (char c = 'a'; c <= CMAX; c++) {
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/SubMatrixTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/*##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -20,25 +20,27 @@
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
/**
- * SubMatrixTest.java
+ * SubMatrixTest.
*
* Created: 29 oct. 2004
*
* @author Benjamin Poussin <poussin(a)codelutin.com>
* @version $Revision$
*
- * Mise a jour: $Date$
- * par : $Author$
+ * Mise a jour: $Date$
+ * par : $Author$
*/
-public class SubMatrixTest extends TestCase { // SubMatrixTest
+public class SubMatrixTest { // SubMatrixTest
public MatrixFactory getFactory() throws Exception {
return MatrixFactory.getInstance();
}
+ @Test
public void testNew() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -50,9 +52,10 @@
new String[] { "dim abc", "dim efg", "dim klm" });
MatrixND smat = mat.getSubMatrix(1, 0, 2);
- assertTrue(Arrays.equals(new int[] { 3, 2, 3 }, smat.getDim()));
+ Assert.assertTrue(Arrays.equals(new int[] { 3, 2, 3 }, smat.getDim()));
}
+ @Test
public void testIterator() throws Exception {
int[][] val18 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 },
{ 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, { 1, 0, 0 },
@@ -90,13 +93,14 @@
// System.out.println(MatrixHelper.coordinatesToString(i.
// getSemanticsCoordinates()));
- assertTrue(Arrays.equals(val18[cpt], i.getCoordinates()));
- assertTrue(Arrays.equals(vals18[cpt], i.getSemanticsCoordinates()));
+ Assert.assertTrue(Arrays.equals(val18[cpt], i.getCoordinates()));
+ Assert.assertTrue(Arrays.equals(vals18[cpt], i.getSemanticsCoordinates()));
cpt++;
}
- assertEquals(18, cpt);
+ Assert.assertEquals(18, cpt);
}
+ @Test
public void testSubSubMatrix() throws Exception {
int[][] val6 = new int[][] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 },
{ 0, 1, 0 }, { 0, 1, 1 }, { 0, 1, 2 }, };
@@ -119,7 +123,7 @@
//System.out.println(" smat2.getDim: "+MatrixHelper.coordinatesToString(
// smat2.getDim()));
- assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, smat2.getDim()));
+ Assert.assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, smat2.getDim()));
// System.out.println(MatrixHelper.coordinatesToString(smat2.getDim()));
@@ -127,13 +131,14 @@
for (MatrixIterator i = smat2.iterator(); i.hasNext();) {
i.next();
- assertTrue(Arrays.equals(val6[cpt], i.getCoordinates()));
- assertTrue(Arrays.equals(vals6[cpt], i.getSemanticsCoordinates()));
+ Assert.assertTrue(Arrays.equals(val6[cpt], i.getCoordinates()));
+ Assert.assertTrue(Arrays.equals(vals6[cpt], i.getSemanticsCoordinates()));
cpt++;
}
- assertEquals(6, cpt);
+ Assert.assertEquals(6, cpt);
}
+ @Test
public void testSubSubGetSet() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -148,11 +153,12 @@
MatrixND smat2 = smat1.getSubMatrix(0, 2, 1);
smat2.setValue(0, 0, 0, 34);
- assertEquals(34, smat2.getValue("c", "e", "k"), 0);
+ Assert.assertEquals(34, smat2.getValue("c", "e", "k"), 0);
smat2.setValue("c", "f", "l", 23);
- assertEquals(23, smat2.getValue(0, 1, 1), 0);
+ Assert.assertEquals(23, smat2.getValue(0, 1, 1), 0);
}
+ @Test
public void testSubMapping() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -164,29 +170,30 @@
new String[] { "dim abc", "dim efg", "dim klm" });
MatrixND smat1 = mat.getSubMatrix(1, new int[] { 0, 1 });
- assertEquals(2, smat1.getDim(1));
- assertEquals(Arrays.asList(new String[] { "e", "f" }), smat1
+ Assert.assertEquals(2, smat1.getDim(1));
+ Assert.assertEquals(Arrays.asList(new String[] { "e", "f" }), smat1
.getSemantics(1));
MatrixND smat2 = smat1.getSubMatrix(0, new Object[] { "c" });
- assertEquals(1, smat2.getDim(0));
- assertEquals(Arrays.asList(new String[] { "c" }), smat2.getSemantics(0));
+ Assert.assertEquals(1, smat2.getDim(0));
+ Assert.assertEquals(Arrays.asList(new String[] { "c" }), smat2.getSemantics(0));
mat.setValue("c", "f", "k", 12);
- assertEquals(12, smat1.getValue(2, 1, 0), 0);
- assertEquals(12, smat1.getValue("c", "f", "k"), 0);
- assertEquals(12, smat2.getValue(0, 1, 0), 0);
- assertEquals(12, smat2.getValue("c", "f", "k"), 0);
+ Assert.assertEquals(12, smat1.getValue(2, 1, 0), 0);
+ Assert.assertEquals(12, smat1.getValue("c", "f", "k"), 0);
+ Assert.assertEquals(12, smat2.getValue(0, 1, 0), 0);
+ Assert.assertEquals(12, smat2.getValue("c", "f", "k"), 0);
smat2.setValue(0, 0, 0, 34);
- assertEquals(34, smat2.getValue("c", "e", "k"), 0);
- assertEquals(34, mat.getValue(2, 0, 0), 0);
- assertEquals(34, mat.getValue("c", "e", "k"), 0);
+ Assert.assertEquals(34, smat2.getValue("c", "e", "k"), 0);
+ Assert.assertEquals(34, mat.getValue(2, 0, 0), 0);
+ Assert.assertEquals(34, mat.getValue("c", "e", "k"), 0);
smat2.setValue("c", "f", "l", 23);
- assertEquals(23, smat2.getValue(0, 1, 1), 0);
- assertEquals(23, mat.getValue(2, 1, 1), 0);
- assertEquals(23, mat.getValue("c", "f", "l"), 0);
+ Assert.assertEquals(23, smat2.getValue(0, 1, 1), 0);
+ Assert.assertEquals(23, mat.getValue(2, 1, 1), 0);
+ Assert.assertEquals(23, mat.getValue("c", "f", "l"), 0);
}
+ @Test
public void testSubAdd() throws Exception {
List s1 = Arrays.asList(new String[] { "a", "b", "c" });
List s2 = Arrays.asList(new String[] { "e", "f", "g" });
@@ -208,37 +215,38 @@
smat1.add(smat2);
- assertEquals(5, mat1.getValue(0, 1, 0), 0);
- assertEquals(5, mat1.getValue(0, 1, 1), 0);
- assertEquals(5, mat1.getValue(0, 1, 2), 0);
- assertEquals(5, mat1.getValue(1, 1, 0), 0);
- assertEquals(5, mat1.getValue(1, 1, 1), 0);
- assertEquals(5, mat1.getValue(1, 1, 2), 0);
- assertEquals(5, mat1.getValue(2, 1, 0), 0);
- assertEquals(5, mat1.getValue(2, 1, 1), 0);
- assertEquals(5, mat1.getValue(2, 1, 2), 0);
- assertEquals(5, mat1.getValue(0, 2, 0), 0);
- assertEquals(5, mat1.getValue(0, 2, 1), 0);
- assertEquals(5, mat1.getValue(0, 2, 2), 0);
- assertEquals(5, mat1.getValue(1, 2, 0), 0);
- assertEquals(5, mat1.getValue(1, 2, 1), 0);
- assertEquals(5, mat1.getValue(1, 2, 2), 0);
- assertEquals(5, mat1.getValue(2, 2, 0), 0);
- assertEquals(5, mat1.getValue(2, 2, 1), 0);
- assertEquals(5, mat1.getValue(2, 2, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 1, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 1, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 1, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 1, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 1, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 1, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 1, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 1, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 1, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 2, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 2, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(0, 2, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 2, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 2, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(1, 2, 2), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 2, 0), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 2, 1), 0);
+ Assert.assertEquals(5, mat1.getValue(2, 2, 2), 0);
- assertEquals(8, mat1.getValue(0, 0, 0), 0);
- assertEquals(8, mat1.getValue(0, 0, 1), 0);
- assertEquals(8, mat1.getValue(0, 0, 2), 0);
- assertEquals(8, mat1.getValue(1, 0, 0), 0);
- assertEquals(8, mat1.getValue(1, 0, 1), 0);
- assertEquals(8, mat1.getValue(1, 0, 2), 0);
- assertEquals(8, mat1.getValue(2, 0, 0), 0);
- assertEquals(8, mat1.getValue(2, 0, 1), 0);
- assertEquals(8, mat1.getValue(2, 0, 2), 0);
+ Assert.assertEquals(8, mat1.getValue(0, 0, 0), 0);
+ Assert.assertEquals(8, mat1.getValue(0, 0, 1), 0);
+ Assert.assertEquals(8, mat1.getValue(0, 0, 2), 0);
+ Assert.assertEquals(8, mat1.getValue(1, 0, 0), 0);
+ Assert.assertEquals(8, mat1.getValue(1, 0, 1), 0);
+ Assert.assertEquals(8, mat1.getValue(1, 0, 2), 0);
+ Assert.assertEquals(8, mat1.getValue(2, 0, 0), 0);
+ Assert.assertEquals(8, mat1.getValue(2, 0, 1), 0);
+ Assert.assertEquals(8, mat1.getValue(2, 0, 2), 0);
}
+ @Test
public void testSubSubMults() throws Exception {
MatrixND mat = null;
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java 2009-03-03 09:07:38 UTC (rev 119)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/gui/MatrixTableModelTest.java 2009-03-03 10:19:18 UTC (rev 120)
@@ -1,5 +1,5 @@
/* *##% lutinmatrix
- * Copyright (C) 2004 - 2008 CodeLutin
+ * Copyright (C) 2004 - 2009 CodeLutin
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -15,42 +15,38 @@
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/
-/* *
- * MatrixTableModelND.java
- *
- * Created: 21 mars 2006 19:05:06
- *
- * @author poussin
- * @version $Revision$
- *
- * Last update: $Date$
- * by : $Author$
- */
-
package org.codelutin.math.matrix.gui;
import java.util.Arrays;
import java.util.List;
-import junit.framework.TestCase;
-
import org.codelutin.math.matrix.MatrixFactory;
import org.codelutin.math.matrix.MatrixND;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
+ * MatrixTableModelND.
+ *
+ * Created: 21 mars 2006 19:05:06
+ *
* @author poussin
- *
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
*/
+public class MatrixTableModelTest {
-public class MatrixTableModelTest extends TestCase {
+ protected MatrixTableModelND model = null;
+ protected MatrixND mat = null;
- MatrixTableModelND model = null;
- MatrixND mat = null;
-
/*
* @see TestCase#setUp()
*/
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
List dim0 = Arrays.asList(new String[] { "dim0-0", "dim0-1", "dim0-2",
"dim0-3" });
List dim1 = Arrays.asList(new String[] { "dim1-0", "dim1-1" });
@@ -65,70 +61,76 @@
model = new MatrixTableModelND(mat);
}
+ @Test
public void testSetMatrix() {
- assertEquals(2, model.addRow);
- assertEquals(3, model.addCol);
+ Assert.assertEquals(2, model.addRow);
+ Assert.assertEquals(3, model.addCol);
int[] val = model.multRowCol;
- assertEquals(true, Arrays.equals(new int[] { 6, 4, 3, 1, 1 }, val));
+ Assert.assertEquals(true, Arrays.equals(new int[] { 6, 4, 3, 1, 1 },
+ val));
}
/*
- * Test method for
- * 'org.codelutin.math.matrix.gui.MatrixTableModelND.isCellEditable(int,
- * int)'
+ * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.isCellEditable(int, int)'
*/
+ @Test
public void testIsCellEditable() {
- assertEquals(false, model.isCellEditable(model.addRow - 1,
+ Assert.assertEquals(false, model.isCellEditable(model.addRow - 1,
model.addCol - 1));
- assertEquals(true, model.isCellEditable(model.addRow, model.addCol));
- assertEquals(true, model.isCellEditable(model.addRow + 1,
+ Assert.assertEquals(true, model.isCellEditable(model.addRow,
+ model.addCol));
+ Assert.assertEquals(true, model.isCellEditable(model.addRow + 1,
model.addCol + 1));
}
/*
- * Test method for
- * 'org.codelutin.math.matrix.gui.MatrixTableModelND.tableToMatrix(int,
- * int)'
+ * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.tableToMatrix(int, int)'
*/
+ @Test
public void testTableToMatrix() {
int[] val = model.tableToMatrix(5, 4);
- assertEquals(true, Arrays.equals(new int[] { 0, 1, 1, 0, 2 }, val));
+ Assert.assertEquals(true, Arrays.equals(new int[] { 0, 1, 1, 0, 2 },
+ val));
val = model.tableToMatrix(0, 0);
- assertEquals(true, Arrays.equals(new int[] { 0, 0, 0, 0, 0 }, val));
+ Assert.assertEquals(true, Arrays.equals(new int[] { 0, 0, 0, 0, 0 },
+ val));
val = model.tableToMatrix(23, 5);
- assertEquals(true, Arrays.equals(new int[] { 3, 1, 1, 1, 2 }, val));
+ Assert.assertEquals(true, Arrays.equals(new int[] { 3, 1, 1, 1, 2 },
+ val));
}
/*
- * Test method for
- * 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValue(int, int)'
+ * Test method for 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValue(int, int)'
*/
+ @Test
public void testGetValue() {
- assertEquals("dim0-0", model.getValue(2, 0));
- assertEquals("dim0-0", model.getValue(3, 0));
- assertEquals("dim0-0", model.getValue(4, 0));
- assertEquals("dim0-0", model.getValue(7, 0));
- assertEquals("dim0-1", model.getValue(8, 0));
+ Assert.assertEquals("dim0-0", model.getValue(2, 0));
+ Assert.assertEquals("dim0-0", model.getValue(3, 0));
+ Assert.assertEquals("dim0-0", model.getValue(4, 0));
+ Assert.assertEquals("dim0-0", model.getValue(7, 0));
+ Assert.assertEquals("dim0-1", model.getValue(8, 0));
- assertEquals("dim2-0", model.getValue(2, 1));
- assertEquals("dim2-0", model.getValue(3, 1));
- assertEquals("dim2-1", model.getValue(5, 1));
+ Assert.assertEquals("dim2-0", model.getValue(2, 1));
+ Assert.assertEquals("dim2-0", model.getValue(3, 1));
+ Assert.assertEquals("dim2-1", model.getValue(5, 1));
- assertEquals("dim4-0", model.getValue(2, 2));
- assertEquals("dim4-1", model.getValue(3, 2));
- assertEquals("dim4-2", model.getValue(4, 2));
- assertEquals("dim4-0", model.getValue(5, 2));
+ Assert.assertEquals("dim4-0", model.getValue(2, 2));
+ Assert.assertEquals("dim4-1", model.getValue(3, 2));
+ Assert.assertEquals("dim4-2", model.getValue(4, 2));
+ Assert.assertEquals("dim4-0", model.getValue(5, 2));
- assertEquals("dim1-0", model.getValue(0, 3));
+ Assert.assertEquals("dim1-0", model.getValue(0, 3));
- assertEquals(0.0, model.getValue(model.addRow, model.addCol));
- assertEquals(0.0, model.getValue(23 + model.addRow, 5 + model.addCol));
+ Assert.assertEquals(0.0, model.getValue(model.addRow, model.addCol));
+ Assert.assertEquals(0.0, model.getValue(23 + model.addRow,
+ 5 + model.addCol));
}
/*
* Test method for
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnName(int)'
*/
+ @Test
public void testGetColumnNameInt() {
}
@@ -137,6 +139,7 @@
* Test method for
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.getRowCount()'
*/
+ @Test
public void testGetRowCount() {
}
@@ -145,6 +148,7 @@
* Test method for
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.getColumnCount()'
*/
+ @Test
public void testGetColumnCount() {
}
@@ -153,6 +157,7 @@
* Test method for
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.getValueAt(int, int)'
*/
+ @Test
public void testGetValueAt() {
}
@@ -162,6 +167,7 @@
* 'org.codelutin.math.matrix.gui.MatrixTableModelND.setValueAt(Object, int,
* int)'
*/
+ @Test
public void testSetValueAtObjectIntInt() {
}
Added: lutinmatrix/trunk/src/test/resources/log4j.properties
===================================================================
--- lutinmatrix/trunk/src/test/resources/log4j.properties (rev 0)
+++ lutinmatrix/trunk/src/test/resources/log4j.properties 2009-03-03 10:19:18 UTC (rev 120)
@@ -0,0 +1,10 @@
+# Global logging configuration
+log4j.rootLogger=ERROR, stdout
+
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+
+# package level
+log4j.logger.org.codelutin.math=DEBUG
\ No newline at end of file
1
0
[Lutinmatrix-commits] r119 - in lutinmatrix/trunk/src: main/java/org/codelutin/math/matrix test/java/org/codelutin/math/matrix
by jcouteau@users.labs.libre-entreprise.org 03 Mar '09
by jcouteau@users.labs.libre-entreprise.org 03 Mar '09
03 Mar '09
Author: jcouteau
Date: 2009-03-03 09:07:38 +0000 (Tue, 03 Mar 2009)
New Revision: 119
Modified:
lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
Log:
Adding a create(double[],int[]) method for 1D and 2D matrices.
Adding tests accordingly.
Modified: lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java
===================================================================
--- lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-02-23 08:48:20 UTC (rev 118)
+++ lutinmatrix/trunk/src/main/java/org/codelutin/math/matrix/MatrixFactory.java 2009-03-03 09:07:38 UTC (rev 119)
@@ -45,150 +45,186 @@
*/
public class MatrixFactory { // MatrixFactory
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private Log log = LogFactory.getLog(MatrixFactory.class);
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(MatrixFactory.class);
- static {
- // on essai d'enregistrer le converter XML
- try {
- // Il faut le faire par pur introspection sinon l'exception
- // NoClassDefFoundError est levé avant d'entrer dans le constructeur
- // static :(
- Class converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
- Object converter = converterClass.newInstance();
+ static {
+ // on essai d'enregistrer le converter XML
+ try {
+ // Il faut le faire par pur introspection sinon l'exception
+ // NoClassDefFoundError est levé avant d'entrer dans le constructeur
+ // static :(
+ Class converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDXMLConverter");
+ Object converter = converterClass.newInstance();
- Class converterFactoryClass = Class
- .forName("org.codelutin.xml.XMLConverterFactory");
- Method m = converterFactoryClass.getMethod("addConverter",
- Class.class, Class
- .forName("org.codelutin.xml.XMLConverter"));
- m.invoke(null, MatrixND.class, converter);
+ Class converterFactoryClass = Class
+ .forName("org.codelutin.xml.XMLConverterFactory");
+ Method m = converterFactoryClass.getMethod("addConverter",
+ Class.class, Class
+ .forName("org.codelutin.xml.XMLConverter"));
+ m.invoke(null, MatrixND.class, converter);
- //org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
- // new MatrixNDXMLConverter());
- log.info("Converter XML pour MatrixND ajoute");
+ // org.codelutin.xml.XMLConverterFactory.addConverter(MatrixND.class,
+ // new MatrixNDXMLConverter());
+ log.info("Converter XML pour MatrixND ajoute");
- // on essai d'enregistrer le converter JDBC
- // le JDBC depend du XML
- try {
- converterClass = Class
- .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
- converter = converterClass.newInstance();
+ // on essai d'enregistrer le converter JDBC
+ // le JDBC depend du XML
+ try {
+ converterClass = Class
+ .forName("org.codelutin.math.matrix.MatrixNDJDBCConverter");
+ converter = converterClass.newInstance();
- converterFactoryClass = Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
- m = converterFactoryClass
- .getMethod(
- "addConverter",
- Class.class,
- Class
- .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
- m.invoke(null, MatrixND.class, converter);
+ converterFactoryClass = Class
+ .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformerFactory");
+ m = converterFactoryClass
+ .getMethod(
+ "addConverter",
+ Class.class,
+ Class
+ .forName("org.codelutin.topia.persistence.jdbctransformer.JDBCTransformer"));
+ m.invoke(null, MatrixND.class, converter);
- // Class converterClass =
- // org.codelutin.math.matrix.MatrixNDJDBCConverter();
- // JDBCTransformerFactory
- // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
- log.info("Converter JDBC pour MatrixND ajoute");
- } catch (Throwable eee) {
- log
- .info("librairie topia non presente. Import/Export JDBC impossible");
- log.debug("L'exception etait", eee);
- }
+ // Class converterClass =
+ // org.codelutin.math.matrix.MatrixNDJDBCConverter();
+ // JDBCTransformerFactory
+ // .addConverter(MatrixND.class, new MatrixNDJDBCConverter());
+ log.info("Converter JDBC pour MatrixND ajoute");
+ } catch (Throwable eee) {
+ log
+ .info("librairie topia non presente. Import/Export JDBC impossible");
+ log.debug("L'exception etait", eee);
+ }
- } catch (Throwable eee) {
- log
- .info("librairie lutinxml non presente. Import/Export XML impossible");
- log.debug("L'exception etait", eee);
- }
+ } catch (Throwable eee) {
+ log
+ .info("librairie lutinxml non presente. Import/Export XML impossible");
+ log.debug("L'exception etait", eee);
+ }
- }
+ }
- /** Valeur par defaut si aucun type de Vector n'est donné */
- static protected Class defaultVectorClass = DoubleBigVector.class;
+ /** Valeur par defaut si aucun type de Vector n'est donné */
+ static protected Class defaultVectorClass = DoubleBigVector.class;
- protected Class vectorClass = null;
+ protected Class vectorClass = null;
- protected MatrixFactory(Class vectorClass) {
- this.vectorClass = vectorClass;
- }
+ protected MatrixFactory(Class vectorClass) {
+ this.vectorClass = vectorClass;
+ }
- static public void setDefaultVectorClass(Class vectorClass) {
- defaultVectorClass = vectorClass;
- }
+ static public void setDefaultVectorClass(Class vectorClass) {
+ defaultVectorClass = vectorClass;
+ }
- static public Class getDefaultVectorClass() {
- return defaultVectorClass;
- }
+ static public Class getDefaultVectorClass() {
+ return defaultVectorClass;
+ }
- /**
- * Retourne une factory utilisant vectorClass comme classe de base a
- * l'implantation des matrices
- */
- static public MatrixFactory getInstance(Class vectorClass) {
- return new MatrixFactory(vectorClass);
- }
+ /**
+ * Retourne une factory utilisant vectorClass comme classe de base a
+ * l'implantation des matrices
+ */
+ static public MatrixFactory getInstance(Class vectorClass) {
+ return new MatrixFactory(vectorClass);
+ }
- /**
- * Utilise par defaut {@link FloatBigVector}
- */
- static public MatrixFactory getInstance() {
- return getInstance(defaultVectorClass);
- }
+ /**
+ * Utilise par defaut {@link FloatBigVector}
+ */
+ static public MatrixFactory getInstance() {
+ return getInstance(defaultVectorClass);
+ }
- public MatrixND create(int[] dim) {
- return new MatrixNDImpl(this, dim);
- }
+ public MatrixND create(int[] dim) {
+ return new MatrixNDImpl(this, dim);
+ }
- public MatrixND create(List[] semantics) {
- return new MatrixNDImpl(this, semantics);
- }
+ /**
+ *
+ * @param values
+ * The values to fill the matrix
+ * @param dim
+ * An array representing the dimensions of the matrix
+ * @return a 2D matrix filled with the values, null if the dimension is more
+ * than 2
+ */
- public MatrixND create(String name, int[] dim) {
- return new MatrixNDImpl(this, name, dim);
- }
+ public MatrixND create(double[] values, int[] dim) {
- public MatrixND create(String name, int[] dim, String[] dimNames) {
- return new MatrixNDImpl(this, name, dim, dimNames);
- }
+ if (dim.length > 2) {
+ return null;
+ }
+ MatrixNDImpl matrix = new MatrixNDImpl(this, dim);
- public MatrixND create(String name, List[] semantics) {
- return new MatrixNDImpl(this, name, semantics);
- }
+ if (dim.length == 2) {
+ for (int i = 0; i < dim[0]; i++) {
+ for (int j = 0; j < dim[1]; j++) {
+ int[] coordinates = {i,j};
+ matrix.setValue(coordinates, values[i * dim[0] + j]);
+ }
+ }
+ }
+ if (dim.length == 1){
+ for (int i=0;i<dim[0];i++) {
+ int[] coordinates = {i};
+ matrix.setValue(coordinates, values[i]);
+ }
+ }
- public MatrixND create(String name, List[] semantics, String[] dimNames) {
- return new MatrixNDImpl(this, name, semantics, dimNames);
- }
+ return matrix;
+ }
- public MatrixND create(MatrixND matrix) {
- return new MatrixNDImpl(this, matrix);
- }
+ public MatrixND create(List[] semantics) {
+ return new MatrixNDImpl(this, semantics);
+ }
- /**
- * Crée une nouvelle matrice identité. Une matrice identité est une matrice
- * à 2 dimensions dont tous les éléments de la diagonal vaut 1
- *
- * @param size la taille de la matrice
- * @return une nouvelle matrice identité
- */
- public MatrixND matrixId(int size) {
- MatrixND result = create(new int[] { size, size });
- for (int i = 0; i < size; i++) {
- result.setValue(i, i, 1);
- }
- return result;
- }
+ public MatrixND create(String name, int[] dim) {
+ return new MatrixNDImpl(this, name, dim);
+ }
- protected Vector createVector(int length) {
- try {
- Constructor c = vectorClass
- .getConstructor(new Class[] { Integer.TYPE });
- return (Vector) c.newInstance(new Object[] { length });
- } catch (Exception eee) {
- throw new RuntimeException("Can't create vector", eee);
- }
- }
+ public MatrixND create(String name, int[] dim, String[] dimNames) {
+ return new MatrixNDImpl(this, name, dim, dimNames);
+ }
+ public MatrixND create(String name, List[] semantics) {
+ return new MatrixNDImpl(this, name, semantics);
+ }
+
+ public MatrixND create(String name, List[] semantics, String[] dimNames) {
+ return new MatrixNDImpl(this, name, semantics, dimNames);
+ }
+
+ public MatrixND create(MatrixND matrix) {
+ return new MatrixNDImpl(this, matrix);
+ }
+
+ /**
+ * Crée une nouvelle matrice identité. Une matrice identité est une matrice
+ * à 2 dimensions dont tous les éléments de la diagonal vaut 1
+ *
+ * @param size
+ * la taille de la matrice
+ * @return une nouvelle matrice identité
+ */
+ public MatrixND matrixId(int size) {
+ MatrixND result = create(new int[] { size, size });
+ for (int i = 0; i < size; i++) {
+ result.setValue(i, i, 1);
+ }
+ return result;
+ }
+
+ protected Vector createVector(int length) {
+ try {
+ Constructor c = vectorClass
+ .getConstructor(new Class[] { Integer.TYPE });
+ return (Vector) c.newInstance(new Object[] { length });
+ } catch (Exception eee) {
+ throw new RuntimeException("Can't create vector", eee);
+ }
+ }
+
} // MatrixFactory
Modified: lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java
===================================================================
--- lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-02-23 08:48:20 UTC (rev 118)
+++ lutinmatrix/trunk/src/test/java/org/codelutin/math/matrix/MatrixNDTest.java 2009-03-03 09:07:38 UTC (rev 119)
@@ -508,6 +508,36 @@
assertEquals(48, mat.getValue(0, 0, 0), 0);
}
+
+ public void testCreateFromDoubleArray() throws Exception {
+ MatrixND mat = null;
+
+ mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8,9}, new int[] {3,3});
+
+ assertEquals(2,mat.getDim().length);
+ assertEquals(3,mat.getDim(0));
+ assertEquals(3,mat.getDim(1));
+ assertEquals(1,(int)mat.getValue(new int[] {0,0}));
+ assertEquals(2,(int)mat.getValue(new int[] {0,1}));
+ assertEquals(3,(int)mat.getValue(new int[] {0,2}));
+ assertEquals(4,(int)mat.getValue(new int[] {1,0}));
+ assertEquals(5,(int)mat.getValue(new int[] {1,1}));
+ assertEquals(6,(int)mat.getValue(new int[] {1,2}));
+ assertEquals(7,(int)mat.getValue(new int[] {2,0}));
+ assertEquals(8,(int)mat.getValue(new int[] {2,1}));
+ assertEquals(9,(int)mat.getValue(new int[] {2,2}));
+
+ mat = getFactory().create(new double[] {1,2,3}, new int[]{3});
+ assertEquals(1,mat.getDim().length);
+ assertEquals(3,mat.getDim(0));
+ assertEquals(1,(int)mat.getValue(new int[] {0}));
+ assertEquals(2,(int)mat.getValue(new int[] {1}));
+ assertEquals(3,(int)mat.getValue(new int[] {2}));
+
+ mat = getFactory().create(new double[] {1,2,3,4,5,6,7,8}, new int[] {2,2,2});
+ assertNull(mat);
+
+ }
public void testReduceDims() throws Exception {
1
0
[Lutinmatrix-commits] r118 - in lutinmatrix/trunk: . src/main src/main/assembly
by chatellier@users.labs.libre-entreprise.org 23 Feb '09
by chatellier@users.labs.libre-entreprise.org 23 Feb '09
23 Feb '09
Author: chatellier
Date: 2009-02-23 08:48:20 +0000 (Mon, 23 Feb 2009)
New Revision: 118
Added:
lutinmatrix/trunk/src/main/assembly/
lutinmatrix/trunk/src/main/assembly/deps.xml
lutinmatrix/trunk/src/main/assembly/full.xml
Modified:
lutinmatrix/trunk/pom.xml
Log:
Update some version, and add some assembly.
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-02-20 18:38:53 UTC (rev 117)
+++ lutinmatrix/trunk/pom.xml 2009-02-23 08:48:20 UTC (rev 118)
@@ -100,6 +100,22 @@
</executions>
</plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/deps.xml</descriptor>
+ <descriptor>src/main/assembly/full.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Added: lutinmatrix/trunk/src/main/assembly/deps.xml
===================================================================
--- lutinmatrix/trunk/src/main/assembly/deps.xml (rev 0)
+++ lutinmatrix/trunk/src/main/assembly/deps.xml 2009-02-23 08:48:20 UTC (rev 118)
@@ -0,0 +1,34 @@
+<assembly>
+ <id>deps</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <!-- This don't support SNAPSHOT -->
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>lib</outputDirectory>
+ <excludes>
+ <exclude>junit:junit</exclude>
+ <exclude>${artifact.groupId}:${artifact.artifactId}</exclude>
+ </excludes>
+ <scope>runtime</scope>
+ </dependencySet>
+ </dependencySets>
+ <files>
+ <file>
+ <!--source>target/${artifact.artifactId}-${artifact.version}.jar</source-->
+ <source>target/${project.build.finalName}.jar</source>
+ </file>
+ <!-- <file>
+ <source>target/classes/THIRD-PARTY.txt</source>
+ </file> -->
+ </files>
+ <fileSets>
+ <fileSet>
+ <includes>
+ <include>README*</include>
+ <include>LICENSE*</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</assembly>
\ No newline at end of file
Added: lutinmatrix/trunk/src/main/assembly/full.xml
===================================================================
--- lutinmatrix/trunk/src/main/assembly/full.xml (rev 0)
+++ lutinmatrix/trunk/src/main/assembly/full.xml 2009-02-23 08:48:20 UTC (rev 118)
@@ -0,0 +1,38 @@
+<assembly>
+ <id>full</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <!-- This don't support SNAPSHOT -->
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>lib</outputDirectory>
+ <excludes>
+ <exclude>${artifact.groupId}:${artifact.artifactId}</exclude>
+ </excludes>
+ <scope>runtime</scope>
+ </dependencySet>
+ </dependencySets>
+ <files>
+ <file>
+ <!--source>target/${artifact.artifactId}-${artifact.version}.jar</source-->
+ <source>target/${project.build.finalName}.jar</source>
+ </file>
+ <!-- <file>
+ <source>target/classes/THIRD-PARTY.txt</source>
+ </file> -->
+ </files>
+ <fileSets>
+ <fileSet>
+ <includes>
+ <include>README*</include>
+ <include>LICENSE*</include>
+ <include>pom.xml</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>src</directory>
+ <useDefaultExcludes>true</useDefaultExcludes>
+ </fileSet>
+ </fileSets>
+</assembly>
\ No newline at end of file
1
0
[Lutinmatrix-commits] r117 - lutinmatrix/trunk
by tchemit@users.labs.libre-entreprise.org 20 Feb '09
by tchemit@users.labs.libre-entreprise.org 20 Feb '09
20 Feb '09
Author: tchemit
Date: 2009-02-20 18:38:53 +0000 (Fri, 20 Feb 2009)
New Revision: 117
Modified:
lutinmatrix/trunk/pom.xml
Log:
push back generic scm values
use zeroConf in jrst
use zeroConf in license-switcher
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-02-18 19:03:55 UTC (rev 116)
+++ lutinmatrix/trunk/pom.xml 2009-02-20 18:38:53 UTC (rev 117)
@@ -89,15 +89,10 @@
<artifactId>maven-jrst-plugin</artifactId>
<version>0.8.4</version>
<configuration>
- <directoryIn>${maven.src.dir}/site</directoryIn>
- <directoryOut>${maven.site.gen.dir}</directoryOut>
<defaultLocale>fr</defaultLocale>
- <inputEncoding>${project.build.sourceEncoding}</inputEncoding>
- <outputEncoding>${project.build.sourceEncoding}</outputEncoding>
</configuration>
<executions>
<execution>
- <phase>pre-site</phase>
<goals>
<goal>jrst</goal>
</goals>
@@ -115,9 +110,9 @@
<!--Source control management-->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinmatrix/lutinmatrix/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/lutinmatrix/lutinmatrix/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinmatrix/tru…</url>
+ <connection>${maven.scm.connection}</connection>
+ <developerConnection>${maven.scm.developerConnection}</developerConnection>
+ <url>${maven.scm.url}</url>
</scm>
<!--Code Lutin Repository-->
@@ -154,9 +149,6 @@
<groupId>org.codelutin</groupId>
<artifactId>maven-license-switcher-plugin</artifactId>
<version>0.6</version>
- <configuration>
- <licenseName>${license-switcher.licenseName}</licenseName>
- </configuration>
<executions>
<execution>
<id>attach-licenses</id>
1
0
[Lutinmatrix-commits] r116 - lutinmatrix/trunk
by tchemit@users.labs.libre-entreprise.org 18 Feb '09
by tchemit@users.labs.libre-entreprise.org 18 Feb '09
18 Feb '09
Author: tchemit
Date: 2009-02-18 19:03:55 +0000 (Wed, 18 Feb 2009)
New Revision: 116
Modified:
lutinmatrix/trunk/pom.xml
Log:
[maven-release-plugin] prepare for next development iteration
Modified: lutinmatrix/trunk/pom.xml
===================================================================
--- lutinmatrix/trunk/pom.xml 2009-02-18 19:03:52 UTC (rev 115)
+++ lutinmatrix/trunk/pom.xml 2009-02-18 19:03:55 UTC (rev 116)
@@ -15,7 +15,7 @@
</parent>
<artifactId>lutinmatrix</artifactId>
- <version>1.2</version>
+ <version>1.3-SNAPSHOT</version>
<dependencies>
@@ -115,9 +115,9 @@
<!--Source control management-->
<scm>
- <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinmatrix/lutinmatrix/tags/1.2</connection>
- <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/lutinmatrix/lutinmatrix/tags/1.2</developerConnection>
- <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinmatrix/tag…</url>
+ <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinmatrix/lutinmatrix/trunk</connection>
+ <developerConnection>scm:svn:svn+ssh://tchemit@labs.libre-entreprise.org/svnroot/lutinmatrix/lutinmatrix/trunk</developerConnection>
+ <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinmatrix/tru…</url>
</scm>
<!--Code Lutin Repository-->
1
0