Révision 213

tmp/org.txm.r.core/.project (revision 213)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.r.core</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.r.core/src/org/txm/stat/package.html (revision 213)
1
<html>
2
<body>
3
<p>Root package of all statistical and numeric computing functions of the toolbox.</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.r.core/src/org/txm/stat/utils/ArrayIndex.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.utils;
29

  
30
import java.util.HashMap;
31
import java.util.Map;
32

  
33
import org.txm.Messages;
34

  
35
// TODO: Auto-generated Javadoc
36
/**
37
 * Utilities for managing index of vector.
38
 * 
39
 * @author sloiseau
40
 * 
41
 */
42
public final class ArrayIndex {
43

  
44
	/**
45
	 * Convert an array of zero-based index to an array of one-base index, that
46
	 * is, add <code>1</code> to all elements.
47
	 * 
48
	 * This method check every index (see exception thrown).
49
	 *
50
	 * @param zero_based the zero based index.
51
	 * @param length the number of elements that can be indexed.
52
	 * @return the one base index.
53
	 */
54
	public static final int[] zeroToOneBasedIndex(int[] zero_based, int length) {
55
		if (zero_based == null || zero_based.length == 0) {
56
			throw new IllegalArgumentException(Messages.ArrayIndex_0);
57
		}
58
		int[] one_based = new int[zero_based.length];
59
		for (int i = 0; i < zero_based.length; i++) {
60
			if (zero_based[i] < 0 || zero_based[i] >= length) {
61
				throw new IllegalArgumentException(Messages.ArrayIndex_1);
62
			}
63
			one_based[i] = zero_based[i] + 1;
64
		}
65
		return one_based;
66
	}
67

  
68
	/**
69
	 * Zero to one based index.
70
	 *
71
	 * @param zero_based the zero_based
72
	 * @return the int
73
	 */
74
	public static final int zeroToOneBasedIndex(int zero_based) {
75
		return zero_based + 1;
76
	}
77

  
78
	/**
79
	 * Get the index (0-based) of the element of subvector into vector. Return
80
	 * <code>-1</code> when no element in vector correspond to the element in
81
	 * subvector.
82
	 *
83
	 * @param vector the vector
84
	 * @param subvector the subvector
85
	 * @return the index
86
	 */
87
	public static int[] getIndex(String[] vector, String[] subvector) {
88
		int[] result = new int[subvector.length];
89
		Map<String, Integer> index = new HashMap<String, Integer>();
90
		for (int i = 0; i < subvector.length; i++) {
91
			index.put(subvector[i], i);
92
			result[i] = -1;
93
		}
94
		for (int i = 0; i < vector.length; i++) {
95
			if (index.containsKey(vector[i])) {
96
				result[index.get(vector[i])] = i;
97
			}
98
		}
99
		return result;
100
	}
101
}
0 102

  
tmp/org.txm.r.core/src/org/txm/stat/utils/ArrayEquals.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.utils;
29

  
30
import java.util.Arrays;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * Utility methods for testing for equality of arrays.
35
 * 
36
 * @author sloiseau
37
 * 
38
 */
39
public final class ArrayEquals {
40

  
41
	/**
42
	 * Test for equality of both array. For consistency with Arrays.equals
43
	 * contract, the two arrays are equals if both are <code>null</code>.
44
	 *
45
	 * @param array1 the array1
46
	 * @param array2 the array2
47
	 * @return <code>true</code> if (1) both arrays are <code>null</code> or if
48
	 * (2) both arrays have the same length and contain pair of arrays
49
	 * equals to each other according to
50
	 * {@link Arrays#equals(int[], int[])}.
51
	 */
52
	public static final boolean deepEquals(int[][] array1, int[][] array2) {
53
		if (array1 == null && array2 == null)
54
			return true;
55
		if (array1 == null || array2 == null)
56
			return false;
57
		if (array1.length != array2.length)
58
			return false;
59
		for (int i = 0; i < array2.length; i++) {
60
			if (!Arrays.equals(array1[i], array2[i]))
61
				return false;
62
		}
63
		return true;
64
	}
65

  
66
}
0 67

  
tmp/org.txm.r.core/src/org/txm/stat/utils/VectorizeArray.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.utils;
29

  
30
import org.txm.Messages;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * Static methods for dealing vectorization of Arrays.
35
 * 
36
 * @author sloiseau
37
 * 
38
 */
39
public final class VectorizeArray {
40

  
41
	/**
42
	 * Convert a <code>double * double</code> array in a <code>double</code>
43
	 * array. Each inner array of the argument is added one after the other into
44
	 * the result array.
45
	 * 
46
	 * <pre>
47
	 * [
48
	 * [1, 2, 3],
49
	 * [4, 5, 6]
50
	 * ]
51
	 * </pre>
52
	 * 
53
	 * result in :
54
	 * 
55
	 * <pre>
56
	 * [1, 2, 3, 4, 5, 6]
57
	 * </pre>
58
	 * 
59
	 * that is, "row first".
60
	 *
61
	 * @param matrix a <code>double * double</code> array where all inner arrays
62
	 * have the same length.
63
	 * @return an array of <code>double</code> produced by vectorization of the
64
	 * matrix.
65
	 */
66
	public final static double[] vectorizeByInner(double[][] matrix) {
67
		if (matrix == null || matrix.length == 0) {
68
			throw new IllegalArgumentException(Messages.VectorizeArray_0);
69
		}
70
		int inner_length = matrix[0].length;
71
		if (inner_length < 1) {
72
			throw new IllegalArgumentException(Messages.VectorizeArray_1);
73
		}
74
		double[] vector = new double[matrix.length * matrix[0].length];
75
		for (int i = 0; i < matrix.length; i++) {
76
			if (matrix[i] == null) {
77
				throw new IllegalArgumentException(Messages.VectorizeArray_10);
78
			}
79
			if (inner_length != matrix[i].length) {
80
				throw new IllegalArgumentException(Messages.VectorizeArray_3);
81
			}
82
			System.arraycopy(matrix[i], 0, vector, i * inner_length,
83
					inner_length);
84
		}
85
		return vector;
86
	}
87

  
88
	/**
89
	 * Convert a <code>int * int</code> array in a <code>double</code> array.
90
	 * Each inner array of the argument is added one after the other into the
91
	 * result array.
92
	 * 
93
	 * <pre>
94
	 * [
95
	 * [1, 2, 3],
96
	 * [4, 5, 6]
97
	 * ]
98
	 * </pre>
99
	 * 
100
	 * result in :
101
	 * 
102
	 * <pre>
103
	 * [1, 2, 3, 4, 5, 6]
104
	 * </pre>
105
	 * 
106
	 * that is, "row first".
107
	 *
108
	 * @param matrix a <code>int * int</code> array where all inner arrays have the
109
	 * same length.
110
	 * @return an array of <code>int</code> produced by vectorization of the
111
	 * matrix.
112
	 */
113
	public final static int[] vectorizeByInner(int[][] matrix) {
114
		if (matrix == null || matrix.length == 0) {
115
			throw new IllegalArgumentException(Messages.VectorizeArray_4);
116
		}
117
		int inner_length = matrix[0].length;
118
		if (inner_length < 1) {
119
			throw new IllegalArgumentException(Messages.VectorizeArray_5);
120
		}
121
		int[] vector = new int[matrix.length * matrix[0].length];
122
		for (int i = 0; i < matrix.length; i++) {
123
			if (matrix[i] == null) {
124
				throw new IllegalArgumentException(Messages.VectorizeArray_10);
125
			}
126
			if (inner_length != matrix[i].length) {
127
				throw new IllegalArgumentException(Messages.VectorizeArray_7);
128
			}
129
			System.arraycopy(matrix[i], 0, vector, i * inner_length,
130
					inner_length);
131
		}
132
		return vector;
133
	}
134

  
135
	/**
136
	 * Convert a <code>double * double</code> array in a <code>double</code>
137
	 * array. The elements of the input array are assembled in the output array
138
	 * so that elements of same index in the outer array are consecutive. So :
139
	 * 
140
	 * <pre>
141
	 * [
142
	 * [1, 2, 3],
143
	 * [4, 5, 6]
144
	 * ]
145
	 * </pre>
146
	 * 
147
	 * result in :
148
	 * 
149
	 * <pre>
150
	 * [1, 4, 2, 5, 3, 6]
151
	 * </pre>
152
	 * 
153
	 * that is, "column first".
154
	 *
155
	 * @param matrix a <code>double * double</code> array where all inner arrays
156
	 * have the same length.
157
	 * @return an array of <code>double</code> produced by vectorization of the
158
	 * matrix.
159
	 */
160
	public final static double[] vectorizeByOuter(double[][] matrix) {
161
		if (matrix == null || matrix.length == 0) {
162
			throw new IllegalArgumentException(Messages.VectorizeArray_8);
163
		}
164
		int inner_length = matrix[0].length;
165
		int outer_length = matrix.length;
166
		if (inner_length < 1) {
167
			throw new IllegalArgumentException(Messages.VectorizeArray_9);
168
		}
169
		double[] vector = new double[matrix.length * matrix[0].length];
170
		for (int i = 0; i < matrix.length; i++) {
171
			if (matrix[i] == null) {
172
				throw new IllegalArgumentException(Messages.VectorizeArray_10);
173
			}
174
			if (inner_length != matrix[i].length) {
175
				throw new IllegalArgumentException(Messages.VectorizeArray_11);
176
			}
177
			for (int j = 0; j < matrix[i].length; j++) {
178
				vector[(j * outer_length) + i] = matrix[i][j];
179
			}
180

  
181
		}
182
		return vector;
183
	}
184

  
185
}
0 186

  
tmp/org.txm.r.core/src/org/txm/stat/utils/PrintArray.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.utils;
29

  
30
import java.util.Arrays;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * Various utilities method for printing arrays.
35
 * 
36
 * @author sloiseau
37
 * 
38
 */
39
public final class PrintArray {
40

  
41
	/**
42
	 * Double array.
43
	 *
44
	 * @param matrix the matrix
45
	 * @return the string
46
	 */
47
	public final static String doubleArray(double[][] matrix) {
48
		// DoubleMatrix2D m = new SparseDoubleMatrix2D(matrix);
49
		// return m.toString();
50
		StringBuffer sb = new StringBuffer();
51
		for (int i = 0; i < matrix.length; i++) {
52
			sb.append(Arrays.toString(matrix[i]));
53
		}
54
		return sb.toString();
55
	}
56

  
57
	/**
58
	 * Int array.
59
	 *
60
	 * @param matrix the matrix
61
	 * @return the string
62
	 */
63
	public final static String intArray(int[][] matrix) {
64
		double[][] doublematrix = new double[matrix.length][matrix[0].length];
65
		for (int i = 0; i < matrix.length; i++) {
66
			for (int j = 0; j < doublematrix[i].length; j++) {
67
				doublematrix[i][j] = matrix[i][j];
68
			}
69
		}
70
		return doubleArray(doublematrix);
71
	}
72

  
73
}
0 74

  
tmp/org.txm.r.core/src/org/txm/stat/utils/CheckArray.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (lun., 06 mai 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.utils;
29

  
30
// TODO: Auto-generated Javadoc
31
/**
32
 * Various utility methods for checking consistency of matrix as java array of
33
 * arrays.
34
 * 
35
 * @author sloiseau
36
 * 
37
 */
38
public final class CheckArray {
39

  
40
	/**
41
	 * Check if an array is not null (or 0-length), does not include null inner
42
	 * array (or 0 length), and if all inner arrays have the same length.
43
	 *
44
	 * @param array the array
45
	 * @return <code>true</code> if the condition are satisfied,
46
	 * <code>false</code> otherwise.
47
	 */
48
	public final static boolean checkMatrixRepresentation(int[][] array) {
49
		// same code as in #checkMatrixRepresentation(double[][])
50
		if (array == null)
51
			return false;
52
		int length = array.length;
53
		if (length < 1)
54
			return false;
55
		if (array[0] == null)
56
			return false;
57
		int firstElementLength = array[0].length;
58
		if (firstElementLength == 0)
59
			return false;
60
		for (int i = 0; i < array.length; i++) {
61
			if (array[i] == null)
62
				return false;
63
			if (array[i].length != firstElementLength)
64
				return false;
65
		}
66
		return true;
67
	}
68

  
69
	/**
70
	 * Check if an array is not null (or 0-length), does not include null inner
71
	 * array (or 0 length), and if all inner arrays have the same length.
72
	 *
73
	 * @param array the array
74
	 * @return <code>true</code> if the condition are satisfied,
75
	 * <code>false</code> otherwise.
76
	 */
77
	public final static boolean checkMatrixRepresentation(double[][] array) {
78
		// same code as in #checkMatrixRepresentation(int[][])
79
		if (array == null)
80
			return false;
81
		int length = array.length;
82
		if (length < 1)
83
			return false;
84
		if (array[0] == null)
85
			return false;
86
		int firstElementLength = array[0].length;
87
		if (firstElementLength == 0)
88
			return false;
89
		for (int i = 0; i < array.length; i++) {
90
			if (array[i] == null)
91
				return false;
92
			if (array[i].length != firstElementLength)
93
				return false;
94
		}
95
		return true;
96
	}
97

  
98
}
0 99

  
tmp/org.txm.r.core/src/org/txm/stat/utils/package.html (revision 213)
1
<html>
2
<body>
3
<p>Utility functions for dealing with array (vectorizing, indexing, checking consistency...).</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.r.core/src/org/txm/stat/ConnectToRserve.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.stat;
29
import org.rosuda.REngine.REXP;
30
import org.rosuda.REngine.RList;
31
import org.rosuda.REngine.Rserve.RConnection;
32

  
33
// TODO: Auto-generated Javadoc
34
/**
35
 * The Class ConnectToRserve.
36
 */
37
class ConnectToRserve {
38
	
39
	/**
40
	 * The main method.
41
	 *
42
	 * @param args the arguments
43
	 */
44
	public static void main(String args[]) {
45
		try {
46
			RConnection c = new RConnection();
47
			String userhome = System.getProperty("user.home"); //$NON-NLS-1$
48
			RList ret = c.eval("source('"+userhome+"/Bureau/R/Rdata')").asList(); //$NON-NLS-1$ //$NON-NLS-2$
49
			
50
			System.out.println("source ret : "+ret.get(1)); //$NON-NLS-1$
51
			System.out.println(ret);
52
			
53
			REXP ret2 = c.eval("print(lexicaltable)"); //$NON-NLS-1$
54
			System.out.println("lexicaltable :"+ret2); //$NON-NLS-1$
55
		}
56
		catch(Exception e) {
57
			org.txm.utils.logger.Log.printStackTrace(e);
58
		}
59
	}
60
}
0 61

  
tmp/org.txm.r.core/src/org/txm/stat/engine/r/rcolt/package.html (revision 213)
1
<html>
2
<body>
3
<p>Converting colt data structure into data structure suited for the R language (mainly vectorized version of matrix).</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.r.core/src/org/txm/stat/engine/r/rcolt/RColt.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (Mon, 06 May 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.engine.r.rcolt;
29

  
30
import cern.colt.function.IntIntDoubleFunction;
31
import cern.colt.matrix.DoubleMatrix2D;
32

  
33
// TODO: Auto-generated Javadoc
34
/**
35
 * Method for transformation of colt matrix into various array.
36
 * 
37
 * @author sloiseau
38
 * 
39
 */
40
public final class RColt {
41

  
42
	/**
43
	 * Double matrix2 d2 int int array.
44
	 *
45
	 * @param matrix the matrix
46
	 * @return the int[][]
47
	 */
48
	public final static int[][] doubleMatrix2D2IntIntArray(DoubleMatrix2D matrix) {
49
		int rows = matrix.rows();
50
		int columns = matrix.columns();
51
		int[][] values = new int[rows][columns];
52
		for (int row = rows; --row >= 0;) {
53
			int[] currentRow = values[row];
54
			for (int column = columns; --column >= 0;) {
55
				currentRow[column] = (int) matrix.getQuick(row, column);
56
			}
57
		}
58
		return values;
59
		// final IntIntDoubleFunction fun = new CreateIntIntArray(matrix.rows(),
60
		// matrix.columns());
61
		// matrix.forEachNonZero(fun);
62
		// return ((CreateIntIntArray)fun).getIntIntArray();
63
	}
64

  
65
	/**
66
	 * Double matrix2 d2 double double array.
67
	 *
68
	 * @param matrix the matrix
69
	 * @return the double[][]
70
	 */
71
	public final static double[][] doubleMatrix2D2DoubleDoubleArray(
72
			DoubleMatrix2D matrix) {
73
		matrix.trimToSize();
74
		return matrix.toArray();
75
	}
76

  
77
	/*
78
	 * public final static int[][] intMatrix2D2IntIntArray (IntMatrix2D matrix)
79
	 * { matrix.trimToSize(); return matrix.toArray(); }
80
	 */
81

  
82
	/**
83
	 * Transform a Colt {@link DoubleMatrix2D} into an array of <code>int</code>
84
	 * .
85
	 * 
86
	 * The value of the matrix are stored by column (the values of the first
87
	 * column, then the values of the second column, etc.)
88
	 *
89
	 * @param matrix the matrix
90
	 * @return an array of <code>int</code>
91
	 * @todo use {@link DoubleMatrix2D#trimToSize()} and
92
	 * {@link DoubleMatrix2D#toArray()}
93
	 */
94
	public final static int[] doubleMatrix2D2IntArray(DoubleMatrix2D matrix) {
95
		final IntIntDoubleFunction fun = new CreateIntArray(matrix.rows(),
96
				matrix.columns());
97
		matrix.forEachNonZero(fun);
98
		return ((CreateIntArray) fun).getIntArray();
99
	}
100

  
101
	// public final static REXP DoubleMatrix2D2REXP(DoubleMatrix2D matrix,
102
	// Rengine engine, String varName) {
103
	// final IntIntDoubleFunction fun = new CreateIntIntArray(matrix.rows(),
104
	// matrix.columns());
105
	// matrix.forEachNonZero(fun);
106
	// int[][] m = ((CreateIntIntArray)fun).getIntIntArray();
107
	// engine.assign(varName, m);
108
	// return ((CreateIntIntArray)fun).getIntIntArray();
109
	// }
110

  
111
	/**
112
	 * The Class CreateIntIntArray.
113
	 */
114
	static class CreateIntIntArray implements IntIntDoubleFunction {
115

  
116
		/** The array. */
117
		private final int[][] array;
118

  
119
		/**
120
		 * Instantiates a new creates the int int array.
121
		 *
122
		 * @param rows the rows
123
		 * @param columns the columns
124
		 */
125
		public CreateIntIntArray(int rows, int columns) {
126
			array = new int[rows][columns];
127
			for (int i = 0; i < array.length; i++) {
128
				for (int j = 0; j < array[i].length; j++) {
129
					array[i][j] = 0;
130
				}
131
			}
132
		}
133

  
134
		/* (non-Javadoc)
135
		 * @see cern.colt.function.IntIntDoubleFunction#apply(int, int, double)
136
		 */
137
		@Override
138
		public double apply(int row, int col, double value) {
139
			array[row][col] = (int) value;
140
			return value;
141
		}
142

  
143
		/**
144
		 * Gets the int int array.
145
		 *
146
		 * @return the int int array
147
		 */
148
		public int[][] getIntIntArray() {
149
			return array;
150
		}
151
	}
152

  
153
	/**
154
	 * The Class CreateIntArray.
155
	 */
156
	static class CreateIntArray implements IntIntDoubleFunction {
157

  
158
		/** The array. */
159
		private final int[] array;
160
		
161
		/** The rows. */
162
		private final int rows;
163

  
164
		/**
165
		 * Instantiates a new creates the int array.
166
		 *
167
		 * @param rows the rows
168
		 * @param columns the columns
169
		 */
170
		public CreateIntArray(int rows, int columns) {
171
			array = new int[rows * columns];
172
			for (int i = 0; i < array.length; i++) {
173
				array[i] = 0;
174
			}
175
			this.rows = rows;
176
		}
177

  
178
		/* (non-Javadoc)
179
		 * @see cern.colt.function.IntIntDoubleFunction#apply(int, int, double)
180
		 */
181
		@Override
182
		public double apply(int row, int col, double value) {
183
			array[(col * rows) + row] = (int) value;
184
			return value;
185
		}
186

  
187
		/**
188
		 * Gets the int array.
189
		 *
190
		 * @return the int array
191
		 */
192
		public int[] getIntArray() {
193
			return array;
194
		}
195
	}
196

  
197
}
0 198

  
tmp/org.txm.r.core/src/org/txm/stat/engine/r/StartRserve.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2015-06-15 15:29:16 +0200 (Mon, 15 Jun 2015) $
25
// $LastChangedRevision: 2989 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.engine.r;
29

  
30
import java.io.File;
31

  
32
import org.rosuda.REngine.Rserve.RConnection;
33
import org.txm.Messages;
34
import org.txm.utils.OSDetector;
35
import org.txm.utils.SystemProxyDetector;
36
import org.txm.utils.StreamHog;
37
import org.txm.utils.logger.Log;
38

  
39
// TODO: Auto-generated Javadoc
40
/**
41
 * Helper class that consumes output of a process. In addition, it filter output
42
 * of the REG command on Windows to look for InstallPath registry entry which
43
 * specif ies the location of R.
44
 * 
45
 * @author RServe library
46
 */
47

  
48
/**
49
 * simple class that start Rserve locally if it's not running already - see
50
 * mainly <code>checkLocalRserve</code> method. It spits out quite some
51
 * debugging outout of the console, so feel free to modif y it for your
52
 * application if desired.
53
 * <p>
54
 * <i>Important:</i> All applications should shutdown every Rserve that they
55
 * started! Never leave Rserve running if you started it after your application
56
 * quits since it may pose a security risk. Inform the user if you started an
57
 * Rserve instance.
58
 */
59
public class StartRserve {
60

  
61
	/** shortcut to <code>launchRserve(cmd, "--no-save --slave", "--no-save --slave", false)</code>. */
62
	public static Process Rserveprocess;
63

  
64
	/**
65
	 * Launch rserve.
66
	 *
67
	 * @param cmd the cmd
68
	 * @param options 
69
	 * @return true, if successful
70
	 */
71
	protected static boolean launchRserve(String cmd, int port, boolean debug, String rArgs, String rServeArgs) {
72
		if (new File(cmd).exists() && !new File(cmd).isDirectory()
73
				&& new File(cmd).canExecute())
74
			return launchRserve(cmd,
75
					"--no-save --slave --encoding utf8 "+rArgs, "--RS-encoding utf8 --no-save --slave --encoding utf8 "+rServeArgs, port, debug); //$NON-NLS-1$ //$NON-NLS-2$
76
		return false;
77
	}
78

  
79
	/**
80
	 * attempt to start Rserve. Note: parameters are <b>not</b> quoted, so avoid
81
	 * using any quotes in arguments
82
	 *
83
	 * @param cmd command necessary to start R
84
	 * @param rargs arguments are are to be passed to R
85
	 * @param rsrvargs arguments to be passed to Rserve
86
	 * @param debug the debug
87
	 * @return <code>true</code> if Rserve is running or was successfully
88
	 * started, <code>false</code> otherwise.
89
	 */
90
	protected static boolean launchRserve(String cmd, String rargs,
91
			String rsrvargs, int port, boolean debug) {
92
		//System.out.println("LAUNCH R SERVER "+cmd+" "+port+" "+debug);
93
		try {
94
			String[] cmdline = null;
95
			// FIXME: don't forget to remove this Window dedicated code if we manage to use http_proxy command line argument
96
			boolean isWindows = false;
97
			
98
			// Windows OS
99
			if (OSDetector.isFamilyWindows()) {
100
				isWindows = true; /* Windows startup */
101
				
102
				
103
				// TODO: old tests for setting proxy in R
104
				//Windows : set --internet2 option to manage proxy if any
105
				
106
//				// set Proxy configuration using Eclipse RCP stored values
107
//				String proxy_conf = "";
108
//				ProxyConf conf = new ProxyConf(RWorkspace.getRWorkspaceInstance());
109
//				if (conf.mustSetProxyConfiguration()) {
110
//					proxy_conf = "http_proxy="+conf.getHttpProxyUrl();
111
//					rsrvargs += " "+proxy_conf; // add the http_proxy parameter
112
//					Log.info("Run Rserve with proxy configuration: "+proxy_conf);
113
//				}
114
				
115
				cmdline = new String[] {
116
						cmd,
117
						rargs, 
118
						"-e", //$NON-NLS-1$
119
						"library(Rserve);Rserve(" //$NON-NLS-1$ 
120
						+ (debug ? "TRUE" : "FALSE")  //$NON-NLS-1$ //$NON-NLS-2$
121
						+ ",port=" + port + "" //$NON-NLS-1$ //$NON-NLS-2$
122
						+ ",args='" //$NON-NLS-1$
123
						+ rsrvargs + "')\" " //$NON-NLS-1$
124
				};	
125
			}
126
			// Mac, Linux
127
			else {
128
				cmdline = new String[] {
129
						"/bin/sh", //$NON-NLS-1$
130
						"-c", //$NON-NLS-1$
131
						"echo 'library(Rserve);Rserve(" //$NON-NLS-1$
132
						+ (debug ? "TRUE" : "FALSE") //$NON-NLS-1$ //$NON-NLS-2$
133
						+ ",port="+port+"" //$NON-NLS-1$ //$NON-NLS-2$
134
						+ ",args=\"" + rsrvargs //$NON-NLS-1$
135
						+ "\")'|" + cmd //$NON-NLS-1$ 
136
						+ " " + rargs }; //$NON-NLS-1$
137
			}
138

  
139
//			ProcessBuilder builder = new ProcessBuilder(cmdline);
140
//			Rserveprocess = builder.start();
141

  
142
			Runtime runtime = Runtime.getRuntime();
143
			Rserveprocess = runtime.exec(cmdline);
144
			
145
			//Log.info(Messages.StartRserve_0+Arrays.toString(cmdline));
146
			StreamHog errStream = new StreamHog(Rserveprocess.getErrorStream(), debug);
147
			StreamHog inStream = new StreamHog(Rserveprocess.getInputStream(), debug);
148
			RWorkspace.getRWorkspaceInstance().registerLogger(errStream, inStream);
149

  
150
			if (!debug && !isWindows)
151
				Rserveprocess.waitFor();
152
			// System.out.println("call terminated, let us try to connect ...");
153
		} catch (Exception x) {
154
			System.err.println(Messages.StartRserve_21 + x.getMessage());
155
			return false;
156
		}
157

  
158
		System.err.print(Messages.StartRserve_22);
159

  
160
		try {
161
			Thread.sleep(200);
162
		} catch (InterruptedException ix) { }
163

  
164
		int attempts = 20;
165
		while (attempts > 0) {
166
			try {
167
				System.out.print("."); //$NON-NLS-1$
168
				RConnection c = new RConnection("127.0.0.1", port); //$NON-NLS-1$
169
				c.close();
170
				return true;
171
			} catch (Exception e2) {
172
				try {
173
					Thread.sleep(2000);
174
				} catch (InterruptedException ix) { }
175
			}
176

  
177
			attempts--;
178
		}
179
		System.out.println(""); //$NON-NLS-1$
180
		return false;
181
	}
182

  
183
	/**
184
	 * checks whether Rserve is running and if that's not the case it attempts
185
	 * to start it using the defaults for the platform where it is run on. This
186
	 * method is meant to be set-and-forget and cover most default setups. For
187
	 * special setups you may get more control over R with <
188
	 * <code>launchRserve</code> instead.
189
	 * @param rServeArgs 
190
	 * @param rargs 
191
	 *
192
	 * @return true, if successful
193
	 */
194
	protected static boolean checkLocalRserve(int port, boolean debug, String rargs, String rServeArgs) {
195
		Log.info(Messages.StartRserve_2);
196
		if (isRserveRunning(port)) {
197
			Log.info(Messages.StartRserve_3+port);
198
			return true;
199
		}
200
		// Windows OS
201
		if (OSDetector.isFamilyWindows()) {
202
			// System.out.println("Windows: query registry to find where R is installed ...");
203
			String installPath = null;
204
			try {
205
				Process rp = Runtime.getRuntime().exec(
206
						"reg query HKLM\\Software\\R-core\\R"); //$NON-NLS-1$
207
				StreamHog regHog = new StreamHog(rp.getInputStream(), true);
208
				rp.waitFor();
209
				regHog.join();
210
				installPath = regHog.getInstallPath();
211
			} catch (Exception rge) {
212
				System.err.println(Messages.StartRserve_28 + rge);
213
				return false;
214
			}
215
			if (installPath == null) {
216
				System.err.println(Messages.StartRserve_29);
217
				return false;
218
			}
219
			// System.out.println(" Found R in : "+installPath +
220
			// "\\bin\\R.exe");
221
			return launchRserve(installPath + "\\bin\\R.exe", port, debug, rargs, rServeArgs); //$NON-NLS-1$
222
		}
223

  
224
		Log.info(Messages.StartRserve_4);
225
		if (launchRserve("R", port, debug, rargs, rServeArgs)) return true; //$NON-NLS-1$
226

  
227
		// R not in the PATH env, try with R common paths
228
		String[] paths = {
229
				"/Library/Frameworks/R.framework/Resources/bin/R", //$NON-NLS-1$
230
				"/usr/local/lib/R/bin/R", //$NON-NLS-1$
231
				"/usr/lib/R/bin/R", //$NON-NLS-1$
232
				"/sw/bin/R", //$NON-NLS-1$
233
				"/usr/common/bin/R", //$NON-NLS-1$
234
		"/opt/bin/R" }; //$NON-NLS-1$
235
		for (String path : paths) {
236
			Log.info(Messages.StartRserve_6+path);
237
			if (new File(path).exists() && launchRserve(path, port, debug, rargs, rServeArgs)) return true;
238
		}
239

  
240
		return false;
241
		//			
242
		//		return (launchRserve("R", port, debug) //$NON-NLS-1$
243
		//				|| /* try some common unix locations of R */
244
		//				(( && launchRserve("/Library/Frameworks/R.framework/Resources/bin/R", port, debug)) //$NON-NLS-1$
245
		//				|| ((new File("/usr/local/lib/R/bin/R")).exists() && launchRserve("/usr/local/lib/R/bin/R")) //$NON-NLS-1$ //$NON-NLS-2$
246
		//				|| ((new File("/usr/lib/R/bin/R")).exists() && launchRserve("/usr/lib/R/bin/R")) //$NON-NLS-1$ //$NON-NLS-2$
247
		//				|| ((new File("/usr/local/bin/R")).exists() && launchRserve("/usr/local/bin/R")) //$NON-NLS-1$ //$NON-NLS-2$
248
		//				|| ((new File("/sw/bin/R")).exists() && launchRserve("/sw/bin/R")) //$NON-NLS-1$ //$NON-NLS-2$
249
		//				|| ((new File("/usr/common/bin/R")).exists() && launchRserve("/usr/common/bin/R")) || ((new File( //$NON-NLS-1$ //$NON-NLS-2$
250
		//				"/opt/bin/R")).exists() && launchRserve("/opt/bin/R"))); //$NON-NLS-1$ //$NON-NLS-2$
251
	}
252

  
253
	/**
254
	 * check whether Rserve is currently running (on local machine and default
255
	 * port).
256
	 * 
257
	 * @return <code>true</code> if local Rserve instance is running,
258
	 *         <code>false</code> otherwise
259
	 */
260
	protected static boolean isRserveRunning(int port) {
261
		try {
262
			new RConnection("127.0.0.1", port); //$NON-NLS-1$
263
			// System.out.println("Rserve is running.");
264
			// c.close();
265
			return true;
266
		} catch (Exception e) {
267
			// System.out.println("First connect try failed with: "+
268
			// e.getMessage());
269
		}
270
		return false;
271
	}
272

  
273

  
274
	public static void main(String[] args) {
275
		System.out.println("result=" + checkLocalRserve(8212, false, "", ""));
276
		try {
277
			System.out.println("Start RServe");
278
			RConnection c = new RConnection("localhost", 8212);
279
			System.out.println("Stop RServe");
280
			c.eval("print(1+1)");
281
			c.eval("2+2");
282
			c.shutdown();
283
			System.out.println("Done");
284
		} catch (Exception x) {
285
			x.printStackTrace();
286
		}
287
	}
288
}
0 289

  
tmp/org.txm.r.core/src/org/txm/stat/engine/r/RServeException.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2013-05-06 17:38:43 +0200 (Mon, 06 May 2013) $
25
// $LastChangedRevision: 2386 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.engine.r;
29

  
30
// TODO: Auto-generated Javadoc
31
/**
32
 * The Class RServeException.
33
 */
34
public class RServeException extends RException {
35

  
36
	/** The Constant serialVersionUID. */
37
	private static final long serialVersionUID = 1L;
38

  
39
	/**
40
	 * Instantiates a new r serve exception.
41
	 */
42
	public RServeException() {
43
		super();
44
		// TODO Auto-generated constructor stub
45
	}
46

  
47
	/**
48
	 * Instantiates a new r serve exception.
49
	 *
50
	 * @param arg0 the arg0
51
	 * @param arg1 the arg1
52
	 */
53
	public RServeException(String arg0, Throwable arg1) {
54
		super(arg0, arg1);
55
		// TODO Auto-generated constructor stub
56
	}
57

  
58
	/**
59
	 * Instantiates a new r serve exception.
60
	 *
61
	 * @param arg0 the arg0
62
	 */
63
	public RServeException(String arg0) {
64
		super(arg0);
65
		// TODO Auto-generated constructor stub
66
	}
67

  
68
	/**
69
	 * Instantiates a new r serve exception.
70
	 *
71
	 * @param arg0 the arg0
72
	 */
73
	public RServeException(Throwable arg0) {
74
		super(arg0);
75
		// TODO Auto-generated constructor stub
76
	}
77

  
78
}
0 79

  
tmp/org.txm.r.core/src/org/txm/stat/engine/r/RFileCommunication.java (revision 213)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate: 2015-05-22 09:06:15 +0200 (Fri, 22 May 2015) $
25
// $LastChangedRevision: 2973 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.stat.engine.r;
29

  
30
import java.io.BufferedWriter;
31
import java.io.File;
32
import java.io.FileWriter;
33
import java.io.IOException;
34

  
35
import org.eclipse.core.runtime.Platform;
36
import org.txm.utils.OSDetector;
37

  
38

  
39
// TODO: Auto-generated Javadoc
40
/**
41
 * The Class RFileCommunication.
42
 */
43
public class RFileCommunication {
44
	
45
	/** The transfertfile. */
46
	File transfertfile;
47
	
48
	/** The transfertfilepath. */
49
	String transfertfilepath;
50

  
51
	/**
52
	 * Instantiates a new r file communication.
53
	 *
54
	 * @throws IOException Signals that an I/O exception has occurred.
55
	 */
56
	public RFileCommunication() throws IOException
57
	{
58
		createTempFile();
59

  
60
	}
61

  
62
	/**
63
	 * Creates the temp file.
64
	 *
65
	 * @throws IOException Signals that an I/O exception has occurred.
66
	 */
67
	public void createTempFile() throws IOException
68
	{
69
		transfertfile = File.createTempFile("Rtransfert","file"); //$NON-NLS-1$ //$NON-NLS-2$
70
		//transfertfile = new File("~/Bureau/RTRANSFERT.txt");
71
		transfertfilepath = transfertfile.getAbsolutePath();
72
		if (OSDetector.isFamilyWindows()) //$NON-NLS-1$ //$NON-NLS-2$
73
		{
74
			//System.out.println("patch path");
75
			transfertfilepath = transfertfilepath.replace("\\", "\\\\"); //$NON-NLS-1$ //$NON-NLS-2$
76
		}
77
		//System.out.println("Transfert file: "+transfertfilepath);
78
	}
79

  
80
	/**
81
	 * Assign.
82
	 *
83
	 * @param variablename the variablename
84
	 * @param matrix the matrix
85
	 * @param nrow the nrow
86
	 * @param ncol the ncol
87
	 * @throws RWorkspaceException the r workspace exception
88
	 */
89
	public void assign(String variablename, int[] matrix, int nrow, int ncol) throws RWorkspaceException
90
	{
91
		writeVector(matrix);
92
		RWorkspace.getRWorkspaceInstance().eval("source(\""+transfertfilepath+"\");"); //$NON-NLS-1$ //$NON-NLS-2$
93
		RWorkspace.getRWorkspaceInstance().eval(variablename+" <- matrix(vectorint, nrow="+nrow+", ncol="+ncol+", byrow=T);"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
94
	}
95

  
96
	/**
97
	 * Assign.
98
	 *
99
	 * @param variablename the variablename
100
	 * @param matrix the matrix
101
	 * @param nrow the nrow
102
	 * @param ncol the ncol
103
	 * @throws RWorkspaceException the r workspace exception
104
	 */
105
	public void assign(String variablename, double[] matrix, int nrow, int ncol) throws RWorkspaceException
106
	{
107
		writeVector(matrix);
108
		RWorkspace.getRWorkspaceInstance().eval("source(\""+transfertfilepath+"\");"); //$NON-NLS-1$ //$NON-NLS-2$
109
		RWorkspace.getRWorkspaceInstance().eval(variablename+" <- matrix(vectordouble, nrow="+nrow+", ncol="+ncol+", byrow=T);"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
110
	}
111

  
112
	/**
113
	 * Assign.
114
	 *
115
	 * @param variablename the variablename
116
	 * @param vector the vector
117
	 * @throws RWorkspaceException the r workspace exception
118
	 */
119
	public void assign(String variablename, int[] vector) throws RWorkspaceException
120
	{
121
		//System.out.println("assign vector "+variablename+" size "+vector.length);
122
		writeVector(vector);
123
		RWorkspace.getRWorkspaceInstance().eval("source(\""+transfertfilepath+"\");"); //$NON-NLS-1$ //$NON-NLS-2$
124
		RWorkspace.getRWorkspaceInstance().eval(variablename+" <- vectorint;"); //$NON-NLS-1$
125
	}
126

  
127
	/**
128
	 * Assign.
129
	 *
130
	 * @param variablename the variablename
131
	 * @param vector the vector
132
	 * @throws RWorkspaceException the r workspace exception
133
	 */
134
	public void assign(String variablename, double[] vector) throws RWorkspaceException
135
	{
136
		//System.out.println("assign vector "+variablename+" size "+vector.length);
137
		writeVector(vector);
138
		RWorkspace.getRWorkspaceInstance().eval("source(\""+transfertfilepath+"\");"); //$NON-NLS-1$ //$NON-NLS-2$
139
		RWorkspace.getRWorkspaceInstance().eval(variablename+" <- vectordouble;"); //$NON-NLS-1$
140
		
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff