Beispiel #1
0
func New(ni, no uint, config *config.Solution) (*Solution, error) {
	power := config.Power
	if power == 0 {
		return nil, errors.New("the interpolation power should be positive")
	}

	var agrid interface {
		hybrid.Grid
		hybrid.Guide
		grid.Parenter
	}
	var abasis hybrid.Basis
	switch config.Rule {
	case "closed":
		agrid = equidistant.NewClosed(ni)
		abasis = polynomial.NewClosed(ni, power)
	case "open":
		agrid = equidistant.NewOpen(ni)
		abasis = polynomial.NewOpen(ni, power)
	default:
		return nil, errors.New("the interpolation rule is unknown")
	}

	return &Solution{
		Algorithm: *hybrid.New(ni, no, agrid, abasis),

		config: config,
		grid:   agrid,
	}, nil
}
Beispiel #2
0
func benchmarkOpenCompute(power uint, b *testing.B) {
	const (
		nd = 10
		ns = 100000
	)

	basis := NewOpen(nd, power)
	indices := generateIndices(nd, ns, equidistant.NewOpen(nd).Refine)
	points := generatePoints(nd, ns, indices, basis.grid.Node)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		for j := 0; j < ns; j++ {
			basis.Compute(indices[j*nd:(j+1)*nd], points[j*nd:(j+1)*nd])
		}
	}
}