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.doublematrix.calculation.general.decomposition; 025 026 import org.ujmp.core.Matrix; 027 import org.ujmp.core.util.DecompositionOps; 028 import org.ujmp.core.util.UJMPSettings; 029 030 public interface SolveSymm<T> extends Solve<T> { 031 032 public static int SQUARETHRESHOLD = 100; 033 034 public T calc(T a, T b); 035 036 public static final SolveSymm<Matrix> MATRIX = new SolveSymm<Matrix>() { 037 038 public final Matrix calc(Matrix a, Matrix b) { 039 if (UJMPSettings.getNumberOfThreads() == 1) { 040 if (a.getRowCount() >= SQUARETHRESHOLD && a.getColumnCount() >= SQUARETHRESHOLD) { 041 return MATRIXSQUARELARGESINGLETHREADED.calc(a, b); 042 } else { 043 return MATRIXSQUARESMALLSINGLETHREADED.calc(a, b); 044 } 045 } else { 046 if (a.getRowCount() >= SQUARETHRESHOLD && a.getColumnCount() >= SQUARETHRESHOLD) { 047 return MATRIXSQUARELARGEMULTITHREADED.calc(a, b); 048 } else { 049 return MATRIXSQUARESMALLMULTITHREADED.calc(a, b); 050 } 051 } 052 } 053 }; 054 055 public static final SolveSymm<Matrix> INSTANCE = MATRIX; 056 057 public static final SolveSymm<Matrix> UJMPSQUARE = new SolveSymm<Matrix>() { 058 059 public final Matrix calc(Matrix a, Matrix b) { 060 return LU.INSTANCE.solve(a, b); 061 } 062 }; 063 064 public static final SolveSymm<Matrix> MATRIXSQUARESMALLSINGLETHREADED = UJMPSQUARE; 065 066 public static final SolveSymm<Matrix> MATRIXSQUARELARGESINGLETHREADED = new SolveSymm<Matrix>() { 067 public final Matrix calc(Matrix a, Matrix b) { 068 // no special implementation for symmetric matrices 069 Solve<Matrix> solve = null; 070 if (UJMPSettings.isUseJBlas()) { 071 solve = DecompositionOps.SOLVE_JBLAS; 072 } 073 if (solve == null && UJMPSettings.isUseOjalgo()) { 074 solve = DecompositionOps.SOLVE_OJALGO; 075 } 076 if (solve == null && UJMPSettings.isUseEJML()) { 077 solve = DecompositionOps.SOLVE_EJML; 078 } 079 if (solve == null && UJMPSettings.isUseMTJ()) { 080 solve = DecompositionOps.SOLVE_MTJ; 081 } 082 if (solve == null) { 083 solve = UJMPSQUARE; 084 } 085 return solve.calc(a, b); 086 } 087 }; 088 089 public static final SolveSymm<Matrix> MATRIXSQUARELARGEMULTITHREADED = new SolveSymm<Matrix>() { 090 public Matrix calc(Matrix a, Matrix b) { 091 // no special implementation for symmetric matrices 092 Solve<Matrix> solve = null; 093 if (UJMPSettings.isUseJBlas()) { 094 solve = DecompositionOps.SOLVE_JBLAS; 095 } 096 if (solve == null && UJMPSettings.isUseOjalgo()) { 097 solve = DecompositionOps.SOLVE_OJALGO; 098 } 099 if (solve == null && UJMPSettings.isUseEJML()) { 100 solve = DecompositionOps.SOLVE_EJML; 101 } 102 if (solve == null) { 103 solve = UJMPSQUARE; 104 } 105 return solve.calc(a, b); 106 } 107 }; 108 109 public static final SolveSymm<Matrix> MATRIXSQUARESMALLMULTITHREADED = UJMPSQUARE; 110 111 }