~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/sparse/SuperLU/SRC/zsp_blas2.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * -- SuperLU routine (version 3.0) --
 
4
 * Univ. of California Berkeley, Xerox Palo Alto Research Center,
 
5
 * and Lawrence Berkeley National Lab.
 
6
 * October 15, 2003
 
7
 *
 
8
 */
 
9
/*
 
10
 * File name:           zsp_blas2.c
 
11
 * Purpose:             Sparse BLAS 2, using some dense BLAS 2 operations.
 
12
 */
 
13
 
 
14
#include "zsp_defs.h"
 
15
 
 
16
/* 
 
17
 * Function prototypes 
 
18
 */
 
19
void zusolve(int, int, doublecomplex*, doublecomplex*);
 
20
void zlsolve(int, int, doublecomplex*, doublecomplex*);
 
21
void zmatvec(int, int, int, doublecomplex*, doublecomplex*, doublecomplex*);
 
22
 
 
23
 
 
24
int
 
25
sp_ztrsv(char *uplo, char *trans, char *diag, SuperMatrix *L, 
 
26
         SuperMatrix *U, doublecomplex *x, SuperLUStat_t *stat, int *info)
 
27
{
 
28
/*
 
29
 *   Purpose
 
30
 *   =======
 
31
 *
 
32
 *   sp_ztrsv() solves one of the systems of equations   
 
33
 *       A*x = b,   or   A'*x = b,
 
34
 *   where b and x are n element vectors and A is a sparse unit , or   
 
35
 *   non-unit, upper or lower triangular matrix.   
 
36
 *   No test for singularity or near-singularity is included in this   
 
37
 *   routine. Such tests must be performed before calling this routine.   
 
38
 *
 
39
 *   Parameters   
 
40
 *   ==========   
 
41
 *
 
42
 *   uplo   - (input) char*
 
43
 *            On entry, uplo specifies whether the matrix is an upper or   
 
44
 *             lower triangular matrix as follows:   
 
45
 *                uplo = 'U' or 'u'   A is an upper triangular matrix.   
 
46
 *                uplo = 'L' or 'l'   A is a lower triangular matrix.   
 
47
 *
 
48
 *   trans  - (input) char*
 
49
 *             On entry, trans specifies the equations to be solved as   
 
50
 *             follows:   
 
51
 *                trans = 'N' or 'n'   A*x = b.   
 
52
 *                trans = 'T' or 't'   A'*x = b.   
 
53
 *                trans = 'C' or 'c'   A'*x = b.   
 
54
 *
 
55
 *   diag   - (input) char*
 
56
 *             On entry, diag specifies whether or not A is unit   
 
57
 *             triangular as follows:   
 
58
 *                diag = 'U' or 'u'   A is assumed to be unit triangular.   
 
59
 *                diag = 'N' or 'n'   A is not assumed to be unit   
 
60
 *                                    triangular.   
 
61
 *           
 
62
 *   L       - (input) SuperMatrix*
 
63
 *             The factor L from the factorization Pr*A*Pc=L*U. Use
 
64
 *             compressed row subscripts storage for supernodes,
 
65
 *             i.e., L has types: Stype = SC, Dtype = SLU_Z, Mtype = TRLU.
 
66
 *
 
67
 *   U       - (input) SuperMatrix*
 
68
 *              The factor U from the factorization Pr*A*Pc=L*U.
 
69
 *              U has types: Stype = NC, Dtype = SLU_Z, Mtype = TRU.
 
70
 *    
 
71
 *   x       - (input/output) doublecomplex*
 
72
 *             Before entry, the incremented array X must contain the n   
 
73
 *             element right-hand side vector b. On exit, X is overwritten 
 
74
 *             with the solution vector x.
 
75
 *
 
76
 *   info    - (output) int*
 
77
 *             If *info = -i, the i-th argument had an illegal value.
 
78
 *
 
79
 */
 
80
#ifdef _CRAY
 
81
    _fcd ftcs1 = _cptofcd("L", strlen("L")),
 
82
         ftcs2 = _cptofcd("N", strlen("N")),
 
83
         ftcs3 = _cptofcd("U", strlen("U"));
 
84
#endif
 
85
    SCformat *Lstore;
 
86
    NCformat *Ustore;
 
87
    doublecomplex   *Lval, *Uval;
 
88
    doublecomplex temp;
 
89
    int incx = 1, incy = 1;
 
90
    doublecomplex alpha = {1.0, 0.0}, beta = {1.0, 0.0};
 
91
    doublecomplex comp_zero = {0.0, 0.0};
 
92
    int nrow;
 
93
    int fsupc, nsupr, nsupc, luptr, istart, irow;
 
94
    int i, k, iptr, jcol;
 
95
    doublecomplex *work;
 
96
    flops_t solve_ops;
 
97
 
 
98
    /* Test the input parameters */
 
99
    *info = 0;
 
100
    if ( !lsame_(uplo,"L") && !lsame_(uplo, "U") ) *info = -1;
 
101
    else if ( !lsame_(trans, "N") && !lsame_(trans, "T") && !lsame_(trans,"C") ) *info = -2;
 
102
    else if ( !lsame_(diag, "U") && !lsame_(diag, "N") ) *info = -3;
 
103
    else if ( L->nrow != L->ncol || L->nrow < 0 ) *info = -4;
 
104
    else if ( U->nrow != U->ncol || U->nrow < 0 ) *info = -5;
 
105
    if ( *info ) {
 
106
        i = -(*info);
 
107
        xerbla_("sp_ztrsv", &i);
 
108
        return 0;
 
109
    }
 
110
 
 
111
    Lstore = L->Store;
 
112
    Lval = Lstore->nzval;
 
113
    Ustore = U->Store;
 
114
    Uval = Ustore->nzval;
 
115
    solve_ops = 0;
 
116
 
 
117
    if ( !(work = doublecomplexCalloc(L->nrow)) )
 
118
        ABORT("Malloc fails for work in sp_ztrsv().");
 
119
    
 
120
    if ( lsame_(trans, "N") ) { /* Form x := inv(A)*x. */
 
121
        
 
122
        if ( lsame_(uplo, "L") ) {
 
123
            /* Form x := inv(L)*x */
 
124
            if ( L->nrow == 0 ) return 0; /* Quick return */
 
125
            
 
126
            for (k = 0; k <= Lstore->nsuper; k++) {
 
127
                fsupc = L_FST_SUPC(k);
 
128
                istart = L_SUB_START(fsupc);
 
129
                nsupr = L_SUB_START(fsupc+1) - istart;
 
130
                nsupc = L_FST_SUPC(k+1) - fsupc;
 
131
                luptr = L_NZ_START(fsupc);
 
132
                nrow = nsupr - nsupc;
 
133
 
 
134
                solve_ops += 4 * nsupc * (nsupc - 1);
 
135
                solve_ops += 8 * nrow * nsupc;
 
136
 
 
137
                if ( nsupc == 1 ) {
 
138
                    for (iptr=istart+1; iptr < L_SUB_START(fsupc+1); ++iptr) {
 
139
                        irow = L_SUB(iptr);
 
140
                        ++luptr;
 
141
                        zz_mult(&comp_zero, &x[fsupc], &Lval[luptr]);
 
142
                        z_sub(&x[irow], &x[irow], &comp_zero);
 
143
                    }
 
144
                } else {
 
145
#ifdef USE_VENDOR_BLAS
 
146
#ifdef _CRAY
 
147
                    CTRSV(ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
 
148
                        &x[fsupc], &incx);
 
149
                
 
150
                    CGEMV(ftcs2, &nrow, &nsupc, &alpha, &Lval[luptr+nsupc], 
 
151
                        &nsupr, &x[fsupc], &incx, &beta, &work[0], &incy);
 
152
#else
 
153
                    ztrsv_("L", "N", "U", &nsupc, &Lval[luptr], &nsupr,
 
154
                        &x[fsupc], &incx);
 
155
                
 
156
                    zgemv_("N", &nrow, &nsupc, &alpha, &Lval[luptr+nsupc], 
 
157
                        &nsupr, &x[fsupc], &incx, &beta, &work[0], &incy);
 
158
#endif
 
159
#else
 
160
                    zlsolve ( nsupr, nsupc, &Lval[luptr], &x[fsupc]);
 
161
                
 
162
                    zmatvec ( nsupr, nsupr-nsupc, nsupc, &Lval[luptr+nsupc],
 
163
                             &x[fsupc], &work[0] );
 
164
#endif          
 
165
                
 
166
                    iptr = istart + nsupc;
 
167
                    for (i = 0; i < nrow; ++i, ++iptr) {
 
168
                        irow = L_SUB(iptr);
 
169
                        z_sub(&x[irow], &x[irow], &work[i]); /* Scatter */
 
170
                        work[i] = comp_zero;
 
171
 
 
172
                    }
 
173
                }
 
174
            } /* for k ... */
 
175
            
 
176
        } else {
 
177
            /* Form x := inv(U)*x */
 
178
            
 
179
            if ( U->nrow == 0 ) return 0; /* Quick return */
 
180
            
 
181
            for (k = Lstore->nsuper; k >= 0; k--) {
 
182
                fsupc = L_FST_SUPC(k);
 
183
                nsupr = L_SUB_START(fsupc+1) - L_SUB_START(fsupc);
 
184
                nsupc = L_FST_SUPC(k+1) - fsupc;
 
185
                luptr = L_NZ_START(fsupc);
 
186
                
 
187
                solve_ops += 4 * nsupc * (nsupc + 1);
 
188
 
 
189
                if ( nsupc == 1 ) {
 
190
                    z_div(&x[fsupc], &x[fsupc], &Lval[luptr]);
 
191
                    for (i = U_NZ_START(fsupc); i < U_NZ_START(fsupc+1); ++i) {
 
192
                        irow = U_SUB(i);
 
193
                        zz_mult(&comp_zero, &x[fsupc], &Uval[i]);
 
194
                        z_sub(&x[irow], &x[irow], &comp_zero);
 
195
                    }
 
196
                } else {
 
197
#ifdef USE_VENDOR_BLAS
 
198
#ifdef _CRAY
 
199
                    CTRSV(ftcs3, ftcs2, ftcs2, &nsupc, &Lval[luptr], &nsupr,
 
200
                       &x[fsupc], &incx);
 
201
#else
 
202
                    ztrsv_("U", "N", "N", &nsupc, &Lval[luptr], &nsupr,
 
203
                           &x[fsupc], &incx);
 
204
#endif
 
205
#else           
 
206
                    zusolve ( nsupr, nsupc, &Lval[luptr], &x[fsupc] );
 
207
#endif          
 
208
 
 
209
                    for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
 
210
                        solve_ops += 8*(U_NZ_START(jcol+1) - U_NZ_START(jcol));
 
211
                        for (i = U_NZ_START(jcol); i < U_NZ_START(jcol+1); 
 
212
                                i++) {
 
213
                            irow = U_SUB(i);
 
214
                        zz_mult(&comp_zero, &x[jcol], &Uval[i]);
 
215
                        z_sub(&x[irow], &x[irow], &comp_zero);
 
216
                        }
 
217
                    }
 
218
                }
 
219
            } /* for k ... */
 
220
            
 
221
        }
 
222
    } else if (lsame_(trans, "T") ) { /* Form x := inv(A')*x */
 
223
        
 
224
        if ( lsame_(uplo, "L") ) {
 
225
            /* Form x := inv(L')*x */
 
226
            if ( L->nrow == 0 ) return 0; /* Quick return */
 
227
            
 
228
            for (k = Lstore->nsuper; k >= 0; --k) {
 
229
                fsupc = L_FST_SUPC(k);
 
230
                istart = L_SUB_START(fsupc);
 
231
                nsupr = L_SUB_START(fsupc+1) - istart;
 
232
                nsupc = L_FST_SUPC(k+1) - fsupc;
 
233
                luptr = L_NZ_START(fsupc);
 
234
 
 
235
                solve_ops += 8 * (nsupr - nsupc) * nsupc;
 
236
 
 
237
                for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
 
238
                    iptr = istart + nsupc;
 
239
                    for (i = L_NZ_START(jcol) + nsupc; 
 
240
                                i < L_NZ_START(jcol+1); i++) {
 
241
                        irow = L_SUB(iptr);
 
242
                        zz_mult(&comp_zero, &x[irow], &Lval[i]);
 
243
                        z_sub(&x[jcol], &x[jcol], &comp_zero);
 
244
                        iptr++;
 
245
                    }
 
246
                }
 
247
                
 
248
                if ( nsupc > 1 ) {
 
249
                    solve_ops += 4 * nsupc * (nsupc - 1);
 
250
#ifdef _CRAY
 
251
                    ftcs1 = _cptofcd("L", strlen("L"));
 
252
                    ftcs2 = _cptofcd(trans, strlen("T"));
 
253
                    ftcs3 = _cptofcd("U", strlen("U"));
 
254
                    CTRSV(ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
 
255
                        &x[fsupc], &incx);
 
256
#else
 
257
                    ztrsv_("L", trans, "U", &nsupc, &Lval[luptr], &nsupr,
 
258
                               &x[fsupc], &incx);
 
259
#endif
 
260
                }
 
261
            }
 
262
        } else {
 
263
            /* Form x := inv(U')*x */
 
264
            if ( U->nrow == 0 ) return 0; /* Quick return */
 
265
            
 
266
            for (k = 0; k <= Lstore->nsuper; k++) {
 
267
                fsupc = L_FST_SUPC(k);
 
268
                nsupr = L_SUB_START(fsupc+1) - L_SUB_START(fsupc);
 
269
                nsupc = L_FST_SUPC(k+1) - fsupc;
 
270
                luptr = L_NZ_START(fsupc);
 
271
 
 
272
                for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
 
273
                    solve_ops += 8*(U_NZ_START(jcol+1) - U_NZ_START(jcol));
 
274
                    for (i = U_NZ_START(jcol); i < U_NZ_START(jcol+1); i++) {
 
275
                        irow = U_SUB(i);
 
276
                        zz_mult(&comp_zero, &x[irow], &Uval[i]);
 
277
                        z_sub(&x[jcol], &x[jcol], &comp_zero);
 
278
                    }
 
279
                }
 
280
 
 
281
                solve_ops += 4 * nsupc * (nsupc + 1);
 
282
 
 
283
                if ( nsupc == 1 ) {
 
284
                    z_div(&x[fsupc], &x[fsupc], &Lval[luptr]);
 
285
                } else {
 
286
#ifdef _CRAY
 
287
                    ftcs1 = _cptofcd("U", strlen("U"));
 
288
                    ftcs2 = _cptofcd(trans, strlen("T"));
 
289
                    ftcs3 = _cptofcd("N", strlen("N"));
 
290
                    CTRSV( ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
 
291
                            &x[fsupc], &incx);
 
292
#else
 
293
                    ztrsv_("U", trans, "N", &nsupc, &Lval[luptr], &nsupr,
 
294
                               &x[fsupc], &incx);
 
295
#endif
 
296
                }
 
297
            } /* for k ... */
 
298
        }
 
299
    } else {  /* Form x := conj(inv(A'))*x */        
 
300
        
 
301
        if ( lsame_(uplo, "L") ) {
 
302
            /* Form x := conj(inv(L'))*x */
 
303
            if ( L->nrow == 0 ) return 0; /* Quick return */
 
304
            
 
305
            for (k = Lstore->nsuper; k >= 0; --k) {
 
306
                fsupc = L_FST_SUPC(k);
 
307
                istart = L_SUB_START(fsupc);
 
308
                nsupr = L_SUB_START(fsupc+1) - istart;
 
309
                nsupc = L_FST_SUPC(k+1) - fsupc;
 
310
                luptr = L_NZ_START(fsupc);
 
311
 
 
312
                solve_ops += 8 * (nsupr - nsupc) * nsupc;
 
313
 
 
314
                for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
 
315
                    iptr = istart + nsupc;
 
316
                    for (i = L_NZ_START(jcol) + nsupc; 
 
317
                                i < L_NZ_START(jcol+1); i++) {
 
318
                        irow = L_SUB(iptr);
 
319
                        zz_conj(&temp, &Lval[i]);
 
320
                        zz_mult(&comp_zero, &x[irow], &temp);
 
321
                        z_sub(&x[jcol], &x[jcol], &comp_zero);
 
322
                        iptr++;
 
323
                    }
 
324
                }
 
325
                
 
326
                if ( nsupc > 1 ) {
 
327
                    solve_ops += 4 * nsupc * (nsupc - 1);
 
328
#ifdef _CRAY
 
329
                    ftcs1 = _cptofcd("L", strlen("L"));
 
330
                    ftcs2 = _cptofcd(trans, strlen("T"));
 
331
                    ftcs3 = _cptofcd("U", strlen("U"));
 
332
                    CTRSV(ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
 
333
                        &x[fsupc], &incx);
 
334
#else
 
335
                    ztrsv_("L", trans, "U", &nsupc, &Lval[luptr], &nsupr,
 
336
                               &x[fsupc], &incx);
 
337
#endif
 
338
                }
 
339
            }
 
340
        } else {
 
341
            /* Form x := conj(inv(U'))*x */
 
342
            if ( U->nrow == 0 ) return 0; /* Quick return */
 
343
            
 
344
            for (k = 0; k <= Lstore->nsuper; k++) {
 
345
                fsupc = L_FST_SUPC(k);
 
346
                nsupr = L_SUB_START(fsupc+1) - L_SUB_START(fsupc);
 
347
                nsupc = L_FST_SUPC(k+1) - fsupc;
 
348
                luptr = L_NZ_START(fsupc);
 
349
 
 
350
                for (jcol = fsupc; jcol < L_FST_SUPC(k+1); jcol++) {
 
351
                    solve_ops += 8*(U_NZ_START(jcol+1) - U_NZ_START(jcol));
 
352
                    for (i = U_NZ_START(jcol); i < U_NZ_START(jcol+1); i++) {
 
353
                        irow = U_SUB(i);
 
354
                        zz_conj(&temp, &Uval[i]);
 
355
                        zz_mult(&comp_zero, &x[irow], &temp);
 
356
                        z_sub(&x[jcol], &x[jcol], &comp_zero);
 
357
                    }
 
358
                }
 
359
 
 
360
                solve_ops += 4 * nsupc * (nsupc + 1);
 
361
 
 
362
                if ( nsupc == 1 ) {
 
363
                    zz_conj(&temp, &Lval[luptr])
 
364
                    z_div(&x[fsupc], &x[fsupc], &temp);
 
365
                } else {
 
366
#ifdef _CRAY
 
367
                    ftcs1 = _cptofcd("U", strlen("U"));
 
368
                    ftcs2 = _cptofcd(trans, strlen("T"));
 
369
                    ftcs3 = _cptofcd("N", strlen("N"));
 
370
                    CTRSV( ftcs1, ftcs2, ftcs3, &nsupc, &Lval[luptr], &nsupr,
 
371
                            &x[fsupc], &incx);
 
372
#else
 
373
                    ztrsv_("U", trans, "N", &nsupc, &Lval[luptr], &nsupr,
 
374
                               &x[fsupc], &incx);
 
375
#endif
 
376
                }
 
377
            } /* for k ... */
 
378
        }
 
379
    }
 
380
 
 
381
    stat->ops[SOLVE] += solve_ops;
 
382
    SUPERLU_FREE(work);
 
383
    return 0;
 
384
}
 
385
 
 
386
 
 
387
 
 
388
int
 
389
sp_zgemv(char *trans, doublecomplex alpha, SuperMatrix *A, doublecomplex *x, 
 
390
         int incx, doublecomplex beta, doublecomplex *y, int incy)
 
391
{
 
392
/*  Purpose   
 
393
    =======   
 
394
 
 
395
    sp_zgemv()  performs one of the matrix-vector operations   
 
396
       y := alpha*A*x + beta*y,   or   y := alpha*A'*x + beta*y,   
 
397
    where alpha and beta are scalars, x and y are vectors and A is a
 
398
    sparse A->nrow by A->ncol matrix.   
 
399
 
 
400
    Parameters   
 
401
    ==========   
 
402
 
 
403
    TRANS  - (input) char*
 
404
             On entry, TRANS specifies the operation to be performed as   
 
405
             follows:   
 
406
                TRANS = 'N' or 'n'   y := alpha*A*x + beta*y.   
 
407
                TRANS = 'T' or 't'   y := alpha*A'*x + beta*y.   
 
408
                TRANS = 'C' or 'c'   y := alpha*A'*x + beta*y.   
 
409
 
 
410
    ALPHA  - (input) doublecomplex
 
411
             On entry, ALPHA specifies the scalar alpha.   
 
412
 
 
413
    A      - (input) SuperMatrix*
 
414
             Before entry, the leading m by n part of the array A must   
 
415
             contain the matrix of coefficients.   
 
416
 
 
417
    X      - (input) doublecomplex*, array of DIMENSION at least   
 
418
             ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n'   
 
419
             and at least   
 
420
             ( 1 + ( m - 1 )*abs( INCX ) ) otherwise.   
 
421
             Before entry, the incremented array X must contain the   
 
422
             vector x.   
 
423
 
 
424
    INCX   - (input) int
 
425
             On entry, INCX specifies the increment for the elements of   
 
426
             X. INCX must not be zero.   
 
427
 
 
428
    BETA   - (input) doublecomplex
 
429
             On entry, BETA specifies the scalar beta. When BETA is   
 
430
             supplied as zero then Y need not be set on input.   
 
431
 
 
432
    Y      - (output) doublecomplex*,  array of DIMENSION at least   
 
433
             ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n'   
 
434
             and at least   
 
435
             ( 1 + ( n - 1 )*abs( INCY ) ) otherwise.   
 
436
             Before entry with BETA non-zero, the incremented array Y   
 
437
             must contain the vector y. On exit, Y is overwritten by the 
 
438
             updated vector y.
 
439
             
 
440
    INCY   - (input) int
 
441
             On entry, INCY specifies the increment for the elements of   
 
442
             Y. INCY must not be zero.   
 
443
 
 
444
    ==== Sparse Level 2 Blas routine.   
 
445
*/
 
446
 
 
447
    /* Local variables */
 
448
    NCformat *Astore;
 
449
    doublecomplex   *Aval;
 
450
    int info;
 
451
    doublecomplex temp, temp1;
 
452
    int lenx, leny, i, j, irow;
 
453
    int iy, jx, jy, kx, ky;
 
454
    int notran;
 
455
    doublecomplex comp_zero = {0.0, 0.0};
 
456
    doublecomplex comp_one = {1.0, 0.0};
 
457
 
 
458
    notran = lsame_(trans, "N");
 
459
    Astore = A->Store;
 
460
    Aval = Astore->nzval;
 
461
    
 
462
    /* Test the input parameters */
 
463
    info = 0;
 
464
    if ( !notran && !lsame_(trans, "T") && !lsame_(trans, "C")) info = 1;
 
465
    else if ( A->nrow < 0 || A->ncol < 0 ) info = 3;
 
466
    else if (incx == 0) info = 5;
 
467
    else if (incy == 0) info = 8;
 
468
    if (info != 0) {
 
469
        xerbla_("sp_zgemv ", &info);
 
470
        return 0;
 
471
    }
 
472
 
 
473
    /* Quick return if possible. */
 
474
    if (A->nrow == 0 || A->ncol == 0 || 
 
475
        z_eq(&alpha, &comp_zero) && 
 
476
        z_eq(&beta, &comp_one))
 
477
        return 0;
 
478
 
 
479
 
 
480
    /* Set  LENX  and  LENY, the lengths of the vectors x and y, and set 
 
481
       up the start points in  X  and  Y. */
 
482
    if (lsame_(trans, "N")) {
 
483
        lenx = A->ncol;
 
484
        leny = A->nrow;
 
485
    } else {
 
486
        lenx = A->nrow;
 
487
        leny = A->ncol;
 
488
    }
 
489
    if (incx > 0) kx = 0;
 
490
    else kx =  - (lenx - 1) * incx;
 
491
    if (incy > 0) ky = 0;
 
492
    else ky =  - (leny - 1) * incy;
 
493
 
 
494
    /* Start the operations. In this version the elements of A are   
 
495
       accessed sequentially with one pass through A. */
 
496
    /* First form  y := beta*y. */
 
497
    if ( !z_eq(&beta, &comp_one) ) {
 
498
        if (incy == 1) {
 
499
            if ( z_eq(&beta, &comp_zero) )
 
500
                for (i = 0; i < leny; ++i) y[i] = comp_zero;
 
501
            else
 
502
                for (i = 0; i < leny; ++i) 
 
503
                  zz_mult(&y[i], &beta, &y[i]);
 
504
        } else {
 
505
            iy = ky;
 
506
            if ( z_eq(&beta, &comp_zero) )
 
507
                for (i = 0; i < leny; ++i) {
 
508
                    y[iy] = comp_zero;
 
509
                    iy += incy;
 
510
                }
 
511
            else
 
512
                for (i = 0; i < leny; ++i) {
 
513
                    zz_mult(&y[iy], &beta, &y[iy]);
 
514
                    iy += incy;
 
515
                }
 
516
        }
 
517
    }
 
518
    
 
519
    if ( z_eq(&alpha, &comp_zero) ) return 0;
 
520
 
 
521
    if ( notran ) {
 
522
        /* Form  y := alpha*A*x + y. */
 
523
        jx = kx;
 
524
        if (incy == 1) {
 
525
            for (j = 0; j < A->ncol; ++j) {
 
526
                if ( !z_eq(&x[jx], &comp_zero) ) {
 
527
                    zz_mult(&temp, &alpha, &x[jx]);
 
528
                    for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
 
529
                        irow = Astore->rowind[i];
 
530
                        zz_mult(&temp1, &temp,  &Aval[i]);
 
531
                        z_add(&y[irow], &y[irow], &temp1);
 
532
                    }
 
533
                }
 
534
                jx += incx;
 
535
            }
 
536
        } else {
 
537
            ABORT("Not implemented.");
 
538
        }
 
539
    } else {
 
540
        /* Form  y := alpha*A'*x + y. */
 
541
        jy = ky;
 
542
        if (incx == 1) {
 
543
            for (j = 0; j < A->ncol; ++j) {
 
544
                temp = comp_zero;
 
545
                for (i = Astore->colptr[j]; i < Astore->colptr[j+1]; ++i) {
 
546
                    irow = Astore->rowind[i];
 
547
                    zz_mult(&temp1, &Aval[i], &x[irow]);
 
548
                    z_add(&temp, &temp, &temp1);
 
549
                }
 
550
                zz_mult(&temp1, &alpha, &temp);
 
551
                z_add(&y[jy], &y[jy], &temp1);
 
552
                jy += incy;
 
553
            }
 
554
        } else {
 
555
            ABORT("Not implemented.");
 
556
        }
 
557
    }
 
558
    return 0;    
 
559
} /* sp_zgemv */
 
560