Skip to content

Commit 0819b10

Browse files
Fabian PedregosaGaelVaroquaux
authored andcommitted
BUILD: add gemv cblas routine
1 parent 86e3616 commit 0819b10

File tree

4 files changed

+472
-0
lines changed

4 files changed

+472
-0
lines changed

sklearn/src/cblas/ATL_drefgemv.c

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/* ---------------------------------------------------------------------
2+
*
3+
* -- Automatically Tuned Linear Algebra Software (ATLAS)
4+
* (C) Copyright 2000 All Rights Reserved
5+
*
6+
* -- ATLAS routine -- Version 3.9.24 -- December 25, 2000
7+
*
8+
* Author : Antoine P. Petitet
9+
* Originally developed at the University of Tennessee,
10+
* Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA.
11+
*
12+
* ---------------------------------------------------------------------
13+
*
14+
* -- Copyright notice and Licensing terms:
15+
*
16+
* Redistribution and use in source and binary forms, with or without
17+
* modification, are permitted provided that the following conditions
18+
* are met:
19+
*
20+
* 1. Redistributions of source code must retain the above copyright
21+
* notice, this list of conditions and the following disclaimer.
22+
* 2. Redistributions in binary form must reproduce the above copyright
23+
* notice, this list of conditions, and the following disclaimer in
24+
* the documentation and/or other materials provided with the distri-
25+
* bution.
26+
* 3. The name of the University, the ATLAS group, or the names of its
27+
* contributors may not be used to endorse or promote products deri-
28+
* ved from this software without specific written permission.
29+
*
30+
* -- Disclaimer:
31+
*
32+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
36+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
37+
* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
38+
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
39+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO-
40+
* RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN-
41+
* CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
42+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43+
*
44+
* ---------------------------------------------------------------------
45+
*/
46+
/*
47+
* Include files
48+
*/
49+
#include "atlas_refmisc.h"
50+
#include "atlas_reflvl2.h"
51+
#include "atlas_reflevel2.h"
52+
53+
void ATL_drefgemv
54+
(
55+
const enum ATLAS_TRANS TRANS,
56+
const int M,
57+
const int N,
58+
const double ALPHA,
59+
const double * A,
60+
const int LDA,
61+
const double * X,
62+
const int INCX,
63+
const double BETA,
64+
double * Y,
65+
const int INCY
66+
)
67+
{
68+
/*
69+
* Purpose
70+
* =======
71+
*
72+
* ATL_drefgemv performs one of the matrix-vector operations
73+
*
74+
* y := alpha * op( A ) * x + beta * y,
75+
*
76+
* where op( X ) is one of
77+
*
78+
* op( X ) = X or op( X ) = X'.
79+
*
80+
* where alpha and beta are scalars, x and y are vectors and op( A ) is
81+
* an m by n matrix.
82+
*
83+
* Arguments
84+
* =========
85+
*
86+
* TRANS (input) const enum ATLAS_TRANS
87+
* On entry, TRANS specifies the operation to be performed as
88+
* follows:
89+
*
90+
* TRANS = AtlasNoTrans y := alpha*A *x + beta*y,
91+
*
92+
* TRANS = AtlasConj y := alpha*A *x + beta*y,
93+
*
94+
* TRANS = AtlasTrans y := alpha*A'*x + beta*y,
95+
*
96+
* TRANS = AtlasConjTrans y := alpha*A'*x + beta*y.
97+
*
98+
* Unchanged on exit.
99+
*
100+
* M (input) const int
101+
* On entry, M specifies the number of rows of the matrix A
102+
* when TRANS = AtlasNoTrans or TRANS = AtlasConj, and the num-
103+
* ber of columns of the matrix A otherwise. M must be at least
104+
* zero. Unchanged on exit.
105+
*
106+
* N (input) const int
107+
* On entry, N specifies the number of columns of the matrix A
108+
* when TRANS = AtlasNoTrans or TRANS = AtlasConj, and the num-
109+
* ber of rows of the matrix A otherwise. N must be at least ze-
110+
* ro. Unchanged on exit.
111+
*
112+
* ALPHA (input) const double
113+
* On entry, ALPHA specifies the scalar alpha. When ALPHA is
114+
* supplied as zero then A and X need not be set on input. Un-
115+
* changed on exit.
116+
*
117+
* A (input) const double *
118+
* On entry, A points to an array of size equal to or greater
119+
* than LDA * ka * sizeof( double ), where ka is n when
120+
* TRANS = AtlasNotrans or TRANS = AtlasConj, and m otherwise.
121+
* Before entry, when TRANS = AtlasNotrans or TRANS = AtlasConj,
122+
* the leading m by n part of the array A must contain the ma-
123+
* trix coefficients, and otherwise the leading n by m part of
124+
* the array A must contain the matrix coefficients. Unchanged
125+
* on exit.
126+
*
127+
* LDA (input) const int
128+
* On entry, LDA specifies the leading dimension of A as decla-
129+
* red in the calling (sub) program. LDA must be at least
130+
* MAX( 1, m ) when TRANS = AtlasNotrans or TRANS = AtlasConj,
131+
* and MAX( 1, n ) otherwise. Unchanged on exit.
132+
*
133+
* X (input) const double *
134+
* On entry, X points to the first entry to be accessed of an
135+
* incremented array of size equal to or greater than
136+
* ( 1 + ( n - 1 ) * abs( INCX ) ) * sizeof( double ),
137+
* that contains the vector x. Unchanged on exit.
138+
*
139+
* INCX (input) const int
140+
* On entry, INCX specifies the increment for the elements of X.
141+
* INCX must not be zero. Unchanged on exit.
142+
*
143+
* BETA (input) const double
144+
* On entry, BETA specifies the scalar beta. When BETA is
145+
* supplied as zero then Y need not be set on input. Unchanged
146+
* on exit.
147+
*
148+
* Y (input/output) double *
149+
* On entry, Y points to the first entry to be accessed of an
150+
* incremented array of size equal to or greater than
151+
* ( 1 + ( m - 1 ) * abs( INCY ) ) * sizeof( double ),
152+
* that contains the vector y. Before entry with BETA non-zero,
153+
* the incremented array Y must contain the vector y. On exit,
154+
* Y is overwritten by the updated vector y.
155+
*
156+
* INCY (input) const int
157+
* On entry, INCY specifies the increment for the elements of Y.
158+
* INCY must not be zero. Unchanged on exit.
159+
*
160+
* ---------------------------------------------------------------------
161+
*/
162+
/* ..
163+
* .. Executable Statements ..
164+
*
165+
*/
166+
if( ( M == 0 ) || ( N == 0 ) ||
167+
( ( ALPHA == ATL_dZERO ) && ( BETA == ATL_dONE ) ) ) return;
168+
169+
if( ALPHA == ATL_dZERO ) { Mdvscal( M, BETA, Y, INCY ); return; }
170+
171+
if( ( TRANS == AtlasNoTrans ) || ( TRANS == AtlasConj ) )
172+
{ ATL_drefgemvN( M, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY ); }
173+
else
174+
{ ATL_drefgemvT( M, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY ); }
175+
/*
176+
* End of ATL_drefgemv
177+
*/
178+
}

sklearn/src/cblas/ATL_drefgemvN.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* ---------------------------------------------------------------------
2+
*
3+
* -- Automatically Tuned Linear Algebra Software (ATLAS)
4+
* (C) Copyright 2000 All Rights Reserved
5+
*
6+
* -- ATLAS routine -- Version 3.9.24 -- December 25, 2000
7+
*
8+
* Author : Antoine P. Petitet
9+
* Originally developed at the University of Tennessee,
10+
* Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA.
11+
*
12+
* ---------------------------------------------------------------------
13+
*
14+
* -- Copyright notice and Licensing terms:
15+
*
16+
* Redistribution and use in source and binary forms, with or without
17+
* modification, are permitted provided that the following conditions
18+
* are met:
19+
*
20+
* 1. Redistributions of source code must retain the above copyright
21+
* notice, this list of conditions and the following disclaimer.
22+
* 2. Redistributions in binary form must reproduce the above copyright
23+
* notice, this list of conditions, and the following disclaimer in
24+
* the documentation and/or other materials provided with the distri-
25+
* bution.
26+
* 3. The name of the University, the ATLAS group, or the names of its
27+
* contributors may not be used to endorse or promote products deri-
28+
* ved from this software without specific written permission.
29+
*
30+
* -- Disclaimer:
31+
*
32+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
36+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
37+
* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
38+
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
39+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO-
40+
* RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN-
41+
* CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
42+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43+
*
44+
* ---------------------------------------------------------------------
45+
*/
46+
/*
47+
* Include files
48+
*/
49+
#include "atlas_refmisc.h"
50+
#include "atlas_reflvl2.h"
51+
#include "atlas_reflevel2.h"
52+
53+
void ATL_drefgemvN
54+
(
55+
const int M,
56+
const int N,
57+
const double ALPHA,
58+
const double * A,
59+
const int LDA,
60+
const double * X,
61+
const int INCX,
62+
const double BETA,
63+
double * Y,
64+
const int INCY
65+
)
66+
{
67+
/*
68+
* Purpose
69+
* =======
70+
*
71+
* ATL_drefgemvN( ... ) <=> ATL_drefgemv( AtlasNoTrans, ... )
72+
*
73+
* See ATL_drefgemv for details.
74+
*
75+
* ---------------------------------------------------------------------
76+
*/
77+
/*
78+
* .. Local Variables ..
79+
*/
80+
register double t0;
81+
int i, iaij, iy, j, jaj, jx;
82+
/* ..
83+
* .. Executable Statements ..
84+
*
85+
*/
86+
Mdvscal( M, BETA, Y, INCY );
87+
for( j = 0, jaj = 0, jx = 0; j < N; j++, jaj += LDA, jx += INCX )
88+
{
89+
t0 = ALPHA * X[jx];
90+
for( i = 0, iaij = jaj, iy = 0; i < M; i++, iaij += 1, iy += INCY )
91+
{ Y[iy] += A[iaij] * t0; }
92+
}
93+
/*
94+
* End of ATL_drefgemvN
95+
*/
96+
}

sklearn/src/cblas/ATL_drefgemvT.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* ---------------------------------------------------------------------
2+
*
3+
* -- Automatically Tuned Linear Algebra Software (ATLAS)
4+
* (C) Copyright 2000 All Rights Reserved
5+
*
6+
* -- ATLAS routine -- Version 3.9.24 -- December 25, 2000
7+
*
8+
* Author : Antoine P. Petitet
9+
* Originally developed at the University of Tennessee,
10+
* Innovative Computing Laboratory, Knoxville TN, 37996-1301, USA.
11+
*
12+
* ---------------------------------------------------------------------
13+
*
14+
* -- Copyright notice and Licensing terms:
15+
*
16+
* Redistribution and use in source and binary forms, with or without
17+
* modification, are permitted provided that the following conditions
18+
* are met:
19+
*
20+
* 1. Redistributions of source code must retain the above copyright
21+
* notice, this list of conditions and the following disclaimer.
22+
* 2. Redistributions in binary form must reproduce the above copyright
23+
* notice, this list of conditions, and the following disclaimer in
24+
* the documentation and/or other materials provided with the distri-
25+
* bution.
26+
* 3. The name of the University, the ATLAS group, or the names of its
27+
* contributors may not be used to endorse or promote products deri-
28+
* ved from this software without specific written permission.
29+
*
30+
* -- Disclaimer:
31+
*
32+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
36+
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
37+
* CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
38+
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
39+
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO-
40+
* RY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (IN-
41+
* CLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
42+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43+
*
44+
* ---------------------------------------------------------------------
45+
*/
46+
/*
47+
* Include files
48+
*/
49+
#include "atlas_refmisc.h"
50+
#include "atlas_reflvl2.h"
51+
#include "atlas_reflevel2.h"
52+
53+
void ATL_drefgemvT
54+
(
55+
const int M,
56+
const int N,
57+
const double ALPHA,
58+
const double * A,
59+
const int LDA,
60+
const double * X,
61+
const int INCX,
62+
const double BETA,
63+
double * Y,
64+
const int INCY
65+
)
66+
{
67+
/*
68+
* Purpose
69+
* =======
70+
*
71+
* ATL_drefgemvT( ... ) <=> ATL_drefgemv( AtlasTrans, ... )
72+
*
73+
* See ATL_drefgemv for details.
74+
*
75+
* ---------------------------------------------------------------------
76+
*/
77+
/*
78+
* .. Local Variables ..
79+
*/
80+
register double t0;
81+
int i, iaij, ix, j, jaj, jy;
82+
/* ..
83+
* .. Executable Statements ..
84+
*
85+
*/
86+
for( j = 0, jaj = 0, jy = 0; j < M; j++, jaj += LDA, jy += INCY )
87+
{
88+
t0 = ATL_dZERO;
89+
for( i = 0, iaij = jaj, ix = 0; i < N; i++, iaij += 1, ix += INCX )
90+
{ t0 += A[iaij] * X[ix]; }
91+
Mdelscal( BETA, Y[jy] ); Y[jy] += ALPHA * t0;
92+
}
93+
/*
94+
* End of ATL_drefgemvT
95+
*/
96+
}

0 commit comments

Comments
 (0)