001 // --- BEGIN LICENSE BLOCK ---
002 /*
003 * Copyright (c) 2009, Mikio L. Braun
004 * All rights reserved.
005 *
006 * Redistribution and use in source and binary forms, with or without
007 * modification, are permitted provided that the following conditions are
008 * met:
009 *
010 * * Redistributions of source code must retain the above copyright
011 * notice, this list of conditions and the following disclaimer.
012 *
013 * * Redistributions in binary form must reproduce the above
014 * copyright notice, this list of conditions and the following
015 * disclaimer in the documentation and/or other materials provided
016 * with the distribution.
017 *
018 * * Neither the name of the Technische Universit?t Berlin nor the
019 * names of its contributors may be used to endorse or promote
020 * products derived from this software without specific prior
021 * written permission.
022 *
023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
026 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
027 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
028 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
029 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
030 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
031 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
032 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
034 */
035 // --- END LICENSE BLOCK ---
036
037 package org.jblas;
038
039 /**
040 * Solving linear equations.
041 */
042 public class Solve {
043 /** Solves the linear equation A*X = B. */
044 public static DoubleMatrix solve(DoubleMatrix A, DoubleMatrix B) {
045 A.assertSquare();
046 DoubleMatrix X = B.dup();
047 int[] ipiv = new int[B.rows];
048 SimpleBlas.gesv(A.dup(), ipiv, X);
049 return X;
050 }
051
052 /** Solves the linear equation A*X = B for symmetric A. */
053 public static DoubleMatrix solveSymmetric(DoubleMatrix A, DoubleMatrix B) {
054 A.assertSquare();
055 DoubleMatrix X = B.dup();
056 int[] ipiv = new int[B.rows];
057 SimpleBlas.sysv('U', A.dup(), ipiv, X);
058 return X;
059 }
060
061
062 /** Solves the linear equation A*X = B for symmetric and positive definite A. */
063 public static DoubleMatrix solvePositive(DoubleMatrix A, DoubleMatrix B) {
064 A.assertSquare();
065 DoubleMatrix X = B.dup();
066 SimpleBlas.posv('U', A.dup(), X);
067 return X;
068 }
069
070 //BEGIN
071 // The code below has been automatically generated.
072 // DO NOT EDIT!
073 /** Solves the linear equation A*X = B. */
074 public static FloatMatrix solve(FloatMatrix A, FloatMatrix B) {
075 A.assertSquare();
076 FloatMatrix X = B.dup();
077 int[] ipiv = new int[B.rows];
078 SimpleBlas.gesv(A.dup(), ipiv, X);
079 return X;
080 }
081
082 /** Solves the linear equation A*X = B for symmetric A. */
083 public static FloatMatrix solveSymmetric(FloatMatrix A, FloatMatrix B) {
084 A.assertSquare();
085 FloatMatrix X = B.dup();
086 int[] ipiv = new int[B.rows];
087 SimpleBlas.sysv('U', A.dup(), ipiv, X);
088 return X;
089 }
090
091
092 /** Solves the linear equation A*X = B for symmetric and positive definite A. */
093 public static FloatMatrix solvePositive(FloatMatrix A, FloatMatrix B) {
094 A.assertSquare();
095 FloatMatrix X = B.dup();
096 SimpleBlas.posv('U', A.dup(), X);
097 return X;
098 }
099
100 //END
101 }