gonum.org/v1/gonum@v0.14.0/blas/gonum/level1cmplx64.go (about)

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