// AsI8 returns the buffer's samples as int8 sample values.
// If the buffer isn't in this format, a copy is created and converted.
// Note that converting might result in loss of resolution.
515955
func (b *PCMBuffer) AsI8() (out []int8) {
	if b == nil {
		return nil
	}
	switch b.DataType {
	case DataTypeI8:
		return b.I8
	case DataTypeI16:
		out = make([]int8, len(b.I16))
		for i := 0; i < len(b.I16); i++ {
			out[i] = int8(b.I16[i])
		}
	case DataTypeI32:
		out = make([]int8, len(b.I32))
		for i := 0; i < len(b.I32); i++ {
			out[i] = int8(b.I32[i])
		}
	case DataTypeF32:
		out = make([]int8, len(b.F32))
		for i := 0; i < len(b.F32); i++ {
			out[i] = int8(b.F32[i])
		}
	case DataTypeF64:
		out = make([]int8, len(b.F64))
		for i := 0; i < len(b.F64); i++ {
			out[i] = int8(b.F64[i])
		}
	}
	return out
}
556508
func (ae *AttributeEncoder) Uint8(typ uint16, v uint8) {
	if ae.err != nil {
		return
	}

	ae.attrs = append(ae.attrs, Attribute{
		Type: typ,
		Data: []byte{v},
	})
}
697811
func Uint8s(b0, b1 []uint8) int {
	d := 0
	for i, x := range b0 {
		d += Uint8(x, b1[i])
	}
	return d
}
110178
func Sample(population []interface{}, k int) (res []interface{}, err error) {
	n := len(population)
	idxs, err := SampleInts(n, k)
	if err != nil {
		return
	}

	res = []interface{}{}
	for _, idx := range idxs {
		res = append(res, population[idx])
	}

	return
}
699279
func isutf8(buf []byte, blen int) int {
	if blen <= 2 {
		return 0
	}
	// invalid utf-8 code
	if buf[0] == byte(0xc0) || buf[0] == byte(0xc1) ||
		buf[0] == byte(0xfe) || buf[0] == byte(0xff) {
		return 0
	}

	var (
		i      int = 3
		maxlen int = 6
	)
	if blen < 6 {
		maxlen = blen
	}
	for ; i < maxlen; i++ {
		fb := utf8FirstByte[i]
		mk := utf8FirstMask[i]
		if buf[0]&mk == fb {
			res := true
			for j := 1; j <= i-1; j++ {
				b := buf[j]
				if b == byte(0xc0) || b == byte(0xc1) ||
					b == byte(0xfe) || b == byte(0xff) {
					return 0
				}
				if b&byte(0xc0) != 0x80 {
					res = false
					break
				}
			}
			if res {
				return i
			}
		}
	}
	return 0
}
147592
func TryToInt8(i interface{}) (r int8, err error) {
	switch t := i.(type) {
	case nil:
		r = 0
	case int:
		r = int8(t)
	case int8:
		r = t
	case *int8:
		r = *t
	case int16:
		r = int8(t)
	case int32:
		r = int8(t)
	case int64:
		r = int8(t)
	case uint:
		r = int8(t)
	case uint8:
		r = int8(t)
	case uint16:
		r = int8(t)
	case uint32:
		r = int8(t)
	case uint64:
		r = int8(t)
	case float32:
		r = int8(t)
	case float64:
		r = int8(t)
	case bool:
		if t {
			r = 1
		}
	case string:
		var v int64
		if v, err = strconv.ParseInt(t, 10, 8); err == nil {
			r = int8(v)
		}
	default:
		err = castError(i, "int8")
	}
	return
}
731502
func (c Context) Ints8(key string, i []int8) Context {
	c.l.context = enc.AppendInts8(enc.AppendKey(c.l.context, key), i)
	return c
}
1030339
func (buf *FloatBuffer) AsFloat32Buffer() *Float32Buffer {
	newB := &Float32Buffer{}
	newB.Data = make([]float32, len(buf.Data))
	for i := 0; i < len(buf.Data); i++ {
		newB.Data[i] = float32(buf.Data[i])
	}
	newB.Format = &Format{
		NumChannels: buf.Format.NumChannels,
		SampleRate:  buf.Format.SampleRate,
	}
	return newB
}
354836
func (d *defaulter) AsInt(v Valuer, dv int) int {
	value, err := v.Value()
	if err != nil {
		d.logValuerError(err)
		return dv
	}
	ivalue, err := strconv.ParseInt(value, 10, 0)
	if err != nil {
		d.logFormatError("int", err)
		return dv
	}
	return int(ivalue)
}
556015
func AsInt(d DataType) (int, bool) {
	value, ok := d.Value().(int)
	return value, ok
}
948139
func (be *BinaryEncoder) WriteInt8(value int8) {
	be.buffer[be.pos] = byte(value)
	be.pos++
}
1131080
func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error) {

	if input.Len() == 0 {
		return nil, EmptyInputErr
	}

	length := input.Len()
	if replacement {

		result := Float64Data{}
		rand.Seed(unixnano())

		// In every step, randomly take the num for
		for i := 0; i < takenum; i++ {
			idx := rand.Intn(length)
			result = append(result, input[idx])
		}

		return result, nil

	} else if !replacement && takenum <= length {

		rand.Seed(unixnano())

		// Get permutation of number of indexies
		perm := rand.Perm(length)
		result := Float64Data{}

		// Get element of input by permutated index
		for _, idx := range perm[0:takenum] {
			result = append(result, input[idx])
		}

		return result, nil

	}

	return nil, BoundsErr
}
1233058
func (g *Group) Int8() *Statement {
	// notest
	s := Int8()
	g.items = append(g.items, s)
	return s
}
232539
func Uint8(b []byte) uint8 {
	if l := len(b); l != 1 {
		panic(fmt.Sprintf("Uint8: unexpected byte slice length: %d", l))
	}

	return b[0]
}
1286742
func CountOne8(value uint8) (uint) {
    value = (value & 0x55) + ((value >> 1) & 0x55);
    value = (value & 0x33) + ((value >> 2) & 0x33);
    value = (value & 0x0f) + ((value >> 4) & 0x0f);

    return uint(value);
}
953044
func (r *Encoder) EncodeInt8(x int8) error {
	if 0 <= x && x < INT_POS_FIXED_COUNT {
		_, err := r.w.Write([]byte{byte(INT_POS_FIXED_START + x)})
		return err
	}
	if -INT_NEG_FIXED_COUNT <= x && x < 0 {
		_, err := r.w.Write([]byte{byte(INT_NEG_FIXED_START - 1 - x)})
		return err
	}
	// x is guaranteed to be in range (-128, 127)
	_, err := r.w.Write([]byte{CHR_INT1, byte(x)})
	return err
}
328265
func (Encoder) AppendInts8(dst []byte, vals []int8) []byte {
	if len(vals) == 0 {
		return append(dst, '[', ']')
	}
	dst = append(dst, '[')
	dst = strconv.AppendInt(dst, int64(vals[0]), 10)
	if len(vals) > 1 {
		for _, val := range vals[1:] {
			dst = strconv.AppendInt(append(dst, ','), int64(val), 10)
		}
	}
	dst = append(dst, ']')
	return dst
}