nulin 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/doc/BSDL +22 -0
- data/doc/COPYING +10 -0
- data/doc/README.en +31 -0
- data/doc/README.ja +36 -0
- data/ext/extconf.rb +33 -0
- data/ext/nulin_native.c +637 -0
- data/lib/narray_extext.rb +113 -0
- data/lib/nulin.rb +51 -0
- data/lib/nulin/cholesky.rb +62 -0
- data/lib/nulin/det.rb +17 -0
- data/lib/nulin/eigensystem.rb +191 -0
- data/lib/nulin/gemm.rb +53 -0
- data/lib/nulin/lls.rb +133 -0
- data/lib/nulin/qr.rb +68 -0
- data/lib/nulin/svd.rb +84 -0
- data/tests/run_test.rb +17 -0
- data/tests/test_cholesky.rb +39 -0
- data/tests/test_det.rb +11 -0
- data/tests/test_eigensystem.rb +71 -0
- data/tests/test_gemm.rb +57 -0
- data/tests/test_lls.rb +51 -0
- data/tests/test_narray.rb +100 -0
- data/tests/test_qr.rb +56 -0
- data/tests/test_svd.rb +51 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 00adc4604c91f8ccc64370847d1aa9110f3bda41
|
4
|
+
data.tar.gz: ddd79723d590b56b640107af787f132b13522aeb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d4f3b87c551814ebadc5a8cb7e06ef273f3b84db97a45ef137278fa58f6a1c05ad8d0c95921725a61364174b78d2421ca310cf2790a2007c4ce4bd3ba97879f
|
7
|
+
data.tar.gz: 5a1a1470a7eada53700f84acaab0069e1fc162f506b901c6a9d735ee8f0f04ab43c0bb41f0bb1d3be2c55d6baf4f67553959c35355992454ea1c2e7e7685bfe5
|
data/doc/BSDL
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 2013 Ippei Obayashi. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
data/doc/COPYING
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Nulin is a free software copyrighted by Ippei Obayashi <ohai@kmc.gr.jp>.
|
2
|
+
This software is distributed under the license of 2-clause BSDL.
|
3
|
+
You can redistribute it and/or modify it under the terms of the
|
4
|
+
2-clause BSDL (see doc/BSDL).
|
5
|
+
|
6
|
+
All files under dev/defs except [sdcz]gemm are from ruby-lapack and
|
7
|
+
copyrighted by Seiya Nishizawa <seiya@gfd-dennou.org>. These
|
8
|
+
files are under Ruby's license. Please see the following URL
|
9
|
+
to see more details.
|
10
|
+
http://ruby.gfd-dennou.org/products/ruby-lapack/index.html
|
data/doc/README.en
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
NuLin
|
2
|
+
|
3
|
+
= What is NuLin?
|
4
|
+
NuLin is a fast linear algebra library using lapack routines
|
5
|
+
in cooperation with NArray.
|
6
|
+
|
7
|
+
NuLin has following functionalities.
|
8
|
+
|
9
|
+
* Basic linear algebra
|
10
|
+
* determinant
|
11
|
+
* Linear Least Square method
|
12
|
+
|
13
|
+
* Eigen problems
|
14
|
+
* Computing eigenvalues and eigenvectors
|
15
|
+
|
16
|
+
* Matrix decomposition
|
17
|
+
* (Pivoted) LU decomposition
|
18
|
+
* Singular value decomposition
|
19
|
+
* QR decomposition
|
20
|
+
* Cholesky decomposition
|
21
|
+
|
22
|
+
= Required C libraries
|
23
|
+
* lapack
|
24
|
+
* f2c.h (libf2c2-dev in debian)
|
25
|
+
|
26
|
+
= Required ruby packages
|
27
|
+
* NArray (you can install NArray from rubygems: gem install narray)
|
28
|
+
|
29
|
+
= TODO
|
30
|
+
* Schur decomposition
|
31
|
+
* GEMM
|
data/doc/README.ja
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
NuLin
|
2
|
+
= このライブラリについて
|
3
|
+
このライブラリは、NArrayを利用して高度な行列演算を行うための
|
4
|
+
ライブラリです。以下の機能を持っています。
|
5
|
+
|
6
|
+
* 基本的なもの
|
7
|
+
* 行列式
|
8
|
+
* 最小二乗法
|
9
|
+
|
10
|
+
* 固有値問題
|
11
|
+
* 固有値と固有ベクトル
|
12
|
+
|
13
|
+
* 行列の分解
|
14
|
+
* (Pivoted) LU分解
|
15
|
+
* 特異値分解
|
16
|
+
* QR分解
|
17
|
+
* コレスキー分解
|
18
|
+
|
19
|
+
これらは LAPACK(および ruby-lapack)を用いて実装されています。
|
20
|
+
|
21
|
+
= 依存するCライブラリ
|
22
|
+
* lapack
|
23
|
+
* f2c.h (debian であれば libf2c2-dev を使う)
|
24
|
+
|
25
|
+
= 依存するrubyパッケージ
|
26
|
+
* NArray (gem install narray でインストールできます)
|
27
|
+
|
28
|
+
= 開発の経緯
|
29
|
+
NArray で使える LAPACK のラッパとして、 ruby-lapack が存在しますが、
|
30
|
+
ruby-lapack は LAPACK の薄いラッパで使い勝手は良くありません。
|
31
|
+
ruby-lapackから使いたい部品を取ってきてこのライブラリを作成しました。
|
32
|
+
インターフェースはScipy.linalgを手本としています。
|
33
|
+
|
34
|
+
= TODO
|
35
|
+
* Schur 分解
|
36
|
+
* GEMM
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
def narray_gem_dir
|
5
|
+
begin
|
6
|
+
require 'rubygems'
|
7
|
+
rescue LoadError
|
8
|
+
return
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
spec = Gem::Specification.find_by_name("narray")
|
13
|
+
$CPPFLAGS += " -I#{spec.full_gem_path}"
|
14
|
+
return
|
15
|
+
rescue Gem::LoadError, NoMethodError
|
16
|
+
end
|
17
|
+
|
18
|
+
spec = Gem.source_index.find_name("narray")
|
19
|
+
if spec.any?
|
20
|
+
$CPPFLAGS += " -I#{spec.last.full_gem_path}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
sitearchdir = CONFIG["sitearchdir"]
|
25
|
+
dir_config("narray", sitearchdir, sitearchdir)
|
26
|
+
narray_gem_dir
|
27
|
+
|
28
|
+
have_header("narray.h")
|
29
|
+
have_header("narray_config.h")
|
30
|
+
have_library("blas")
|
31
|
+
have_library("lapack")
|
32
|
+
|
33
|
+
create_makefile("nulin_native")
|
data/ext/nulin_native.c
ADDED
@@ -0,0 +1,637 @@
|
|
1
|
+
#include <math.h>
|
2
|
+
#include "ruby.h"
|
3
|
+
#include "narray.h"
|
4
|
+
#include "f2c.h"
|
5
|
+
#include "cblas.h"
|
6
|
+
|
7
|
+
static VALUE id_real = Qnil, id_imag = Qnil;
|
8
|
+
|
9
|
+
static int nulin_check_narray(VALUE a)
|
10
|
+
{
|
11
|
+
if(!NA_IsNArray(a))
|
12
|
+
rb_raise(rb_eTypeError, "A paramter must be NArray");
|
13
|
+
return 0;
|
14
|
+
}
|
15
|
+
|
16
|
+
#define COMPLEX_STRUCT(x) \
|
17
|
+
{ NUM2DBL(rb_funcall(x, id_real, 0)), NUM2DBL(rb_funcall(x, id_imag, 0)) }
|
18
|
+
|
19
|
+
|
20
|
+
extern void dgeev_(char* jobvl,char* jobvr,integer* n,doublereal* a,integer* lda,doublereal* wr,doublereal* wi,doublereal* vl,integer* ldvl,doublereal* vr,integer* ldvr,doublereal* work,integer* lwork,integer* info);
|
21
|
+
static VALUE nulin_dgeev(VALUE self,VALUE jobvl,VALUE jobvr,VALUE n,VALUE a,VALUE lda,VALUE wr,VALUE wi,VALUE vl,VALUE ldvl,VALUE vr,VALUE ldvr,VALUE work,VALUE lwork,VALUE info)
|
22
|
+
{
|
23
|
+
char JOBVL = StringValueCStr(jobvl)[0];
|
24
|
+
char JOBVR = StringValueCStr(jobvr)[0];
|
25
|
+
integer N = NUM2INT(n);
|
26
|
+
doublereal* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublereal*);
|
27
|
+
integer LDA = NUM2INT(lda);
|
28
|
+
doublereal* WR = NA_PTR_TYPE((nulin_check_narray(wr),wr), doublereal*);
|
29
|
+
doublereal* WI = NA_PTR_TYPE((nulin_check_narray(wi),wi), doublereal*);
|
30
|
+
doublereal* VL = NA_PTR_TYPE((nulin_check_narray(vl),vl), doublereal*);
|
31
|
+
integer LDVL = NUM2INT(ldvl);
|
32
|
+
doublereal* VR = NA_PTR_TYPE((nulin_check_narray(vr),vr), doublereal*);
|
33
|
+
integer LDVR = NUM2INT(ldvr);
|
34
|
+
doublereal* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublereal*);
|
35
|
+
integer LWORK = NUM2INT(lwork);
|
36
|
+
integer INFO = NUM2INT(info);
|
37
|
+
dgeev_(&JOBVL,&JOBVR,&N,A,&LDA,WR,WI,VL,&LDVL,VR,&LDVR,WORK,&LWORK,&INFO);
|
38
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
39
|
+
}
|
40
|
+
|
41
|
+
extern void sgeev_(char* jobvl,char* jobvr,integer* n,real* a,integer* lda,real* wr,real* wi,real* vl,integer* ldvl,real* vr,integer* ldvr,real* work,integer* lwork,integer* info);
|
42
|
+
static VALUE nulin_sgeev(VALUE self,VALUE jobvl,VALUE jobvr,VALUE n,VALUE a,VALUE lda,VALUE wr,VALUE wi,VALUE vl,VALUE ldvl,VALUE vr,VALUE ldvr,VALUE work,VALUE lwork,VALUE info)
|
43
|
+
{
|
44
|
+
char JOBVL = StringValueCStr(jobvl)[0];
|
45
|
+
char JOBVR = StringValueCStr(jobvr)[0];
|
46
|
+
integer N = NUM2INT(n);
|
47
|
+
real* A = NA_PTR_TYPE((nulin_check_narray(a),a), real*);
|
48
|
+
integer LDA = NUM2INT(lda);
|
49
|
+
real* WR = NA_PTR_TYPE((nulin_check_narray(wr),wr), real*);
|
50
|
+
real* WI = NA_PTR_TYPE((nulin_check_narray(wi),wi), real*);
|
51
|
+
real* VL = NA_PTR_TYPE((nulin_check_narray(vl),vl), real*);
|
52
|
+
integer LDVL = NUM2INT(ldvl);
|
53
|
+
real* VR = NA_PTR_TYPE((nulin_check_narray(vr),vr), real*);
|
54
|
+
integer LDVR = NUM2INT(ldvr);
|
55
|
+
real* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), real*);
|
56
|
+
integer LWORK = NUM2INT(lwork);
|
57
|
+
integer INFO = NUM2INT(info);
|
58
|
+
sgeev_(&JOBVL,&JOBVR,&N,A,&LDA,WR,WI,VL,&LDVL,VR,&LDVR,WORK,&LWORK,&INFO);
|
59
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
60
|
+
}
|
61
|
+
|
62
|
+
extern void zgeev_(char* jobvl,char* jobvr,integer* n,doublecomplex* a,integer* lda,doublecomplex* w,doublecomplex* vl,integer* ldvl,doublecomplex* vr,integer* ldvr,doublecomplex* work,integer* lwork,doublereal* rwork,integer* info);
|
63
|
+
static VALUE nulin_zgeev(VALUE self,VALUE jobvl,VALUE jobvr,VALUE n,VALUE a,VALUE lda,VALUE w,VALUE vl,VALUE ldvl,VALUE vr,VALUE ldvr,VALUE work,VALUE lwork,VALUE rwork,VALUE info)
|
64
|
+
{
|
65
|
+
char JOBVL = StringValueCStr(jobvl)[0];
|
66
|
+
char JOBVR = StringValueCStr(jobvr)[0];
|
67
|
+
integer N = NUM2INT(n);
|
68
|
+
doublecomplex* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublecomplex*);
|
69
|
+
integer LDA = NUM2INT(lda);
|
70
|
+
doublecomplex* W = NA_PTR_TYPE((nulin_check_narray(w),w), doublecomplex*);
|
71
|
+
doublecomplex* VL = NA_PTR_TYPE((nulin_check_narray(vl),vl), doublecomplex*);
|
72
|
+
integer LDVL = NUM2INT(ldvl);
|
73
|
+
doublecomplex* VR = NA_PTR_TYPE((nulin_check_narray(vr),vr), doublecomplex*);
|
74
|
+
integer LDVR = NUM2INT(ldvr);
|
75
|
+
doublecomplex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublecomplex*);
|
76
|
+
integer LWORK = NUM2INT(lwork);
|
77
|
+
doublereal* RWORK = NA_PTR_TYPE((nulin_check_narray(rwork),rwork), doublereal*);
|
78
|
+
integer INFO = NUM2INT(info);
|
79
|
+
zgeev_(&JOBVL,&JOBVR,&N,A,&LDA,W,VL,&LDVL,VR,&LDVR,WORK,&LWORK,RWORK,&INFO);
|
80
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
81
|
+
}
|
82
|
+
|
83
|
+
extern void cgeev_(char* jobvl,char* jobvr,integer* n,complex* a,integer* lda,complex* w,complex* vl,integer* ldvl,complex* vr,integer* ldvr,complex* work,integer* lwork,real* rwork,integer* info);
|
84
|
+
static VALUE nulin_cgeev(VALUE self,VALUE jobvl,VALUE jobvr,VALUE n,VALUE a,VALUE lda,VALUE w,VALUE vl,VALUE ldvl,VALUE vr,VALUE ldvr,VALUE work,VALUE lwork,VALUE rwork,VALUE info)
|
85
|
+
{
|
86
|
+
char JOBVL = StringValueCStr(jobvl)[0];
|
87
|
+
char JOBVR = StringValueCStr(jobvr)[0];
|
88
|
+
integer N = NUM2INT(n);
|
89
|
+
complex* A = NA_PTR_TYPE((nulin_check_narray(a),a), complex*);
|
90
|
+
integer LDA = NUM2INT(lda);
|
91
|
+
complex* W = NA_PTR_TYPE((nulin_check_narray(w),w), complex*);
|
92
|
+
complex* VL = NA_PTR_TYPE((nulin_check_narray(vl),vl), complex*);
|
93
|
+
integer LDVL = NUM2INT(ldvl);
|
94
|
+
complex* VR = NA_PTR_TYPE((nulin_check_narray(vr),vr), complex*);
|
95
|
+
integer LDVR = NUM2INT(ldvr);
|
96
|
+
complex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), complex*);
|
97
|
+
integer LWORK = NUM2INT(lwork);
|
98
|
+
real* RWORK = NA_PTR_TYPE((nulin_check_narray(rwork),rwork), real*);
|
99
|
+
integer INFO = NUM2INT(info);
|
100
|
+
cgeev_(&JOBVL,&JOBVR,&N,A,&LDA,W,VL,&LDVL,VR,&LDVR,WORK,&LWORK,RWORK,&INFO);
|
101
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
102
|
+
}
|
103
|
+
|
104
|
+
extern void dgesvd_(char* jobu,char* jobvt,integer* m,integer* n,doublereal* a,integer* lda,doublereal* s,doublereal* u,integer* ldu,doublereal* vt,integer* ldvt,doublereal* work,integer* lwork,integer* info);
|
105
|
+
static VALUE nulin_dgesvd(VALUE self,VALUE jobu,VALUE jobvt,VALUE m,VALUE n,VALUE a,VALUE lda,VALUE s,VALUE u,VALUE ldu,VALUE vt,VALUE ldvt,VALUE work,VALUE lwork,VALUE info)
|
106
|
+
{
|
107
|
+
char JOBU = StringValueCStr(jobu)[0];
|
108
|
+
char JOBVT = StringValueCStr(jobvt)[0];
|
109
|
+
integer M = NUM2INT(m);
|
110
|
+
integer N = NUM2INT(n);
|
111
|
+
doublereal* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublereal*);
|
112
|
+
integer LDA = NUM2INT(lda);
|
113
|
+
doublereal* S = NA_PTR_TYPE((nulin_check_narray(s),s), doublereal*);
|
114
|
+
doublereal* U = NA_PTR_TYPE((nulin_check_narray(u),u), doublereal*);
|
115
|
+
integer LDU = NUM2INT(ldu);
|
116
|
+
doublereal* VT = NA_PTR_TYPE((nulin_check_narray(vt),vt), doublereal*);
|
117
|
+
integer LDVT = NUM2INT(ldvt);
|
118
|
+
doublereal* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublereal*);
|
119
|
+
integer LWORK = NUM2INT(lwork);
|
120
|
+
integer INFO = NUM2INT(info);
|
121
|
+
dgesvd_(&JOBU,&JOBVT,&M,&N,A,&LDA,S,U,&LDU,VT,&LDVT,WORK,&LWORK,&INFO);
|
122
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
123
|
+
}
|
124
|
+
|
125
|
+
extern void sgesvd_(char* jobu,char* jobvt,integer* m,integer* n,real* a,integer* lda,real* s,real* u,integer* ldu,real* vt,integer* ldvt,real* work,integer* lwork,integer* info);
|
126
|
+
static VALUE nulin_sgesvd(VALUE self,VALUE jobu,VALUE jobvt,VALUE m,VALUE n,VALUE a,VALUE lda,VALUE s,VALUE u,VALUE ldu,VALUE vt,VALUE ldvt,VALUE work,VALUE lwork,VALUE info)
|
127
|
+
{
|
128
|
+
char JOBU = StringValueCStr(jobu)[0];
|
129
|
+
char JOBVT = StringValueCStr(jobvt)[0];
|
130
|
+
integer M = NUM2INT(m);
|
131
|
+
integer N = NUM2INT(n);
|
132
|
+
real* A = NA_PTR_TYPE((nulin_check_narray(a),a), real*);
|
133
|
+
integer LDA = NUM2INT(lda);
|
134
|
+
real* S = NA_PTR_TYPE((nulin_check_narray(s),s), real*);
|
135
|
+
real* U = NA_PTR_TYPE((nulin_check_narray(u),u), real*);
|
136
|
+
integer LDU = NUM2INT(ldu);
|
137
|
+
real* VT = NA_PTR_TYPE((nulin_check_narray(vt),vt), real*);
|
138
|
+
integer LDVT = NUM2INT(ldvt);
|
139
|
+
real* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), real*);
|
140
|
+
integer LWORK = NUM2INT(lwork);
|
141
|
+
integer INFO = NUM2INT(info);
|
142
|
+
sgesvd_(&JOBU,&JOBVT,&M,&N,A,&LDA,S,U,&LDU,VT,&LDVT,WORK,&LWORK,&INFO);
|
143
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
144
|
+
}
|
145
|
+
|
146
|
+
extern void zgesvd_(char* jobu,char* jobvt,integer* m,integer* n,doublecomplex* a,integer* lda,doublereal* s,doublecomplex* u,integer* ldu,doublecomplex* vt,integer* ldvt,doublecomplex* work,integer* lwork,doublereal* rwork,integer* info);
|
147
|
+
static VALUE nulin_zgesvd(VALUE self,VALUE jobu,VALUE jobvt,VALUE m,VALUE n,VALUE a,VALUE lda,VALUE s,VALUE u,VALUE ldu,VALUE vt,VALUE ldvt,VALUE work,VALUE lwork,VALUE rwork,VALUE info)
|
148
|
+
{
|
149
|
+
char JOBU = StringValueCStr(jobu)[0];
|
150
|
+
char JOBVT = StringValueCStr(jobvt)[0];
|
151
|
+
integer M = NUM2INT(m);
|
152
|
+
integer N = NUM2INT(n);
|
153
|
+
doublecomplex* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublecomplex*);
|
154
|
+
integer LDA = NUM2INT(lda);
|
155
|
+
doublereal* S = NA_PTR_TYPE((nulin_check_narray(s),s), doublereal*);
|
156
|
+
doublecomplex* U = NA_PTR_TYPE((nulin_check_narray(u),u), doublecomplex*);
|
157
|
+
integer LDU = NUM2INT(ldu);
|
158
|
+
doublecomplex* VT = NA_PTR_TYPE((nulin_check_narray(vt),vt), doublecomplex*);
|
159
|
+
integer LDVT = NUM2INT(ldvt);
|
160
|
+
doublecomplex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublecomplex*);
|
161
|
+
integer LWORK = NUM2INT(lwork);
|
162
|
+
doublereal* RWORK = NA_PTR_TYPE((nulin_check_narray(rwork),rwork), doublereal*);
|
163
|
+
integer INFO = NUM2INT(info);
|
164
|
+
zgesvd_(&JOBU,&JOBVT,&M,&N,A,&LDA,S,U,&LDU,VT,&LDVT,WORK,&LWORK,RWORK,&INFO);
|
165
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
166
|
+
}
|
167
|
+
|
168
|
+
extern void cgesvd_(char* jobu,char* jobvt,integer* m,integer* n,complex* a,integer* lda,real* s,complex* u,integer* ldu,complex* vt,integer* ldvt,complex* work,integer* lwork,real* rwork,integer* info);
|
169
|
+
static VALUE nulin_cgesvd(VALUE self,VALUE jobu,VALUE jobvt,VALUE m,VALUE n,VALUE a,VALUE lda,VALUE s,VALUE u,VALUE ldu,VALUE vt,VALUE ldvt,VALUE work,VALUE lwork,VALUE rwork,VALUE info)
|
170
|
+
{
|
171
|
+
char JOBU = StringValueCStr(jobu)[0];
|
172
|
+
char JOBVT = StringValueCStr(jobvt)[0];
|
173
|
+
integer M = NUM2INT(m);
|
174
|
+
integer N = NUM2INT(n);
|
175
|
+
complex* A = NA_PTR_TYPE((nulin_check_narray(a),a), complex*);
|
176
|
+
integer LDA = NUM2INT(lda);
|
177
|
+
real* S = NA_PTR_TYPE((nulin_check_narray(s),s), real*);
|
178
|
+
complex* U = NA_PTR_TYPE((nulin_check_narray(u),u), complex*);
|
179
|
+
integer LDU = NUM2INT(ldu);
|
180
|
+
complex* VT = NA_PTR_TYPE((nulin_check_narray(vt),vt), complex*);
|
181
|
+
integer LDVT = NUM2INT(ldvt);
|
182
|
+
complex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), complex*);
|
183
|
+
integer LWORK = NUM2INT(lwork);
|
184
|
+
real* RWORK = NA_PTR_TYPE((nulin_check_narray(rwork),rwork), real*);
|
185
|
+
integer INFO = NUM2INT(info);
|
186
|
+
cgesvd_(&JOBU,&JOBVT,&M,&N,A,&LDA,S,U,&LDU,VT,&LDVT,WORK,&LWORK,RWORK,&INFO);
|
187
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
188
|
+
}
|
189
|
+
|
190
|
+
extern void dgelqf_(integer* m,integer* n,doublereal* a,integer* lda,doublereal* tau,doublereal* work,integer* lwork,integer* info);
|
191
|
+
static VALUE nulin_dgelqf(VALUE self,VALUE m,VALUE n,VALUE a,VALUE lda,VALUE tau,VALUE work,VALUE lwork,VALUE info)
|
192
|
+
{
|
193
|
+
integer M = NUM2INT(m);
|
194
|
+
integer N = NUM2INT(n);
|
195
|
+
doublereal* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublereal*);
|
196
|
+
integer LDA = NUM2INT(lda);
|
197
|
+
doublereal* TAU = NA_PTR_TYPE((nulin_check_narray(tau),tau), doublereal*);
|
198
|
+
doublereal* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublereal*);
|
199
|
+
integer LWORK = NUM2INT(lwork);
|
200
|
+
integer INFO = NUM2INT(info);
|
201
|
+
dgelqf_(&M,&N,A,&LDA,TAU,WORK,&LWORK,&INFO);
|
202
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
203
|
+
}
|
204
|
+
|
205
|
+
extern void sgelqf_(integer* m,integer* n,real* a,integer* lda,real* tau,real* work,integer* lwork,integer* info);
|
206
|
+
static VALUE nulin_sgelqf(VALUE self,VALUE m,VALUE n,VALUE a,VALUE lda,VALUE tau,VALUE work,VALUE lwork,VALUE info)
|
207
|
+
{
|
208
|
+
integer M = NUM2INT(m);
|
209
|
+
integer N = NUM2INT(n);
|
210
|
+
real* A = NA_PTR_TYPE((nulin_check_narray(a),a), real*);
|
211
|
+
integer LDA = NUM2INT(lda);
|
212
|
+
real* TAU = NA_PTR_TYPE((nulin_check_narray(tau),tau), real*);
|
213
|
+
real* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), real*);
|
214
|
+
integer LWORK = NUM2INT(lwork);
|
215
|
+
integer INFO = NUM2INT(info);
|
216
|
+
sgelqf_(&M,&N,A,&LDA,TAU,WORK,&LWORK,&INFO);
|
217
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
218
|
+
}
|
219
|
+
|
220
|
+
extern void zgelqf_(integer* m,integer* n,doublecomplex* a,integer* lda,doublecomplex* tau,doublecomplex* work,integer* lwork,integer* info);
|
221
|
+
static VALUE nulin_zgelqf(VALUE self,VALUE m,VALUE n,VALUE a,VALUE lda,VALUE tau,VALUE work,VALUE lwork,VALUE info)
|
222
|
+
{
|
223
|
+
integer M = NUM2INT(m);
|
224
|
+
integer N = NUM2INT(n);
|
225
|
+
doublecomplex* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublecomplex*);
|
226
|
+
integer LDA = NUM2INT(lda);
|
227
|
+
doublecomplex* TAU = NA_PTR_TYPE((nulin_check_narray(tau),tau), doublecomplex*);
|
228
|
+
doublecomplex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublecomplex*);
|
229
|
+
integer LWORK = NUM2INT(lwork);
|
230
|
+
integer INFO = NUM2INT(info);
|
231
|
+
zgelqf_(&M,&N,A,&LDA,TAU,WORK,&LWORK,&INFO);
|
232
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
233
|
+
}
|
234
|
+
|
235
|
+
extern void cgelqf_(integer* m,integer* n,complex* a,integer* lda,complex* tau,complex* work,integer* lwork,integer* info);
|
236
|
+
static VALUE nulin_cgelqf(VALUE self,VALUE m,VALUE n,VALUE a,VALUE lda,VALUE tau,VALUE work,VALUE lwork,VALUE info)
|
237
|
+
{
|
238
|
+
integer M = NUM2INT(m);
|
239
|
+
integer N = NUM2INT(n);
|
240
|
+
complex* A = NA_PTR_TYPE((nulin_check_narray(a),a), complex*);
|
241
|
+
integer LDA = NUM2INT(lda);
|
242
|
+
complex* TAU = NA_PTR_TYPE((nulin_check_narray(tau),tau), complex*);
|
243
|
+
complex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), complex*);
|
244
|
+
integer LWORK = NUM2INT(lwork);
|
245
|
+
integer INFO = NUM2INT(info);
|
246
|
+
cgelqf_(&M,&N,A,&LDA,TAU,WORK,&LWORK,&INFO);
|
247
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
248
|
+
}
|
249
|
+
|
250
|
+
extern void dorglq_(integer* m,integer* n,integer* k,doublereal* a,integer* lda,doublereal* tau,doublereal* work,integer* lwork,integer* info);
|
251
|
+
static VALUE nulin_dorglq(VALUE self,VALUE m,VALUE n,VALUE k,VALUE a,VALUE lda,VALUE tau,VALUE work,VALUE lwork,VALUE info)
|
252
|
+
{
|
253
|
+
integer M = NUM2INT(m);
|
254
|
+
integer N = NUM2INT(n);
|
255
|
+
integer K = NUM2INT(k);
|
256
|
+
doublereal* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublereal*);
|
257
|
+
integer LDA = NUM2INT(lda);
|
258
|
+
doublereal* TAU = NA_PTR_TYPE((nulin_check_narray(tau),tau), doublereal*);
|
259
|
+
doublereal* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublereal*);
|
260
|
+
integer LWORK = NUM2INT(lwork);
|
261
|
+
integer INFO = NUM2INT(info);
|
262
|
+
dorglq_(&M,&N,&K,A,&LDA,TAU,WORK,&LWORK,&INFO);
|
263
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
264
|
+
}
|
265
|
+
|
266
|
+
extern void sorglq_(integer* m,integer* n,integer* k,real* a,integer* lda,real* tau,real* work,integer* lwork,integer* info);
|
267
|
+
static VALUE nulin_sorglq(VALUE self,VALUE m,VALUE n,VALUE k,VALUE a,VALUE lda,VALUE tau,VALUE work,VALUE lwork,VALUE info)
|
268
|
+
{
|
269
|
+
integer M = NUM2INT(m);
|
270
|
+
integer N = NUM2INT(n);
|
271
|
+
integer K = NUM2INT(k);
|
272
|
+
real* A = NA_PTR_TYPE((nulin_check_narray(a),a), real*);
|
273
|
+
integer LDA = NUM2INT(lda);
|
274
|
+
real* TAU = NA_PTR_TYPE((nulin_check_narray(tau),tau), real*);
|
275
|
+
real* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), real*);
|
276
|
+
integer LWORK = NUM2INT(lwork);
|
277
|
+
integer INFO = NUM2INT(info);
|
278
|
+
sorglq_(&M,&N,&K,A,&LDA,TAU,WORK,&LWORK,&INFO);
|
279
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
280
|
+
}
|
281
|
+
|
282
|
+
extern void zunglq_(integer* m,integer* n,integer* k,doublecomplex* a,integer* lda,doublecomplex* tau,doublecomplex* work,integer* lwork,integer* info);
|
283
|
+
static VALUE nulin_zunglq(VALUE self,VALUE m,VALUE n,VALUE k,VALUE a,VALUE lda,VALUE tau,VALUE work,VALUE lwork,VALUE info)
|
284
|
+
{
|
285
|
+
integer M = NUM2INT(m);
|
286
|
+
integer N = NUM2INT(n);
|
287
|
+
integer K = NUM2INT(k);
|
288
|
+
doublecomplex* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublecomplex*);
|
289
|
+
integer LDA = NUM2INT(lda);
|
290
|
+
doublecomplex* TAU = NA_PTR_TYPE((nulin_check_narray(tau),tau), doublecomplex*);
|
291
|
+
doublecomplex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublecomplex*);
|
292
|
+
integer LWORK = NUM2INT(lwork);
|
293
|
+
integer INFO = NUM2INT(info);
|
294
|
+
zunglq_(&M,&N,&K,A,&LDA,TAU,WORK,&LWORK,&INFO);
|
295
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
296
|
+
}
|
297
|
+
|
298
|
+
extern void cunglq_(integer* m,integer* n,integer* k,complex* a,integer* lda,complex* tau,complex* work,integer* lwork,integer* info);
|
299
|
+
static VALUE nulin_cunglq(VALUE self,VALUE m,VALUE n,VALUE k,VALUE a,VALUE lda,VALUE tau,VALUE work,VALUE lwork,VALUE info)
|
300
|
+
{
|
301
|
+
integer M = NUM2INT(m);
|
302
|
+
integer N = NUM2INT(n);
|
303
|
+
integer K = NUM2INT(k);
|
304
|
+
complex* A = NA_PTR_TYPE((nulin_check_narray(a),a), complex*);
|
305
|
+
integer LDA = NUM2INT(lda);
|
306
|
+
complex* TAU = NA_PTR_TYPE((nulin_check_narray(tau),tau), complex*);
|
307
|
+
complex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), complex*);
|
308
|
+
integer LWORK = NUM2INT(lwork);
|
309
|
+
integer INFO = NUM2INT(info);
|
310
|
+
cunglq_(&M,&N,&K,A,&LDA,TAU,WORK,&LWORK,&INFO);
|
311
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
312
|
+
}
|
313
|
+
|
314
|
+
extern void dgels_(char* trans,integer* m,integer* n,integer* nrhs,doublereal* a,integer* lda,doublereal* b,integer* ldb,doublereal* work,integer* lwork,integer* info);
|
315
|
+
static VALUE nulin_dgels(VALUE self,VALUE trans,VALUE m,VALUE n,VALUE nrhs,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE work,VALUE lwork,VALUE info)
|
316
|
+
{
|
317
|
+
char TRANS = StringValueCStr(trans)[0];
|
318
|
+
integer M = NUM2INT(m);
|
319
|
+
integer N = NUM2INT(n);
|
320
|
+
integer NRHS = NUM2INT(nrhs);
|
321
|
+
doublereal* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublereal*);
|
322
|
+
integer LDA = NUM2INT(lda);
|
323
|
+
doublereal* B = NA_PTR_TYPE((nulin_check_narray(b),b), doublereal*);
|
324
|
+
integer LDB = NUM2INT(ldb);
|
325
|
+
doublereal* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublereal*);
|
326
|
+
integer LWORK = NUM2INT(lwork);
|
327
|
+
integer INFO = NUM2INT(info);
|
328
|
+
dgels_(&TRANS,&M,&N,&NRHS,A,&LDA,B,&LDB,WORK,&LWORK,&INFO);
|
329
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
330
|
+
}
|
331
|
+
|
332
|
+
extern void sgels_(char* trans,integer* m,integer* n,integer* nrhs,real* a,integer* lda,real* b,integer* ldb,real* work,integer* lwork,integer* info);
|
333
|
+
static VALUE nulin_sgels(VALUE self,VALUE trans,VALUE m,VALUE n,VALUE nrhs,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE work,VALUE lwork,VALUE info)
|
334
|
+
{
|
335
|
+
char TRANS = StringValueCStr(trans)[0];
|
336
|
+
integer M = NUM2INT(m);
|
337
|
+
integer N = NUM2INT(n);
|
338
|
+
integer NRHS = NUM2INT(nrhs);
|
339
|
+
real* A = NA_PTR_TYPE((nulin_check_narray(a),a), real*);
|
340
|
+
integer LDA = NUM2INT(lda);
|
341
|
+
real* B = NA_PTR_TYPE((nulin_check_narray(b),b), real*);
|
342
|
+
integer LDB = NUM2INT(ldb);
|
343
|
+
real* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), real*);
|
344
|
+
integer LWORK = NUM2INT(lwork);
|
345
|
+
integer INFO = NUM2INT(info);
|
346
|
+
sgels_(&TRANS,&M,&N,&NRHS,A,&LDA,B,&LDB,WORK,&LWORK,&INFO);
|
347
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
348
|
+
}
|
349
|
+
|
350
|
+
extern void zgels_(char* trans,integer* m,integer* n,integer* nrhs,doublecomplex* a,integer* lda,doublecomplex* b,integer* ldb,doublecomplex* work,integer* lwork,integer* info);
|
351
|
+
static VALUE nulin_zgels(VALUE self,VALUE trans,VALUE m,VALUE n,VALUE nrhs,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE work,VALUE lwork,VALUE info)
|
352
|
+
{
|
353
|
+
char TRANS = StringValueCStr(trans)[0];
|
354
|
+
integer M = NUM2INT(m);
|
355
|
+
integer N = NUM2INT(n);
|
356
|
+
integer NRHS = NUM2INT(nrhs);
|
357
|
+
doublecomplex* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublecomplex*);
|
358
|
+
integer LDA = NUM2INT(lda);
|
359
|
+
doublecomplex* B = NA_PTR_TYPE((nulin_check_narray(b),b), doublecomplex*);
|
360
|
+
integer LDB = NUM2INT(ldb);
|
361
|
+
doublecomplex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublecomplex*);
|
362
|
+
integer LWORK = NUM2INT(lwork);
|
363
|
+
integer INFO = NUM2INT(info);
|
364
|
+
zgels_(&TRANS,&M,&N,&NRHS,A,&LDA,B,&LDB,WORK,&LWORK,&INFO);
|
365
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
366
|
+
}
|
367
|
+
|
368
|
+
extern void cgels_(char* trans,integer* m,integer* n,integer* nrhs,complex* a,integer* lda,complex* b,integer* ldb,complex* work,integer* lwork,integer* info);
|
369
|
+
static VALUE nulin_cgels(VALUE self,VALUE trans,VALUE m,VALUE n,VALUE nrhs,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE work,VALUE lwork,VALUE info)
|
370
|
+
{
|
371
|
+
char TRANS = StringValueCStr(trans)[0];
|
372
|
+
integer M = NUM2INT(m);
|
373
|
+
integer N = NUM2INT(n);
|
374
|
+
integer NRHS = NUM2INT(nrhs);
|
375
|
+
complex* A = NA_PTR_TYPE((nulin_check_narray(a),a), complex*);
|
376
|
+
integer LDA = NUM2INT(lda);
|
377
|
+
complex* B = NA_PTR_TYPE((nulin_check_narray(b),b), complex*);
|
378
|
+
integer LDB = NUM2INT(ldb);
|
379
|
+
complex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), complex*);
|
380
|
+
integer LWORK = NUM2INT(lwork);
|
381
|
+
integer INFO = NUM2INT(info);
|
382
|
+
cgels_(&TRANS,&M,&N,&NRHS,A,&LDA,B,&LDB,WORK,&LWORK,&INFO);
|
383
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
384
|
+
}
|
385
|
+
|
386
|
+
extern void dgelss_(integer* m,integer* n,integer* nrhs,doublereal* a,integer* lda,doublereal* b,integer* ldb,doublereal* s,doublereal* rcond,integer* rank,doublereal* work,integer* lwork,integer* info);
|
387
|
+
static VALUE nulin_dgelss(VALUE self,VALUE m,VALUE n,VALUE nrhs,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE s,VALUE rcond,VALUE rank,VALUE work,VALUE lwork,VALUE info)
|
388
|
+
{
|
389
|
+
integer M = NUM2INT(m);
|
390
|
+
integer N = NUM2INT(n);
|
391
|
+
integer NRHS = NUM2INT(nrhs);
|
392
|
+
doublereal* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublereal*);
|
393
|
+
integer LDA = NUM2INT(lda);
|
394
|
+
doublereal* B = NA_PTR_TYPE((nulin_check_narray(b),b), doublereal*);
|
395
|
+
integer LDB = NUM2INT(ldb);
|
396
|
+
doublereal* S = NA_PTR_TYPE((nulin_check_narray(s),s), doublereal*);
|
397
|
+
doublereal RCOND = NUM2DBL(rcond);
|
398
|
+
integer RANK = NUM2INT(rank);
|
399
|
+
doublereal* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublereal*);
|
400
|
+
integer LWORK = NUM2INT(lwork);
|
401
|
+
integer INFO = NUM2INT(info);
|
402
|
+
dgelss_(&M,&N,&NRHS,A,&LDA,B,&LDB,S,&RCOND,&RANK,WORK,&LWORK,&INFO);
|
403
|
+
return rb_ary_new3(2, INT2NUM(RANK),INT2NUM(INFO));
|
404
|
+
}
|
405
|
+
|
406
|
+
extern void sgelss_(integer* m,integer* n,integer* nrhs,real* a,integer* lda,real* b,integer* ldb,real* s,real* rcond,integer* rank,real* work,integer* lwork,integer* info);
|
407
|
+
static VALUE nulin_sgelss(VALUE self,VALUE m,VALUE n,VALUE nrhs,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE s,VALUE rcond,VALUE rank,VALUE work,VALUE lwork,VALUE info)
|
408
|
+
{
|
409
|
+
integer M = NUM2INT(m);
|
410
|
+
integer N = NUM2INT(n);
|
411
|
+
integer NRHS = NUM2INT(nrhs);
|
412
|
+
real* A = NA_PTR_TYPE((nulin_check_narray(a),a), real*);
|
413
|
+
integer LDA = NUM2INT(lda);
|
414
|
+
real* B = NA_PTR_TYPE((nulin_check_narray(b),b), real*);
|
415
|
+
integer LDB = NUM2INT(ldb);
|
416
|
+
real* S = NA_PTR_TYPE((nulin_check_narray(s),s), real*);
|
417
|
+
real RCOND = NUM2DBL(rcond);
|
418
|
+
integer RANK = NUM2INT(rank);
|
419
|
+
real* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), real*);
|
420
|
+
integer LWORK = NUM2INT(lwork);
|
421
|
+
integer INFO = NUM2INT(info);
|
422
|
+
sgelss_(&M,&N,&NRHS,A,&LDA,B,&LDB,S,&RCOND,&RANK,WORK,&LWORK,&INFO);
|
423
|
+
return rb_ary_new3(2, INT2NUM(RANK),INT2NUM(INFO));
|
424
|
+
}
|
425
|
+
|
426
|
+
extern void zgelss_(integer* m,integer* n,integer* nrhs,doublecomplex* a,integer* lda,doublecomplex* b,integer* ldb,doublereal* s,doublereal* rcond,integer* rank,doublecomplex* work,integer* lwork,doublereal* rwork,integer* info);
|
427
|
+
static VALUE nulin_zgelss(VALUE self,VALUE m,VALUE n,VALUE nrhs,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE s,VALUE rcond,VALUE rank,VALUE work,VALUE lwork,VALUE rwork,VALUE info)
|
428
|
+
{
|
429
|
+
integer M = NUM2INT(m);
|
430
|
+
integer N = NUM2INT(n);
|
431
|
+
integer NRHS = NUM2INT(nrhs);
|
432
|
+
doublecomplex* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublecomplex*);
|
433
|
+
integer LDA = NUM2INT(lda);
|
434
|
+
doublecomplex* B = NA_PTR_TYPE((nulin_check_narray(b),b), doublecomplex*);
|
435
|
+
integer LDB = NUM2INT(ldb);
|
436
|
+
doublereal* S = NA_PTR_TYPE((nulin_check_narray(s),s), doublereal*);
|
437
|
+
doublereal RCOND = NUM2DBL(rcond);
|
438
|
+
integer RANK = NUM2INT(rank);
|
439
|
+
doublecomplex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), doublecomplex*);
|
440
|
+
integer LWORK = NUM2INT(lwork);
|
441
|
+
doublereal* RWORK = NA_PTR_TYPE((nulin_check_narray(rwork),rwork), doublereal*);
|
442
|
+
integer INFO = NUM2INT(info);
|
443
|
+
zgelss_(&M,&N,&NRHS,A,&LDA,B,&LDB,S,&RCOND,&RANK,WORK,&LWORK,RWORK,&INFO);
|
444
|
+
return rb_ary_new3(2, INT2NUM(RANK),INT2NUM(INFO));
|
445
|
+
}
|
446
|
+
|
447
|
+
extern void cgelss_(integer* m,integer* n,integer* nrhs,complex* a,integer* lda,complex* b,integer* ldb,real* s,real* rcond,integer* rank,complex* work,integer* lwork,real* rwork,integer* info);
|
448
|
+
static VALUE nulin_cgelss(VALUE self,VALUE m,VALUE n,VALUE nrhs,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE s,VALUE rcond,VALUE rank,VALUE work,VALUE lwork,VALUE rwork,VALUE info)
|
449
|
+
{
|
450
|
+
integer M = NUM2INT(m);
|
451
|
+
integer N = NUM2INT(n);
|
452
|
+
integer NRHS = NUM2INT(nrhs);
|
453
|
+
complex* A = NA_PTR_TYPE((nulin_check_narray(a),a), complex*);
|
454
|
+
integer LDA = NUM2INT(lda);
|
455
|
+
complex* B = NA_PTR_TYPE((nulin_check_narray(b),b), complex*);
|
456
|
+
integer LDB = NUM2INT(ldb);
|
457
|
+
real* S = NA_PTR_TYPE((nulin_check_narray(s),s), real*);
|
458
|
+
real RCOND = NUM2DBL(rcond);
|
459
|
+
integer RANK = NUM2INT(rank);
|
460
|
+
complex* WORK = NA_PTR_TYPE((nulin_check_narray(work),work), complex*);
|
461
|
+
integer LWORK = NUM2INT(lwork);
|
462
|
+
real* RWORK = NA_PTR_TYPE((nulin_check_narray(rwork),rwork), real*);
|
463
|
+
integer INFO = NUM2INT(info);
|
464
|
+
cgelss_(&M,&N,&NRHS,A,&LDA,B,&LDB,S,&RCOND,&RANK,WORK,&LWORK,RWORK,&INFO);
|
465
|
+
return rb_ary_new3(2, INT2NUM(RANK),INT2NUM(INFO));
|
466
|
+
}
|
467
|
+
|
468
|
+
extern void dpotrf_(char* uplo,integer* n,doublereal* a,integer* lda,integer* info);
|
469
|
+
static VALUE nulin_dpotrf(VALUE self,VALUE uplo,VALUE n,VALUE a,VALUE lda,VALUE info)
|
470
|
+
{
|
471
|
+
char UPLO = StringValueCStr(uplo)[0];
|
472
|
+
integer N = NUM2INT(n);
|
473
|
+
doublereal* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublereal*);
|
474
|
+
integer LDA = NUM2INT(lda);
|
475
|
+
integer INFO = NUM2INT(info);
|
476
|
+
dpotrf_(&UPLO,&N,A,&LDA,&INFO);
|
477
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
478
|
+
}
|
479
|
+
|
480
|
+
extern void spotrf_(char* uplo,integer* n,real* a,integer* lda,integer* info);
|
481
|
+
static VALUE nulin_spotrf(VALUE self,VALUE uplo,VALUE n,VALUE a,VALUE lda,VALUE info)
|
482
|
+
{
|
483
|
+
char UPLO = StringValueCStr(uplo)[0];
|
484
|
+
integer N = NUM2INT(n);
|
485
|
+
real* A = NA_PTR_TYPE((nulin_check_narray(a),a), real*);
|
486
|
+
integer LDA = NUM2INT(lda);
|
487
|
+
integer INFO = NUM2INT(info);
|
488
|
+
spotrf_(&UPLO,&N,A,&LDA,&INFO);
|
489
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
490
|
+
}
|
491
|
+
|
492
|
+
extern void zpotrf_(char* uplo,integer* n,doublecomplex* a,integer* lda,integer* info);
|
493
|
+
static VALUE nulin_zpotrf(VALUE self,VALUE uplo,VALUE n,VALUE a,VALUE lda,VALUE info)
|
494
|
+
{
|
495
|
+
char UPLO = StringValueCStr(uplo)[0];
|
496
|
+
integer N = NUM2INT(n);
|
497
|
+
doublecomplex* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublecomplex*);
|
498
|
+
integer LDA = NUM2INT(lda);
|
499
|
+
integer INFO = NUM2INT(info);
|
500
|
+
zpotrf_(&UPLO,&N,A,&LDA,&INFO);
|
501
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
502
|
+
}
|
503
|
+
|
504
|
+
extern void cpotrf_(char* uplo,integer* n,complex* a,integer* lda,integer* info);
|
505
|
+
static VALUE nulin_cpotrf(VALUE self,VALUE uplo,VALUE n,VALUE a,VALUE lda,VALUE info)
|
506
|
+
{
|
507
|
+
char UPLO = StringValueCStr(uplo)[0];
|
508
|
+
integer N = NUM2INT(n);
|
509
|
+
complex* A = NA_PTR_TYPE((nulin_check_narray(a),a), complex*);
|
510
|
+
integer LDA = NUM2INT(lda);
|
511
|
+
integer INFO = NUM2INT(info);
|
512
|
+
cpotrf_(&UPLO,&N,A,&LDA,&INFO);
|
513
|
+
return rb_ary_new3(1, INT2NUM(INFO));
|
514
|
+
}
|
515
|
+
|
516
|
+
extern void dgemm_(char* transa,char* transb,integer* n,integer* m,integer* k,doublereal* alpha,doublereal* a,integer* lda,doublereal* b,integer* ldb,doublereal* beta,doublereal* c,integer* ldc);
|
517
|
+
static VALUE nulin_dgemm(VALUE self,VALUE transa,VALUE transb,VALUE n,VALUE m,VALUE k,VALUE alpha,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE beta,VALUE c,VALUE ldc)
|
518
|
+
{
|
519
|
+
char TRANSA = StringValueCStr(transa)[0];
|
520
|
+
char TRANSB = StringValueCStr(transb)[0];
|
521
|
+
integer N = NUM2INT(n);
|
522
|
+
integer M = NUM2INT(m);
|
523
|
+
integer K = NUM2INT(k);
|
524
|
+
doublereal ALPHA = NUM2DBL(alpha);
|
525
|
+
doublereal* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublereal*);
|
526
|
+
integer LDA = NUM2INT(lda);
|
527
|
+
doublereal* B = NA_PTR_TYPE((nulin_check_narray(b),b), doublereal*);
|
528
|
+
integer LDB = NUM2INT(ldb);
|
529
|
+
doublereal BETA = NUM2DBL(beta);
|
530
|
+
doublereal* C = NA_PTR_TYPE((nulin_check_narray(c),c), doublereal*);
|
531
|
+
integer LDC = NUM2INT(ldc);
|
532
|
+
dgemm_(&TRANSA,&TRANSB,&N,&M,&K,&ALPHA,A,&LDA,B,&LDB,&BETA,C,&LDC);
|
533
|
+
return Qnil;
|
534
|
+
}
|
535
|
+
|
536
|
+
extern void sgemm_(char* transa,char* transb,integer* n,integer* m,integer* k,real* alpha,real* a,integer* lda,real* b,integer* ldb,real* beta,real* c,integer* ldc);
|
537
|
+
static VALUE nulin_sgemm(VALUE self,VALUE transa,VALUE transb,VALUE n,VALUE m,VALUE k,VALUE alpha,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE beta,VALUE c,VALUE ldc)
|
538
|
+
{
|
539
|
+
char TRANSA = StringValueCStr(transa)[0];
|
540
|
+
char TRANSB = StringValueCStr(transb)[0];
|
541
|
+
integer N = NUM2INT(n);
|
542
|
+
integer M = NUM2INT(m);
|
543
|
+
integer K = NUM2INT(k);
|
544
|
+
real ALPHA = NUM2DBL(alpha);
|
545
|
+
real* A = NA_PTR_TYPE((nulin_check_narray(a),a), real*);
|
546
|
+
integer LDA = NUM2INT(lda);
|
547
|
+
real* B = NA_PTR_TYPE((nulin_check_narray(b),b), real*);
|
548
|
+
integer LDB = NUM2INT(ldb);
|
549
|
+
real BETA = NUM2DBL(beta);
|
550
|
+
real* C = NA_PTR_TYPE((nulin_check_narray(c),c), real*);
|
551
|
+
integer LDC = NUM2INT(ldc);
|
552
|
+
sgemm_(&TRANSA,&TRANSB,&N,&M,&K,&ALPHA,A,&LDA,B,&LDB,&BETA,C,&LDC);
|
553
|
+
return Qnil;
|
554
|
+
}
|
555
|
+
|
556
|
+
extern void zgemm_(char* transa,char* transb,integer* n,integer* m,integer* k,doublecomplex* alpha,doublecomplex* a,integer* lda,doublecomplex* b,integer* ldb,doublecomplex* beta,doublecomplex* c,integer* ldc);
|
557
|
+
static VALUE nulin_zgemm(VALUE self,VALUE transa,VALUE transb,VALUE n,VALUE m,VALUE k,VALUE alpha,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE beta,VALUE c,VALUE ldc)
|
558
|
+
{
|
559
|
+
char TRANSA = StringValueCStr(transa)[0];
|
560
|
+
char TRANSB = StringValueCStr(transb)[0];
|
561
|
+
integer N = NUM2INT(n);
|
562
|
+
integer M = NUM2INT(m);
|
563
|
+
integer K = NUM2INT(k);
|
564
|
+
doublecomplex ALPHA = COMPLEX_STRUCT(alpha);
|
565
|
+
doublecomplex* A = NA_PTR_TYPE((nulin_check_narray(a),a), doublecomplex*);
|
566
|
+
integer LDA = NUM2INT(lda);
|
567
|
+
doublecomplex* B = NA_PTR_TYPE((nulin_check_narray(b),b), doublecomplex*);
|
568
|
+
integer LDB = NUM2INT(ldb);
|
569
|
+
doublecomplex BETA = COMPLEX_STRUCT(beta);
|
570
|
+
doublecomplex* C = NA_PTR_TYPE((nulin_check_narray(c),c), doublecomplex*);
|
571
|
+
integer LDC = NUM2INT(ldc);
|
572
|
+
zgemm_(&TRANSA,&TRANSB,&N,&M,&K,&ALPHA,A,&LDA,B,&LDB,&BETA,C,&LDC);
|
573
|
+
return Qnil;
|
574
|
+
}
|
575
|
+
|
576
|
+
extern void cgemm_(char* transa,char* transb,integer* n,integer* m,integer* k,complex* alpha,complex* a,integer* lda,complex* b,integer* ldb,complex* beta,complex* c,integer* ldc);
|
577
|
+
static VALUE nulin_cgemm(VALUE self,VALUE transa,VALUE transb,VALUE n,VALUE m,VALUE k,VALUE alpha,VALUE a,VALUE lda,VALUE b,VALUE ldb,VALUE beta,VALUE c,VALUE ldc)
|
578
|
+
{
|
579
|
+
char TRANSA = StringValueCStr(transa)[0];
|
580
|
+
char TRANSB = StringValueCStr(transb)[0];
|
581
|
+
integer N = NUM2INT(n);
|
582
|
+
integer M = NUM2INT(m);
|
583
|
+
integer K = NUM2INT(k);
|
584
|
+
complex ALPHA = COMPLEX_STRUCT(alpha);
|
585
|
+
complex* A = NA_PTR_TYPE((nulin_check_narray(a),a), complex*);
|
586
|
+
integer LDA = NUM2INT(lda);
|
587
|
+
complex* B = NA_PTR_TYPE((nulin_check_narray(b),b), complex*);
|
588
|
+
integer LDB = NUM2INT(ldb);
|
589
|
+
complex BETA = COMPLEX_STRUCT(beta);
|
590
|
+
complex* C = NA_PTR_TYPE((nulin_check_narray(c),c), complex*);
|
591
|
+
integer LDC = NUM2INT(ldc);
|
592
|
+
cgemm_(&TRANSA,&TRANSB,&N,&M,&K,&ALPHA,A,&LDA,B,&LDB,&BETA,C,&LDC);
|
593
|
+
return Qnil;
|
594
|
+
}
|
595
|
+
|
596
|
+
|
597
|
+
void Init_nulin_native(void)
|
598
|
+
{
|
599
|
+
VALUE mNuLin = rb_define_module("NuLin");
|
600
|
+
VALUE mNuLin_Native = rb_define_module_under(mNuLin, "Native");
|
601
|
+
id_real = rb_intern("real");
|
602
|
+
id_imag = rb_intern("imag");
|
603
|
+
|
604
|
+
rb_define_module_function(mNuLin_Native, "dgeev", nulin_dgeev, 14);
|
605
|
+
rb_define_module_function(mNuLin_Native, "sgeev", nulin_sgeev, 14);
|
606
|
+
rb_define_module_function(mNuLin_Native, "zgeev", nulin_zgeev, 14);
|
607
|
+
rb_define_module_function(mNuLin_Native, "cgeev", nulin_cgeev, 14);
|
608
|
+
rb_define_module_function(mNuLin_Native, "dgesvd", nulin_dgesvd, 14);
|
609
|
+
rb_define_module_function(mNuLin_Native, "sgesvd", nulin_sgesvd, 14);
|
610
|
+
rb_define_module_function(mNuLin_Native, "zgesvd", nulin_zgesvd, 15);
|
611
|
+
rb_define_module_function(mNuLin_Native, "cgesvd", nulin_cgesvd, 15);
|
612
|
+
rb_define_module_function(mNuLin_Native, "dgelqf", nulin_dgelqf, 8);
|
613
|
+
rb_define_module_function(mNuLin_Native, "sgelqf", nulin_sgelqf, 8);
|
614
|
+
rb_define_module_function(mNuLin_Native, "zgelqf", nulin_zgelqf, 8);
|
615
|
+
rb_define_module_function(mNuLin_Native, "cgelqf", nulin_cgelqf, 8);
|
616
|
+
rb_define_module_function(mNuLin_Native, "dorglq", nulin_dorglq, 9);
|
617
|
+
rb_define_module_function(mNuLin_Native, "sorglq", nulin_sorglq, 9);
|
618
|
+
rb_define_module_function(mNuLin_Native, "zunglq", nulin_zunglq, 9);
|
619
|
+
rb_define_module_function(mNuLin_Native, "cunglq", nulin_cunglq, 9);
|
620
|
+
rb_define_module_function(mNuLin_Native, "dgels", nulin_dgels, 11);
|
621
|
+
rb_define_module_function(mNuLin_Native, "sgels", nulin_sgels, 11);
|
622
|
+
rb_define_module_function(mNuLin_Native, "zgels", nulin_zgels, 11);
|
623
|
+
rb_define_module_function(mNuLin_Native, "cgels", nulin_cgels, 11);
|
624
|
+
rb_define_module_function(mNuLin_Native, "dgelss", nulin_dgelss, 13);
|
625
|
+
rb_define_module_function(mNuLin_Native, "sgelss", nulin_sgelss, 13);
|
626
|
+
rb_define_module_function(mNuLin_Native, "zgelss", nulin_zgelss, 14);
|
627
|
+
rb_define_module_function(mNuLin_Native, "cgelss", nulin_cgelss, 14);
|
628
|
+
rb_define_module_function(mNuLin_Native, "dpotrf", nulin_dpotrf, 5);
|
629
|
+
rb_define_module_function(mNuLin_Native, "spotrf", nulin_spotrf, 5);
|
630
|
+
rb_define_module_function(mNuLin_Native, "zpotrf", nulin_zpotrf, 5);
|
631
|
+
rb_define_module_function(mNuLin_Native, "cpotrf", nulin_cpotrf, 5);
|
632
|
+
rb_define_module_function(mNuLin_Native, "dgemm", nulin_dgemm, 13);
|
633
|
+
rb_define_module_function(mNuLin_Native, "sgemm", nulin_sgemm, 13);
|
634
|
+
rb_define_module_function(mNuLin_Native, "zgemm", nulin_zgemm, 13);
|
635
|
+
rb_define_module_function(mNuLin_Native, "cgemm", nulin_cgemm, 13);
|
636
|
+
|
637
|
+
}
|