MCPcopy
hub / github.com/qax-os/excelize / prepareTrendGrowth

Function prepareTrendGrowth

calc.go:8572–8623  ·  view source on GitHub ↗

prepareTrendGrowth check and return the result.

(bLOG bool, mtxX, mtxY [][]float64)

Source from the content-addressed store, hash-verified

8570
8571// prepareTrendGrowth check and return the result.
8572func prepareTrendGrowth(bLOG bool, mtxX, mtxY [][]float64) (*trendGrowthMatrixInfo, formulaArg) {
8573 var nCX, nRX, M, N, trendType int
8574 nRY, nCY := len(mtxY), len(mtxY[0])
8575 cntY := nCY * nRY
8576 newY := prepareTrendGrowthMtxY(bLOG, mtxY)
8577 if newY == nil {
8578 return nil, newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM)
8579 }
8580 var newX [][]float64
8581 if len(mtxX) != 0 {
8582 nRX, nCX = len(mtxX), len(mtxX[0])
8583 if newX = prepareTrendGrowthMtxX(mtxX); newX == nil {
8584 return nil, newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM)
8585 }
8586 if nCX == nCY && nRX == nRY {
8587 trendType, M, N = 1, 1, cntY // simple regression
8588 } else if nCY != 1 && nRY != 1 {
8589 return nil, newErrorFormulaArg(formulaErrorREF, formulaErrorREF)
8590 } else if nCY == 1 {
8591 if nRX != nRY {
8592 return nil, newErrorFormulaArg(formulaErrorREF, formulaErrorREF)
8593 }
8594 trendType, M, N = 2, nCX, nRY
8595 } else if nCX != nCY {
8596 return nil, newErrorFormulaArg(formulaErrorREF, formulaErrorREF)
8597 } else {
8598 trendType, M, N = 3, nRX, nCY
8599 }
8600 } else {
8601 newX = getNewMatrix(nCY, nRY)
8602 nCX, nRX = nCY, nRY
8603 num := 1.0
8604 for i := 0; i < nRY; i++ {
8605 for j := 0; j < nCY; j++ {
8606 newX[j][i] = num
8607 num++
8608 }
8609 }
8610 trendType, M, N = 1, 1, cntY
8611 }
8612 return &trendGrowthMatrixInfo{
8613 trendType: trendType,
8614 nCX: nCX,
8615 nCY: nCY,
8616 nRX: nRX,
8617 nRY: nRY,
8618 M: M,
8619 N: N,
8620 mtxX: newX,
8621 mtxY: newY,
8622 }, newEmptyFormulaArg()
8623}
8624
8625// calcPosition calculate position for matrix by given index.
8626func calcPosition(mtx [][]float64, idx int) (row, col int) {

Callers 2

calcTrendGrowthFunction · 0.85
TestPrepareTrendGrowthFunction · 0.85

Calls 5

prepareTrendGrowthMtxYFunction · 0.85
newErrorFormulaArgFunction · 0.85
prepareTrendGrowthMtxXFunction · 0.85
getNewMatrixFunction · 0.85
newEmptyFormulaArgFunction · 0.85

Tested by 1

TestPrepareTrendGrowthFunction · 0.68