Ejemplo n.º 1
0
// Returns Y = X^H*Y for real or complex X, Y.
//
// ARGUMENTS
//  X         float or complex matrix
//  Y         float or complex matrix.  Must have the same type as X.
//
// OPTIONS
//  n         integer.  If n<0, the default value of n is used.
//            The default value is equal to nx = 1+(len(x)-offsetx-1)/incx or 0 if
//            len(x) > offsetx+1.  If the default value is used, it must be equal to
//            ny = 1+(len(y)-offsetx-1)/|incy| or 0 if len(y) > offsety+1
//  incx      nonzero integer [default=1]
//  incy      nonzero integer [default=1]
//  offsetx   nonnegative integer [default=0]
//  offsety   nonnegative integer [default=0]
//
func Dot(X, Y matrix.Matrix, opts ...linalg.Option) (v matrix.Scalar) {
	v = matrix.FScalar(math.NaN())
	//cv = cmplx.NaN()
	ind := linalg.GetIndexOpts(opts...)
	err := check_level1_func(ind, fdot, X, Y)
	if err != nil {
		return
	}
	if ind.Nx == 0 {
		return matrix.FScalar(0.0)
	}
	sameType := matrix.EqualTypes(X, Y)
	if !sameType {
		err = onError("arrays not of same type")
		return
	}
	switch X.(type) {
	case *matrix.ComplexMatrix:
		Xa := X.(*matrix.ComplexMatrix).ComplexArray()
		Ya := Y.(*matrix.ComplexMatrix).ComplexArray()
		v = matrix.CScalar(zdotc(ind.Nx, Xa[ind.OffsetX:], ind.IncX, Ya[ind.OffsetY:], ind.IncY))
	case *matrix.FloatMatrix:
		Xa := X.(*matrix.FloatMatrix).FloatArray()
		Ya := Y.(*matrix.FloatMatrix).FloatArray()
		v = matrix.FScalar(ddot(ind.Nx, Xa[ind.OffsetX:], ind.IncX, Ya[ind.OffsetY:], ind.IncY))
		//default:
		//	err = onError("not implemented for parameter types", )
	}
	return
}
Ejemplo n.º 2
0
func TestDgemv(t *testing.T) {
	fmt.Printf("* L2 * test gemv: Y = alpha * A * X + beta * Y\n")
	A := matrix.FloatNew(3, 2, []float64{1, 1, 1, 2, 2, 2})
	X := matrix.FloatVector([]float64{1, 1})
	Y := matrix.FloatVector([]float64{0, 0, 0})
	alpha := matrix.FScalar(1.0)
	beta := matrix.FScalar(0.0)
	fmt.Printf("before: alpha=1.0, beta=0.0\nA=\n%v\nX=\n%v\nY=\n%v\n", A, X, Y)
	err := Gemv(A, X, Y, alpha, beta)
	fmt.Printf("after:\nA=\n%v\nX=\n%v\nY=\n%v\n", A, X, Y)
	fmt.Printf("* L2 * test gemv: X = alpha * A.T * Y + beta * X\n")
	err = Gemv(A, Y, X, alpha, beta, linalg.OptTrans)
	if err != nil {
		fmt.Printf("error: %s\n", err)
	}
	fmt.Printf("after:\nA=\n%v\nX=\n%v\nY=\n%v\n", A, X, Y)
}
Ejemplo n.º 3
0
func TestDaxpy(t *testing.T) {
	fmt.Printf("* L1 * test axpy: Y = alpha * X + Y\n")
	X := matrix.FloatVector([]float64{1, 1, 1})
	Y := matrix.FloatVector([]float64{0, 0, 0})
	fmt.Printf("before:\nX=\n%v\nY=\n%v\n", X, Y)
	Axpy(X, Y, matrix.FScalar(5.0))
	fmt.Printf("after:\nX=\n%v\nY=\n%v\n", X, Y)
}
Ejemplo n.º 4
0
// Returns ||Re x||_1 + ||Im x||_1.
//
// ARGUMENTS
//  X       float or complex matrix
//
// OPTIONS
//  n       integer.  If n<0, the default value of n is used.
//          The default value is equal to n = 1+(len(x)-offset-1)/inc or 0 if
//          len(x) > offset+1
//  inc     positive integer
//  offset  nonnegative integer
//
func Asum(X matrix.Matrix, opts ...linalg.Option) (v matrix.Scalar) {
	v = matrix.FScalar(math.NaN())
	ind := linalg.GetIndexOpts(opts...)
	err := check_level1_func(ind, fasum, X, nil)
	if err != nil {
		return
	}
	if ind.Nx == 0 {
		return
	}
	switch X.(type) {
	case *matrix.ComplexMatrix:
		Xa := X.(*matrix.ComplexMatrix).ComplexArray()
		v = matrix.FScalar(dzasum(ind.Nx, Xa[ind.OffsetX:], ind.IncX))
	case *matrix.FloatMatrix:
		Xa := X.(*matrix.FloatMatrix).FloatArray()
		v = matrix.FScalar(dasum(ind.Nx, Xa[ind.OffsetX:], ind.IncX))
		//default:
		//	err = onError("not implemented for parameter types", )
	}
	return
}
Ejemplo n.º 5
0
// Dscal: X = alpha * X
func TestDscal(t *testing.T) {
	fmt.Printf("* L1 * test scal: X = alpha * X\n")
	alpha := matrix.FScalar(2.0)
	A := matrix.FloatVector([]float64{1.0, 1.0, 1.0, 1.0, 1.0, 1.0})
	Scal(A, alpha)
	fmt.Printf("Dscal 2.0 * A\n")
	fmt.Printf("%s\n", A)
	A = matrix.FloatVector([]float64{1.0, 1.0, 1.0, 1.0, 1.0, 1.0})
	Scal(A, alpha, &linalg.IOpt{"offset", 3})
	fmt.Printf("Dscal 2.0 * A[3:]\n")
	fmt.Printf("%s\n", A)
	A = matrix.FloatVector([]float64{1.0, 1.0, 1.0, 1.0, 1.0, 1.0})
	fmt.Printf("Dscal 2.0* A[::2]\n")
	Scal(A, alpha, &linalg.IOpt{"inc", 2})
	fmt.Printf("%s\n", A)
}