1 /*
2 Copyright � 1999 CERN - European Organization for Nuclear Research.
3 Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose
4 is hereby granted without fee, provided that the above copyright notice appear in all copies and
5 that both that copyright notice and this permission notice appear in supporting documentation.
6 CERN makes no representations about the suitability of this software for any purpose.
7 It is provided "as is" without expressed or implied warranty.
8 */
9 package cern.colt.matrix.doublealgo;
10
11 import cern.colt.matrix.DoubleMatrix1D;
12 import cern.colt.matrix.DoubleMatrix2D;
13 /**
14 Deprecated; Basic element-by-element transformations on {@link cern.colt.matrix.DoubleMatrix1D} and {@link cern.colt.matrix.DoubleMatrix2D}.
15 All transformations modify the first argument matrix to hold the result of the transformation.
16 Use idioms like <tt>result = mult(matrix.copy(),5)</tt> to leave source matrices unaffected.
17 <p>
18 If your favourite transformation is not provided by this class, consider using method <tt>assign</tt> in combination with prefabricated function objects of {@link cern.jet.math.Functions},
19 using idioms like
20 <table>
21 <td class="PRE">
22 <pre>
23 cern.jet.math.Functions F = cern.jet.math.Functions.functions; // alias
24 matrix.assign(F.square);
25 matrix.assign(F.sqrt);
26 matrix.assign(F.sin);
27 matrix.assign(F.log);
28 matrix.assign(F.log(b));
29 matrix.assign(otherMatrix, F.min);
30 matrix.assign(otherMatrix, F.max);
31 </pre>
32 </td>
33 </table>
34 Here are some <a href="../doc-files/functionObjects.html">other examples</a>.
35 <p>
36 Implementation: Performance optimized for medium to very large matrices.
37 In fact, there is now nomore a performance advantage in using this class; The assign (transform) methods directly defined on matrices are now just as fast.
38 Thus, this class will soon be removed altogether.
39
40 @deprecated
41 @author wolfgang.hoschek@cern.ch
42 @version 1.0, 09/24/99
43 */
44 public class Transform extends cern.colt.PersistentObject {
45 /**
46 * Little trick to allow for "aliasing", that is, renaming this class.
47 * Normally you would write
48 * <pre>
49 * Transform.mult(myMatrix,2);
50 * Transform.plus(myMatrix,5);
51 * </pre>
52 * Since this class has only static methods, but no instance methods
53 * you can also shorten the name "DoubleTransform" to a name that better suits you, for example "Trans".
54 * <pre>
55 * Transform T = Transform.transform; // kind of "alias"
56 * T.mult(myMatrix,2);
57 * T.plus(myMatrix,5);
58 * </pre>
59 */
60 public static final Transform transform = new Transform();
61
62 private static final cern.jet.math.Functions F = cern.jet.math.Functions.functions; // alias
63
64 /**
65 * Makes this class non instantiable, but still let's others inherit from it.
66 */
Transform()67 protected Transform() {}
68 /**
69 * <tt>A[i] = Math.abs(A[i])</tt>.
70 * @param A the matrix to modify.
71 * @return <tt>A</tt> (for convenience only).
72 */
abs(DoubleMatrix1D A)73 public static DoubleMatrix1D abs(DoubleMatrix1D A) {
74 return A.assign(F.abs);
75 }
76 /**
77 * <tt>A[row,col] = Math.abs(A[row,col])</tt>.
78 * @param A the matrix to modify.
79 * @return <tt>A</tt> (for convenience only).
80 */
abs(DoubleMatrix2D A)81 public static DoubleMatrix2D abs(DoubleMatrix2D A) {
82 return A.assign(F.abs);
83 }
84 /**
85 * <tt>A = A / s <=> A[i] = A[i] / s</tt>.
86 * @param A the matrix to modify.
87 * @param s the scalar; can have any value.
88 * @return <tt>A</tt> (for convenience only).
89 */
div(DoubleMatrix1D A, double s)90 public static DoubleMatrix1D div(DoubleMatrix1D A, double s) {
91 return A.assign(F.div(s));
92 }
93 /**
94 * <tt>A = A / B <=> A[i] = A[i] / B[i]</tt>.
95 * @param A the matrix to modify.
96 * @param B the matrix to stay unaffected.
97 * @return <tt>A</tt> (for convenience only).
98 */
div(DoubleMatrix1D A, DoubleMatrix1D B)99 public static DoubleMatrix1D div(DoubleMatrix1D A, DoubleMatrix1D B) {
100 return A.assign(B,F.div);
101 }
102 /**
103 * <tt>A = A / s <=> A[row,col] = A[row,col] / s</tt>.
104 * @param A the matrix to modify.
105 * @param s the scalar; can have any value.
106 * @return <tt>A</tt> (for convenience only).
107 */
div(DoubleMatrix2D A, double s)108 public static DoubleMatrix2D div(DoubleMatrix2D A, double s) {
109 return A.assign(F.div(s));
110 }
111 /**
112 * <tt>A = A / B <=> A[row,col] = A[row,col] / B[row,col]</tt>.
113 * @param A the matrix to modify.
114 * @param B the matrix to stay unaffected.
115 * @return <tt>A</tt> (for convenience only).
116 */
div(DoubleMatrix2D A, DoubleMatrix2D B)117 public static DoubleMatrix2D div(DoubleMatrix2D A, DoubleMatrix2D B) {
118 return A.assign(B,F.div);
119 }
120 /**
121 * <tt>A[row,col] = A[row,col] == s ? 1 : 0</tt>; ignores tolerance.
122 * @param A the matrix to modify.
123 * @param s the scalar; can have any value.
124 * @return <tt>A</tt> (for convenience only).
125 */
equals(DoubleMatrix2D A, double s)126 public static DoubleMatrix2D equals(DoubleMatrix2D A, double s) {
127 return A.assign(F.equals(s));
128 }
129 /**
130 * <tt>A[row,col] = A[row,col] == B[row,col] ? 1 : 0</tt>; ignores tolerance.
131 * @param A the matrix to modify.
132 * @param B the matrix to stay unaffected.
133 * @return <tt>A</tt> (for convenience only).
134 */
equals(DoubleMatrix2D A, DoubleMatrix2D B)135 public static DoubleMatrix2D equals(DoubleMatrix2D A, DoubleMatrix2D B) {
136 return A.assign(B,F.equals);
137 }
138 /**
139 * <tt>A[row,col] = A[row,col] > s ? 1 : 0</tt>.
140 * @param A the matrix to modify.
141 * @param s the scalar; can have any value.
142 * @return <tt>A</tt> (for convenience only).
143 */
greater(DoubleMatrix2D A, double s)144 public static DoubleMatrix2D greater(DoubleMatrix2D A, double s) {
145 return A.assign(F.greater(s));
146 }
147 /**
148 * <tt>A[row,col] = A[row,col] > B[row,col] ? 1 : 0</tt>.
149 * @param A the matrix to modify.
150 * @param B the matrix to stay unaffected.
151 * @return <tt>A</tt> (for convenience only).
152 */
greater(DoubleMatrix2D A, DoubleMatrix2D B)153 public static DoubleMatrix2D greater(DoubleMatrix2D A, DoubleMatrix2D B) {
154 return A.assign(B,F.greater);
155 }
156 /**
157 * <tt>A[row,col] = A[row,col] < s ? 1 : 0</tt>.
158 * @param A the matrix to modify.
159 * @param s the scalar; can have any value.
160 * @return <tt>A</tt> (for convenience only).
161 */
less(DoubleMatrix2D A, double s)162 public static DoubleMatrix2D less(DoubleMatrix2D A, double s) {
163 return A.assign(F.less(s));
164 }
165 /**
166 * <tt>A[row,col] = A[row,col] < B[row,col] ? 1 : 0</tt>.
167 * @param A the matrix to modify.
168 * @param B the matrix to stay unaffected.
169 * @return <tt>A</tt> (for convenience only).
170 */
less(DoubleMatrix2D A, DoubleMatrix2D B)171 public static DoubleMatrix2D less(DoubleMatrix2D A, DoubleMatrix2D B) {
172 return A.assign(B,F.less);
173 }
174 /**
175 * <tt>A = A - s <=> A[i] = A[i] - s</tt>.
176 * @param A the matrix to modify.
177 * @param s the scalar; can have any value.
178 * @return <tt>A</tt> (for convenience only).
179 */
minus(DoubleMatrix1D A, double s)180 public static DoubleMatrix1D minus(DoubleMatrix1D A, double s) {
181 return A.assign(F.minus(s));
182 }
183 /**
184 * <tt>A = A - B <=> A[i] = A[i] - B[i]</tt>.
185 * @param A the matrix to modify.
186 * @param B the matrix to stay unaffected.
187 * @return <tt>A</tt> (for convenience only).
188 */
minus(DoubleMatrix1D A, DoubleMatrix1D B)189 public static DoubleMatrix1D minus(DoubleMatrix1D A, DoubleMatrix1D B) {
190 return A.assign(B,F.minus);
191 }
192 /**
193 * <tt>A = A - s <=> A[row,col] = A[row,col] - s</tt>.
194 * @param A the matrix to modify.
195 * @param s the scalar; can have any value.
196 * @return <tt>A</tt> (for convenience only).
197 */
minus(DoubleMatrix2D A, double s)198 public static DoubleMatrix2D minus(DoubleMatrix2D A, double s) {
199 return A.assign(F.minus(s));
200 }
201 /**
202 * <tt>A = A - B <=> A[row,col] = A[row,col] - B[row,col]</tt>.
203 * @param A the matrix to modify.
204 * @param B the matrix to stay unaffected.
205 * @return <tt>A</tt> (for convenience only).
206 */
minus(DoubleMatrix2D A, DoubleMatrix2D B)207 public static DoubleMatrix2D minus(DoubleMatrix2D A, DoubleMatrix2D B) {
208 return A.assign(B,F.minus);
209 }
210 /**
211 * <tt>A = A - B*s <=> A[i] = A[i] - B[i]*s</tt>.
212 * @param A the matrix to modify.
213 * @param B the matrix to stay unaffected.
214 * @param s the scalar; can have any value.
215 * @return <tt>A</tt> (for convenience only).
216 */
minusMult(DoubleMatrix1D A, DoubleMatrix1D B, double s)217 public static DoubleMatrix1D minusMult(DoubleMatrix1D A, DoubleMatrix1D B, double s) {
218 return A.assign(B,F.minusMult(s));
219 }
220 /**
221 * <tt>A = A - B*s <=> A[row,col] = A[row,col] - B[row,col]*s</tt>.
222 * @param A the matrix to modify.
223 * @param B the matrix to stay unaffected.
224 * @param s the scalar; can have any value.
225 * @return <tt>A</tt> (for convenience only).
226 */
minusMult(DoubleMatrix2D A, DoubleMatrix2D B, double s)227 public static DoubleMatrix2D minusMult(DoubleMatrix2D A, DoubleMatrix2D B, double s) {
228 return A.assign(B,F.minusMult(s));
229 }
230 /**
231 * <tt>A = A * s <=> A[i] = A[i] * s</tt>.
232 * @param A the matrix to modify.
233 * @param s the scalar; can have any value.
234 * @return <tt>A</tt> (for convenience only).
235 */
mult(DoubleMatrix1D A, double s)236 public static DoubleMatrix1D mult(DoubleMatrix1D A, double s) {
237 return A.assign(F.mult(s));
238 }
239 /**
240 * <tt>A = A * B <=> A[i] = A[i] * B[i]</tt>.
241 * @param A the matrix to modify.
242 * @param B the matrix to stay unaffected.
243 * @return <tt>A</tt> (for convenience only).
244 */
mult(DoubleMatrix1D A, DoubleMatrix1D B)245 public static DoubleMatrix1D mult(DoubleMatrix1D A, DoubleMatrix1D B) {
246 return A.assign(B,F.mult);
247 }
248 /**
249 * <tt>A = A * s <=> A[row,col] = A[row,col] * s</tt>.
250 * @param A the matrix to modify.
251 * @param s the scalar; can have any value.
252 * @return <tt>A</tt> (for convenience only).
253 */
mult(DoubleMatrix2D A, double s)254 public static DoubleMatrix2D mult(DoubleMatrix2D A, double s) {
255 return A.assign(F.mult(s));
256 }
257 /**
258 * <tt>A = A * B <=> A[row,col] = A[row,col] * B[row,col]</tt>.
259 * @param A the matrix to modify.
260 * @param B the matrix to stay unaffected.
261 * @return <tt>A</tt> (for convenience only).
262 */
mult(DoubleMatrix2D A, DoubleMatrix2D B)263 public static DoubleMatrix2D mult(DoubleMatrix2D A, DoubleMatrix2D B) {
264 return A.assign(B,F.mult);
265 }
266 /**
267 * <tt>A = -A <=> A[i] = -A[i]</tt> for all cells.
268 * @return <tt>A</tt> (for convenience only).
269 */
negate(DoubleMatrix1D A)270 public static DoubleMatrix1D negate(DoubleMatrix1D A) {
271 return A.assign(F.mult(-1));
272 }
273 /**
274 * <tt>A = -A <=> A[row,col] = -A[row,col]</tt>.
275 * @return <tt>A</tt> (for convenience only).
276 */
negate(DoubleMatrix2D A)277 public static DoubleMatrix2D negate(DoubleMatrix2D A) {
278 return A.assign(F.mult(-1));
279 }
280 /**
281 * <tt>A = A + s <=> A[i] = A[i] + s</tt>.
282 * @param A the matrix to modify.
283 * @param s the scalar; can have any value.
284 * @return <tt>A</tt> (for convenience only).
285 */
plus(DoubleMatrix1D A, double s)286 public static DoubleMatrix1D plus(DoubleMatrix1D A, double s) {
287 return A.assign(F.plus(s));
288 }
289 /**
290 * <tt>A = A + B <=> A[i] = A[i] + B[i]</tt>.
291 * @param A the matrix to modify.
292 * @param B the matrix to stay unaffected.
293 * @return <tt>A</tt> (for convenience only).
294 */
plus(DoubleMatrix1D A, DoubleMatrix1D B)295 public static DoubleMatrix1D plus(DoubleMatrix1D A, DoubleMatrix1D B) {
296 return A.assign(B,F.plus);
297 }
298 /**
299 * <tt>A = A + s <=> A[row,col] = A[row,col] + s</tt>.
300 * @param A the matrix to modify.
301 * @param s the scalar; can have any value.
302 * @return <tt>A</tt> (for convenience only).
303 */
plus(DoubleMatrix2D A, double s)304 public static DoubleMatrix2D plus(DoubleMatrix2D A, double s) {
305 return A.assign(F.plus(s));
306 }
307 /**
308 * <tt>A = A + B <=> A[row,col] = A[row,col] + B[row,col]</tt>.
309 * @param A the matrix to modify.
310 * @param B the matrix to stay unaffected.
311 * @return <tt>A</tt> (for convenience only).
312 */
plus(DoubleMatrix2D A, DoubleMatrix2D B)313 public static DoubleMatrix2D plus(DoubleMatrix2D A, DoubleMatrix2D B) {
314 return A.assign(B,F.plus);
315 }
316 /**
317 * <tt>A = A + B*s<=> A[i] = A[i] + B[i]*s</tt>.
318 * @param A the matrix to modify.
319 * @param B the matrix to stay unaffected.
320 * @param s the scalar; can have any value.
321 * @return <tt>A</tt> (for convenience only).
322 */
plusMult(DoubleMatrix1D A, DoubleMatrix1D B, double s)323 public static DoubleMatrix1D plusMult(DoubleMatrix1D A, DoubleMatrix1D B, double s) {
324 return A.assign(B,F.plusMult(s));
325 }
326 /**
327 * <tt>A = A + B*s <=> A[row,col] = A[row,col] + B[row,col]*s</tt>.
328 * @param A the matrix to modify.
329 * @param B the matrix to stay unaffected.
330 * @param s the scalar; can have any value.
331 * @return <tt>A</tt> (for convenience only).
332 */
plusMult(DoubleMatrix2D A, DoubleMatrix2D B, double s)333 public static DoubleMatrix2D plusMult(DoubleMatrix2D A, DoubleMatrix2D B, double s) {
334 return A.assign(B,F.plusMult(s));
335 }
336 /**
337 * <tt>A = A<sup>s</sup> <=> A[i] = Math.pow(A[i], s)</tt>.
338 * @param A the matrix to modify.
339 * @param s the scalar; can have any value.
340 * @return <tt>A</tt> (for convenience only).
341 */
pow(DoubleMatrix1D A, double s)342 public static DoubleMatrix1D pow(DoubleMatrix1D A, double s) {
343 return A.assign(F.pow(s));
344 }
345 /**
346 * <tt>A = A<sup>B</sup> <=> A[i] = Math.pow(A[i], B[i])</tt>.
347 * @param A the matrix to modify.
348 * @param B the matrix to stay unaffected.
349 * @return <tt>A</tt> (for convenience only).
350 */
pow(DoubleMatrix1D A, DoubleMatrix1D B)351 public static DoubleMatrix1D pow(DoubleMatrix1D A, DoubleMatrix1D B) {
352 return A.assign(B,F.pow);
353 }
354 /**
355 * <tt>A = A<sup>s</sup> <=> A[row,col] = Math.pow(A[row,col], s)</tt>.
356 * @param A the matrix to modify.
357 * @param s the scalar; can have any value.
358 * @return <tt>A</tt> (for convenience only).
359 */
pow(DoubleMatrix2D A, double s)360 public static DoubleMatrix2D pow(DoubleMatrix2D A, double s) {
361 return A.assign(F.pow(s));
362 }
363 /**
364 * <tt>A = A<sup>B</sup> <=> A[row,col] = Math.pow(A[row,col], B[row,col])</tt>.
365 * @param A the matrix to modify.
366 * @param B the matrix to stay unaffected.
367 * @return <tt>A</tt> (for convenience only).
368 */
pow(DoubleMatrix2D A, DoubleMatrix2D B)369 public static DoubleMatrix2D pow(DoubleMatrix2D A, DoubleMatrix2D B) {
370 return A.assign(B,F.pow);
371 }
372 }
373