<commit_before>package polynomial

import (
	"math"

	"github.com/ready-steady/adapt/grid/equidistant"
)

// Open is a basis in (0, 1)^n.
type Open struct {
	nd   uint
	grid equidistant.Open
}

// NewOpen creates a basis.
func NewOpen(dimensions, power uint) *Open {
	if power != 1 {
		panic("not implemented")
	}
	return &Open{
		nd:   dimensions,
		grid: *equidistant.NewOpen(1),
	}
}

// Compute evaluates a basis function.
func (self *Open) Compute(index []uint64, point []float64) float64 {
	return compute(index, point, self.nd, self.compute)
}

// Integrate computes the integral of a basis function.
func (self *Open) Integrate(index []uint64) float64 {
	return integrate(index, self.nd, self.integrate)
}

func (self *Open) compute(level, order uint64, x float64) float64 {
	if level == 0 {
		return 1.0
	}
	xi, h, count := self.grid.Node(level, order)
	switch order {
	case 0:
		if x >= 2.0*h {
			return 0.0
		}
		return 2.0 - x/h
	case count - 1:
		left := float64(count - 1)
		if x <= left*h {
			return 0.0
		}
		return x/h - left
	default:
		Δ := math.Abs(x - xi)
		if Δ >= h {
			return 0.0
		}
		return 1.0 - Δ/h
	}
}

func (self *Open) integrate(level, order uint64) float64 {
	if level == 0 {
		return 1.0
	}
	_, _, count := self.grid.Node(level, order)
	switch order {
	case 0, count - 1:
		return 2.0 / float64(count+1)
	default:
		return 1.0 / float64(count+1)
	}
}<commit_msg>b/polynomial: make a cosmetic adjustment<commit_after>package polynomial

import (
	"math"

	"github.com/ready-steady/adapt/grid/equidistant"
)

// Open is a basis in (0, 1)^n.
type Open struct {
	nd   uint
	grid equidistant.Open
}

// NewOpen creates a basis.
func NewOpen(dimensions, power uint) *Open {
	if power != 1 {
		panic("not implemented")
	}
	return &Open{
		nd:   dimensions,
		grid: *equidistant.NewOpen(1),
	}
}

// Compute evaluates a basis function.
func (self *Open) Compute(index []uint64, point []float64) float64 {
	return compute(index, point, self.nd, self.compute)
}

// Integrate computes the integral of a basis function.
func (self *Open) Integrate(index []uint64) float64 {
	return integrate(index, self.nd, self.integrate)
}

func (self *Open) compute(level, order uint64, x float64) float64 {
	if level == 0 {
		return 1.0
	}
	xi, h, count := self.grid.Node(level, order)
	switch order {
	case 0:
		if x >= 2.0*h {
			return 0.0
		}
		return 2.0 - x/h
	case count - 1:
		left := float64(count - 1)
		if x <= left*h {
			return 0.0
		}
		return x/h - left
	default:
		Δ := math.Abs(x - xi)
		if Δ >= h {
			return 0.0
		}
		return 1.0 - Δ/h
	}
}

func (self *Open) integrate(level, order uint64) float64 {
	if level == 0 {
		return 1.0
	}
	_, h, count := self.grid.Node(level, order)
	switch order {
	case 0, count - 1:
		return 2.0 * h
	default:
		return 1.0 * h
	}
}
{'fraction_non_alphanumeric': 0.13953488372093023, 'fraction_numerical': 0.04007155635062612, 'mean_word_length': 2.994285714285714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2609054', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1075, 'n_words': 325}