github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/blas/gonum/level1cmplx64.go (about) 1 // Code generated by "go generate github.com/jingcheng-WU/gonum/blas/gonum”; DO NOT EDIT. 2 3 // Copyright ©2017 The Gonum Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 package gonum 8 9 import ( 10 math "github.com/jingcheng-WU/gonum/internal/math32" 11 12 "github.com/jingcheng-WU/gonum/blas" 13 "github.com/jingcheng-WU/gonum/internal/asm/c64" 14 ) 15 16 var _ blas.Complex64Level1 = Implementation{} 17 18 // Scasum returns the sum of the absolute values of the elements of x 19 // \sum_i |Re(x[i])| + |Im(x[i])| 20 // Scasum returns 0 if incX is negative. 21 // 22 // Complex64 implementations are autogenerated and not directly tested. 23 func (Implementation) Scasum(n int, x []complex64, incX int) float32 { 24 if n < 0 { 25 panic(nLT0) 26 } 27 if incX < 1 { 28 if incX == 0 { 29 panic(zeroIncX) 30 } 31 return 0 32 } 33 var sum float32 34 if incX == 1 { 35 if len(x) < n { 36 panic(shortX) 37 } 38 for _, v := range x[:n] { 39 sum += scabs1(v) 40 } 41 return sum 42 } 43 if (n-1)*incX >= len(x) { 44 panic(shortX) 45 } 46 for i := 0; i < n; i++ { 47 v := x[i*incX] 48 sum += scabs1(v) 49 } 50 return sum 51 } 52 53 // Scnrm2 computes the Euclidean norm of the complex vector x, 54 // ‖x‖_2 = sqrt(\sum_i x[i] * conj(x[i])). 55 // This function returns 0 if incX is negative. 56 // 57 // Complex64 implementations are autogenerated and not directly tested. 58 func (Implementation) Scnrm2(n int, x []complex64, incX int) float32 { 59 if incX < 1 { 60 if incX == 0 { 61 panic(zeroIncX) 62 } 63 return 0 64 } 65 if n < 1 { 66 if n == 0 { 67 return 0 68 } 69 panic(nLT0) 70 } 71 if (n-1)*incX >= len(x) { 72 panic(shortX) 73 } 74 var ( 75 scale float32 76 ssq float32 = 1 77 ) 78 if incX == 1 { 79 for _, v := range x[:n] { 80 re, im := math.Abs(real(v)), math.Abs(imag(v)) 81 if re != 0 { 82 if re > scale { 83 ssq = 1 + ssq*(scale/re)*(scale/re) 84 scale = re 85 } else { 86 ssq += (re / scale) * (re / scale) 87 } 88 } 89 if im != 0 { 90 if im > scale { 91 ssq = 1 + ssq*(scale/im)*(scale/im) 92 scale = im 93 } else { 94 ssq += (im / scale) * (im / scale) 95 } 96 } 97 } 98 if math.IsInf(scale, 1) { 99 return math.Inf(1) 100 } 101 return scale * math.Sqrt(ssq) 102 } 103 for ix := 0; ix < n*incX; ix += incX { 104 re, im := math.Abs(real(x[ix])), math.Abs(imag(x[ix])) 105 if re != 0 { 106 if re > scale { 107 ssq = 1 + ssq*(scale/re)*(scale/re) 108 scale = re 109 } else { 110 ssq += (re / scale) * (re / scale) 111 } 112 } 113 if im != 0 { 114 if im > scale { 115 ssq = 1 + ssq*(scale/im)*(scale/im) 116 scale = im 117 } else { 118 ssq += (im / scale) * (im / scale) 119 } 120 } 121 } 122 if math.IsInf(scale, 1) { 123 return math.Inf(1) 124 } 125 return scale * math.Sqrt(ssq) 126 } 127 128 // Icamax returns the index of the first element of x having largest |Re(·)|+|Im(·)|. 129 // Icamax returns -1 if n is 0 or incX is negative. 130 // 131 // Complex64 implementations are autogenerated and not directly tested. 132 func (Implementation) Icamax(n int, x []complex64, incX int) int { 133 if incX < 1 { 134 if incX == 0 { 135 panic(zeroIncX) 136 } 137 // Return invalid index. 138 return -1 139 } 140 if n < 1 { 141 if n == 0 { 142 // Return invalid index. 143 return -1 144 } 145 panic(nLT0) 146 } 147 if len(x) <= (n-1)*incX { 148 panic(shortX) 149 } 150 idx := 0 151 max := scabs1(x[0]) 152 if incX == 1 { 153 for i, v := range x[1:n] { 154 absV := scabs1(v) 155 if absV > max { 156 max = absV 157 idx = i + 1 158 } 159 } 160 return idx 161 } 162 ix := incX 163 for i := 1; i < n; i++ { 164 absV := scabs1(x[ix]) 165 if absV > max { 166 max = absV 167 idx = i 168 } 169 ix += incX 170 } 171 return idx 172 } 173 174 // Caxpy adds alpha times x to y: 175 // y[i] += alpha * x[i] for all i 176 // 177 // Complex64 implementations are autogenerated and not directly tested. 178 func (Implementation) Caxpy(n int, alpha complex64, x []complex64, incX int, y []complex64, incY int) { 179 if incX == 0 { 180 panic(zeroIncX) 181 } 182 if incY == 0 { 183 panic(zeroIncY) 184 } 185 if n < 1 { 186 if n == 0 { 187 return 188 } 189 panic(nLT0) 190 } 191 if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { 192 panic(shortX) 193 } 194 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { 195 panic(shortY) 196 } 197 if alpha == 0 { 198 return 199 } 200 if incX == 1 && incY == 1 { 201 c64.AxpyUnitary(alpha, x[:n], y[:n]) 202 return 203 } 204 var ix, iy int 205 if incX < 0 { 206 ix = (1 - n) * incX 207 } 208 if incY < 0 { 209 iy = (1 - n) * incY 210 } 211 c64.AxpyInc(alpha, x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy)) 212 } 213 214 // Ccopy copies the vector x to vector y. 215 // 216 // Complex64 implementations are autogenerated and not directly tested. 217 func (Implementation) Ccopy(n int, x []complex64, incX int, y []complex64, incY int) { 218 if incX == 0 { 219 panic(zeroIncX) 220 } 221 if incY == 0 { 222 panic(zeroIncY) 223 } 224 if n < 1 { 225 if n == 0 { 226 return 227 } 228 panic(nLT0) 229 } 230 if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { 231 panic(shortX) 232 } 233 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { 234 panic(shortY) 235 } 236 if incX == 1 && incY == 1 { 237 copy(y[:n], x[:n]) 238 return 239 } 240 var ix, iy int 241 if incX < 0 { 242 ix = (-n + 1) * incX 243 } 244 if incY < 0 { 245 iy = (-n + 1) * incY 246 } 247 for i := 0; i < n; i++ { 248 y[iy] = x[ix] 249 ix += incX 250 iy += incY 251 } 252 } 253 254 // Cdotc computes the dot product 255 // xᴴ · y 256 // of two complex vectors x and y. 257 // 258 // Complex64 implementations are autogenerated and not directly tested. 259 func (Implementation) Cdotc(n int, x []complex64, incX int, y []complex64, incY int) complex64 { 260 if incX == 0 { 261 panic(zeroIncX) 262 } 263 if incY == 0 { 264 panic(zeroIncY) 265 } 266 if n <= 0 { 267 if n == 0 { 268 return 0 269 } 270 panic(nLT0) 271 } 272 if incX == 1 && incY == 1 { 273 if len(x) < n { 274 panic(shortX) 275 } 276 if len(y) < n { 277 panic(shortY) 278 } 279 return c64.DotcUnitary(x[:n], y[:n]) 280 } 281 var ix, iy int 282 if incX < 0 { 283 ix = (-n + 1) * incX 284 } 285 if incY < 0 { 286 iy = (-n + 1) * incY 287 } 288 if ix >= len(x) || (n-1)*incX >= len(x) { 289 panic(shortX) 290 } 291 if iy >= len(y) || (n-1)*incY >= len(y) { 292 panic(shortY) 293 } 294 return c64.DotcInc(x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy)) 295 } 296 297 // Cdotu computes the dot product 298 // xᵀ · y 299 // of two complex vectors x and y. 300 // 301 // Complex64 implementations are autogenerated and not directly tested. 302 func (Implementation) Cdotu(n int, x []complex64, incX int, y []complex64, incY int) complex64 { 303 if incX == 0 { 304 panic(zeroIncX) 305 } 306 if incY == 0 { 307 panic(zeroIncY) 308 } 309 if n <= 0 { 310 if n == 0 { 311 return 0 312 } 313 panic(nLT0) 314 } 315 if incX == 1 && incY == 1 { 316 if len(x) < n { 317 panic(shortX) 318 } 319 if len(y) < n { 320 panic(shortY) 321 } 322 return c64.DotuUnitary(x[:n], y[:n]) 323 } 324 var ix, iy int 325 if incX < 0 { 326 ix = (-n + 1) * incX 327 } 328 if incY < 0 { 329 iy = (-n + 1) * incY 330 } 331 if ix >= len(x) || (n-1)*incX >= len(x) { 332 panic(shortX) 333 } 334 if iy >= len(y) || (n-1)*incY >= len(y) { 335 panic(shortY) 336 } 337 return c64.DotuInc(x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy)) 338 } 339 340 // Csscal scales the vector x by a real scalar alpha. 341 // Csscal has no effect if incX < 0. 342 // 343 // Complex64 implementations are autogenerated and not directly tested. 344 func (Implementation) Csscal(n int, alpha float32, x []complex64, incX int) { 345 if incX < 1 { 346 if incX == 0 { 347 panic(zeroIncX) 348 } 349 return 350 } 351 if (n-1)*incX >= len(x) { 352 panic(shortX) 353 } 354 if n < 1 { 355 if n == 0 { 356 return 357 } 358 panic(nLT0) 359 } 360 if alpha == 0 { 361 if incX == 1 { 362 x = x[:n] 363 for i := range x { 364 x[i] = 0 365 } 366 return 367 } 368 for ix := 0; ix < n*incX; ix += incX { 369 x[ix] = 0 370 } 371 return 372 } 373 if incX == 1 { 374 x = x[:n] 375 for i, v := range x { 376 x[i] = complex(alpha*real(v), alpha*imag(v)) 377 } 378 return 379 } 380 for ix := 0; ix < n*incX; ix += incX { 381 v := x[ix] 382 x[ix] = complex(alpha*real(v), alpha*imag(v)) 383 } 384 } 385 386 // Cscal scales the vector x by a complex scalar alpha. 387 // Cscal has no effect if incX < 0. 388 // 389 // Complex64 implementations are autogenerated and not directly tested. 390 func (Implementation) Cscal(n int, alpha complex64, x []complex64, incX int) { 391 if incX < 1 { 392 if incX == 0 { 393 panic(zeroIncX) 394 } 395 return 396 } 397 if (n-1)*incX >= len(x) { 398 panic(shortX) 399 } 400 if n < 1 { 401 if n == 0 { 402 return 403 } 404 panic(nLT0) 405 } 406 if alpha == 0 { 407 if incX == 1 { 408 x = x[:n] 409 for i := range x { 410 x[i] = 0 411 } 412 return 413 } 414 for ix := 0; ix < n*incX; ix += incX { 415 x[ix] = 0 416 } 417 return 418 } 419 if incX == 1 { 420 c64.ScalUnitary(alpha, x[:n]) 421 return 422 } 423 c64.ScalInc(alpha, x, uintptr(n), uintptr(incX)) 424 } 425 426 // Cswap exchanges the elements of two complex vectors x and y. 427 // 428 // Complex64 implementations are autogenerated and not directly tested. 429 func (Implementation) Cswap(n int, x []complex64, incX int, y []complex64, incY int) { 430 if incX == 0 { 431 panic(zeroIncX) 432 } 433 if incY == 0 { 434 panic(zeroIncY) 435 } 436 if n < 1 { 437 if n == 0 { 438 return 439 } 440 panic(nLT0) 441 } 442 if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { 443 panic(shortX) 444 } 445 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { 446 panic(shortY) 447 } 448 if incX == 1 && incY == 1 { 449 x = x[:n] 450 for i, v := range x { 451 x[i], y[i] = y[i], v 452 } 453 return 454 } 455 var ix, iy int 456 if incX < 0 { 457 ix = (-n + 1) * incX 458 } 459 if incY < 0 { 460 iy = (-n + 1) * incY 461 } 462 for i := 0; i < n; i++ { 463 x[ix], y[iy] = y[iy], x[ix] 464 ix += incX 465 iy += incY 466 } 467 }