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 --- 036package org.jblas; 037 038import org.jblas.util.Logger; 039 040/** 041 * Native BLAS and LAPACK functions. 042 * 043 * <p>The NativeBlas class contains the native BLAS and LAPACK functions. Each 044 * Fortran function is mapped to a static method of this class. For each array argument, 045 * an additional parameter is introduced which gives the offset from the beginning of 046 * the passed array. In C, you would be able to pass a different pointer, but 047 * in Java, you can only pass the whole array.</p> 048 * 049 * <p>Note that due to the way the JNI is usually implemented, the arrays are first 050 * copied outside of the JVM before the function is called. This means that 051 * functions whose runtime is linear in the amount of memory do usually not 052 * run faster just because you are using a native implementation. This holds true 053 * for most Level 1 BLAS routines (like vector addition), and unfortunately also 054 * for most Level 2 BLAS routines (like matrix-vector multiplication). For these, 055 * there exists a class JavaBlas which contains Java implementations.</p> 056 * 057 * <p>In LAPACK, there exist routines which require workspace to be allocated together 058 * with a standard procedure for computing the size of these workspaces. jblas 059 * automatically also generates wrappers for these routines with automatic 060 * workspace allocation. These routines have the same name, but the workspace 061 * arguments are removed.</p> 062 * 063 * <p>Finally, an example: The fortran routine<pre> 064 * SUBROUTINE DAXPY(N,DA,DX,INCX,DY,INCY) 065 * DOUBLE PRECISION DA 066 * INTEGER INCX,INCY,N 067 * DOUBLE PRECISION DX(*),DY(*) 068 * </pre> 069 * becomes <pre> 070 * public static native void daxpy(int n, double da, double[] dx, int dxIdx, 071 * int incx, double[] dy, int dyIdx, int incy); 072 * </pre> 073 */ 074public class NativeBlas { 075 076 static { 077 NativeBlasLibraryLoader.loadLibraryAndCheckErrors(); 078 } 079 080 private static int[] intDummy = new int[1]; 081 private static double[] doubleDummy = new double[1]; 082 private static float[] floatDummy = new float[1]; 083 084 public static native void ccopy(int n, float[] cx, int cxIdx, int incx, float[] cy, int cyIdx, int incy); 085 public static native void dcopy(int n, double[] dx, int dxIdx, int incx, double[] dy, int dyIdx, int incy); 086 public static native void scopy(int n, float[] sx, int sxIdx, int incx, float[] sy, int syIdx, int incy); 087 public static native void zcopy(int n, double[] zx, int zxIdx, int incx, double[] zy, int zyIdx, int incy); 088 public static native void cswap(int n, float[] cx, int cxIdx, int incx, float[] cy, int cyIdx, int incy); 089 public static native void dswap(int n, double[] dx, int dxIdx, int incx, double[] dy, int dyIdx, int incy); 090 public static native void sswap(int n, float[] sx, int sxIdx, int incx, float[] sy, int syIdx, int incy); 091 public static native void zswap(int n, double[] zx, int zxIdx, int incx, double[] zy, int zyIdx, int incy); 092 public static native void caxpy(int n, ComplexFloat ca, float[] cx, int cxIdx, int incx, float[] cy, int cyIdx, int incy); 093 public static native void daxpy(int n, double da, double[] dx, int dxIdx, int incx, double[] dy, int dyIdx, int incy); 094 public static native void saxpy(int n, float sa, float[] sx, int sxIdx, int incx, float[] sy, int syIdx, int incy); 095 public static native void zaxpy(int n, ComplexDouble za, double[] zx, int zxIdx, int incx, double[] zy, int zyIdx, int incy); 096 public static native void cscal(int n, ComplexFloat ca, float[] cx, int cxIdx, int incx); 097 public static native void dscal(int n, double da, double[] dx, int dxIdx, int incx); 098 public static native void sscal(int n, float sa, float[] sx, int sxIdx, int incx); 099 public static native void zscal(int n, ComplexDouble za, double[] zx, int zxIdx, int incx); 100 public static native void csscal(int n, float sa, float[] cx, int cxIdx, int incx); 101 public static native void zdscal(int n, double da, double[] zx, int zxIdx, int incx); 102 public static native ComplexFloat cdotc(int n, float[] cx, int cxIdx, int incx, float[] cy, int cyIdx, int incy); 103 public static native ComplexFloat cdotu(int n, float[] cx, int cxIdx, int incx, float[] cy, int cyIdx, int incy); 104 public static native double ddot(int n, double[] dx, int dxIdx, int incx, double[] dy, int dyIdx, int incy); 105 public static native float sdot(int n, float[] sx, int sxIdx, int incx, float[] sy, int syIdx, int incy); 106 public static native ComplexDouble zdotc(int n, double[] zx, int zxIdx, int incx, double[] zy, int zyIdx, int incy); 107 public static native ComplexDouble zdotu(int n, double[] zx, int zxIdx, int incx, double[] zy, int zyIdx, int incy); 108 public static native double dnrm2(int n, double[] x, int xIdx, int incx); 109 public static native double dznrm2(int n, double[] x, int xIdx, int incx); 110 public static native float scnrm2(int n, float[] x, int xIdx, int incx); 111 public static native float snrm2(int n, float[] x, int xIdx, int incx); 112 public static native double dasum(int n, double[] dx, int dxIdx, int incx); 113 public static native double dzasum(int n, double[] zx, int zxIdx, int incx); 114 public static native float sasum(int n, float[] sx, int sxIdx, int incx); 115 public static native float scasum(int n, float[] cx, int cxIdx, int incx); 116 public static native int icamax(int n, float[] cx, int cxIdx, int incx); 117 public static native int idamax(int n, double[] dx, int dxIdx, int incx); 118 public static native int isamax(int n, float[] sx, int sxIdx, int incx); 119 public static native int izamax(int n, double[] zx, int zxIdx, int incx); 120 public static native void cgemv(char trans, int m, int n, ComplexFloat alpha, float[] a, int aIdx, int lda, float[] x, int xIdx, int incx, ComplexFloat beta, float[] y, int yIdx, int incy); 121 public static native void dgemv(char trans, int m, int n, double alpha, double[] a, int aIdx, int lda, double[] x, int xIdx, int incx, double beta, double[] y, int yIdx, int incy); 122 public static native void sgemv(char trans, int m, int n, float alpha, float[] a, int aIdx, int lda, float[] x, int xIdx, int incx, float beta, float[] y, int yIdx, int incy); 123 public static native void zgemv(char trans, int m, int n, ComplexDouble alpha, double[] a, int aIdx, int lda, double[] x, int xIdx, int incx, ComplexDouble beta, double[] y, int yIdx, int incy); 124 public static native void cgerc(int m, int n, ComplexFloat alpha, float[] x, int xIdx, int incx, float[] y, int yIdx, int incy, float[] a, int aIdx, int lda); 125 public static native void cgeru(int m, int n, ComplexFloat alpha, float[] x, int xIdx, int incx, float[] y, int yIdx, int incy, float[] a, int aIdx, int lda); 126 public static native void dger(int m, int n, double alpha, double[] x, int xIdx, int incx, double[] y, int yIdx, int incy, double[] a, int aIdx, int lda); 127 public static native void sger(int m, int n, float alpha, float[] x, int xIdx, int incx, float[] y, int yIdx, int incy, float[] a, int aIdx, int lda); 128 public static native void zgerc(int m, int n, ComplexDouble alpha, double[] x, int xIdx, int incx, double[] y, int yIdx, int incy, double[] a, int aIdx, int lda); 129 public static native void zgeru(int m, int n, ComplexDouble alpha, double[] x, int xIdx, int incx, double[] y, int yIdx, int incy, double[] a, int aIdx, int lda); 130 public static native void cgemm(char transa, char transb, int m, int n, int k, ComplexFloat alpha, float[] a, int aIdx, int lda, float[] b, int bIdx, int ldb, ComplexFloat beta, float[] c, int cIdx, int ldc); 131 public static native void dgemm(char transa, char transb, int m, int n, int k, double alpha, double[] a, int aIdx, int lda, double[] b, int bIdx, int ldb, double beta, double[] c, int cIdx, int ldc); 132 public static native void sgemm(char transa, char transb, int m, int n, int k, float alpha, float[] a, int aIdx, int lda, float[] b, int bIdx, int ldb, float beta, float[] c, int cIdx, int ldc); 133 public static native void zgemm(char transa, char transb, int m, int n, int k, ComplexDouble alpha, double[] a, int aIdx, int lda, double[] b, int bIdx, int ldb, ComplexDouble beta, double[] c, int cIdx, int ldc); 134 public static native int dgesv(int n, int nrhs, double[] a, int aIdx, int lda, int[] ipiv, int ipivIdx, double[] b, int bIdx, int ldb); 135 public static native int sgesv(int n, int nrhs, float[] a, int aIdx, int lda, int[] ipiv, int ipivIdx, float[] b, int bIdx, int ldb); 136 public static native int dsysv(char uplo, int n, int nrhs, double[] a, int aIdx, int lda, int[] ipiv, int ipivIdx, double[] b, int bIdx, int ldb, double[] work, int workIdx, int lwork); 137 public static int dsysv(char uplo, int n, int nrhs, double[] a, int aIdx, int lda, int[] ipiv, int ipivIdx, double[] b, int bIdx, int ldb) { 138 int info; 139 double[] work = new double[1]; 140 int lwork; 141 info = dsysv(uplo, n, nrhs, doubleDummy, 0, lda, intDummy, 0, doubleDummy, 0, ldb, work, 0, -1); 142 if (info != 0) 143 return info; 144 lwork = (int) work[0]; work = new double[lwork]; 145 info = dsysv(uplo, n, nrhs, a, aIdx, lda, ipiv, ipivIdx, b, bIdx, ldb, work, 0, lwork); 146 return info; 147 } 148 149 public static native int ssysv(char uplo, int n, int nrhs, float[] a, int aIdx, int lda, int[] ipiv, int ipivIdx, float[] b, int bIdx, int ldb, float[] work, int workIdx, int lwork); 150 public static int ssysv(char uplo, int n, int nrhs, float[] a, int aIdx, int lda, int[] ipiv, int ipivIdx, float[] b, int bIdx, int ldb) { 151 int info; 152 float[] work = new float[1]; 153 int lwork; 154 info = ssysv(uplo, n, nrhs, floatDummy, 0, lda, intDummy, 0, floatDummy, 0, ldb, work, 0, -1); 155 if (info != 0) 156 return info; 157 lwork = (int) work[0]; work = new float[lwork]; 158 info = ssysv(uplo, n, nrhs, a, aIdx, lda, ipiv, ipivIdx, b, bIdx, ldb, work, 0, lwork); 159 return info; 160 } 161 162 public static native int dsyev(char jobz, char uplo, int n, double[] a, int aIdx, int lda, double[] w, int wIdx, double[] work, int workIdx, int lwork); 163 public static int dsyev(char jobz, char uplo, int n, double[] a, int aIdx, int lda, double[] w, int wIdx) { 164 int info; 165 double[] work = new double[1]; 166 int lwork; 167 info = dsyev(jobz, uplo, n, doubleDummy, 0, lda, doubleDummy, 0, work, 0, -1); 168 if (info != 0) 169 return info; 170 lwork = (int) work[0]; work = new double[lwork]; 171 info = dsyev(jobz, uplo, n, a, aIdx, lda, w, wIdx, work, 0, lwork); 172 return info; 173 } 174 175 public static native int ssyev(char jobz, char uplo, int n, float[] a, int aIdx, int lda, float[] w, int wIdx, float[] work, int workIdx, int lwork); 176 public static int ssyev(char jobz, char uplo, int n, float[] a, int aIdx, int lda, float[] w, int wIdx) { 177 int info; 178 float[] work = new float[1]; 179 int lwork; 180 info = ssyev(jobz, uplo, n, floatDummy, 0, lda, floatDummy, 0, work, 0, -1); 181 if (info != 0) 182 return info; 183 lwork = (int) work[0]; work = new float[lwork]; 184 info = ssyev(jobz, uplo, n, a, aIdx, lda, w, wIdx, work, 0, lwork); 185 return info; 186 } 187 188 public static native int dsyevd(char jobz, char uplo, int n, double[] a, int aIdx, int lda, double[] w, int wIdx, double[] work, int workIdx, int lwork, int[] iwork, int iworkIdx, int liwork); 189 public static int dsyevd(char jobz, char uplo, int n, double[] a, int aIdx, int lda, double[] w, int wIdx) { 190 int info; 191 double[] work = new double[1]; 192 int lwork; 193 int[] iwork = new int[1]; 194 int liwork; 195 info = dsyevd(jobz, uplo, n, doubleDummy, 0, lda, doubleDummy, 0, work, 0, -1, iwork, 0, -1); 196 if (info != 0) 197 return info; 198 lwork = (int) work[0]; work = new double[lwork]; 199 liwork = (int) iwork[0]; iwork = new int[liwork]; 200 info = dsyevd(jobz, uplo, n, a, aIdx, lda, w, wIdx, work, 0, lwork, iwork, 0, liwork); 201 return info; 202 } 203 204 public static native int dsyevr(char jobz, char range, char uplo, int n, double[] a, int aIdx, int lda, double vl, double vu, int il, int iu, double abstol, int[] m, int mIdx, double[] w, int wIdx, double[] z, int zIdx, int ldz, int[] isuppz, int isuppzIdx, double[] work, int workIdx, int lwork, int[] iwork, int iworkIdx, int liwork); 205 public static int dsyevr(char jobz, char range, char uplo, int n, double[] a, int aIdx, int lda, double vl, double vu, int il, int iu, double abstol, int[] m, int mIdx, double[] w, int wIdx, double[] z, int zIdx, int ldz, int[] isuppz, int isuppzIdx) { 206 int info; 207 double[] work = new double[1]; 208 int lwork; 209 int[] iwork = new int[1]; 210 int liwork; 211 info = dsyevr(jobz, range, uplo, n, doubleDummy, 0, lda, vl, vu, il, iu, abstol, intDummy, 0, doubleDummy, 0, doubleDummy, 0, ldz, intDummy, 0, work, 0, -1, iwork, 0, -1); 212 if (info != 0) 213 return info; 214 lwork = (int) work[0]; work = new double[lwork]; 215 liwork = (int) iwork[0]; iwork = new int[liwork]; 216 info = dsyevr(jobz, range, uplo, n, a, aIdx, lda, vl, vu, il, iu, abstol, m, mIdx, w, wIdx, z, zIdx, ldz, isuppz, isuppzIdx, work, 0, lwork, iwork, 0, liwork); 217 return info; 218 } 219 220 public static native int dsyevx(char jobz, char range, char uplo, int n, double[] a, int aIdx, int lda, double vl, double vu, int il, int iu, double abstol, int[] m, int mIdx, double[] w, int wIdx, double[] z, int zIdx, int ldz, double[] work, int workIdx, int lwork, int[] iwork, int iworkIdx, int[] ifail, int ifailIdx); 221 public static int dsyevx(char jobz, char range, char uplo, int n, double[] a, int aIdx, int lda, double vl, double vu, int il, int iu, double abstol, int[] m, int mIdx, double[] w, int wIdx, double[] z, int zIdx, int ldz, int[] iwork, int iworkIdx, int[] ifail, int ifailIdx) { 222 int info; 223 double[] work = new double[1]; 224 int lwork; 225 info = dsyevx(jobz, range, uplo, n, doubleDummy, 0, lda, vl, vu, il, iu, abstol, intDummy, 0, doubleDummy, 0, doubleDummy, 0, ldz, work, 0, -1, intDummy, 0, intDummy, 0); 226 if (info != 0) 227 return info; 228 lwork = (int) work[0]; work = new double[lwork]; 229 info = dsyevx(jobz, range, uplo, n, a, aIdx, lda, vl, vu, il, iu, abstol, m, mIdx, w, wIdx, z, zIdx, ldz, work, 0, lwork, iwork, iworkIdx, ifail, ifailIdx); 230 return info; 231 } 232 233 public static native int ssyevd(char jobz, char uplo, int n, float[] a, int aIdx, int lda, float[] w, int wIdx, float[] work, int workIdx, int lwork, int[] iwork, int iworkIdx, int liwork); 234 public static int ssyevd(char jobz, char uplo, int n, float[] a, int aIdx, int lda, float[] w, int wIdx) { 235 int info; 236 float[] work = new float[1]; 237 int lwork; 238 int[] iwork = new int[1]; 239 int liwork; 240 info = ssyevd(jobz, uplo, n, floatDummy, 0, lda, floatDummy, 0, work, 0, -1, iwork, 0, -1); 241 if (info != 0) 242 return info; 243 lwork = (int) work[0]; work = new float[lwork]; 244 liwork = (int) iwork[0]; iwork = new int[liwork]; 245 info = ssyevd(jobz, uplo, n, a, aIdx, lda, w, wIdx, work, 0, lwork, iwork, 0, liwork); 246 return info; 247 } 248 249 public static native int ssyevr(char jobz, char range, char uplo, int n, float[] a, int aIdx, int lda, float vl, float vu, int il, int iu, float abstol, int[] m, int mIdx, float[] w, int wIdx, float[] z, int zIdx, int ldz, int[] isuppz, int isuppzIdx, float[] work, int workIdx, int lwork, int[] iwork, int iworkIdx, int liwork); 250 public static int ssyevr(char jobz, char range, char uplo, int n, float[] a, int aIdx, int lda, float vl, float vu, int il, int iu, float abstol, int[] m, int mIdx, float[] w, int wIdx, float[] z, int zIdx, int ldz, int[] isuppz, int isuppzIdx) { 251 int info; 252 float[] work = new float[1]; 253 int lwork; 254 int[] iwork = new int[1]; 255 int liwork; 256 info = ssyevr(jobz, range, uplo, n, floatDummy, 0, lda, vl, vu, il, iu, abstol, intDummy, 0, floatDummy, 0, floatDummy, 0, ldz, intDummy, 0, work, 0, -1, iwork, 0, -1); 257 if (info != 0) 258 return info; 259 lwork = (int) work[0]; work = new float[lwork]; 260 liwork = (int) iwork[0]; iwork = new int[liwork]; 261 info = ssyevr(jobz, range, uplo, n, a, aIdx, lda, vl, vu, il, iu, abstol, m, mIdx, w, wIdx, z, zIdx, ldz, isuppz, isuppzIdx, work, 0, lwork, iwork, 0, liwork); 262 return info; 263 } 264 265 public static native int ssyevx(char jobz, char range, char uplo, int n, float[] a, int aIdx, int lda, float vl, float vu, int il, int iu, float abstol, int[] m, int mIdx, float[] w, int wIdx, float[] z, int zIdx, int ldz, float[] work, int workIdx, int lwork, int[] iwork, int iworkIdx, int[] ifail, int ifailIdx); 266 public static int ssyevx(char jobz, char range, char uplo, int n, float[] a, int aIdx, int lda, float vl, float vu, int il, int iu, float abstol, int[] m, int mIdx, float[] w, int wIdx, float[] z, int zIdx, int ldz, int[] iwork, int iworkIdx, int[] ifail, int ifailIdx) { 267 int info; 268 float[] work = new float[1]; 269 int lwork; 270 info = ssyevx(jobz, range, uplo, n, floatDummy, 0, lda, vl, vu, il, iu, abstol, intDummy, 0, floatDummy, 0, floatDummy, 0, ldz, work, 0, -1, intDummy, 0, intDummy, 0); 271 if (info != 0) 272 return info; 273 lwork = (int) work[0]; work = new float[lwork]; 274 info = ssyevx(jobz, range, uplo, n, a, aIdx, lda, vl, vu, il, iu, abstol, m, mIdx, w, wIdx, z, zIdx, ldz, work, 0, lwork, iwork, iworkIdx, ifail, ifailIdx); 275 return info; 276 } 277 278 public static native int dposv(char uplo, int n, int nrhs, double[] a, int aIdx, int lda, double[] b, int bIdx, int ldb); 279 public static native int sposv(char uplo, int n, int nrhs, float[] a, int aIdx, int lda, float[] b, int bIdx, int ldb); 280 public static native int cgeev(char jobvl, char jobvr, int n, float[] a, int aIdx, int lda, float[] w, int wIdx, float[] vl, int vlIdx, int ldvl, float[] vr, int vrIdx, int ldvr, float[] work, int workIdx, int lwork, float[] rwork, int rworkIdx); 281 public static int cgeev(char jobvl, char jobvr, int n, float[] a, int aIdx, int lda, float[] w, int wIdx, float[] vl, int vlIdx, int ldvl, float[] vr, int vrIdx, int ldvr, float[] rwork, int rworkIdx) { 282 int info; 283 float[] work = new float[1*2]; 284 int lwork; 285 info = cgeev(jobvl, jobvr, n, floatDummy, 0, lda, floatDummy, 0, floatDummy, 0, ldvl, floatDummy, 0, ldvr, work, 0, -1, floatDummy, 0); 286 if (info != 0) 287 return info; 288 lwork = (int) work[0]; work = new float[lwork*2]; 289 info = cgeev(jobvl, jobvr, n, a, aIdx, lda, w, wIdx, vl, vlIdx, ldvl, vr, vrIdx, ldvr, work, 0, lwork, rwork, rworkIdx); 290 return info; 291 } 292 293 public static native int dgeev(char jobvl, char jobvr, int n, double[] a, int aIdx, int lda, double[] wr, int wrIdx, double[] wi, int wiIdx, double[] vl, int vlIdx, int ldvl, double[] vr, int vrIdx, int ldvr, double[] work, int workIdx, int lwork); 294 public static int dgeev(char jobvl, char jobvr, int n, double[] a, int aIdx, int lda, double[] wr, int wrIdx, double[] wi, int wiIdx, double[] vl, int vlIdx, int ldvl, double[] vr, int vrIdx, int ldvr) { 295 int info; 296 double[] work = new double[1]; 297 int lwork; 298 info = dgeev(jobvl, jobvr, n, doubleDummy, 0, lda, doubleDummy, 0, doubleDummy, 0, doubleDummy, 0, ldvl, doubleDummy, 0, ldvr, work, 0, -1); 299 if (info != 0) 300 return info; 301 lwork = (int) work[0]; work = new double[lwork]; 302 info = dgeev(jobvl, jobvr, n, a, aIdx, lda, wr, wrIdx, wi, wiIdx, vl, vlIdx, ldvl, vr, vrIdx, ldvr, work, 0, lwork); 303 return info; 304 } 305 306 public static native int sgeev(char jobvl, char jobvr, int n, float[] a, int aIdx, int lda, float[] wr, int wrIdx, float[] wi, int wiIdx, float[] vl, int vlIdx, int ldvl, float[] vr, int vrIdx, int ldvr, float[] work, int workIdx, int lwork); 307 public static int sgeev(char jobvl, char jobvr, int n, float[] a, int aIdx, int lda, float[] wr, int wrIdx, float[] wi, int wiIdx, float[] vl, int vlIdx, int ldvl, float[] vr, int vrIdx, int ldvr) { 308 int info; 309 float[] work = new float[1]; 310 int lwork; 311 info = sgeev(jobvl, jobvr, n, floatDummy, 0, lda, floatDummy, 0, floatDummy, 0, floatDummy, 0, ldvl, floatDummy, 0, ldvr, work, 0, -1); 312 if (info != 0) 313 return info; 314 lwork = (int) work[0]; work = new float[lwork]; 315 info = sgeev(jobvl, jobvr, n, a, aIdx, lda, wr, wrIdx, wi, wiIdx, vl, vlIdx, ldvl, vr, vrIdx, ldvr, work, 0, lwork); 316 return info; 317 } 318 319 public static native int zgeev(char jobvl, char jobvr, int n, double[] a, int aIdx, int lda, double[] w, int wIdx, double[] vl, int vlIdx, int ldvl, double[] vr, int vrIdx, int ldvr, double[] work, int workIdx, int lwork, double[] rwork, int rworkIdx); 320 public static int zgeev(char jobvl, char jobvr, int n, double[] a, int aIdx, int lda, double[] w, int wIdx, double[] vl, int vlIdx, int ldvl, double[] vr, int vrIdx, int ldvr, double[] rwork, int rworkIdx) { 321 int info; 322 double[] work = new double[1*2]; 323 int lwork; 324 info = zgeev(jobvl, jobvr, n, doubleDummy, 0, lda, doubleDummy, 0, doubleDummy, 0, ldvl, doubleDummy, 0, ldvr, work, 0, -1, doubleDummy, 0); 325 if (info != 0) 326 return info; 327 lwork = (int) work[0]; work = new double[lwork*2]; 328 info = zgeev(jobvl, jobvr, n, a, aIdx, lda, w, wIdx, vl, vlIdx, ldvl, vr, vrIdx, ldvr, work, 0, lwork, rwork, rworkIdx); 329 return info; 330 } 331 332 public static native int dgetrf(int m, int n, double[] a, int aIdx, int lda, int[] ipiv, int ipivIdx); 333 public static native int sgetrf(int m, int n, float[] a, int aIdx, int lda, int[] ipiv, int ipivIdx); 334 public static native int dpotrf(char uplo, int n, double[] a, int aIdx, int lda); 335 public static native int spotrf(char uplo, int n, float[] a, int aIdx, int lda); 336 public static native int cgesvd(char jobu, char jobvt, int m, int n, float[] a, int aIdx, int lda, float[] s, int sIdx, float[] u, int uIdx, int ldu, float[] vt, int vtIdx, int ldvt, float[] work, int workIdx, int lwork, float[] rwork, int rworkIdx); 337 public static int cgesvd(char jobu, char jobvt, int m, int n, float[] a, int aIdx, int lda, float[] s, int sIdx, float[] u, int uIdx, int ldu, float[] vt, int vtIdx, int ldvt, float[] rwork, int rworkIdx) { 338 int info; 339 float[] work = new float[1*2]; 340 int lwork; 341 info = cgesvd(jobu, jobvt, m, n, floatDummy, 0, lda, floatDummy, 0, floatDummy, 0, ldu, floatDummy, 0, ldvt, work, 0, -1, floatDummy, 0); 342 if (info != 0) 343 return info; 344 lwork = (int) work[0]; work = new float[lwork*2]; 345 info = cgesvd(jobu, jobvt, m, n, a, aIdx, lda, s, sIdx, u, uIdx, ldu, vt, vtIdx, ldvt, work, 0, lwork, rwork, rworkIdx); 346 return info; 347 } 348 349 public static native int dgesvd(char jobu, char jobvt, int m, int n, double[] a, int aIdx, int lda, double[] s, int sIdx, double[] u, int uIdx, int ldu, double[] vt, int vtIdx, int ldvt, double[] work, int workIdx, int lwork); 350 public static int dgesvd(char jobu, char jobvt, int m, int n, double[] a, int aIdx, int lda, double[] s, int sIdx, double[] u, int uIdx, int ldu, double[] vt, int vtIdx, int ldvt) { 351 int info; 352 double[] work = new double[1]; 353 int lwork; 354 info = dgesvd(jobu, jobvt, m, n, doubleDummy, 0, lda, doubleDummy, 0, doubleDummy, 0, ldu, doubleDummy, 0, ldvt, work, 0, -1); 355 if (info != 0) 356 return info; 357 lwork = (int) work[0]; work = new double[lwork]; 358 info = dgesvd(jobu, jobvt, m, n, a, aIdx, lda, s, sIdx, u, uIdx, ldu, vt, vtIdx, ldvt, work, 0, lwork); 359 return info; 360 } 361 362 public static native int sgesvd(char jobu, char jobvt, int m, int n, float[] a, int aIdx, int lda, float[] s, int sIdx, float[] u, int uIdx, int ldu, float[] vt, int vtIdx, int ldvt, float[] work, int workIdx, int lwork); 363 public static int sgesvd(char jobu, char jobvt, int m, int n, float[] a, int aIdx, int lda, float[] s, int sIdx, float[] u, int uIdx, int ldu, float[] vt, int vtIdx, int ldvt) { 364 int info; 365 float[] work = new float[1]; 366 int lwork; 367 info = sgesvd(jobu, jobvt, m, n, floatDummy, 0, lda, floatDummy, 0, floatDummy, 0, ldu, floatDummy, 0, ldvt, work, 0, -1); 368 if (info != 0) 369 return info; 370 lwork = (int) work[0]; work = new float[lwork]; 371 info = sgesvd(jobu, jobvt, m, n, a, aIdx, lda, s, sIdx, u, uIdx, ldu, vt, vtIdx, ldvt, work, 0, lwork); 372 return info; 373 } 374 375 public static native int zgesvd(char jobu, char jobvt, int m, int n, double[] a, int aIdx, int lda, double[] s, int sIdx, double[] u, int uIdx, int ldu, double[] vt, int vtIdx, int ldvt, double[] work, int workIdx, int lwork, double[] rwork, int rworkIdx); 376 public static int zgesvd(char jobu, char jobvt, int m, int n, double[] a, int aIdx, int lda, double[] s, int sIdx, double[] u, int uIdx, int ldu, double[] vt, int vtIdx, int ldvt, double[] rwork, int rworkIdx) { 377 int info; 378 double[] work = new double[1*2]; 379 int lwork; 380 info = zgesvd(jobu, jobvt, m, n, doubleDummy, 0, lda, doubleDummy, 0, doubleDummy, 0, ldu, doubleDummy, 0, ldvt, work, 0, -1, doubleDummy, 0); 381 if (info != 0) 382 return info; 383 lwork = (int) work[0]; work = new double[lwork*2]; 384 info = zgesvd(jobu, jobvt, m, n, a, aIdx, lda, s, sIdx, u, uIdx, ldu, vt, vtIdx, ldvt, work, 0, lwork, rwork, rworkIdx); 385 return info; 386 } 387 388 public static native int dsygvd(int itype, char jobz, char uplo, int n, double[] a, int aIdx, int lda, double[] b, int bIdx, int ldb, double[] w, int wIdx, double[] work, int workIdx, int lwork, int[] iwork, int iworkIdx, int liwork); 389 public static int dsygvd(int itype, char jobz, char uplo, int n, double[] a, int aIdx, int lda, double[] b, int bIdx, int ldb, double[] w, int wIdx) { 390 int info; 391 double[] work = new double[1]; 392 int lwork; 393 int[] iwork = new int[1]; 394 int liwork; 395 info = dsygvd(itype, jobz, uplo, n, doubleDummy, 0, lda, doubleDummy, 0, ldb, doubleDummy, 0, work, 0, -1, iwork, 0, -1); 396 if (info != 0) 397 return info; 398 lwork = (int) work[0]; work = new double[lwork]; 399 liwork = (int) iwork[0]; iwork = new int[liwork]; 400 info = dsygvd(itype, jobz, uplo, n, a, aIdx, lda, b, bIdx, ldb, w, wIdx, work, 0, lwork, iwork, 0, liwork); 401 return info; 402 } 403 404 public static native int ssygvd(int itype, char jobz, char uplo, int n, float[] a, int aIdx, int lda, float[] b, int bIdx, int ldb, float[] w, int wIdx, float[] work, int workIdx, int lwork, int[] iwork, int iworkIdx, int liwork); 405 public static int ssygvd(int itype, char jobz, char uplo, int n, float[] a, int aIdx, int lda, float[] b, int bIdx, int ldb, float[] w, int wIdx) { 406 int info; 407 float[] work = new float[1]; 408 int lwork; 409 int[] iwork = new int[1]; 410 int liwork; 411 info = ssygvd(itype, jobz, uplo, n, floatDummy, 0, lda, floatDummy, 0, ldb, floatDummy, 0, work, 0, -1, iwork, 0, -1); 412 if (info != 0) 413 return info; 414 lwork = (int) work[0]; work = new float[lwork]; 415 liwork = (int) iwork[0]; iwork = new int[liwork]; 416 info = ssygvd(itype, jobz, uplo, n, a, aIdx, lda, b, bIdx, ldb, w, wIdx, work, 0, lwork, iwork, 0, liwork); 417 return info; 418 } 419 420 public static native int dgelsd(int m, int n, int nrhs, double[] a, int aIdx, int lda, double[] b, int bIdx, int ldb, double[] s, int sIdx, double rcond, int[] rank, int rankIdx, double[] work, int workIdx, int lwork, int[] iwork, int iworkIdx); 421 public static int dgelsd(int m, int n, int nrhs, double[] a, int aIdx, int lda, double[] b, int bIdx, int ldb, double[] s, int sIdx, double rcond, int[] rank, int rankIdx, int[] iwork, int iworkIdx) { 422 int info; 423 double[] work = new double[1]; 424 int lwork; 425 info = dgelsd(m, n, nrhs, doubleDummy, 0, lda, doubleDummy, 0, ldb, doubleDummy, 0, rcond, intDummy, 0, work, 0, -1, intDummy, 0); 426 if (info != 0) 427 return info; 428 lwork = (int) work[0]; work = new double[lwork]; 429 info = dgelsd(m, n, nrhs, a, aIdx, lda, b, bIdx, ldb, s, sIdx, rcond, rank, rankIdx, work, 0, lwork, iwork, iworkIdx); 430 return info; 431 } 432 433 public static native int sgelsd(int m, int n, int nrhs, float[] a, int aIdx, int lda, float[] b, int bIdx, int ldb, float[] s, int sIdx, float rcond, int[] rank, int rankIdx, float[] work, int workIdx, int lwork, int[] iwork, int iworkIdx); 434 public static int sgelsd(int m, int n, int nrhs, float[] a, int aIdx, int lda, float[] b, int bIdx, int ldb, float[] s, int sIdx, float rcond, int[] rank, int rankIdx, int[] iwork, int iworkIdx) { 435 int info; 436 float[] work = new float[1]; 437 int lwork; 438 info = sgelsd(m, n, nrhs, floatDummy, 0, lda, floatDummy, 0, ldb, floatDummy, 0, rcond, intDummy, 0, work, 0, -1, intDummy, 0); 439 if (info != 0) 440 return info; 441 lwork = (int) work[0]; work = new float[lwork]; 442 info = sgelsd(m, n, nrhs, a, aIdx, lda, b, bIdx, ldb, s, sIdx, rcond, rank, rankIdx, work, 0, lwork, iwork, iworkIdx); 443 return info; 444 } 445 446 public static native int ilaenv(int ispec, String name, String opts, int n1, int n2, int n3, int n4); 447 public static native int dgeqrf(int m, int n, double[] a, int aIdx, int lda, double[] tau, int tauIdx, double[] work, int workIdx, int lwork); 448 public static int dgeqrf(int m, int n, double[] a, int aIdx, int lda, double[] tau, int tauIdx) { 449 int info; 450 double[] work = new double[1]; 451 int lwork; 452 info = dgeqrf(m, n, doubleDummy, 0, lda, doubleDummy, 0, work, 0, -1); 453 if (info != 0) 454 return info; 455 lwork = (int) work[0]; work = new double[lwork]; 456 info = dgeqrf(m, n, a, aIdx, lda, tau, tauIdx, work, 0, lwork); 457 return info; 458 } 459 460 public static native int sgeqrf(int m, int n, float[] a, int aIdx, int lda, float[] tau, int tauIdx, float[] work, int workIdx, int lwork); 461 public static int sgeqrf(int m, int n, float[] a, int aIdx, int lda, float[] tau, int tauIdx) { 462 int info; 463 float[] work = new float[1]; 464 int lwork; 465 info = sgeqrf(m, n, floatDummy, 0, lda, floatDummy, 0, work, 0, -1); 466 if (info != 0) 467 return info; 468 lwork = (int) work[0]; work = new float[lwork]; 469 info = sgeqrf(m, n, a, aIdx, lda, tau, tauIdx, work, 0, lwork); 470 return info; 471 } 472 473 public static native int dormqr(char side, char trans, int m, int n, int k, double[] a, int aIdx, int lda, double[] tau, int tauIdx, double[] c, int cIdx, int ldc, double[] work, int workIdx, int lwork); 474 public static int dormqr(char side, char trans, int m, int n, int k, double[] a, int aIdx, int lda, double[] tau, int tauIdx, double[] c, int cIdx, int ldc) { 475 int info; 476 double[] work = new double[1]; 477 int lwork; 478 info = dormqr(side, trans, m, n, k, doubleDummy, 0, lda, doubleDummy, 0, doubleDummy, 0, ldc, work, 0, -1); 479 if (info != 0) 480 return info; 481 lwork = (int) work[0]; work = new double[lwork]; 482 info = dormqr(side, trans, m, n, k, a, aIdx, lda, tau, tauIdx, c, cIdx, ldc, work, 0, lwork); 483 return info; 484 } 485 486 public static native int sormqr(char side, char trans, int m, int n, int k, float[] a, int aIdx, int lda, float[] tau, int tauIdx, float[] c, int cIdx, int ldc, float[] work, int workIdx, int lwork); 487 public static int sormqr(char side, char trans, int m, int n, int k, float[] a, int aIdx, int lda, float[] tau, int tauIdx, float[] c, int cIdx, int ldc) { 488 int info; 489 float[] work = new float[1]; 490 int lwork; 491 info = sormqr(side, trans, m, n, k, floatDummy, 0, lda, floatDummy, 0, floatDummy, 0, ldc, work, 0, -1); 492 if (info != 0) 493 return info; 494 lwork = (int) work[0]; work = new float[lwork]; 495 info = sormqr(side, trans, m, n, k, a, aIdx, lda, tau, tauIdx, c, cIdx, ldc, work, 0, lwork); 496 return info; 497 } 498 499 500}