// Dsyr performs the rank-one update
//  a += alpha * x * x^T
// where a is an n×n symmetric matrix, and x is a vector.
972224
func (impl *Standard) Dsyr(ul blas.Uplo, n int, alpha float64, x []float64, incX int, a []float64, lda int) {
	// declared at cublasgen.h:1172:17 enum CUBLAS_STATUS { ... } cublasDsyr ...
	if impl.e != nil {
		return
	}

	if n < 0 {
		panic("blas: n < 0")
	}
	if incX == 0 {
		panic("blas: zero x index increment")
	}
	if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
		panic("blas: x index out of range")
	}
	impl.e = status(C.cublasDsyr(C.cublasHandle_t(impl.h), uplo2cublasUplo(ul), C.int(n), (*C.double)(&alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&a[0]), C.int(lda)))
}
858518
func (s optionDescriptorSlice) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
202474
func blockXOR(dst, src []uint32, n int) {
	for i, v := range src[:n] {
		dst[i] ^= v
	}
}
1353179
func (a *Writer) SGR(sgr ...string) (int, error) {
	return a.WriteString(SGR(sgr...))
}
375737
func (m *Matrix) Diagonal() *Matrix {
	rows, cols := m.Size()
	rank := minInt(rows, cols)
	m2 := New(rank, rank)

	for index := 0; index < rank; index++ {
		m2.Set(index, index, m.Get(index, index))
	}
	return m2
}
284364
func Cor(x, y Vector) (float64, error) {
	n := float64(len(x))
	xy, err := Product(x, y)
	if err != nil {
		return NA, err
	}

	sx := x.Sd()
	sy := y.Sd()

	mx := x.Mean()
	my := y.Mean()

	r := (xy.Sum() - n*mx*my) / ((n - 1) * sx * sy)
	return r, nil
}
788539
func (l *LeastSquares) J() (float64, error) {
	var sum float64

	for i := range l.trainingSet {
		prediction, err := l.Predict(l.trainingSet[i])
		if err != nil {
			return 0, err
		}

		sum += (l.expectedResults[i] - prediction[0]) * (l.expectedResults[i] - prediction[0])
	}

	// add regularization term!
	//
	// notice that the constant term doesn't matter
	for i := 1; i < len(l.Parameters); i++ {
		sum += l.regularization * l.Parameters[i] * l.Parameters[i]
	}

	return sum / float64(2*len(l.trainingSet)), nil
}
999932
func (b *LEDDriver) UpLeftArrow() (err error) {
	buf := []byte{0x1E, 0x18, 0x14, 0x12, 0x01}
	err = b.WriteMatrix(buf)
	return
}
1068354
func (x Vector) Rank() Vector {
	y := x.Copy()
	y.Sort()

	// equivalent to a minimum rank (tie) method
	rank := 0
	ranks := make(Vector, len(x))
	for i, _ := range ranks {
		ranks[i] = -1
	}

	for i, _ := range y {
		for j, _ := range x {
			if y[i] == x[j] && ranks[j] == -1 {
				ranks[j] = float64(rank)
			}
		}
		rank++
	}

	return ranks
}
1201109
func (impl *Standard) Dscal(n int, alpha float64, x []float64, incX int) {
	// declared at cublasgen.h:251:17 enum CUBLAS_STATUS { ... } cublasDscal ...
	if impl.e != nil {
		return
	}

	if n < 0 {
		panic("blas: n < 0")
	}
	if incX == 0 {
		panic("blas: zero x index increment")
	}
	if incX < 0 {
		return
	}
	if incX > 0 && (n-1)*incX >= len(x) {
		panic("blas: x index out of range")
	}
	if n == 0 {
		return
	}
	impl.e = status(C.cublasDscal(C.cublasHandle_t(impl.h), C.int(n), (*C.double)(&alpha), (*C.double)(&x[0]), C.int(incX)))
}
1189134
func (sis *SortedIntSet) decr(num int) {
	if sis.useTreeMap {
		count, ok := sis.dict[num]
		assert(ok)
		if count == 1 {
			delete(sis.dict, num)
			// Fall back to simple arrays once we touch zero again
			if len(sis.dict) == 0 {
				sis.useTreeMap = false
				sis.values = sis.values[:0] // reuse slice
				sis.counts = sis.counts[:0] // reuse slice
			}
		} else {
			sis.dict[num] = count - 1
		}
		return
	}

	for i, v := range sis.values {
		if v == num {
			sis.counts[i]--
			if sis.counts[i] == 0 {
				limit := len(sis.values) - 1
				if i < limit {
					sis.values = append(sis.values[:i], sis.values[i+1:]...)
					sis.counts = append(sis.counts[:i], sis.counts[i+1:]...)
				} else {
					sis.values = sis.values[:i]
					sis.counts = sis.counts[:i]
				}
			}
			return
		}
	}

	panic("should not be here!")
}
852705
func (m Mat3x2) Row(row int) Vec2 {
	return Vec2{m[row+0], m[row+3]}
}
1314970
func (m *Matrix) T() *Matrix {
	newMat := make([][]float32, m.Cols)
	var wg sync.WaitGroup
	for y := 0; y < int(m.Cols); y++ {
		wg.Add(1)
		go m.t(newMat, y, &wg)
	}
	wg.Wait()
	return NewMatrix(newMat)
}
1028163
func Zeros(r, c uint) *Matrix {
	res := make([][]float32, r)
	for y := 0; y < int(r); y++ {
		res[y] = make([]float32, c)
	}
	return NewMatrix(res)
}
941437
func DirectionLtr() Property {
	property := Property{propertyType: "direction"}
	property.values = append(property.values, "ltr")

	return property
}
1278630
func (m *matrix3x3) det() float64 {
	//      | a  b  c |
	//  det | d  e  f | = aei + bfg + cdh - ceg - bdi - afh
	//      | g  h  i |
	return m[0][0]*m[1][1]*m[2][2] + m[0][1]*m[1][2]*m[2][0] + m[0][2]*m[1][0]*m[2][1] -
		m[0][2]*m[1][1]*m[2][0] - m[0][1]*m[1][0]*m[2][2] - m[0][0]*m[1][2]*m[2][1]
}
868947
func (impl *Standard) Daxpy(n int, alpha float64, x []float64, incX int, y []float64, incY int) {
	// declared at cublasgen.h:304:17 enum CUBLAS_STATUS { ... } cublasDaxpy ...
	if impl.e != nil {
		return
	}

	if n < 0 {
		panic("blas: n < 0")
	}
	if incX == 0 {
		panic("blas: zero x index increment")
	}
	if incY == 0 {
		panic("blas: zero y index increment")
	}
	if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
		panic("blas: x index out of range")
	}
	if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
		panic("blas: y index out of range")
	}
	if n == 0 {
		return
	}
	impl.e = status(C.cublasDaxpy(C.cublasHandle_t(impl.h), C.int(n), (*C.double)(&alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY)))
}