// genEncMatrix generate encoding matrix. upper: Identity_Matrix; lower: Cauchy_Matrix
178186
func genEncMatrix(d, p int) matrix {
	r := d + p
	m := make([]byte, r*d)
	// create identity matrix upper
	for i := 0; i < d; i++ {
		m[i*d+i] = byte(1)
	}
	// create cauchy matrix below
	off := d * d // offset of encMatrix
	for i := d; i < r; i++ {
		for j := 0; j < d; j++ {
			d := i ^ j
			a := inverseTbl[d]
			m[off] = byte(a)
			off++
		}
	}
	return m
}
1130813
func (p *Point) MultiplyMatrixVector(m *Matrix) *Point {
	x := m.Val[m00]*p.X + m.Val[m01]*p.Y + m.Val[m02]
	y := m.Val[m10]*p.X + m.Val[m11]*p.Y + m.Val[m12]
	p.X, p.Y = x, y
	return p
}
326608
func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
	bs, fnerr := iv.MarshalJSON()
	f.e.marshalAsis(bs, fnerr)
}
51871
func NewMatrix(m, n int) (mat *MatMxN) {
	if shouldPool {
		return &MatMxN{m: m, n: n, dat: grabFromPool(m * n)}
	} else {
		return &MatMxN{m: m, n: n, dat: make([]float64, m*n)}
	}
}
943699
func (a *AIP1640Driver) DrawMatrix(data [8]byte) {
	for i := 0; i < 8; i++ {
		a.buffer[7-i] = data[i]
	}
}
891309
func (m *Matrix) DiagonalVector() Vector {
	rows, cols := m.Size()
	rank := minInt(rows, cols)
	values := make([]float64, rank)

	for index := 0; index < rank; index++ {
		values[index] = m.Get(index, index)
	}
	return Vector(values)
}
900658
func (b *LEDDriver) ReadMatrix() (data []byte, err error) {
	data, err = b.adaptor().ReadCharacteristic(ledMatrixStateCharacteristic)
	return
}
685548
func GenerateCrossFoldValidationConfusionMatrices(data base.FixedDataGrid, cls base.Classifier, folds int) ([]ConfusionMatrix, error) {
	_, rows := data.Size()

	// Assign each row to a fold
	foldMap := make([]int, rows)
	inverseFoldMap := make(map[int][]int)
	for i := 0; i < rows; i++ {
		fold := rand.Intn(folds)
		foldMap[i] = fold
		if _, ok := inverseFoldMap[fold]; !ok {
			inverseFoldMap[fold] = make([]int, 0)
		}
		inverseFoldMap[fold] = append(inverseFoldMap[fold], i)
	}

	ret := make([]ConfusionMatrix, folds)

	// Create training/test views for each fold
	for i := 0; i < folds; i++ {
		// Fold i is for testing
		testData := base.NewInstancesViewFromVisible(data, inverseFoldMap[i], data.AllAttributes())
		otherRows := make([]int, 0)
		for j := 0; j < folds; j++ {
			if i == j {
				continue
			}
			otherRows = append(otherRows, inverseFoldMap[j]...)
		}
		trainData := base.NewInstancesViewFromVisible(data, otherRows, data.AllAttributes())
		// Train
		err := cls.Fit(trainData)
		if err != nil {
			return nil, err
		}
		// Predict
		pred, err := cls.Predict(testData)
		if err != nil {
			return nil, err
		}
		// Evaluate
		cf, err := GetConfusionMatrix(testData, pred)
		if err != nil {
			return nil, err
		}
		ret[i] = cf
	}
	return ret, nil
}
862645
func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldTags, indent int, assumeNonEmpty bool) error {
	ws := strings.Repeat("  ", indent)

	// Check whether type is primitive, needs to be done after interface check.
	if enc := primitiveStringEncoders[t.Kind()]; enc != "" && tags.asString {
		fmt.Fprintf(g.out, ws+enc+"\n", in)
		return nil
	} else if enc := primitiveEncoders[t.Kind()]; enc != "" {
		fmt.Fprintf(g.out, ws+enc+"\n", in)
		return nil
	}

	switch t.Kind() {
	case reflect.Slice:
		elem := t.Elem()
		iVar := g.uniqueVarName()
		vVar := g.uniqueVarName()

		if t.Elem().Kind() == reflect.Uint8 && elem.Name() == "uint8" {
			fmt.Fprintln(g.out, ws+"out.Base64Bytes("+in+")")
		} else {
			if !assumeNonEmpty {
				fmt.Fprintln(g.out, ws+"if "+in+" == nil && (out.Flags & jwriter.NilSliceAsEmpty) == 0 {")
				fmt.Fprintln(g.out, ws+`  out.RawString("null")`)
				fmt.Fprintln(g.out, ws+"} else {")
			} else {
				fmt.Fprintln(g.out, ws+"{")
			}
			fmt.Fprintln(g.out, ws+"  out.RawByte('[')")
			fmt.Fprintln(g.out, ws+"  for "+iVar+", "+vVar+" := range "+in+" {")
			fmt.Fprintln(g.out, ws+"    if "+iVar+" > 0 {")
			fmt.Fprintln(g.out, ws+"      out.RawByte(',')")
			fmt.Fprintln(g.out, ws+"    }")

			if err := g.genTypeEncoder(elem, vVar, tags, indent+2, false); err != nil {
				return err
			}

			fmt.Fprintln(g.out, ws+"  }")
			fmt.Fprintln(g.out, ws+"  out.RawByte(']')")
			fmt.Fprintln(g.out, ws+"}")
		}

	case reflect.Array:
		elem := t.Elem()
		iVar := g.uniqueVarName()

		if t.Elem().Kind() == reflect.Uint8 && elem.Name() == "uint8" {
			fmt.Fprintln(g.out, ws+"out.Base64Bytes("+in+"[:])")
		} else {
			fmt.Fprintln(g.out, ws+"out.RawByte('[')")
			fmt.Fprintln(g.out, ws+"for "+iVar+" := range "+in+" {")
			fmt.Fprintln(g.out, ws+"  if "+iVar+" > 0 {")
			fmt.Fprintln(g.out, ws+"    out.RawByte(',')")
			fmt.Fprintln(g.out, ws+"  }")

			if err := g.genTypeEncoder(elem, "("+in+")["+iVar+"]", tags, indent+1, false); err != nil {
				return err
			}

			fmt.Fprintln(g.out, ws+"}")
			fmt.Fprintln(g.out, ws+"out.RawByte(']')")
		}

	case reflect.Struct:
		enc := g.getEncoderName(t)
		g.addType(t)

		fmt.Fprintln(g.out, ws+enc+"(out, "+in+")")

	case reflect.Ptr:
		if !assumeNonEmpty {
			fmt.Fprintln(g.out, ws+"if "+in+" == nil {")
			fmt.Fprintln(g.out, ws+`  out.RawString("null")`)
			fmt.Fprintln(g.out, ws+"} else {")
		}

		if err := g.genTypeEncoder(t.Elem(), "*"+in, tags, indent+1, false); err != nil {
			return err
		}

		if !assumeNonEmpty {
			fmt.Fprintln(g.out, ws+"}")
		}

	case reflect.Map:
		key := t.Key()
		keyEnc, ok := primitiveStringEncoders[key.Kind()]
		if !ok && !hasCustomMarshaler(key) {
			return fmt.Errorf("map key type %v not supported: only string and integer keys and types implementing Marshaler interfaces are allowed", key)
		} // else assume the caller knows what they are doing and that the custom marshaler performs the translation from the key type to a string or integer
		tmpVar := g.uniqueVarName()

		if !assumeNonEmpty {
			fmt.Fprintln(g.out, ws+"if "+in+" == nil && (out.Flags & jwriter.NilMapAsEmpty) == 0 {")
			fmt.Fprintln(g.out, ws+"  out.RawString(`null`)")
			fmt.Fprintln(g.out, ws+"} else {")
		} else {
			fmt.Fprintln(g.out, ws+"{")
		}
		fmt.Fprintln(g.out, ws+"  out.RawByte('{')")
		fmt.Fprintln(g.out, ws+"  "+tmpVar+"First := true")
		fmt.Fprintln(g.out, ws+"  for "+tmpVar+"Name, "+tmpVar+"Value := range "+in+" {")
		fmt.Fprintln(g.out, ws+"    if "+tmpVar+"First { "+tmpVar+"First = false } else { out.RawByte(',') }")

		// NOTE: extra check for TextMarshaler. It overrides default methods.
		if reflect.PtrTo(key).Implements(reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()) {
			fmt.Fprintln(g.out, ws+"    "+fmt.Sprintf("out.RawText(("+tmpVar+"Name).MarshalText()"+")"))
		} else if keyEnc != "" {
			fmt.Fprintln(g.out, ws+"    "+fmt.Sprintf(keyEnc, tmpVar+"Name"))
		} else {
			if err := g.genTypeEncoder(key, tmpVar+"Name", tags, indent+2, false); err != nil {
				return err
			}
		}

		fmt.Fprintln(g.out, ws+"    out.RawByte(':')")

		if err := g.genTypeEncoder(t.Elem(), tmpVar+"Value", tags, indent+2, false); err != nil {
			return err
		}

		fmt.Fprintln(g.out, ws+"  }")
		fmt.Fprintln(g.out, ws+"  out.RawByte('}')")
		fmt.Fprintln(g.out, ws+"}")

	case reflect.Interface:
		if t.NumMethod() != 0 {
			return fmt.Errorf("interface type %v not supported: only interface{} is allowed", t)
		}
		fmt.Fprintln(g.out, ws+"if m, ok := "+in+".(easyjson.Marshaler); ok {")
		fmt.Fprintln(g.out, ws+"  m.MarshalEasyJSON(out)")
		fmt.Fprintln(g.out, ws+"} else if m, ok := "+in+".(json.Marshaler); ok {")
		fmt.Fprintln(g.out, ws+"  out.Raw(m.MarshalJSON())")
		fmt.Fprintln(g.out, ws+"} else {")
		fmt.Fprintln(g.out, ws+"  out.Raw(json.Marshal("+in+"))")
		fmt.Fprintln(g.out, ws+"}")

	default:
		return fmt.Errorf("don't know how to encode %v", t)
	}
	return nil
}
253434
func (pattern *Pattern) GetMatrix(matrix *Matrix) {
	C.cairo_pattern_get_matrix(pattern.Ptr, (*C.cairo_matrix_t)(unsafe.Pointer(matrix)))
	if err := pattern.status(); err != nil {
		panic(err)
	}
}
1137046
func (m *Matrix) BroadcastFunc(f func(float32, ...interface{}) float32, args ...interface{}) *Matrix {
	newMatrix := make([][]float32, m.Rows)
	var wg sync.WaitGroup
	for y := 0; y < int(m.Rows); y++ {
		wg.Add(1)
		go m.execFunc(newMatrix, y, &wg, f, args...)
	}
	wg.Wait()
	return NewMatrix(newMatrix)
}
1323025
func (cr *Context) GetFontMatrix(matrix *Matrix) {
	C.cairo_get_font_matrix(cr.Ptr, (*C.cairo_matrix_t)(unsafe.Pointer(matrix)))
	if err := cr.status(); err != nil {
		panic(err)
	}
}
176855
func (m *MT19937) Int64() uint64 {

	var (
		i int
		x uint64
	)

	mag01 := [2]uint64{0, MatrixA}

	if m.mti >= NN { /* generate NN words at one time */

		/* if Seed() has not been called, */
		/* a default initial seed is used */
		if m.mti == NN+1 {
			m.Seed(5489)
		}

		for i = 0; i < NN-MM; i++ {
			x = (m.mt[i] & UM) | (m.mt[i+1] & LM)
			m.mt[i] = m.mt[i+MM] ^ (x >> 1) ^ mag01[(int)(x&1)]
		}
		for ; i < NN-1; i++ {
			x = (m.mt[i] & UM) | (m.mt[i+1] & LM)
			m.mt[i] = m.mt[i+(MM-NN)] ^ (x >> 1) ^ mag01[(int)(x&1)]
		}
		x = (m.mt[NN-1] & UM) | (m.mt[0] & LM)
		m.mt[NN-1] = m.mt[MM-1] ^ (x >> 1) ^ mag01[(int)(x&1)]

		m.mti = 0
	}

	x = m.mt[m.mti]
	m.mti++

	x ^= (x >> 29) & 0x5555555555555555
	x ^= (x << 17) & 0x71D67FFFEDA60000
	x ^= (x << 37) & 0xFFF7EEE000000000
	x ^= (x >> 43)

	return x
}
234814
func (cr *Context) IdentityMatrix() {
	C.cairo_identity_matrix(cr.Ptr)
	if err := cr.status(); err != nil {
		panic(err)
	}
}
381971
func (cr *Context) GetMatrix(matrix *Matrix) {
	C.cairo_get_matrix(cr.Ptr, (*C.cairo_matrix_t)(unsafe.Pointer(matrix)))
	if err := cr.status(); err != nil {
		panic(err)
	}
}
257215
func (p *Pattern) genaratePattern() {
	if p.Generator == "" {
		p.Generator = PATTERNS[int(utils.HexVal(p.Hash, 20, 1))]
	} else {
		if !isPattern(p.Generator) {
			panic("Error: the requested generator is invalid.")
		}
	}

	switch p.Generator {
	case "chevrons":
		p.geoChevrons()
	case "concentric-circles":
		p.geoConcentricCircles()
	case "diamonds":
		p.geoDiamonds()
	case "hexagons":
		p.geoHexagons()
	case "mosaic-squares":
		p.geoMosaicSquares()
	case "nested-squares":
		p.geoNestedSquares()
	case "octagons":
		p.geoOctagons()
	case "overlapping-circles":
		p.geoOverlappingCircles()
	case "overlapping-rings":
		p.geoOverlappingRings()
	case "plaid":
		p.geoPlaid()
	case "plus-signs":
		p.geoPlusSigns()
	case "sine-waves":
		p.geoSineWaves()
	case "squares":
		p.geoSquares()
	case "tessellation":
		p.geoTessellation()
	case "triangles":
		p.geoTriangles()
	case "xes":
		p.geoXes()
	}
}
729025
func (scaledFont *ScaledFont) GetFontMatrix(fontMatrix *Matrix) {
	C.cairo_scaled_font_get_font_matrix(scaledFont.Ptr, (*C.cairo_matrix_t)(unsafe.Pointer(fontMatrix)))
	if err := scaledFont.status(); err != nil {
		panic(err)
	}
}