[2806] | 1 | /*************************************************************************
|
---|
| 2 | Copyright (c) 2005-2007, Sergey Bochkanov (ALGLIB project).
|
---|
| 3 |
|
---|
| 4 | >>> SOURCE LICENSE >>>
|
---|
| 5 | This program is free software; you can redistribute it and/or modify
|
---|
| 6 | it under the terms of the GNU General Public License as published by
|
---|
| 7 | the Free Software Foundation (www.fsf.org); either version 2 of the
|
---|
| 8 | License, or (at your option) any later version.
|
---|
| 9 |
|
---|
| 10 | This program is distributed in the hope that it will be useful,
|
---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | GNU General Public License for more details.
|
---|
| 14 |
|
---|
| 15 | A copy of the GNU General Public License is available at
|
---|
| 16 | http://www.fsf.org/licensing/licenses
|
---|
| 17 |
|
---|
| 18 | >>> END OF LICENSE >>>
|
---|
| 19 | *************************************************************************/
|
---|
| 20 |
|
---|
| 21 | using System;
|
---|
| 22 |
|
---|
| 23 | namespace alglib
|
---|
| 24 | {
|
---|
| 25 | public class cblas
|
---|
| 26 | {
|
---|
| 27 | public static void complexmatrixvectormultiply(ref AP.Complex[,] a,
|
---|
| 28 | int i1,
|
---|
| 29 | int i2,
|
---|
| 30 | int j1,
|
---|
| 31 | int j2,
|
---|
| 32 | bool transa,
|
---|
| 33 | bool conja,
|
---|
| 34 | ref AP.Complex[] x,
|
---|
| 35 | int ix1,
|
---|
| 36 | int ix2,
|
---|
| 37 | AP.Complex alpha,
|
---|
| 38 | ref AP.Complex[] y,
|
---|
| 39 | int iy1,
|
---|
| 40 | int iy2,
|
---|
| 41 | AP.Complex beta,
|
---|
| 42 | ref AP.Complex[] t)
|
---|
| 43 | {
|
---|
| 44 | int i = 0;
|
---|
| 45 | AP.Complex v = 0;
|
---|
| 46 | int i_ = 0;
|
---|
| 47 | int i1_ = 0;
|
---|
| 48 |
|
---|
| 49 | if( !transa )
|
---|
| 50 | {
|
---|
| 51 |
|
---|
| 52 | //
|
---|
| 53 | // y := alpha*A*x + beta*y
|
---|
| 54 | //
|
---|
| 55 | // or
|
---|
| 56 | //
|
---|
| 57 | // y := alpha*conj(A)*x + beta*y
|
---|
| 58 | //
|
---|
| 59 | if( i1>i2 | j1>j2 )
|
---|
| 60 | {
|
---|
| 61 | return;
|
---|
| 62 | }
|
---|
| 63 | System.Diagnostics.Debug.Assert(j2-j1==ix2-ix1, "ComplexMatrixVectorMultiply: A and X dont match!");
|
---|
| 64 | System.Diagnostics.Debug.Assert(i2-i1==iy2-iy1, "ComplexMatrixVectorMultiply: A and Y dont match!");
|
---|
| 65 |
|
---|
| 66 | //
|
---|
| 67 | // beta*y
|
---|
| 68 | //
|
---|
| 69 | if( beta==0 )
|
---|
| 70 | {
|
---|
| 71 | for(i=iy1; i<=iy2; i++)
|
---|
| 72 | {
|
---|
| 73 | y[i] = 0;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | else
|
---|
| 77 | {
|
---|
| 78 | for(i_=iy1; i_<=iy2;i_++)
|
---|
| 79 | {
|
---|
| 80 | y[i_] = beta*y[i_];
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | //
|
---|
| 85 | // conj?
|
---|
| 86 | //
|
---|
| 87 | if( conja )
|
---|
| 88 | {
|
---|
| 89 | for(i_=ix1; i_<=ix2;i_++)
|
---|
| 90 | {
|
---|
| 91 | t[i_] = AP.Math.Conj(x[i_]);
|
---|
| 92 | }
|
---|
| 93 | alpha = AP.Math.Conj(alpha);
|
---|
| 94 | for(i_=iy1; i_<=iy2;i_++)
|
---|
| 95 | {
|
---|
| 96 | y[i_] = AP.Math.Conj(y[i_]);
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | else
|
---|
| 100 | {
|
---|
| 101 | for(i_=ix1; i_<=ix2;i_++)
|
---|
| 102 | {
|
---|
| 103 | t[i_] = x[i_];
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | //
|
---|
| 108 | // alpha*A*x
|
---|
| 109 | //
|
---|
| 110 | for(i=i1; i<=i2; i++)
|
---|
| 111 | {
|
---|
| 112 | i1_ = (ix1)-(j1);
|
---|
| 113 | v = 0.0;
|
---|
| 114 | for(i_=j1; i_<=j2;i_++)
|
---|
| 115 | {
|
---|
| 116 | v += a[i,i_]*x[i_+i1_];
|
---|
| 117 | }
|
---|
| 118 | y[iy1+i-i1] = y[iy1+i-i1]+alpha*v;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | //
|
---|
| 122 | // conj?
|
---|
| 123 | //
|
---|
| 124 | if( conja )
|
---|
| 125 | {
|
---|
| 126 | for(i_=iy1; i_<=iy2;i_++)
|
---|
| 127 | {
|
---|
| 128 | y[i_] = AP.Math.Conj(y[i_]);
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | else
|
---|
| 133 | {
|
---|
| 134 |
|
---|
| 135 | //
|
---|
| 136 | // y := alpha*A'*x + beta*y;
|
---|
| 137 | //
|
---|
| 138 | // or
|
---|
| 139 | //
|
---|
| 140 | // y := alpha*conj(A')*x + beta*y;
|
---|
| 141 | //
|
---|
| 142 | if( i1>i2 | j1>j2 )
|
---|
| 143 | {
|
---|
| 144 | return;
|
---|
| 145 | }
|
---|
| 146 | System.Diagnostics.Debug.Assert(i2-i1==ix2-ix1, "ComplexMatrixVectorMultiply: A and X dont match!");
|
---|
| 147 | System.Diagnostics.Debug.Assert(j2-j1==iy2-iy1, "ComplexMatrixVectorMultiply: A and Y dont match!");
|
---|
| 148 |
|
---|
| 149 | //
|
---|
| 150 | // beta*y
|
---|
| 151 | //
|
---|
| 152 | if( beta==0 )
|
---|
| 153 | {
|
---|
| 154 | for(i=iy1; i<=iy2; i++)
|
---|
| 155 | {
|
---|
| 156 | y[i] = 0;
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 | else
|
---|
| 160 | {
|
---|
| 161 | for(i_=iy1; i_<=iy2;i_++)
|
---|
| 162 | {
|
---|
| 163 | y[i_] = beta*y[i_];
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | //
|
---|
| 168 | // conj?
|
---|
| 169 | //
|
---|
| 170 | if( conja )
|
---|
| 171 | {
|
---|
| 172 | for(i_=ix1; i_<=ix2;i_++)
|
---|
| 173 | {
|
---|
| 174 | t[i_] = AP.Math.Conj(x[i_]);
|
---|
| 175 | }
|
---|
| 176 | alpha = AP.Math.Conj(alpha);
|
---|
| 177 | for(i_=iy1; i_<=iy2;i_++)
|
---|
| 178 | {
|
---|
| 179 | y[i_] = AP.Math.Conj(y[i_]);
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 | else
|
---|
| 183 | {
|
---|
| 184 | for(i_=ix1; i_<=ix2;i_++)
|
---|
| 185 | {
|
---|
| 186 | t[i_] = x[i_];
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | //
|
---|
| 191 | // alpha*A'*x
|
---|
| 192 | //
|
---|
| 193 | for(i=i1; i<=i2; i++)
|
---|
| 194 | {
|
---|
| 195 | v = alpha*x[ix1+i-i1];
|
---|
| 196 | i1_ = (j1) - (iy1);
|
---|
| 197 | for(i_=iy1; i_<=iy2;i_++)
|
---|
| 198 | {
|
---|
| 199 | y[i_] = y[i_] + v*a[i,i_+i1_];
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | //
|
---|
| 204 | // conj?
|
---|
| 205 | //
|
---|
| 206 | if( conja )
|
---|
| 207 | {
|
---|
| 208 | for(i_=iy1; i_<=iy2;i_++)
|
---|
| 209 | {
|
---|
| 210 | y[i_] = AP.Math.Conj(y[i_]);
|
---|
| 211 | }
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | }
|
---|