// IFFT returns the inverse FFT of the complex-valued slice.
767225
func IFFT(x []complex128) []complex128 {
	lx := len(x)
	r := make([]complex128, lx)

	// Reverse inputs, which is calculated with modulo N, hence x[0] as an outlier
	r[0] = x[0]
	for i := 1; i < lx; i++ {
		r[i] = x[lx-i]
	}

	r = FFT(r)

	N := complex(float64(lx), 0)
	for n := range r {
		r[n] /= N
	}
	return r
}
1104615
func IfUnset(onlyIf FieldFormatterFunc) FieldFormatterFunc {
	return func(value interface{}, op FieldOperation) (interface{}, error) {
		if onlyIf != nil {
			if typeutil.IsZero(value) {
				return onlyIf(value, op)
			}
		}

		return value, nil
	}
}
1012866
func InitF(Len int, Less func(i, j int) bool, Swap func(i, j int)) {
	// heapify
	for i := Len/2 - 1; i >= 0; i-- {
		heapDown(Len, Less, Swap, i)
	}
}
447207
func interpolationFuncSort() ast.Function {
	return ast.Function{
		ArgTypes:   []ast.Type{ast.TypeList},
		ReturnType: ast.TypeList,
		Variadic:   false,
		Callback: func(args []interface{}) (interface{}, error) {
			inputList := args[0].([]ast.Variable)

			// Ensure that all the list members are strings and
			// create a string slice from them
			members := make([]string, len(inputList))
			for i, val := range inputList {
				if val.Type != ast.TypeString {
					return nil, fmt.Errorf(
						"sort() may only be used with lists of strings - %s at index %d",
						val.Type.String(), i)
				}

				members[i] = val.Value.(string)
			}

			sort.Strings(members)
			return stringSliceToVariableValue(members), nil
		},
	}
}
1171946
func SliceOf(in interface{}) interface{} {
	value := reflect.ValueOf(in)

	sliceType := reflect.SliceOf(reflect.TypeOf(in))
	slice := reflect.New(sliceType)
	sliceValue := reflect.MakeSlice(sliceType, 0, 0)
	sliceValue = reflect.Append(sliceValue, value)
	slice.Elem().Set(sliceValue)

	return slice.Elem().Interface()
}
766797
func interpolationFuncBase64Decode() ast.Function {
	return ast.Function{
		ArgTypes:   []ast.Type{ast.TypeString},
		ReturnType: ast.TypeString,
		Callback: func(args []interface{}) (interface{}, error) {
			s := args[0].(string)
			sDec, err := base64.StdEncoding.DecodeString(s)
			if err != nil {
				return "", fmt.Errorf("failed to decode base64 data '%s'", s)
			}
			return string(sDec), nil
		},
	}
}
1259635
func calculateF(b uint, epsilon float64) uint {
	f := uint(math.Ceil(math.Log(2 * float64(b) / epsilon)))
	f = f / 8
	if f <= 0 {
		f = 1
	}
	return f
}
1315774
func InterQuartileRange(input Float64Data) (float64, error) {
	if input.Len() == 0 {
		return math.NaN(), EmptyInputErr
	}
	qs, _ := Quartile(input)
	iqr := qs.Q3 - qs.Q1
	return iqr, nil
}
1334660
func gfInverse(a gfElement) gfElement {
	if a == gfZero {
		log.Panicln("No multiplicative inverse of 0")
	}

	return gfExpTable[255-gfLogTable[a]]
}
969826
func interpolationFuncJSONEncode() ast.Function {
	return ast.Function{
		ArgTypes:   []ast.Type{ast.TypeAny},
		ReturnType: ast.TypeString,
		Callback: func(args []interface{}) (interface{}, error) {
			var toEncode interface{}

			switch typedArg := args[0].(type) {
			case string:
				toEncode = typedArg

			case []ast.Variable:
				strings := make([]string, len(typedArg))

				for i, v := range typedArg {
					if v.Type != ast.TypeString {
						variable, _ := hil.InterfaceToVariable(typedArg)
						toEncode, _ = hil.VariableToInterface(variable)

						jEnc, err := json.Marshal(toEncode)
						if err != nil {
							return "", fmt.Errorf("failed to encode JSON data '%s'", toEncode)
						}
						return string(jEnc), nil

					}
					strings[i] = v.Value.(string)
				}
				toEncode = strings

			case map[string]ast.Variable:
				stringMap := make(map[string]string)
				for k, v := range typedArg {
					if v.Type != ast.TypeString {
						variable, _ := hil.InterfaceToVariable(typedArg)
						toEncode, _ = hil.VariableToInterface(variable)

						jEnc, err := json.Marshal(toEncode)
						if err != nil {
							return "", fmt.Errorf("failed to encode JSON data '%s'", toEncode)
						}
						return string(jEnc), nil
					}
					stringMap[k] = v.Value.(string)
				}
				toEncode = stringMap

			default:
				return "", fmt.Errorf("unknown type for JSON encoding: %T", args[0])
			}

			jEnc, err := json.Marshal(toEncode)
			if err != nil {
				return "", fmt.Errorf("failed to encode JSON data '%s'", toEncode)
			}
			return string(jEnc), nil
		},
	}
}
255162
func fourier(dst []fermat, src []fermat, backward bool, n int, k uint) {
	var rec func(dst, src []fermat, size uint)
	tmp := make(fermat, n+1)  // pre-allocate temporary variables.
	tmp2 := make(fermat, n+1) // pre-allocate temporary variables.

	// The recursion function of the FFT.
	// The root of unity used in the transform is ω=1<<(ω2shift/2).
	// The source array may use shifted indices (i.e. the i-th
	// element is src[i << idxShift]).
	rec = func(dst, src []fermat, size uint) {
		idxShift := k - size
		ω2shift := (4 * n * _W) >> size
		if backward {
			ω2shift = -ω2shift
		}

		// Easy cases.
		if len(src[0]) != n+1 || len(dst[0]) != n+1 {
			panic("len(src[0]) != n+1 || len(dst[0]) != n+1")
		}
		switch size {
		case 0:
			copy(dst[0], src[0])
			return
		case 1:
			dst[0].Add(src[0], src[1<<idxShift]) // dst[0] = src[0] + src[1]
			dst[1].Sub(src[0], src[1<<idxShift]) // dst[1] = src[0] - src[1]
			return
		}

		// Let P(x) = src[0] + src[1<<idxShift] * x + ... + src[K-1 << idxShift] * x^(K-1)
		// The P(x) = Q1(x²) + x*Q2(x²)
		// where Q1's coefficients are src with indices shifted by 1
		// where Q2's coefficients are src[1<<idxShift:] with indices shifted by 1

		// Split destination vectors in halves.
		dst1 := dst[:1<<(size-1)]
		dst2 := dst[1<<(size-1):]
		// Transform Q1 and Q2 in the halves.
		rec(dst1, src, size-1)
		rec(dst2, src[1<<idxShift:], size-1)

		// Reconstruct P's transform from transforms of Q1 and Q2.
		// dst[i]            is dst1[i] + ω^i * dst2[i]
		// dst[i + 1<<(k-1)] is dst1[i] + ω^(i+K/2) * dst2[i]
		//
		for i := range dst1 {
			tmp.ShiftHalf(dst2[i], i*ω2shift, tmp2) // ω^i * dst2[i]
			dst2[i].Sub(dst1[i], tmp)
			dst1[i].Add(dst1[i], tmp)
		}
	}
	rec(dst, src, k)
}
366954
func (t *TFIDF) InverseDocumentFrequency(word string) float64 {
	w, _ := t.Words.Get(word)
	return math.Log(float64(t.DocumentCount)) - math.Log(float64(w.DocsSeen)+1)
}
413897
func BackwardsIf(to int, fx func(int, func())) {
	state := true
	for i := to; i > 0; i-- {
		if !state {
			break
		}
		fx(i, func() { state = false })
	}
}
538551
func (f Float64) If(fn func(float64)) {
	if f.Present() {
		fn(*f.value)
	}
}
1263451
func Interpolate(a, b *T, t float32) T {
	t1 := 1 - t
	return T{
		a[0]*t1 + b[0]*t,
		a[1]*t1 + b[1]*t,
		a[2]*t1 + b[2]*t,
	}
}
419412
func (fcomp *fcomp) ifelse(cond syntax.Expr, t, f *block) {
	switch cond := cond.(type) {
	case *syntax.UnaryExpr:
		if cond.Op == syntax.NOT {
			// if not x then goto t else goto f
			//    =>
			// if x then goto f else goto t
			fcomp.ifelse(cond.X, f, t)
			return
		}

	case *syntax.BinaryExpr:
		switch cond.Op {
		case syntax.AND:
			// if x and y then goto t else goto f
			//    =>
			// if x then ifelse(y, t, f) else goto f
			fcomp.expr(cond.X)
			y := fcomp.newBlock()
			fcomp.condjump(CJMP, y, f)

			fcomp.block = y
			fcomp.ifelse(cond.Y, t, f)
			return

		case syntax.OR:
			// if x or y then goto t else goto f
			//    =>
			// if x then goto t else ifelse(y, t, f)
			fcomp.expr(cond.X)
			y := fcomp.newBlock()
			fcomp.condjump(CJMP, t, y)

			fcomp.block = y
			fcomp.ifelse(cond.Y, t, f)
			return
		case syntax.NOT_IN:
			// if x not in y then goto t else goto f
			//    =>
			// if x in y then goto f else goto t
			copy := *cond
			copy.Op = syntax.IN
			fcomp.expr(&copy)
			fcomp.condjump(CJMP, f, t)
			return
		}
	}

	// general case
	fcomp.expr(cond)
	fcomp.condjump(CJMP, t, f)
}
723446
func interpolationFuncLower() ast.Function {
	return ast.Function{
		ArgTypes:   []ast.Type{ast.TypeString},
		ReturnType: ast.TypeString,
		Callback: func(args []interface{}) (interface{}, error) {
			toLower := args[0].(string)
			return strings.ToLower(toLower), nil
		},
	}
}