nmatrix-lapacke 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/nmatrix/data/data.h +7 -8
- data/ext/nmatrix/data/ruby_object.h +1 -4
- data/ext/nmatrix/math/asum.h +10 -31
- data/ext/nmatrix/math/cblas_templates_core.h +10 -10
- data/ext/nmatrix/math/getrf.h +2 -2
- data/ext/nmatrix/math/imax.h +12 -9
- data/ext/nmatrix/math/laswp.h +3 -3
- data/ext/nmatrix/math/long_dtype.h +16 -3
- data/ext/nmatrix/math/magnitude.h +54 -0
- data/ext/nmatrix/math/nrm2.h +19 -14
- data/ext/nmatrix/math/trsm.h +40 -36
- data/ext/nmatrix/math/util.h +14 -0
- data/ext/nmatrix/nmatrix.h +39 -1
- data/ext/nmatrix/storage/common.h +9 -3
- data/ext/nmatrix/storage/yale/class.h +1 -1
- data/ext/nmatrix_lapacke/extconf.rb +3 -136
- data/ext/nmatrix_lapacke/lapacke.cpp +104 -84
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgeqrf.c +77 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_cgeqrf_work.c +89 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_cunmqr.c +88 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_cunmqr_work.c +111 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgeqrf.c +75 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_dgeqrf_work.c +87 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_dormqr.c +86 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_dormqr_work.c +109 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgeqrf.c +75 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_sgeqrf_work.c +87 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_sormqr.c +86 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_sormqr_work.c +109 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgeqrf.c +77 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_zgeqrf_work.c +89 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_zunmqr.c +88 -0
- data/ext/nmatrix_lapacke/lapacke/src/lapacke_zunmqr_work.c +111 -0
- data/ext/nmatrix_lapacke/lapacke/utils/lapacke_c_nancheck.c +51 -0
- data/ext/nmatrix_lapacke/lapacke/utils/lapacke_d_nancheck.c +51 -0
- data/ext/nmatrix_lapacke/lapacke/utils/lapacke_s_nancheck.c +51 -0
- data/ext/nmatrix_lapacke/lapacke/utils/lapacke_z_nancheck.c +51 -0
- data/ext/nmatrix_lapacke/math_lapacke.cpp +149 -17
- data/ext/nmatrix_lapacke/math_lapacke/lapacke_templates.h +76 -0
- data/lib/nmatrix/lapacke.rb +118 -0
- data/spec/00_nmatrix_spec.rb +50 -1
- data/spec/02_slice_spec.rb +21 -21
- data/spec/blas_spec.rb +25 -3
- data/spec/math_spec.rb +233 -5
- data/spec/plugins/lapacke/lapacke_spec.rb +187 -0
- data/spec/shortcuts_spec.rb +145 -5
- data/spec/spec_helper.rb +24 -1
- metadata +38 -8
@@ -0,0 +1,88 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
Copyright (c) 2014, Intel Corp.
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright notice,
|
9
|
+
this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of Intel Corporation nor the names of its contributors
|
14
|
+
may be used to endorse or promote products derived from this software
|
15
|
+
without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
21
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
22
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
27
|
+
THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
*****************************************************************************
|
29
|
+
* Contents: Native high-level C interface to LAPACK function zunmqr
|
30
|
+
* Author: Intel Corporation
|
31
|
+
* Generated November 2015
|
32
|
+
*****************************************************************************/
|
33
|
+
|
34
|
+
#include "lapacke_utils.h"
|
35
|
+
|
36
|
+
lapack_int LAPACKE_zunmqr( int matrix_layout, char side, char trans,
|
37
|
+
lapack_int m, lapack_int n, lapack_int k,
|
38
|
+
const lapack_complex_double* a, lapack_int lda,
|
39
|
+
const lapack_complex_double* tau,
|
40
|
+
lapack_complex_double* c, lapack_int ldc )
|
41
|
+
{
|
42
|
+
lapack_int info = 0;
|
43
|
+
lapack_int lwork = -1;
|
44
|
+
lapack_complex_double* work = NULL;
|
45
|
+
lapack_complex_double work_query;
|
46
|
+
lapack_int r;
|
47
|
+
if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) {
|
48
|
+
LAPACKE_xerbla( "LAPACKE_zunmqr", -1 );
|
49
|
+
return -1;
|
50
|
+
}
|
51
|
+
#ifndef LAPACK_DISABLE_NAN_CHECK
|
52
|
+
/* Optionally check input matrices for NaNs */
|
53
|
+
r = LAPACKE_lsame( side, 'l' ) ? m : n;
|
54
|
+
if( LAPACKE_zge_nancheck( matrix_layout, r, k, a, lda ) ) {
|
55
|
+
return -7;
|
56
|
+
}
|
57
|
+
if( LAPACKE_zge_nancheck( matrix_layout, m, n, c, ldc ) ) {
|
58
|
+
return -10;
|
59
|
+
}
|
60
|
+
if( LAPACKE_z_nancheck( k, tau, 1 ) ) {
|
61
|
+
return -9;
|
62
|
+
}
|
63
|
+
#endif
|
64
|
+
/* Query optimal working array(s) size */
|
65
|
+
info = LAPACKE_zunmqr_work( matrix_layout, side, trans, m, n, k, a, lda, tau,
|
66
|
+
c, ldc, &work_query, lwork );
|
67
|
+
if( info != 0 ) {
|
68
|
+
goto exit_level_0;
|
69
|
+
}
|
70
|
+
lwork = LAPACK_Z2INT( work_query );
|
71
|
+
/* Allocate memory for work arrays */
|
72
|
+
work = (lapack_complex_double*)
|
73
|
+
LAPACKE_malloc( sizeof(lapack_complex_double) * lwork );
|
74
|
+
if( work == NULL ) {
|
75
|
+
info = LAPACK_WORK_MEMORY_ERROR;
|
76
|
+
goto exit_level_0;
|
77
|
+
}
|
78
|
+
/* Call middle-level interface */
|
79
|
+
info = LAPACKE_zunmqr_work( matrix_layout, side, trans, m, n, k, a, lda, tau,
|
80
|
+
c, ldc, work, lwork );
|
81
|
+
/* Release memory and exit */
|
82
|
+
LAPACKE_free( work );
|
83
|
+
exit_level_0:
|
84
|
+
if( info == LAPACK_WORK_MEMORY_ERROR ) {
|
85
|
+
LAPACKE_xerbla( "LAPACKE_zunmqr", info );
|
86
|
+
}
|
87
|
+
return info;
|
88
|
+
}
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
Copyright (c) 2014, Intel Corp.
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright notice,
|
9
|
+
this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of Intel Corporation nor the names of its contributors
|
14
|
+
may be used to endorse or promote products derived from this software
|
15
|
+
without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
21
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
22
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
27
|
+
THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
*****************************************************************************
|
29
|
+
* Contents: Native middle-level C interface to LAPACK function zunmqr
|
30
|
+
* Author: Intel Corporation
|
31
|
+
* Generated November 2015
|
32
|
+
*****************************************************************************/
|
33
|
+
|
34
|
+
#include "lapacke_utils.h"
|
35
|
+
|
36
|
+
lapack_int LAPACKE_zunmqr_work( int matrix_layout, char side, char trans,
|
37
|
+
lapack_int m, lapack_int n, lapack_int k,
|
38
|
+
const lapack_complex_double* a, lapack_int lda,
|
39
|
+
const lapack_complex_double* tau,
|
40
|
+
lapack_complex_double* c, lapack_int ldc,
|
41
|
+
lapack_complex_double* work, lapack_int lwork )
|
42
|
+
{
|
43
|
+
lapack_int info = 0;
|
44
|
+
if( matrix_layout == LAPACK_COL_MAJOR ) {
|
45
|
+
/* Call LAPACK function and adjust info */
|
46
|
+
LAPACK_zunmqr( &side, &trans, &m, &n, &k, a, &lda, tau, c, &ldc, work,
|
47
|
+
&lwork, &info );
|
48
|
+
if( info < 0 ) {
|
49
|
+
info = info - 1;
|
50
|
+
}
|
51
|
+
} else if( matrix_layout == LAPACK_ROW_MAJOR ) {
|
52
|
+
lapack_int r = LAPACKE_lsame( side, 'l' ) ? m : n;
|
53
|
+
lapack_int lda_t = MAX(1,r);
|
54
|
+
lapack_int ldc_t = MAX(1,m);
|
55
|
+
lapack_complex_double* a_t = NULL;
|
56
|
+
lapack_complex_double* c_t = NULL;
|
57
|
+
/* Check leading dimension(s) */
|
58
|
+
if( lda < k ) {
|
59
|
+
info = -8;
|
60
|
+
LAPACKE_xerbla( "LAPACKE_zunmqr_work", info );
|
61
|
+
return info;
|
62
|
+
}
|
63
|
+
if( ldc < n ) {
|
64
|
+
info = -11;
|
65
|
+
LAPACKE_xerbla( "LAPACKE_zunmqr_work", info );
|
66
|
+
return info;
|
67
|
+
}
|
68
|
+
/* Query optimal working array(s) size if requested */
|
69
|
+
if( lwork == -1 ) {
|
70
|
+
LAPACK_zunmqr( &side, &trans, &m, &n, &k, a, &lda_t, tau, c, &ldc_t,
|
71
|
+
work, &lwork, &info );
|
72
|
+
return (info < 0) ? (info - 1) : info;
|
73
|
+
}
|
74
|
+
/* Allocate memory for temporary array(s) */
|
75
|
+
a_t = (lapack_complex_double*)
|
76
|
+
LAPACKE_malloc( sizeof(lapack_complex_double) * lda_t * MAX(1,k) );
|
77
|
+
if( a_t == NULL ) {
|
78
|
+
info = LAPACK_TRANSPOSE_MEMORY_ERROR;
|
79
|
+
goto exit_level_0;
|
80
|
+
}
|
81
|
+
c_t = (lapack_complex_double*)
|
82
|
+
LAPACKE_malloc( sizeof(lapack_complex_double) * ldc_t * MAX(1,n) );
|
83
|
+
if( c_t == NULL ) {
|
84
|
+
info = LAPACK_TRANSPOSE_MEMORY_ERROR;
|
85
|
+
goto exit_level_1;
|
86
|
+
}
|
87
|
+
/* Transpose input matrices */
|
88
|
+
LAPACKE_zge_trans( matrix_layout, r, k, a, lda, a_t, lda_t );
|
89
|
+
LAPACKE_zge_trans( matrix_layout, m, n, c, ldc, c_t, ldc_t );
|
90
|
+
/* Call LAPACK function and adjust info */
|
91
|
+
LAPACK_zunmqr( &side, &trans, &m, &n, &k, a_t, &lda_t, tau, c_t, &ldc_t,
|
92
|
+
work, &lwork, &info );
|
93
|
+
if( info < 0 ) {
|
94
|
+
info = info - 1;
|
95
|
+
}
|
96
|
+
/* Transpose output matrices */
|
97
|
+
LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, c_t, ldc_t, c, ldc );
|
98
|
+
/* Release memory and exit */
|
99
|
+
LAPACKE_free( c_t );
|
100
|
+
exit_level_1:
|
101
|
+
LAPACKE_free( a_t );
|
102
|
+
exit_level_0:
|
103
|
+
if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
|
104
|
+
LAPACKE_xerbla( "LAPACKE_zunmqr_work", info );
|
105
|
+
}
|
106
|
+
} else {
|
107
|
+
info = -1;
|
108
|
+
LAPACKE_xerbla( "LAPACKE_zunmqr_work", info );
|
109
|
+
}
|
110
|
+
return info;
|
111
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
Copyright (c) 2010, Intel Corp.
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright notice,
|
9
|
+
this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of Intel Corporation nor the names of its contributors
|
14
|
+
may be used to endorse or promote products derived from this software
|
15
|
+
without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
21
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
22
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
27
|
+
THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
******************************************************************************
|
29
|
+
* Contents: Native C interface to LAPACK utility function
|
30
|
+
* Author: Intel Corporation
|
31
|
+
* Created in February, 2010
|
32
|
+
*****************************************************************************/
|
33
|
+
#include "lapacke_utils.h"
|
34
|
+
|
35
|
+
/* Check a vector for NaN entries. */
|
36
|
+
|
37
|
+
lapack_logical LAPACKE_c_nancheck( lapack_int n,
|
38
|
+
const lapack_complex_float *x,
|
39
|
+
lapack_int incx )
|
40
|
+
{
|
41
|
+
lapack_int i, inc;
|
42
|
+
|
43
|
+
if( incx == 0 ) return (lapack_logical) LAPACK_CISNAN( x[0] );
|
44
|
+
inc = ( incx > 0 ) ? incx : -incx ;
|
45
|
+
|
46
|
+
for( i = 0; i < n*inc; i+=inc ) {
|
47
|
+
if( LAPACK_CISNAN( x[i] ) )
|
48
|
+
return (lapack_logical) 1;
|
49
|
+
}
|
50
|
+
return (lapack_logical) 0;
|
51
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
Copyright (c) 2010, Intel Corp.
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright notice,
|
9
|
+
this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of Intel Corporation nor the names of its contributors
|
14
|
+
may be used to endorse or promote products derived from this software
|
15
|
+
without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
21
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
22
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
27
|
+
THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
******************************************************************************
|
29
|
+
* Contents: Native C interface to LAPACK utility function
|
30
|
+
* Author: Intel Corporation
|
31
|
+
* Created in February, 2010
|
32
|
+
*****************************************************************************/
|
33
|
+
#include "lapacke_utils.h"
|
34
|
+
|
35
|
+
/* Check a vector for NaN entries. */
|
36
|
+
|
37
|
+
lapack_logical LAPACKE_d_nancheck( lapack_int n,
|
38
|
+
const double *x,
|
39
|
+
lapack_int incx )
|
40
|
+
{
|
41
|
+
lapack_int i, inc;
|
42
|
+
|
43
|
+
if( incx == 0 ) return (lapack_logical) LAPACK_DISNAN( x[0] );
|
44
|
+
inc = ( incx > 0 ) ? incx : -incx ;
|
45
|
+
|
46
|
+
for( i = 0; i < n*inc; i+=inc ) {
|
47
|
+
if( LAPACK_DISNAN( x[i] ) )
|
48
|
+
return (lapack_logical) 1;
|
49
|
+
}
|
50
|
+
return (lapack_logical) 0;
|
51
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
Copyright (c) 2010, Intel Corp.
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright notice,
|
9
|
+
this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of Intel Corporation nor the names of its contributors
|
14
|
+
may be used to endorse or promote products derived from this software
|
15
|
+
without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
21
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
22
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
27
|
+
THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
******************************************************************************
|
29
|
+
* Contents: Native C interface to LAPACK utility function
|
30
|
+
* Author: Intel Corporation
|
31
|
+
* Created in February, 2010
|
32
|
+
*****************************************************************************/
|
33
|
+
#include "lapacke_utils.h"
|
34
|
+
|
35
|
+
/* Check a vector for NaN entries. */
|
36
|
+
|
37
|
+
lapack_logical LAPACKE_s_nancheck( lapack_int n,
|
38
|
+
const float *x,
|
39
|
+
lapack_int incx )
|
40
|
+
{
|
41
|
+
lapack_int i, inc;
|
42
|
+
|
43
|
+
if( incx == 0 ) return (lapack_logical) LAPACK_SISNAN( x[0] );
|
44
|
+
inc = ( incx > 0 ) ? incx : -incx ;
|
45
|
+
|
46
|
+
for( i = 0; i < n*inc; i+=inc ) {
|
47
|
+
if( LAPACK_SISNAN( x[i] ) )
|
48
|
+
return (lapack_logical) 1;
|
49
|
+
}
|
50
|
+
return (lapack_logical) 0;
|
51
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/*****************************************************************************
|
2
|
+
Copyright (c) 2010, Intel Corp.
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright notice,
|
9
|
+
this list of conditions and the following disclaimer.
|
10
|
+
* Redistributions in binary form must reproduce the above copyright
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
12
|
+
documentation and/or other materials provided with the distribution.
|
13
|
+
* Neither the name of Intel Corporation nor the names of its contributors
|
14
|
+
may be used to endorse or promote products derived from this software
|
15
|
+
without specific prior written permission.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
21
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
22
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
27
|
+
THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
******************************************************************************
|
29
|
+
* Contents: Native C interface to LAPACK utility function
|
30
|
+
* Author: Intel Corporation
|
31
|
+
* Created in February, 2010
|
32
|
+
*****************************************************************************/
|
33
|
+
#include "lapacke_utils.h"
|
34
|
+
|
35
|
+
/* Check a vector for NaN entries. */
|
36
|
+
|
37
|
+
lapack_logical LAPACKE_z_nancheck( lapack_int n,
|
38
|
+
const lapack_complex_double *x,
|
39
|
+
lapack_int incx )
|
40
|
+
{
|
41
|
+
lapack_int i, inc;
|
42
|
+
|
43
|
+
if( incx == 0 ) return (lapack_logical) LAPACK_ZISNAN( x[0] );
|
44
|
+
inc = ( incx > 0 ) ? incx : -incx ;
|
45
|
+
|
46
|
+
for( i = 0; i < n*inc; i+=inc ) {
|
47
|
+
if( LAPACK_ZISNAN( x[i] ) )
|
48
|
+
return (lapack_logical) 1;
|
49
|
+
}
|
50
|
+
return (lapack_logical) 0;
|
51
|
+
}
|
@@ -77,6 +77,11 @@ extern "C" {
|
|
77
77
|
static VALUE nm_lapacke_lapacke_potrs(VALUE self, VALUE order, VALUE uplo, VALUE n, VALUE nrhs, VALUE a, VALUE lda, VALUE b, VALUE ldb);
|
78
78
|
static VALUE nm_lapacke_lapacke_potri(VALUE self, VALUE order, VALUE uplo, VALUE n, VALUE a, VALUE lda);
|
79
79
|
|
80
|
+
static VALUE nm_lapacke_lapacke_geqrf(VALUE self, VALUE order, VALUE m, VALUE n, VALUE a, VALUE lda, VALUE tau);
|
81
|
+
static VALUE nm_lapacke_lapacke_ormqr(VALUE self, VALUE order, VALUE side, VALUE trans, VALUE m, VALUE n, VALUE k, VALUE a, VALUE lda, VALUE tau, VALUE c, VALUE ldc);
|
82
|
+
static VALUE nm_lapacke_lapacke_unmqr(VALUE self, VALUE order, VALUE side, VALUE trans, VALUE m, VALUE n, VALUE k, VALUE a, VALUE lda, VALUE tau, VALUE c, VALUE ldc);
|
83
|
+
|
84
|
+
|
80
85
|
static VALUE nm_lapacke_lapacke_gesvd(VALUE self, VALUE order, VALUE jobu, VALUE jobvt, VALUE m, VALUE n, VALUE a, VALUE lda, VALUE s, VALUE u, VALUE ldu, VALUE vt, VALUE ldvt, VALUE superb);
|
81
86
|
static VALUE nm_lapacke_lapacke_gesdd(VALUE self, VALUE order, VALUE jobz, VALUE m, VALUE n, VALUE a, VALUE lda, VALUE s, VALUE u, VALUE ldu, VALUE vt, VALUE ldvt);
|
82
87
|
static VALUE nm_lapacke_lapacke_geev(VALUE self, VALUE order, VALUE jobvl, VALUE jobvr, VALUE n, VALUE a, VALUE lda, VALUE w, VALUE wi, VALUE vl, VALUE ldvl, VALUE vr, VALUE ldvr);
|
@@ -121,6 +126,10 @@ void nm_math_init_lapack() {
|
|
121
126
|
rb_define_singleton_method(cNMatrix_LAPACKE_LAPACK, "lapacke_potrs", (METHOD)nm_lapacke_lapacke_potrs, 8);
|
122
127
|
rb_define_singleton_method(cNMatrix_LAPACKE_LAPACK, "lapacke_potri", (METHOD)nm_lapacke_lapacke_potri, 5);
|
123
128
|
|
129
|
+
rb_define_singleton_method(cNMatrix_LAPACKE_LAPACK, "lapacke_geqrf", (METHOD)nm_lapacke_lapacke_geqrf, 6);
|
130
|
+
rb_define_singleton_method(cNMatrix_LAPACKE_LAPACK, "lapacke_ormqr", (METHOD)nm_lapacke_lapacke_ormqr, 11);
|
131
|
+
rb_define_singleton_method(cNMatrix_LAPACKE_LAPACK, "lapacke_unmqr", (METHOD)nm_lapacke_lapacke_unmqr, 11);
|
132
|
+
|
124
133
|
rb_define_singleton_method(cNMatrix_LAPACKE_LAPACK, "lapacke_gesvd", (METHOD)nm_lapacke_lapacke_gesvd, 13);
|
125
134
|
rb_define_singleton_method(cNMatrix_LAPACKE_LAPACK, "lapacke_gesdd", (METHOD)nm_lapacke_lapacke_gesdd, 11);
|
126
135
|
rb_define_singleton_method(cNMatrix_LAPACKE_LAPACK, "lapacke_geev", (METHOD)nm_lapacke_lapacke_geev, 12);
|
@@ -311,11 +320,11 @@ static VALUE nm_lapacke_cblas_nrm2(VALUE self, VALUE n, VALUE x, VALUE incx) {
|
|
311
320
|
|
312
321
|
static void (*ttable[nm::NUM_DTYPES])(const int N, const void* X, const int incX, void* sum) = {
|
313
322
|
NULL, NULL, NULL, NULL, NULL, // no help for integers
|
314
|
-
nm::math::lapacke::cblas_nrm2<float32_t
|
315
|
-
nm::math::lapacke::cblas_nrm2<float64_t
|
316
|
-
nm::math::lapacke::cblas_nrm2<
|
317
|
-
nm::math::lapacke::cblas_nrm2<
|
318
|
-
nm::math::lapacke::cblas_nrm2<nm::RubyObject
|
323
|
+
nm::math::lapacke::cblas_nrm2<float32_t>,
|
324
|
+
nm::math::lapacke::cblas_nrm2<float64_t>,
|
325
|
+
nm::math::lapacke::cblas_nrm2<nm::Complex64>,
|
326
|
+
nm::math::lapacke::cblas_nrm2<nm::Complex128>,
|
327
|
+
nm::math::lapacke::cblas_nrm2<nm::RubyObject>
|
319
328
|
};
|
320
329
|
|
321
330
|
nm::dtype_t dtype = NM_DTYPE(x);
|
@@ -360,16 +369,16 @@ static VALUE nm_lapacke_cblas_nrm2(VALUE self, VALUE n, VALUE x, VALUE incx) {
|
|
360
369
|
static VALUE nm_lapacke_cblas_asum(VALUE self, VALUE n, VALUE x, VALUE incx) {
|
361
370
|
|
362
371
|
static void (*ttable[nm::NUM_DTYPES])(const int N, const void* X, const int incX, void* sum) = {
|
363
|
-
nm::math::lapacke::cblas_asum<uint8_t
|
364
|
-
nm::math::lapacke::cblas_asum<int8_t
|
365
|
-
nm::math::lapacke::cblas_asum<int16_t
|
366
|
-
nm::math::lapacke::cblas_asum<int32_t
|
367
|
-
nm::math::lapacke::cblas_asum<int64_t
|
368
|
-
nm::math::lapacke::cblas_asum<float32_t
|
369
|
-
nm::math::lapacke::cblas_asum<float64_t
|
370
|
-
nm::math::lapacke::cblas_asum<
|
371
|
-
nm::math::lapacke::cblas_asum<
|
372
|
-
nm::math::lapacke::cblas_asum<nm::RubyObject
|
372
|
+
nm::math::lapacke::cblas_asum<uint8_t>,
|
373
|
+
nm::math::lapacke::cblas_asum<int8_t>,
|
374
|
+
nm::math::lapacke::cblas_asum<int16_t>,
|
375
|
+
nm::math::lapacke::cblas_asum<int32_t>,
|
376
|
+
nm::math::lapacke::cblas_asum<int64_t>,
|
377
|
+
nm::math::lapacke::cblas_asum<float32_t>,
|
378
|
+
nm::math::lapacke::cblas_asum<float64_t>,
|
379
|
+
nm::math::lapacke::cblas_asum<nm::Complex64>,
|
380
|
+
nm::math::lapacke::cblas_asum<nm::Complex128>,
|
381
|
+
nm::math::lapacke::cblas_asum<nm::RubyObject>
|
373
382
|
};
|
374
383
|
|
375
384
|
nm::dtype_t dtype = NM_DTYPE(x);
|
@@ -647,7 +656,7 @@ static VALUE nm_lapacke_lapacke_getri(VALUE self, VALUE order, VALUE n, VALUE a,
|
|
647
656
|
|
648
657
|
// Allocate the C version of the pivot index array
|
649
658
|
int* ipiv_;
|
650
|
-
if (
|
659
|
+
if (!RB_TYPE_P(ipiv, T_ARRAY)) {
|
651
660
|
rb_raise(rb_eArgError, "ipiv must be of type Array");
|
652
661
|
} else {
|
653
662
|
ipiv_ = NM_ALLOCA_N(int, RARRAY_LEN(ipiv));
|
@@ -739,7 +748,7 @@ static VALUE nm_lapacke_lapacke_getrs(VALUE self, VALUE order, VALUE trans, VALU
|
|
739
748
|
|
740
749
|
// Allocate the C version of the pivot index array
|
741
750
|
int* ipiv_;
|
742
|
-
if (
|
751
|
+
if (!RB_TYPE_P(ipiv, T_ARRAY)) {
|
743
752
|
rb_raise(rb_eArgError, "ipiv must be of type Array");
|
744
753
|
} else {
|
745
754
|
ipiv_ = NM_ALLOCA_N(int, RARRAY_LEN(ipiv));
|
@@ -963,5 +972,128 @@ static VALUE nm_lapacke_lapacke_geev(VALUE self, VALUE order, VALUE jobvl, VALUE
|
|
963
972
|
}
|
964
973
|
}
|
965
974
|
|
975
|
+
/*
|
976
|
+
* GEQRF calculates the QR factorization for an MxN real or complex matrix.
|
977
|
+
*
|
978
|
+
* The QR factorization is A = QR, where Q is orthogonal and R is Upper Triangular
|
979
|
+
* +A+ is overwritten with the elements of R and Q with Q being represented by the
|
980
|
+
* elements below A's diagonal and an array of scalar factors in the output NMatrix.
|
981
|
+
*
|
982
|
+
* The matrix Q is represented as a product of elementary reflectors
|
983
|
+
* Q = H(1) H(2) . . . H(k), where k = min(m,n).
|
984
|
+
*
|
985
|
+
* Each H(i) has the form
|
986
|
+
*
|
987
|
+
* H(i) = I - tau * v * v'
|
988
|
+
*
|
989
|
+
* http://www.netlib.org/lapack/explore-html/d3/d69/dgeqrf_8f.html
|
990
|
+
*/
|
991
|
+
|
992
|
+
static VALUE nm_lapacke_lapacke_geqrf(VALUE self, VALUE order, VALUE m, VALUE n, VALUE a, VALUE lda, VALUE tau) {
|
993
|
+
static int (*ttable[nm::NUM_DTYPES])(const enum CBLAS_ORDER order, const int m, const int n, void* a, const int lda, void* tau) = {
|
994
|
+
NULL, NULL, NULL, NULL, NULL,
|
995
|
+
nm::math::lapacke::lapacke_geqrf<float>,
|
996
|
+
nm::math::lapacke::lapacke_geqrf<double>,
|
997
|
+
nm::math::lapacke::lapacke_geqrf<nm::Complex64>,
|
998
|
+
nm::math::lapacke::lapacke_geqrf<nm::Complex128>,
|
999
|
+
NULL
|
1000
|
+
};
|
1001
|
+
|
1002
|
+
int M = FIX2INT(m),
|
1003
|
+
N = FIX2INT(n);
|
1004
|
+
|
1005
|
+
nm::dtype_t dtype = NM_DTYPE(a);
|
1006
|
+
|
1007
|
+
if (!ttable[dtype]) {
|
1008
|
+
rb_raise(nm_eDataTypeError, "this matrix operation is undefined for integer matrices");
|
1009
|
+
return Qfalse;
|
1010
|
+
} else {
|
1011
|
+
int info = ttable[dtype](blas_order_sym(order), M, N, NM_STORAGE_DENSE(a)->elements, FIX2INT(lda), NM_STORAGE_DENSE(tau)->elements);
|
1012
|
+
return INT2FIX(info);
|
1013
|
+
}
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
/* ORMQR calculates the orthogonal matrix Q from TAU and A after calling GEQRF on a real matrix
|
1017
|
+
*
|
1018
|
+
*
|
1019
|
+
* The matrix Q is represented as a product of elementary reflectors
|
1020
|
+
* Q = H(1) H(2) . . . H(k), where k = min(m,n).
|
1021
|
+
*
|
1022
|
+
* Each H(i) has the form
|
1023
|
+
*
|
1024
|
+
* H(i) = I - tau * v * v'
|
1025
|
+
*
|
1026
|
+
* v is contained in the matrix passed to GEQRF
|
1027
|
+
*
|
1028
|
+
* www.netlib.org/lapack/explore-html/da/d82/dormqr_8f.html
|
1029
|
+
*/
|
1030
|
+
|
1031
|
+
static VALUE nm_lapacke_lapacke_ormqr(VALUE self, VALUE order, VALUE side, VALUE trans, VALUE m, VALUE n, VALUE k, VALUE a, VALUE lda, VALUE tau, VALUE c, VALUE ldc) {
|
1032
|
+
static int (*ttable[nm::NUM_DTYPES])(const enum CBLAS_ORDER order, char side, char trans, const int m, const int n, const int k, void* a, const int lda, void* tau, void* c, const int ldc) = {
|
1033
|
+
NULL, NULL, NULL, NULL, NULL,
|
1034
|
+
nm::math::lapacke::lapacke_ormqr<float>,
|
1035
|
+
nm::math::lapacke::lapacke_ormqr<double>,
|
1036
|
+
NULL,NULL,NULL // no complex or Ruby objects
|
1037
|
+
};
|
1038
|
+
|
1039
|
+
int M = FIX2INT(m),
|
1040
|
+
N = FIX2INT(n),
|
1041
|
+
K = FIX2INT(k);
|
1042
|
+
|
1043
|
+
char SIDE = lapacke_side_sym(side),
|
1044
|
+
TRANS = lapacke_transpose_sym(trans);
|
1045
|
+
|
1046
|
+
nm::dtype_t dtype = NM_DTYPE(a);
|
1047
|
+
|
1048
|
+
|
1049
|
+
if (!ttable[dtype]) {
|
1050
|
+
rb_raise(nm_eDataTypeError, "this matrix operation is undefined for integer matrices");
|
1051
|
+
return Qfalse;
|
1052
|
+
} else {
|
1053
|
+
int info = ttable[dtype](blas_order_sym(order), SIDE, TRANS, M, N, K, NM_STORAGE_DENSE(a)->elements, FIX2INT(lda), NM_STORAGE_DENSE(tau)->elements, NM_STORAGE_DENSE(c)->elements, FIX2INT(ldc));
|
1054
|
+
return INT2FIX(info);
|
1055
|
+
}
|
1056
|
+
}
|
1057
|
+
|
1058
|
+
/* UNMQR calculates the orthogonal matrix Q from TAU and A after calling GEQRF on a complex matrix.
|
1059
|
+
*
|
1060
|
+
*
|
1061
|
+
* The matrix Q is represented as a product of elementary reflectors
|
1062
|
+
* Q = H(1) H(2) . . . H(k), where k = min(m,n).
|
1063
|
+
*
|
1064
|
+
* Each H(i) has the form
|
1065
|
+
*
|
1066
|
+
* H(i) = I - tau * v * v'
|
1067
|
+
*
|
1068
|
+
* v is contained in the matrix passed to GEQRF
|
1069
|
+
*
|
1070
|
+
* http://www.netlib.org/lapack/explore-html/d5/d65/zunmqr_8f.html
|
1071
|
+
*/
|
1072
|
+
|
1073
|
+
static VALUE nm_lapacke_lapacke_unmqr(VALUE self, VALUE order, VALUE side, VALUE trans, VALUE m, VALUE n, VALUE k, VALUE a, VALUE lda, VALUE tau, VALUE c, VALUE ldc) {
|
1074
|
+
static int (*ttable[nm::NUM_DTYPES])(const enum CBLAS_ORDER order, char side, char trans, const int m, const int n, const int k, void* a, const int lda, void* tau, void* c, const int ldc) = {
|
1075
|
+
NULL, NULL, NULL, NULL, NULL,NULL,NULL, // no non-complex ops
|
1076
|
+
nm::math::lapacke::lapacke_unmqr<nm::Complex64>,
|
1077
|
+
nm::math::lapacke::lapacke_unmqr<nm::Complex128>,
|
1078
|
+
NULL // no Ruby objects
|
1079
|
+
};
|
1080
|
+
|
1081
|
+
int M = FIX2INT(m),
|
1082
|
+
N = FIX2INT(n),
|
1083
|
+
K = FIX2INT(k);
|
1084
|
+
|
1085
|
+
char SIDE = lapacke_side_sym(side),
|
1086
|
+
TRANS = lapacke_transpose_sym(trans);
|
1087
|
+
|
1088
|
+
nm::dtype_t dtype = NM_DTYPE(a);
|
1089
|
+
|
1090
|
+
if (!ttable[dtype]) {
|
1091
|
+
rb_raise(nm_eDataTypeError, "this matrix operation is valid only for complex datatypes");
|
1092
|
+
return Qfalse;
|
1093
|
+
} else {
|
1094
|
+
int info = ttable[dtype](blas_order_sym(order), SIDE, TRANS, M, N, K, NM_STORAGE_DENSE(a)->elements, FIX2INT(lda), NM_STORAGE_DENSE(tau)->elements, NM_STORAGE_DENSE(c)->elements, FIX2INT(ldc));
|
1095
|
+
return INT2FIX(info);
|
1096
|
+
}
|
1097
|
+
}
|
966
1098
|
|
967
1099
|
}
|