001    /*
002     * Copyright (C) 2008-2010 by Holger Arndt
003     *
004     * This file is part of the Universal Java Matrix Package (UJMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * UJMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * UJMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with UJMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.ujmp.core.util;
025    
026    import org.ujmp.core.Matrix;
027    import org.ujmp.core.doublematrix.calculation.general.decomposition.Chol;
028    import org.ujmp.core.doublematrix.calculation.general.decomposition.Eig;
029    import org.ujmp.core.doublematrix.calculation.general.decomposition.Inv;
030    import org.ujmp.core.doublematrix.calculation.general.decomposition.InvSPD;
031    import org.ujmp.core.doublematrix.calculation.general.decomposition.LU;
032    import org.ujmp.core.doublematrix.calculation.general.decomposition.QR;
033    import org.ujmp.core.doublematrix.calculation.general.decomposition.SVD;
034    import org.ujmp.core.doublematrix.calculation.general.decomposition.Solve;
035    import org.ujmp.core.doublematrix.calculation.general.decomposition.SolveSPD;
036    
037    @SuppressWarnings("unchecked")
038    public abstract class DecompositionOps {
039    
040            public static SVD<Matrix> SVD_UJMP = org.ujmp.core.doublematrix.calculation.general.decomposition.SVD.INSTANCE;
041    
042            public static SVD<Matrix> SVD_EJML = null;
043    
044            public static SVD<Matrix> SVD_OJALGO = null;
045    
046            public static SVD<Matrix> SVD_MTJ = null;
047    
048            public static Inv<Matrix> INV_UJMP = org.ujmp.core.doublematrix.calculation.general.decomposition.Inv.INSTANCE;
049    
050            public static Inv<Matrix> INV_EJML = null;
051    
052            public static Inv<Matrix> INV_OJALGO = null;
053    
054            public static Inv<Matrix> INV_JBLAS = null;
055    
056            public static Inv<Matrix> INV_MTJ = null;
057    
058            public static InvSPD<Matrix> INVSPD_UJMP = org.ujmp.core.doublematrix.calculation.general.decomposition.InvSPD.INSTANCE;
059    
060            public static InvSPD<Matrix> INVSPD_EJML = null;
061    
062            public static InvSPD<Matrix> INVSPD_OJALGO = null;
063    
064            public static InvSPD<Matrix> INVSPD_JBLAS = null;
065    
066            public static InvSPD<Matrix> INVSPD_MTJ = null;
067    
068            public static InvSPD<Matrix> INVSPD_PARALLELCOLT = null;
069    
070            public static Solve<Matrix> SOLVE_UJMP = org.ujmp.core.doublematrix.calculation.general.decomposition.Solve.INSTANCE;
071    
072            public static Solve<Matrix> SOLVE_EJML = null;
073    
074            public static Solve<Matrix> SOLVE_OJALGO = null;
075    
076            public static Solve<Matrix> SOLVE_PARALLELCOLT = null;
077    
078            public static Solve<Matrix> SOLVE_MTJ = null;
079    
080            public static Solve<Matrix> SOLVE_JBLAS = null;
081    
082            public static SolveSPD<Matrix> SOLVESPD_UJMP = org.ujmp.core.doublematrix.calculation.general.decomposition.SolveSPD.INSTANCE;
083    
084            public static SolveSPD<Matrix> SOLVESPD_EJML = null;
085    
086            public static SolveSPD<Matrix> SOLVESPD_OJALGO = null;
087    
088            public static SolveSPD<Matrix> SOLVESPD_MTJ = null;
089    
090            public static SolveSPD<Matrix> SOLVESPD_JBLAS = null;
091    
092            public static LU<Matrix> LU_UJMP = org.ujmp.core.doublematrix.calculation.general.decomposition.LU.INSTANCE;
093    
094            public static LU<Matrix> LU_EJML = null;
095    
096            public static LU<Matrix> LU_OJALGO = null;
097    
098            public static LU<Matrix> LU_MTJ = null;
099    
100            public static LU<Matrix> LU_JBLAS = null;
101    
102            public static QR<Matrix> QR_UJMP = org.ujmp.core.doublematrix.calculation.general.decomposition.QR.INSTANCE;
103    
104            public static QR<Matrix> QR_EJML = null;
105    
106            public static QR<Matrix> QR_OJALGO = null;
107    
108            public static QR<Matrix> QR_MTJ = null;
109    
110            public static Chol<Matrix> CHOL_UJMP = org.ujmp.core.doublematrix.calculation.general.decomposition.Chol.INSTANCE;
111    
112            public static Chol<Matrix> CHOL_EJML = null;
113    
114            public static Chol<Matrix> CHOL_OJALGO = null;
115    
116            public static Chol<Matrix> CHOL_MTJ = null;
117    
118            public static Chol<Matrix> CHOL_JBLAS = null;
119    
120            public static Eig<Matrix> EIG_UJMP = org.ujmp.core.doublematrix.calculation.general.decomposition.Eig.INSTANCE;
121    
122            public static Eig<Matrix> EIG_EJML = null;
123    
124            public static Eig<Matrix> EIG_OJALGO = null;
125    
126            public static Eig<Matrix> EIG_MTJ = null;
127    
128            public static Eig<Matrix> EIG_JBLAS = null;
129    
130            static {
131                    init();
132            }
133    
134            public static void init() {
135                    initSVD();
136                    initInv();
137                    initInvSPD();
138                    initSolve();
139                    initSolveSPD();
140                    initLU();
141                    initQR();
142                    initChol();
143                    initEig();
144            }
145    
146            public static void initSVD() {
147                    try {
148                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ejml.Plugin").newInstance();
149                            if (p.isAvailable()) {
150                                    SVD_EJML = (SVD<Matrix>) Class.forName("org.ujmp.ejml.calculation.SVD")
151                                                    .newInstance();
152                            }
153                    } catch (Throwable t) {
154                    }
155                    try {
156                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ojalgo.Plugin")
157                                            .newInstance();
158                            if (p.isAvailable()) {
159                                    SVD_OJALGO = (SVD<Matrix>) Class.forName("org.ujmp.ojalgo.calculation.SVD")
160                                                    .newInstance();
161                            }
162                    } catch (Throwable t) {
163                    }
164                    try {
165                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.mtj.Plugin").newInstance();
166                            if (p.isAvailable()) {
167                                    SVD_MTJ = (SVD<Matrix>) Class.forName("org.ujmp.mtj.calculation.SVD").newInstance();
168                            }
169                    } catch (Throwable t) {
170                    }
171            }
172    
173            public static void initInv() {
174                    try {
175                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ejml.Plugin").newInstance();
176                            if (p.isAvailable()) {
177                                    INV_EJML = (Inv<Matrix>) Class.forName("org.ujmp.ejml.calculation.Inv")
178                                                    .newInstance();
179                            }
180                    } catch (Throwable t) {
181                    }
182                    try {
183                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ojalgo.Plugin")
184                                            .newInstance();
185                            if (p.isAvailable()) {
186                                    INV_OJALGO = (Inv<Matrix>) Class.forName("org.ujmp.ojalgo.calculation.Inv")
187                                                    .newInstance();
188                            }
189                    } catch (Throwable t) {
190                    }
191                    try {
192                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.jblas.Plugin")
193                                            .newInstance();
194                            if (p.isAvailable()) {
195                                    INV_JBLAS = (Inv<Matrix>) Class.forName("org.ujmp.jblas.calculation.Inv")
196                                                    .newInstance();
197                            }
198                    } catch (Throwable t) {
199                    }
200                    try {
201                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.mtj.Plugin").newInstance();
202                            if (p.isAvailable()) {
203                                    INV_MTJ = (Inv<Matrix>) Class.forName("org.ujmp.mtj.calculation.Inv").newInstance();
204                            }
205                    } catch (Throwable t) {
206                    }
207            }
208    
209            public static void initInvSPD() {
210                    try {
211                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ejml.Plugin").newInstance();
212                            if (p.isAvailable()) {
213                                    INVSPD_EJML = (InvSPD<Matrix>) Class.forName("org.ujmp.ejml.calculation.InvSPD")
214                                                    .newInstance();
215                            }
216                    } catch (Throwable t) {
217                    }
218                    try {
219                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ojalgo.Plugin")
220                                            .newInstance();
221                            if (p.isAvailable()) {
222                                    INVSPD_OJALGO = (InvSPD<Matrix>) Class
223                                                    .forName("org.ujmp.ojalgo.calculation.InvSPD").newInstance();
224                            }
225                    } catch (Throwable t) {
226                    }
227                    try {
228                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.jblas.Plugin")
229                                            .newInstance();
230                            if (p.isAvailable()) {
231                                    INVSPD_JBLAS = (InvSPD<Matrix>) Class.forName("org.ujmp.jblas.calculation.InvSPD")
232                                                    .newInstance();
233                            }
234                    } catch (Throwable t) {
235                    }
236                    try {
237                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.mtj.Plugin").newInstance();
238                            if (p.isAvailable()) {
239                                    INVSPD_MTJ = (InvSPD<Matrix>) Class.forName("org.ujmp.mtj.calculation.InvSPD")
240                                                    .newInstance();
241                            }
242                    } catch (Throwable t) {
243                    }
244                    try {
245                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.parallelcolt.Plugin")
246                                            .newInstance();
247                            if (p.isAvailable()) {
248                                    INVSPD_PARALLELCOLT = (InvSPD<Matrix>) Class.forName(
249                                                    "org.ujmp.parallelcolt.calculation.InvSPD").newInstance();
250                            }
251                    } catch (Throwable t) {
252                    }
253            }
254    
255            public static void initSolve() {
256                    try {
257                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ejml.Plugin").newInstance();
258                            if (p.isAvailable()) {
259                                    SOLVE_EJML = (Solve<Matrix>) Class.forName("org.ujmp.ejml.calculation.Solve")
260                                                    .newInstance();
261                            }
262                    } catch (Throwable t) {
263                    }
264                    try {
265                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ojalgo.Plugin")
266                                            .newInstance();
267                            if (p.isAvailable()) {
268                                    SOLVE_OJALGO = (Solve<Matrix>) Class.forName("org.ujmp.ojalgo.calculation.Solve")
269                                                    .newInstance();
270                            }
271                    } catch (Throwable t) {
272                    }
273                    try {
274                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.jblas.Plugin")
275                                            .newInstance();
276                            if (p.isAvailable()) {
277                                    SOLVE_JBLAS = (Solve<Matrix>) Class.forName("org.ujmp.jblas.calculation.Solve")
278                                                    .newInstance();
279                            }
280                    } catch (Throwable t) {
281                    }
282                    try {
283                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.mtj.Plugin").newInstance();
284                            if (p.isAvailable()) {
285                                    SOLVE_MTJ = (Solve<Matrix>) Class.forName("org.ujmp.mtj.calculation.Solve")
286                                                    .newInstance();
287                            }
288                    } catch (Throwable t) {
289                    }
290                    try {
291                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.parallelcolt.Plugin")
292                                            .newInstance();
293                            if (p.isAvailable()) {
294                                    SOLVE_PARALLELCOLT = (Solve<Matrix>) Class.forName(
295                                                    "org.ujmp.parallelcolt.calculation.Solve").newInstance();
296                            }
297                    } catch (Throwable t) {
298                    }
299            }
300    
301            public static void initSolveSPD() {
302                    try {
303                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ejml.Plugin").newInstance();
304                            if (p.isAvailable()) {
305                                    SOLVESPD_EJML = (SolveSPD<Matrix>) Class.forName(
306                                                    "org.ujmp.ejml.calculation.SolveSPD").newInstance();
307                            }
308                    } catch (Throwable t) {
309                    }
310                    try {
311                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ojalgo.Plugin")
312                                            .newInstance();
313                            if (p.isAvailable()) {
314                                    SOLVESPD_OJALGO = (SolveSPD<Matrix>) Class.forName(
315                                                    "org.ujmp.ojalgo.calculation.SolveSPD").newInstance();
316                            }
317                    } catch (Throwable t) {
318                    }
319                    try {
320                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.jblas.Plugin")
321                                            .newInstance();
322                            if (p.isAvailable()) {
323                                    SOLVESPD_JBLAS = (SolveSPD<Matrix>) Class.forName(
324                                                    "org.ujmp.jblas.calculation.SolveSPD").newInstance();
325                            }
326                    } catch (Throwable t) {
327                    }
328                    try {
329                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.mtj.Plugin").newInstance();
330                            if (p.isAvailable()) {
331                                    SOLVESPD_MTJ = (SolveSPD<Matrix>) Class
332                                                    .forName("org.ujmp.mtj.calculation.SolveSPD").newInstance();
333                            }
334                    } catch (Throwable t) {
335                    }
336            }
337    
338            public static void initLU() {
339                    try {
340                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ejml.Plugin").newInstance();
341                            if (p.isAvailable()) {
342                                    LU_EJML = (LU<Matrix>) Class.forName("org.ujmp.ejml.calculation.LU").newInstance();
343                            }
344                    } catch (Throwable t) {
345                    }
346                    try {
347                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ojalgo.Plugin")
348                                            .newInstance();
349                            if (p.isAvailable()) {
350                                    LU_OJALGO = (LU<Matrix>) Class.forName("org.ujmp.ojalgo.calculation.LU")
351                                                    .newInstance();
352                            }
353                    } catch (Throwable t) {
354                    }
355                    try {
356                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.mtj.Plugin").newInstance();
357                            if (p.isAvailable()) {
358                                    LU_MTJ = (LU<Matrix>) Class.forName("org.ujmp.mtj.calculation.LU").newInstance();
359                            }
360                    } catch (Throwable t) {
361                    }
362                    try {
363                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.jblas.Plugin")
364                                            .newInstance();
365                            if (p.isAvailable()) {
366                                    LU_JBLAS = (LU<Matrix>) Class.forName("org.ujmp.jblas.calculation.LU")
367                                                    .newInstance();
368                            }
369                    } catch (Throwable t) {
370                    }
371            }
372    
373            public static void initQR() {
374                    try {
375                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ejml.Plugin").newInstance();
376                            if (p.isAvailable()) {
377                                    QR_EJML = (QR<Matrix>) Class.forName("org.ujmp.ejml.calculation.QR").newInstance();
378                            }
379                    } catch (Throwable t) {
380                    }
381                    try {
382                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ojalgo.Plugin")
383                                            .newInstance();
384                            if (p.isAvailable()) {
385                                    QR_OJALGO = (QR<Matrix>) Class.forName("org.ujmp.ojalgo.calculation.QR")
386                                                    .newInstance();
387                            }
388                    } catch (Throwable t) {
389                    }
390                    try {
391                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.mtj.Plugin").newInstance();
392                            if (p.isAvailable()) {
393                                    QR_MTJ = (QR<Matrix>) Class.forName("org.ujmp.mtj.calculation.QR").newInstance();
394                            }
395                    } catch (Throwable t) {
396                    }
397            }
398    
399            public static void initChol() {
400                    try {
401                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ejml.Plugin").newInstance();
402                            if (p.isAvailable()) {
403                                    CHOL_EJML = (Chol<Matrix>) Class.forName("org.ujmp.ejml.calculation.Chol")
404                                                    .newInstance();
405                            }
406                    } catch (Throwable t) {
407                    }
408                    try {
409                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ojalgo.Plugin")
410                                            .newInstance();
411                            if (p.isAvailable()) {
412                                    CHOL_OJALGO = (Chol<Matrix>) Class.forName("org.ujmp.ojalgo.calculation.Chol")
413                                                    .newInstance();
414                            }
415                    } catch (Throwable t) {
416                    }
417                    try {
418                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.mtj.Plugin").newInstance();
419                            if (p.isAvailable()) {
420                                    CHOL_MTJ = (Chol<Matrix>) Class.forName("org.ujmp.mtj.calculation.Chol")
421                                                    .newInstance();
422                            }
423                    } catch (Throwable t) {
424                    }
425                    try {
426                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.jblas.Plugin")
427                                            .newInstance();
428                            if (p.isAvailable()) {
429                                    CHOL_JBLAS = (Chol<Matrix>) Class.forName("org.ujmp.jblas.calculation.Chol")
430                                                    .newInstance();
431                            }
432                    } catch (Throwable t) {
433                    }
434            }
435    
436            public static void initEig() {
437                    try {
438                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ejml.Plugin").newInstance();
439                            if (p.isAvailable()) {
440                                    EIG_EJML = (Eig<Matrix>) Class.forName("org.ujmp.ejml.calculation.Eig")
441                                                    .newInstance();
442                            }
443                    } catch (Throwable t) {
444                    }
445                    try {
446                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.ojalgo.Plugin")
447                                            .newInstance();
448                            if (p.isAvailable()) {
449                                    EIG_OJALGO = (Eig<Matrix>) Class.forName("org.ujmp.ojalgo.calculation.Eig")
450                                                    .newInstance();
451                            }
452                    } catch (Throwable t) {
453                    }
454                    try {
455                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.mtj.Plugin").newInstance();
456                            if (p.isAvailable()) {
457                                    EIG_MTJ = (Eig<Matrix>) Class.forName("org.ujmp.mtj.calculation.Eig").newInstance();
458                            }
459                    } catch (Throwable t) {
460                    }
461                    try {
462                            AbstractPlugin p = (AbstractPlugin) Class.forName("org.ujmp.jblas.Plugin")
463                                            .newInstance();
464                            if (p.isAvailable()) {
465                                    EIG_JBLAS = (Eig<Matrix>) Class.forName("org.ujmp.jblas.calculation.Eig")
466                                                    .newInstance();
467                            }
468                    } catch (Throwable t) {
469                    }
470            }
471    
472    }