本文整理匯總了Golang中github.com/hrautila/cvx/sets.DimensionSet.SumSquared方法的典型用法代碼示例。如果您正苦於以下問題:Golang DimensionSet.SumSquared方法的具體用法?Golang DimensionSet.SumSquared怎麽用?Golang DimensionSet.SumSquared使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hrautila/cvx/sets.DimensionSet
的用法示例。
在下文中一共展示了DimensionSet.SumSquared方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sgemv
/*
Matrix-vector multiplication.
A is a matrix or spmatrix of size (m, n) where
N = dims['l'] + sum(dims['q']) + sum( k**2 for k in dims['s'] )
representing a mapping from R^n to S.
If trans is 'N':
y := alpha*A*x + beta * y (trans = 'N').
x is a vector of length n. y is a vector of length N.
If trans is 'T':
y := alpha*A'*x + beta * y (trans = 'T').
x is a vector of length N. y is a vector of length n.
The 's' components in S are stored in unpacked 'L' storage.
*/
func sgemv(A, x, y *matrix.FloatMatrix, alpha, beta float64, dims *sets.DimensionSet, opts ...la_.Option) error {
m := dims.Sum("l", "q") + dims.SumSquared("s")
n := la_.GetIntOpt("n", -1, opts...)
if n == -1 {
n = A.Cols()
}
trans := la_.GetIntOpt("trans", int(la_.PNoTrans), opts...)
offsetX := la_.GetIntOpt("offsetx", 0, opts...)
offsetY := la_.GetIntOpt("offsety", 0, opts...)
offsetA := la_.GetIntOpt("offseta", 0, opts...)
if trans == int(la_.PTrans) && alpha != 0.0 {
trisc(x, dims, offsetX)
//fmt.Printf("trisc x=\n%v\n", x.ConvertToString())
}
//fmt.Printf("alpha=%.4f beta=%.4f m=%d n=%d\n", alpha, beta, m, n)
//fmt.Printf("A=\n%v\nx=\n%v\ny=\n%v\n", A, x.ConvertToString(), y.ConvertToString())
err := blas.GemvFloat(A, x, y, alpha, beta, &la_.IOpt{"trans", trans},
&la_.IOpt{"n", n}, &la_.IOpt{"m", m}, &la_.IOpt{"offseta", offsetA},
&la_.IOpt{"offsetx", offsetX}, &la_.IOpt{"offsety", offsetY})
//fmt.Printf("gemv y=\n%v\n", y.ConvertToString())
if trans == int(la_.PTrans) && alpha != 0.0 {
triusc(x, dims, offsetX)
}
return err
}
示例2: Cpl
// Solves a convex optimization problem with a linear objective
//
// minimize c'*x
// subject to f(x) <= 0
// G*x <= h
// A*x = b.
//
// f is vector valued, convex and twice differentiable. The linear
// inequalities are with respect to a cone C defined as the Cartesian
// product of N + M + 1 cones:
//
// C = C_0 x C_1 x .... x C_N x C_{N+1} x ... x C_{N+M}.
//
// The first cone C_0 is the nonnegative orthant of dimension ml. The
// next N cones are second order cones of dimension r[0], ..., r[N-1].
// The second order cone of dimension m is defined as
//
// { (u0, u1) in R x R^{m-1} | u0 >= ||u1||_2 }.
//
// The next M cones are positive semidefinite cones of order t[0], ..., t[M-1] >= 0.
//
// The structure of C is specified by DimensionSet dims which holds following sets
//
// dims.At("l") l, the dimension of the nonnegative orthant (array of length 1)
// dims.At("q") r[0], ... r[N-1], list with the dimesions of the second-order cones
// dims.At("s") t[0], ... t[M-1], array with the dimensions of the positive
// semidefinite cones
//
// The default value for dims is l: []int{h.Rows()}, q: []int{}, s: []int{}.
//
// On exit Solution contains the result and information about the accurancy of the
// solution. if SolutionStatus is Optimal then Solution.Result contains solutions
// for the problems.
//
// Result.At("x")[0] primal solution
// Result.At("snl")[0] non-linear constraint slacks
// Result.At("sl")[0] linear constraint slacks
// Result.At("y")[0] values for linear equality constraints y
// Result.At("znl")[0] values of dual variables for nonlinear inequalities
// Result.At("zl")[0] values of dual variables for linear inequalities
//
// If err is non-nil then sol is nil and err contains information about the argument or
// computation error.
//
func Cpl(F ConvexProg, c, G, h, A, b *matrix.FloatMatrix, dims *sets.DimensionSet, solopts *SolverOptions) (sol *Solution, err error) {
var mnl int
var x0 *matrix.FloatMatrix
mnl, x0, err = F.F0()
if err != nil {
return
}
if x0.Cols() != 1 {
err = errors.New("'x0' must be matrix with one column")
return
}
if c == nil {
err = errors.New("'c' must be non nil matrix")
return
}
if !c.SizeMatch(x0.Size()) {
err = errors.New(fmt.Sprintf("'c' must be matrix of size (%d,1)", x0.Rows()))
return
}
if h == nil {
h = matrix.FloatZeros(0, 1)
}
if h.Cols() > 1 {
err = errors.New("'h' must be matrix with 1 column")
return
}
if dims == nil {
dims = sets.NewDimensionSet("l", "q", "s")
dims.Set("l", []int{h.Rows()})
}
cdim := dims.Sum("l", "q") + dims.SumSquared("s")
//cdim_pckd := dims.Sum("l", "q") + dims.SumPacked("s")
//cdim_diag := dims.Sum("l", "q", "s")
if h.Rows() != cdim {
err = errors.New(fmt.Sprintf("'h' must be float matrix of size (%d,1)", cdim))
return
}
if G == nil {
G = matrix.FloatZeros(0, c.Rows())
}
if !G.SizeMatch(cdim, c.Rows()) {
estr := fmt.Sprintf("'G' must be of size (%d,%d)", cdim, c.Rows())
err = errors.New(estr)
return
}
// Check A and set defaults if it is nil
if A == nil {
//.........這裏部分代碼省略.........
示例3: cpl_solver
// Internal CPL solver for CP and CLP problems. Everything is wrapped to proper interfaces
func cpl_solver(F ConvexVarProg, c MatrixVariable, G MatrixVarG, h *matrix.FloatMatrix,
A MatrixVarA, b MatrixVariable, dims *sets.DimensionSet, kktsolver KKTCpSolverVar,
solopts *SolverOptions, x0 MatrixVariable, mnl int) (sol *Solution, err error) {
const (
STEP = 0.99
BETA = 0.5
ALPHA = 0.01
EXPON = 3
MAX_RELAXED_ITERS = 8
)
var refinement int
sol = &Solution{Unknown,
nil,
0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0}
feasTolerance := FEASTOL
absTolerance := ABSTOL
relTolerance := RELTOL
maxIter := MAXITERS
if solopts.FeasTol > 0.0 {
feasTolerance = solopts.FeasTol
}
if solopts.AbsTol > 0.0 {
absTolerance = solopts.AbsTol
}
if solopts.RelTol > 0.0 {
relTolerance = solopts.RelTol
}
if solopts.Refinement > 0 {
refinement = solopts.Refinement
} else {
refinement = 1
}
if solopts.MaxIter > 0 {
maxIter = solopts.MaxIter
}
if x0 == nil {
mnl, x0, err = F.F0()
if err != nil {
return
}
}
if c == nil {
err = errors.New("Must define objective.")
return
}
if h == nil {
h = matrix.FloatZeros(0, 1)
}
if dims == nil {
err = errors.New("Problem dimensions not defined.")
return
}
if err = checkConeLpDimensions(dims); err != nil {
return
}
cdim := dims.Sum("l", "q") + dims.SumSquared("s")
cdim_diag := dims.Sum("l", "q", "s")
if h.Rows() != cdim {
err = errors.New(fmt.Sprintf("'h' must be float matrix of size (%d,1)", cdim))
return
}
if G == nil {
err = errors.New("'G' must be non-nil MatrixG interface.")
return
}
fG := func(x, y MatrixVariable, alpha, beta float64, trans la.Option) error {
return G.Gf(x, y, alpha, beta, trans)
}
// Check A and set defaults if it is nil
if A == nil {
err = errors.New("'A' must be non-nil MatrixA interface.")
return
}
fA := func(x, y MatrixVariable, alpha, beta float64, trans la.Option) error {
return A.Af(x, y, alpha, beta, trans)
}
if b == nil {
err = errors.New("'b' must be non-nil MatrixVariable interface.")
return
}
if kktsolver == nil {
err = errors.New("nil kktsolver not allowed.")
return
}
//.........這裏部分代碼省略.........
示例4: CplCustomMatrix
// Solves a convex optimization problem with a linear objective
//
// minimize c'*x
// subject to f(x) <= 0
// G*x <= h
// A*x = b.
//
// using custom KTT equation solver and custom constraints G and A.
//
func CplCustomMatrix(F ConvexProg, c *matrix.FloatMatrix, G MatrixG, h *matrix.FloatMatrix,
A MatrixA, b *matrix.FloatMatrix, dims *sets.DimensionSet, kktsolver KKTCpSolver,
solopts *SolverOptions) (sol *Solution, err error) {
var mnl int
var x0 *matrix.FloatMatrix
mnl, x0, err = F.F0()
if err != nil {
return
}
if x0.Cols() != 1 {
err = errors.New("'x0' must be matrix with one column")
return
}
if c == nil {
err = errors.New("'c' must be non nil matrix")
return
}
if !c.SizeMatch(x0.Size()) {
err = errors.New(fmt.Sprintf("'c' must be matrix of size (%d,1)", x0.Rows()))
return
}
if h == nil {
h = matrix.FloatZeros(0, 1)
}
if h.Cols() > 1 {
err = errors.New("'h' must be matrix with 1 column")
return
}
if dims == nil {
dims = sets.NewDimensionSet("l", "q", "s")
dims.Set("l", []int{h.Rows()})
}
cdim := dims.Sum("l", "q") + dims.SumSquared("s")
if h.Rows() != cdim {
err = errors.New(fmt.Sprintf("'h' must be float matrix of size (%d,1)", cdim))
return
}
// Check b and set defaults if it is nil
if b == nil {
b = matrix.FloatZeros(0, 1)
}
if b.Cols() != 1 {
estr := fmt.Sprintf("'b' must be a matrix with 1 column")
err = errors.New(estr)
return
}
mc := matrixVar{c}
mb := matrixVar{b}
var mG MatrixVarG
var mA MatrixVarA
if G == nil {
mG = &matrixVarG{matrix.FloatZeros(0, c.Rows()), dims}
} else {
mG = &matrixIfG{G}
}
if A == nil {
mA = &matrixVarA{matrix.FloatZeros(0, c.Rows())}
} else {
mA = &matrixIfA{A}
}
return cpl_problem(F, &mc, mG, h, mA, &mb, dims, kktsolver, solopts, x0, mnl)
}
示例5: CplCustomKKT
// Solves a convex optimization problem with a linear objective
//
// minimize c'*x
// subject to f(x) <= 0
// G*x <= h
// A*x = b.
//
// using custom KTT equation solver.
//
func CplCustomKKT(F ConvexProg, c *matrix.FloatMatrix, G, h, A, b *matrix.FloatMatrix,
dims *sets.DimensionSet, kktsolver KKTCpSolver,
solopts *SolverOptions) (sol *Solution, err error) {
var mnl int
var x0 *matrix.FloatMatrix
mnl, x0, err = F.F0()
if err != nil {
return
}
if x0.Cols() != 1 {
err = errors.New("'x0' must be matrix with one column")
return
}
if c == nil {
err = errors.New("'c' must be non nil matrix")
return
}
if !c.SizeMatch(x0.Size()) {
err = errors.New(fmt.Sprintf("'c' must be matrix of size (%d,1)", x0.Rows()))
return
}
if h == nil {
h = matrix.FloatZeros(0, 1)
}
if h.Cols() > 1 {
err = errors.New("'h' must be matrix with 1 column")
return
}
if dims == nil {
dims = sets.NewDimensionSet("l", "q", "s")
dims.Set("l", []int{h.Rows()})
}
cdim := dims.Sum("l", "q") + dims.SumSquared("s")
if h.Rows() != cdim {
err = errors.New(fmt.Sprintf("'h' must be float matrix of size (%d,1)", cdim))
return
}
if G == nil {
G = matrix.FloatZeros(0, c.Rows())
}
if !G.SizeMatch(cdim, c.Rows()) {
estr := fmt.Sprintf("'G' must be of size (%d,%d)", cdim, c.Rows())
err = errors.New(estr)
return
}
// Check A and set defaults if it is nil
if A == nil {
// zeros rows reduces Gemv to vector products
A = matrix.FloatZeros(0, c.Rows())
}
if A.Cols() != c.Rows() {
estr := fmt.Sprintf("'A' must have %d columns", c.Rows())
err = errors.New(estr)
return
}
// Check b and set defaults if it is nil
if b == nil {
b = matrix.FloatZeros(0, 1)
}
if b.Cols() != 1 {
estr := fmt.Sprintf("'b' must be a matrix with 1 column")
err = errors.New(estr)
return
}
if b.Rows() != A.Rows() {
estr := fmt.Sprintf("'b' must have length %d", A.Rows())
err = errors.New(estr)
return
}
var mc = matrixVar{c}
var mb = matrixVar{b}
var mA = matrixVarA{A}
var mG = matrixVarG{G, dims}
return cpl_problem(F, &mc, &mG, h, &mA, &mb, dims, kktsolver, solopts, x0, mnl)
}
示例6: conelp_solver
func conelp_solver(c MatrixVariable, G MatrixVarG, h *matrix.FloatMatrix,
A MatrixVarA, b MatrixVariable, dims *sets.DimensionSet, kktsolver KKTConeSolverVar,
solopts *SolverOptions, primalstart, dualstart *sets.FloatMatrixSet) (sol *Solution, err error) {
err = nil
const EXPON = 3
const STEP = 0.99
sol = &Solution{Unknown,
nil,
0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0}
var refinement int
if solopts.Refinement > 0 {
refinement = solopts.Refinement
} else {
refinement = 0
if len(dims.At("q")) > 0 || len(dims.At("s")) > 0 {
refinement = 1
}
}
feasTolerance := FEASTOL
absTolerance := ABSTOL
relTolerance := RELTOL
maxIter := MAXITERS
if solopts.FeasTol > 0.0 {
feasTolerance = solopts.FeasTol
}
if solopts.AbsTol > 0.0 {
absTolerance = solopts.AbsTol
}
if solopts.RelTol > 0.0 {
relTolerance = solopts.RelTol
}
if solopts.MaxIter > 0 {
maxIter = solopts.MaxIter
}
if err = checkConeLpDimensions(dims); err != nil {
return
}
cdim := dims.Sum("l", "q") + dims.SumSquared("s")
//cdim_pckd := dims.Sum("l", "q") + dims.SumPacked("s")
cdim_diag := dims.Sum("l", "q", "s")
if h.Rows() != cdim {
err = errors.New(fmt.Sprintf("'h' must be float matrix of size (%d,1)", cdim))
return
}
// Data for kth 'q' constraint are found in rows indq[k]:indq[k+1] of G.
indq := make([]int, 0)
indq = append(indq, dims.At("l")[0])
for _, k := range dims.At("q") {
indq = append(indq, indq[len(indq)-1]+k)
}
// Data for kth 's' constraint are found in rows inds[k]:inds[k+1] of G.
inds := make([]int, 0)
inds = append(inds, indq[len(indq)-1])
for _, k := range dims.At("s") {
inds = append(inds, inds[len(inds)-1]+k*k)
}
Gf := func(x, y MatrixVariable, alpha, beta float64, trans la.Option) error {
return G.Gf(x, y, alpha, beta, trans)
}
Af := func(x, y MatrixVariable, alpha, beta float64, trans la.Option) error {
return A.Af(x, y, alpha, beta, trans)
}
// kktsolver(W) returns a routine for solving 3x3 block KKT system
//
// [ 0 A' G'*W^{-1} ] [ ux ] [ bx ]
// [ A 0 0 ] [ uy ] = [ by ].
// [ G 0 -W' ] [ uz ] [ bz ]
if kktsolver == nil {
err = errors.New("nil kktsolver not allowed.")
return
}
// res() evaluates residual in 5x5 block KKT system
//
// [ vx ] [ 0 ] [ 0 A' G' c ] [ ux ]
// [ vy ] [ 0 ] [-A 0 0 b ] [ uy ]
// [ vz ] += [ W'*us ] - [-G 0 0 h ] [ W^{-1}*uz ]
// [ vtau ] [ dg*ukappa ] [-c' -b' -h' 0 ] [ utau/dg ]
//
// vs += lmbda o (dz + ds)
// vkappa += lmbdg * (dtau + dkappa).
ws3 := matrix.FloatZeros(cdim, 1)
wz3 := matrix.FloatZeros(cdim, 1)
checkpnt.AddMatrixVar("ws3", ws3)
checkpnt.AddMatrixVar("wz3", wz3)
//
//.........這裏部分代碼省略.........
示例7: ConeLpCustomMatrix
// Solves a pair of primal and dual cone programs using custom KKT solver and constraint
// interfaces MatrixG and MatrixA
//
func ConeLpCustomMatrix(c *matrix.FloatMatrix, G MatrixG, h *matrix.FloatMatrix,
A MatrixA, b *matrix.FloatMatrix, dims *sets.DimensionSet, kktsolver KKTConeSolver,
solopts *SolverOptions, primalstart, dualstart *sets.FloatMatrixSet) (sol *Solution, err error) {
err = nil
if c == nil || c.Cols() > 1 {
err = errors.New("'c' must be matrix with 1 column")
return
}
if h == nil || h.Cols() > 1 {
err = errors.New("'h' must be matrix with 1 column")
return
}
if err = checkConeLpDimensions(dims); err != nil {
return
}
cdim := dims.Sum("l", "q") + dims.SumSquared("s")
cdim_pckd := dims.Sum("l", "q") + dims.SumPacked("s")
//cdim_diag := dims.Sum("l", "q", "s")
if h.Rows() != cdim {
err = errors.New(fmt.Sprintf("'h' must be float matrix of size (%d,1)", cdim))
return
}
// Data for kth 'q' constraint are found in rows indq[k]:indq[k+1] of G.
indq := make([]int, 0)
indq = append(indq, dims.At("l")[0])
for _, k := range dims.At("q") {
indq = append(indq, indq[len(indq)-1]+k)
}
// Data for kth 's' constraint are found in rows inds[k]:inds[k+1] of G.
inds := make([]int, 0)
inds = append(inds, indq[len(indq)-1])
for _, k := range dims.At("s") {
inds = append(inds, inds[len(inds)-1]+k*k)
}
// Check b and set defaults if it is nil
if b == nil {
b = matrix.FloatZeros(0, 1)
}
if b.Cols() != 1 {
estr := fmt.Sprintf("'b' must be a matrix with 1 column")
err = errors.New(estr)
return
}
if b.Rows() > c.Rows() || b.Rows()+cdim_pckd < c.Rows() {
err = errors.New("Rank(A) < p or Rank([G; A]) < n")
return
}
if kktsolver == nil {
err = errors.New("nil kktsolver not allowed.")
return
}
var mA MatrixVarA
var mG MatrixVarG
if G == nil {
mG = &matrixVarG{matrix.FloatZeros(0, c.Rows()), dims}
} else {
mG = &matrixIfG{G}
}
if A == nil {
mA = &matrixVarA{matrix.FloatZeros(0, c.Rows())}
} else {
mA = &matrixIfA{A}
}
var mc = &matrixVar{c}
var mb = &matrixVar{b}
return conelp_problem(mc, mG, h, mA, mb, dims, kktsolver, solopts, primalstart, dualstart)
}
示例8: ConeLpCustomKKT
// Solves a pair of primal and dual cone programs using custom KKT solver.
//
func ConeLpCustomKKT(c, G, h, A, b *matrix.FloatMatrix, dims *sets.DimensionSet,
kktsolver KKTConeSolver, solopts *SolverOptions, primalstart,
dualstart *sets.FloatMatrixSet) (sol *Solution, err error) {
if c == nil || c.Cols() > 1 {
err = errors.New("'c' must be matrix with 1 column")
return
}
if h == nil {
h = matrix.FloatZeros(0, 1)
}
if h.Cols() > 1 {
err = errors.New("'h' must be matrix with 1 column")
return
}
if dims == nil {
dims = sets.NewDimensionSet("l", "q", "s")
dims.Set("l", []int{h.Rows()})
}
cdim := dims.Sum("l", "q") + dims.SumSquared("s")
cdim_pckd := dims.Sum("l", "q") + dims.SumPacked("s")
//cdim_diag := dims.Sum("l", "q", "s")
if G == nil {
G = matrix.FloatZeros(0, c.Rows())
}
if !G.SizeMatch(cdim, c.Rows()) {
estr := fmt.Sprintf("'G' must be of size (%d,%d)", cdim, c.Rows())
err = errors.New(estr)
return
}
// Check A and set defaults if it is nil
if A == nil {
// zeros rows reduces Gemv to vector products
A = matrix.FloatZeros(0, c.Rows())
}
if A.Cols() != c.Rows() {
estr := fmt.Sprintf("'A' must have %d columns", c.Rows())
err = errors.New(estr)
return
}
// Check b and set defaults if it is nil
if b == nil {
b = matrix.FloatZeros(0, 1)
}
if b.Cols() != 1 {
estr := fmt.Sprintf("'b' must be a matrix with 1 column")
err = errors.New(estr)
return
}
if b.Rows() != A.Rows() {
estr := fmt.Sprintf("'b' must have length %d", A.Rows())
err = errors.New(estr)
return
}
if b.Rows() > c.Rows() || b.Rows()+cdim_pckd < c.Rows() {
err = errors.New("Rank(A) < p or Rank([G; A]) < n")
return
}
mA := &matrixVarA{A}
mG := &matrixVarG{G, dims}
mc := &matrixVar{c}
mb := &matrixVar{b}
return conelp_problem(mc, mG, h, mA, mb, dims, kktsolver, solopts, primalstart, dualstart)
}
示例9: ConeLp
// Solves a pair of primal and dual cone programs
//
// minimize c'*x
// subject to G*x + s = h
// A*x = b
// s >= 0
//
// maximize -h'*z - b'*y
// subject to G'*z + A'*y + c = 0
// z >= 0.
//
// The inequalities are with respect to a cone C defined as the Cartesian
// product of N + M + 1 cones:
//
// C = C_0 x C_1 x .... x C_N x C_{N+1} x ... x C_{N+M}.
//
// The first cone C_0 is the nonnegative orthant of dimension ml.
// The next N cones are second order cones of dimension r[0], ..., r[N-1].
// The second order cone of dimension m is defined as
//
// { (u0, u1) in R x R^{m-1} | u0 >= ||u1||_2 }.
//
// The next M cones are positive semidefinite cones of order t[0], ..., t[M-1] >= 0.
//
// The structure of C is specified by DimensionSet dims which holds following sets
//
// dims.At("l") l, the dimension of the nonnegative orthant (array of length 1)
// dims.At("q") r[0], ... r[N-1], list with the dimesions of the second-order cones
// dims.At("s") t[0], ... t[M-1], array with the dimensions of the positive
// semidefinite cones
//
// The default value for dims is l: []int{G.Rows()}, q: []int{}, s: []int{}.
//
// Arguments primalstart, dualstart are optional starting points for primal and
// dual problems. If non-nil then primalstart is a FloatMatrixSet having two entries.
//
// primalstart.At("x")[0] starting point for x
// primalstart.At("s")[0] starting point for s
// dualstart.At("y")[0] starting point for y
// dualstart.At("z")[0] starting point for z
//
// On exit Solution contains the result and information about the accurancy of the
// solution. if SolutionStatus is Optimal then Solution.Result contains solutions
// for the problems.
//
// Result.At("x")[0] solution for x
// Result.At("y")[0] solution for y
// Result.At("s")[0] solution for s
// Result.At("z")[0] solution for z
//
func ConeLp(c, G, h, A, b *matrix.FloatMatrix, dims *sets.DimensionSet, solopts *SolverOptions,
primalstart, dualstart *sets.FloatMatrixSet) (sol *Solution, err error) {
if c == nil || c.Cols() > 1 {
err = errors.New("'c' must be matrix with 1 column")
return
}
if c.Rows() < 1 {
err = errors.New("No variables, 'c' must have at least one row")
return
}
if h == nil || h.Cols() > 1 {
err = errors.New("'h' must be matrix with 1 column")
return
}
if dims == nil {
dims = sets.NewDimensionSet("l", "q", "s")
dims.Set("l", []int{h.Rows()})
}
cdim := dims.Sum("l", "q") + dims.SumSquared("s")
cdim_pckd := dims.Sum("l", "q") + dims.SumPacked("s")
if h.Rows() != cdim {
err = errors.New(fmt.Sprintf("'h' must be float matrix of size (%d,1)", cdim))
return
}
if G == nil {
G = matrix.FloatZeros(0, c.Rows())
}
if !G.SizeMatch(cdim, c.Rows()) {
estr := fmt.Sprintf("'G' must be of size (%d,%d)", cdim, c.Rows())
err = errors.New(estr)
return
}
// Check A and set defaults if it is nil
if A == nil {
// zeros rows reduces Gemv to vector products
A = matrix.FloatZeros(0, c.Rows())
}
if A.Cols() != c.Rows() {
estr := fmt.Sprintf("'A' must have %d columns", c.Rows())
err = errors.New(estr)
return
}
//.........這裏部分代碼省略.........