func Prod(s []complex128) complex128 {
	prod := 1 + 0i
	for _, val := range s {
		prod *= val
	}
	return prod
}
Prod returns the product of the elements of the slice.
Returns 1 if len(s) = 0.
package cmplxs
import (
	"errors"
	"math"
	"math/cmplx"
	"gonum.org/v1/gonum/cmplxs/cscalar"
	"gonum.org/v1/gonum/internal/asm/c128"
)
const (
	zeroLength   = "cmplxs: zero length slice"
	shortSpan    = "cmplxs: slice length less than 2"
	badLength    = "cmplxs: slice lengths do not match"
	badDstLength = "cmplxs: destination slice length does not match input"
)
func Abs(dst []float64, s []complex128) {
	if len(dst) != len(s) {
		panic(badDstLength)
	}
	for i, v := range s {
		dst[i] = cmplx.Abs(v)
	}
}
func Add(dst, s []complex128) {
	if len(dst) != len(s) {
		panic(badLength)
	}
	c128.AxpyUnitaryTo(dst, 1, s, dst)
}
func AddTo(dst, s, t []complex128) []complex128 {
	if len(s) != len(t) {
		panic(badLength)
	}
	if len(dst) != len(s) {
		panic(badDstLength)
	}
	c128.AxpyUnitaryTo(dst, 1, s, t)
	return dst
}
func AddConst(c complex128, dst []complex128) {
	c128.AddConst(c, dst)
}
func AddScaled(dst []complex128, alpha complex128, s []complex128) {
	if len(dst) != len(s) {
		panic(badLength)
	}
	c128.AxpyUnitaryTo(dst, alpha, s, dst)
}
func AddScaledTo(dst, y []complex128, alpha complex128, s []complex128) []complex128 {
	if len(s) != len(y) {
		panic(badLength)
	}
	if len(dst) != len(y) {
		panic(badDstLength)
	}
	c128.AxpyUnitaryTo(dst, alpha, s, y)
	return dst
}
func Count(f func(complex128) bool, s []complex128) int {
	var n int
	for _, val := range s {
		if f(val) {
			n++
		}
	}
	return n
}
func Complex(dst []complex128, real, imag []float64) []complex128 {
	if len(real) != len(imag) {
		panic(badLength)
	}
	if len(dst) != len(real) {
		panic(badDstLength)
	}
	if len(dst) == 0 {
		return dst
	}
	for i, r := range real {
		dst[i] = complex(r, imag[i])
	}
	return dst
}
func CumProd(dst, s []complex128) []complex128 {
	if len(dst) != len(s) {
		panic(badDstLength)
	}
	if len(dst) == 0 {
		return dst
	}
	return c128.CumProd(dst, s)
}
func CumSum(dst, s []complex128) []complex128 {
	if len(dst) != len(s) {
		panic(badDstLength)
	}
	if len(dst) == 0 {
		return dst
	}
	return c128.CumSum(dst, s)
}
func Distance(s, t []complex128, L float64) float64 {
	if len(s) != len(t) {
		panic(badLength)
	}
	if len(s) == 0 {
		return 0
	}
	var norm float64
	switch {
	case L == 2:
		return c128.L2DistanceUnitary(s, t)
	case L == 1:
		for i, v := range s {
			norm += cmplx.Abs(t[i] - v)
		}
		return norm
	case math.IsInf(L, 1):
		for i, v := range s {
			absDiff := cmplx.Abs(t[i] - v)
			if absDiff > norm {
				norm = absDiff
			}
		}
		return norm
	default:
		for i, v := range s {
			norm += math.Pow(cmplx.Abs(t[i]-v), L)
		}
		return math.Pow(norm, 1/L)
	}
}
func Div(dst, s []complex128) {
	if len(dst) != len(s) {
		panic(badLength)
	}
	c128.Div(dst, s)
}
func DivTo(dst, s, t []complex128) []complex128 {
	if len(s) != len(t) {
		panic(badLength)
	}
	if len(dst) != len(s) {
		panic(badDstLength)
	}
	return c128.DivTo(dst, s, t)
}
func Dot(s1, s2 []complex128) complex128 {
	if len(s1) != len(s2) {
		panic(badLength)
	}
	return c128.DotUnitary(s1, s2)
}
func Equal(s1, s2 []complex128) bool {
	if len(s1) != len(s2) {
		return false
	}
	for i, val := range s1 {
		if s2[i] != val {
			return false
		}
	}
	return true
}
func EqualApprox(s1, s2 []complex128, tol float64) bool {
	if len(s1) != len(s2) {
		return false
	}
	for i, a := range s1 {
		if !cscalar.EqualWithinAbsOrRel(a, s2[i], tol, tol) {
			return false
		}
	}
	return true
}
func EqualFunc(s1, s2 []complex128, f func(complex128, complex128) bool) bool {
	if len(s1) != len(s2) {
		return false
	}
	for i, val := range s1 {
		if !f(val, s2[i]) {
			return false
		}
	}
	return true
}
func EqualLengths(slices ...[]complex128) bool {
	if len(slices) == 0 {
		return true
	}
	l := len(slices[0])
	for i := 1; i < len(slices); i++ {
		if len(slices[i]) != l {
			return false
		}
	}
	return true
}
func Find(inds []int, f func(complex128) bool, s []complex128, k int) ([]int, error) {
	inds = inds[:0]
	if k == 0 {
		return inds, nil
	}
	if k < 0 {
		for i, val := range s {
			if f(val) {
				inds = append(inds, i)
			}
		}
		return inds, nil
	}
	nFound := 0
	for i, val := range s {
		if f(val) {
			inds = append(inds, i)
			nFound++
			if nFound == k {
				return inds, nil
			}
		}
	}
	return inds, errors.New("cmplxs: insufficient elements found")
}
func HasNaN(s []complex128) bool {
	for _, v := range s {
		if cmplx.IsNaN(v) {
			return true
		}
	}
	return false
}
func Imag(dst []float64, src []complex128) []float64 {
	if len(dst) != len(src) {
		panic(badDstLength)
	}
	if len(dst) == 0 {
		return dst
	}
	for i, z := range src {
		dst[i] = imag(z)
	}
	return dst
}
func LogSpan(dst []complex128, l, u complex128) []complex128 {
	Span(dst, cmplx.Log(l), cmplx.Log(u))
	for i := range dst {
		dst[i] = cmplx.Exp(dst[i])
	}
	return dst
}
func MaxAbs(s []complex128) complex128 {
	return s[MaxAbsIdx(s)]
}
func MaxAbsIdx(s []complex128) int {
	if len(s) == 0 {
		panic(zeroLength)
	}
	max := math.NaN()
	var ind int
	for i, v := range s {
		if cmplx.IsNaN(v) {
			continue
		}
		if a := cmplx.Abs(v); a > max || math.IsNaN(max) {
			max = a
			ind = i
		}
	}
	return ind
}
func MinAbs(s []complex128) complex128 {
	return s[MinAbsIdx(s)]
}
func MinAbsIdx(s []complex128) int {
	if len(s) == 0 {
		panic(zeroLength)
	}
	min := math.NaN()
	var ind int
	for i, v := range s {
		if cmplx.IsNaN(v) {
			continue
		}
		if a := cmplx.Abs(v); a < min || math.IsNaN(min) {
			min = a
			ind = i
		}
	}
	return ind
}
func Mul(dst, s []complex128) {
	if len(dst) != len(s) {
		panic(badLength)
	}
	for i, val := range s {
		dst[i] *= val
	}
}
func MulConj(dst, s []complex128) {
	if len(dst) != len(s) {
		panic(badLength)
	}
	for i, val := range s {
		dst[i] *= cmplx.Conj(val)
	}
}
func MulConjTo(dst, s, t []complex128) []complex128 {
	if len(s) != len(t) {
		panic(badLength)
	}
	if len(dst) != len(s) {
		panic(badDstLength)
	}
	for i, val := range t {
		dst[i] = cmplx.Conj(val) * s[i]
	}
	return dst
}
func MulTo(dst, s, t []complex128) []complex128 {
	if len(s) != len(t) {
		panic(badLength)
	}
	if len(dst) != len(s) {
		panic(badDstLength)
	}
	for i, val := range t {
		dst[i] = val * s[i]
	}
	return dst
}
func NearestIdx(s []complex128, v complex128) int {
	if len(s) == 0 {
		panic(zeroLength)
	}
	switch {
	case cmplx.IsNaN(v):
		return 0
	case cmplx.IsInf(v):
		return MaxAbsIdx(s)
	}
	var ind int
	dist := math.NaN()
	for i, val := range s {
		newDist := cmplx.Abs(v - val)
		if math.IsNaN(newDist) {
			continue
		}
		if newDist < dist || math.IsNaN(dist) {
			dist = newDist
			ind = i
		}
	}
	return ind
}
func Norm(s []complex128, L float64) float64 {
	if len(s) == 0 {
		return 0
	}
	var norm float64
	switch {
	case L == 2:
		return c128.L2NormUnitary(s)
	case L == 1:
		for _, v := range s {
			norm += cmplx.Abs(v)
		}
		return norm
	case math.IsInf(L, 1):
		for _, v := range s {
			norm = math.Max(norm, cmplx.Abs(v))
		}
		return norm
	default:
		for _, v := range s {
			norm += math.Pow(cmplx.Abs(v), L)
		}
		return math.Pow(norm, 1/L)
	}
}