Documentation
¶
Index ¶
- Constants
- Variables
- func AbsCosTheta(d Direction) float64
- func AddVec(res, a, b *mat.VecDense) *mat.VecDense
- func AddVecs(res *mat.VecDense, vecs ...*mat.VecDense) *mat.VecDense
- func CalculateStrideForTensor(shape []int) ([]int, int)
- func Clamp(value, minimum, maximum float64) float64
- func ClampUnit(value float64) float64
- func CosTheta(d Direction) float64
- func CosineHemisphereIntegral(dim int) float64
- func CosineHemispherePDF(w Direction) float64
- func Cross(res, u, v *mat.VecDense) *mat.VecDense
- func Cross2(u, v *mat.VecDense) *mat.VecDense
- func Cross4(u, v, w *mat.VecDense) *mat.VecDense
- func Distance(a, b *mat.VecDense) float64
- func DurandKerner(coeffs []complex128, tol float64, maxIter int) ([]complex128, error)
- func FormatVec(v *mat.VecDense) string
- func GramSchmidt(v ...*mat.VecDense) []*mat.VecDense
- func IdentityTransform4() [4][4]float64
- func IsFinite(value float64) bool
- func IsUpperHemisphere(d Direction) bool
- func Lerp(minimum, maximum, t float64) float64
- func MatrixToSlice(m *mat.Dense) [][]float64
- func MaxVec(a, b *mat.VecDense) *mat.VecDense
- func MinVec(a, b *mat.VecDense) *mat.VecDense
- func MulVec(res *mat.VecDense, a *mat.Dense, b *mat.VecDense) *mat.VecDense
- func NewtonRaphson(f func([]float64) []float64, x0 []float64, options *NewtonOptions) ([]float64, error)
- func Normalize(v *mat.VecDense) *mat.VecDense
- func NumericalJacobian(f func([]float64) []float64, x []float64, eps float64) ([][]float64, error)
- func PositiveMod(value, period float64) float64
- func Project(v, u *mat.VecDense) *mat.VecDense
- func RealRoots(roots []complex128, tol float64) []float64
- func SameHemisphere(a, b Direction) bool
- func ScaleVec(res *mat.VecDense, s float64, v *mat.VecDense) *mat.VecDense
- func ScaleVec2(s float64, v *mat.VecDense) *mat.VecDense
- func SignChanged(a, b float64) bool
- func SolveCubicEquationAnalytical(a, b, c, d float64) ([]complex128, error)
- func SolveCubicEquationReal(a, b, c, d float64) ([]float64, error)
- func SolveLinearEquation(a, b float64) ([]float64, error)
- func SolveLinearEquationAnalytical(a, b float64) ([]complex128, error)
- func SolveLinearSystem(A [][]float64, b []float64) ([]float64, error)
- func SolvePolynomial(coeffs []complex128) ([]complex128, error)
- func SolvePolynomialReal(coeffs []float64) ([]float64, error)
- func SolvePolynomialRealNumeric(coeffs []float64) ([]float64, error)
- func SolveQuadraticEquationAnalytical(a, b, c float64) ([]complex128, error)
- func SolveQuadraticEquationReal(a, b, c float64) ([]float64, error)
- func SolveQuarticEquationAnalytical(a4, a3, a2, a1, a0 float64) ([]complex128, error)
- func SolveQuarticEquationReal(a4, a3, a2, a1, a0 float64) ([]float64, error)
- func SquaredDistance(a, b *mat.VecDense) float64
- func SubVec(res, a, b *mat.VecDense) *mat.VecDense
- type Direction
- func (d Direction) Add(other Direction) Direction
- func (d Direction) Component(i int) float64
- func (d Direction) Dot(other Direction) float64
- func (d Direction) IsFinite() bool
- func (d Direction) Len() int
- func (d Direction) Length() float64
- func (d Direction) MulScalar(v float64) Direction
- func (d Direction) Normalize() Direction
- type Frame
- type NewtonOptions
- type Number
- type Sample2D
- type SparseTensor
- func (t *SparseTensor[T]) Add(other *SparseTensor[T]) (*SparseTensor[T], error)
- func (t *SparseTensor[T]) Get(index []int) (T, error)
- func (t *SparseTensor[T]) IterNonZero(fn func(index []int, value T))
- func (t *SparseTensor[T]) MustGet(index []int) T
- func (t *SparseTensor[T]) NNZ() int
- func (t *SparseTensor[T]) ScalarMul(scalar T) *SparseTensor[T]
- func (t *SparseTensor[T]) Set(index []int, value T) error
- func (t *SparseTensor[T]) ToCOO() *SparseTensor[T]
- func (t *SparseTensor[T]) ToHash() *SparseTensor[T]
- type SparseTensorEntry
- type SparseTensorFormat
- type Tensor
- func (t *Tensor[T]) Add(a, b *Tensor[T]) *Tensor[T]
- func (t *Tensor[T]) CoordinateToIndex(coordinate ...int) int
- func (t *Tensor[T]) Get(coordinate ...int) T
- func (t *Tensor[T]) GetCoordinates(i int) []int
- func (t *Tensor[T]) Reshape(newShape []int) *Tensor[T]
- func (t *Tensor[T]) ScalarMul(scalar T) *Tensor[T]
- func (t *Tensor[T]) Set(value T, coordinate ...int)
- func (t *Tensor[T]) Sub(a, b *Tensor[T]) *Tensor[T]
Constants ¶
const ( DefaultTol = 1e-12 DefaultMaxIter = 10000 )
Variables ¶
var ( ErrNoSolution = errors.New("no solution") ErrInfiniteSolutions = errors.New("infinite solutions") ErrInvalidInput = errors.New("invalid input") ErrNonSquareSystem = errors.New("linear system must be square") ErrSingularMatrix = errors.New("singular matrix") ErrNotConverged = errors.New("not converged") ErrDegreeTooHigh = errors.New("polynomial degree too high") ErrZeroPolynomial = errors.New("zero polynomial") )
Functions ¶
func AbsCosTheta ¶
func CosineHemispherePDF ¶
func DurandKerner ¶
func DurandKerner(coeffs []complex128, tol float64, maxIter int) ([]complex128, error)
func GramSchmidt ¶
GramSchmidt Perform Gram Schmidt orthogonalization on any number of vectors
func IdentityTransform4 ¶
func IdentityTransform4() [4][4]float64
func IsUpperHemisphere ¶
func NewtonRaphson ¶
func NewtonRaphson( f func([]float64) []float64, x0 []float64, options *NewtonOptions, ) ([]float64, error)
NewtonRaphson solves a nonlinear square system:
f(x) = 0
f must return the same number of equations as len(x0).
func NumericalJacobian ¶
func NumericalJacobian( f func([]float64) []float64, x []float64, eps float64, ) ([][]float64, error)
NumericalJacobian computes the central-difference numerical Jacobian.
It returns an m*n matrix, where:
m = len(f(x)) n = len(x)
func PositiveMod ¶
func RealRoots ¶
func RealRoots(roots []complex128, tol float64) []float64
RealRoots filters approximately real roots from complex roots.
func SameHemisphere ¶
func SignChanged ¶
func SolveCubicEquationAnalytical ¶
func SolveCubicEquationAnalytical(a, b, c, d float64) ([]complex128, error)
SolveCubicEquationAnalytical solves:
a*x^3 + b*x^2 + c*x + d = 0
It returns all complex roots, including repeated roots.
func SolveCubicEquationReal ¶
SolveCubicEquationReal solves:
a*x^3 + b*x^2 + c*x + d = 0
It returns only real roots.
func SolveLinearEquation ¶
SolveLinearEquation solves:
a*x + b = 0
Return values:
- one root: []float64{x}
- no solution: ErrNoSolution
- infinite solutions: ErrInfiniteSolutions
func SolveLinearEquationAnalytical ¶
func SolveLinearEquationAnalytical(a, b float64) ([]complex128, error)
SolveLinearEquationAnalytical solves:
a*x + b = 0
func SolveLinearSystem ¶
SolveLinearSystem solves:
A*x = b
using Gaussian elimination with partial pivoting.
func SolvePolynomial ¶
func SolvePolynomial(coeffs []complex128) ([]complex128, error)
SolvePolynomial solves a polynomial with complex coefficients.
Coefficients must be ordered from highest degree to constant term:
a_n*x^n + a_{n-1}*x^{n-1} + ... + a_1*x + a_0
Example:
x^3 - 1 = 0
should be passed as:
[]complex128{1, 0, 0, -1}
For degree 1 and 2, it uses direct formulas. For degree 3 and above, it uses the Durand-Kerner method.
func SolvePolynomialReal ¶
SolvePolynomialReal solves a real-coefficient polynomial and returns its real roots.
Coefficients must be ordered from highest degree to constant term:
coeffs = []float64{a_n, a_{n-1}, ..., a_1, a_0}
Supported degree:
0: no roots 1: linear 2: quadratic 3: cubic 4: quartic
For degree > 4, this function falls back to numeric real-root isolation.
func SolvePolynomialRealNumeric ¶
SolvePolynomialRealNumeric solves real roots for arbitrary-degree real polynomials.
Coefficients must be ordered from highest degree to constant term:
coeffs = []float64{a_n, a_{n-1}, ..., a_1, a_0}
This function returns only real roots.
Method:
- recursively solve roots of the derivative
- split the real line into monotonic intervals
- use bisection where sign changes occur
- check derivative critical points to catch even-multiplicity roots
func SolveQuadraticEquationAnalytical ¶
func SolveQuadraticEquationAnalytical(a, b, c float64) ([]complex128, error)
SolveQuadraticEquationAnalytical solves:
a*x^2 + b*x + c = 0
It returns all complex roots, including repeated roots.
func SolveQuadraticEquationReal ¶
SolveQuadraticEquationReal solves:
a*x^2 + b*x + c = 0
It returns only real roots.
func SolveQuarticEquationAnalytical ¶
func SolveQuarticEquationAnalytical(a4, a3, a2, a1, a0 float64) ([]complex128, error)
SolveQuarticEquationAnalytical solves:
a4*x^4 + a3*x^3 + a2*x^2 + a1*x + a0 = 0
using Ferrari's closed-form method.
It returns all complex roots, including repeated roots.
func SolveQuarticEquationReal ¶
SolveQuarticEquationReal solves:
a4*x^4 + a3*x^3 + a2*x^2 + a1*x + a0 = 0
It returns only real roots.
This implementation uses derivative critical points to split the real line into monotonic intervals, then applies bisection on intervals with sign changes. It also checks critical points directly so even-multiplicity roots are not missed.
func SquaredDistance ¶
Types ¶
type Direction ¶
type Direction []float64
func CosineSampleHemisphere ¶
func NewDirection ¶
type Frame ¶
type Frame struct {
Geometry geometry.Geometry
Point *mat.VecDense
Tangent *mat.VecDense
Bitangent *mat.VecDense
Normal *mat.VecDense
Tangents []*mat.VecDense
}
func NewFrameFromNormalInGeometry ¶
NewFrameFromNormalInGeometry builds a metric-orthonormal surface frame at p. n must be an intrinsic tangent-space normal vector (an ambient gradient should first be converted with Geometry.IntrinsicNormal).
type NewtonOptions ¶
NewtonOptions controls Newton-Raphson behavior.
type SparseTensor ¶
type SparseTensor[T Number] struct { Shape []int `json:"shape"` Format SparseTensorFormat `json:"format"` Default T `json:"default"` Entries []SparseTensorEntry[T] `json:"entries"` // contains filtered or unexported fields }
func NewSparseTensor ¶
func NewSparseTensor[T Number](shape []int, format SparseTensorFormat) *SparseTensor[T]
func NewSparseTensorFromEntries ¶
func NewSparseTensorFromEntries[T Number]( shape []int, format SparseTensorFormat, entries []SparseTensorEntry[T], ) (*SparseTensor[T], error)
func (*SparseTensor[T]) Add ¶
func (t *SparseTensor[T]) Add(other *SparseTensor[T]) (*SparseTensor[T], error)
func (*SparseTensor[T]) Get ¶
func (t *SparseTensor[T]) Get(index []int) (T, error)
func (*SparseTensor[T]) IterNonZero ¶
func (t *SparseTensor[T]) IterNonZero(fn func(index []int, value T))
func (*SparseTensor[T]) MustGet ¶
func (t *SparseTensor[T]) MustGet(index []int) T
func (*SparseTensor[T]) NNZ ¶
func (t *SparseTensor[T]) NNZ() int
func (*SparseTensor[T]) ScalarMul ¶
func (t *SparseTensor[T]) ScalarMul(scalar T) *SparseTensor[T]
func (*SparseTensor[T]) Set ¶
func (t *SparseTensor[T]) Set(index []int, value T) error
func (*SparseTensor[T]) ToCOO ¶
func (t *SparseTensor[T]) ToCOO() *SparseTensor[T]
func (*SparseTensor[T]) ToHash ¶
func (t *SparseTensor[T]) ToHash() *SparseTensor[T]
type SparseTensorEntry ¶
type SparseTensorFormat ¶
type SparseTensorFormat string
const ( SparseTensorCOO SparseTensorFormat = "coo" SparseTensorHash SparseTensorFormat = "hash" SparseTensorCSR SparseTensorFormat = "csr" SparseTensorCSC SparseTensorFormat = "csc" SparseTensorBlock SparseTensorFormat = "block" )
type Tensor ¶
type Tensor[T Number] struct { Data []T `json:"data"` Shape []int `json:"shape"` Stride []int `json:"stride"` Offset int `json:"offset"` }