utils

package
v0.0.0-...-88f8085 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NODETOL = 1.e-12
)

Variables

View Source
var (
	// Low storage 4th order Runge Kutta coefficients
	RK4a = []float64{
		0.0,
		-567301805773.0 / 1357537059087.0,
		-2404267990393.0 / 2016746695238.0,
		-3550918686646.0 / 2091501179385.0,
		-1275806237668.0 / 842570457699.0,
	}
	RK4b = []float64{
		1432997174477.0 / 9575080441755.0,
		5161836677717.0 / 13612068292357.0,
		1720146321549.0 / 2090206949498.0,
		3134564353537.0 / 4481467310338.0,
		2277821191437.0 / 14882151754819.0,
	}
	RK4c = []float64{
		0.0,
		1432997174477.0 / 9575080441755.0,
		2526269341429.0 / 6820363962896.0,
		2006345519317.0 / 3224310063776.0,
		2802321613138.0 / 2924317926251.0,
		1.,
	}
)

Functions

func ArraysTo2Vector

func ArraysTo2Vector(r1, r2 []float64, scaleO ...float64) (g [][2]float64)

func ArraysToPoints

func ArraysToPoints(r1, r2 []float64) (points []graphics2D.Point)

func ColMajorIndex

func ColMajorIndex(nc, i, j int) (ind int)

func ConstArray

func ConstArray(N int, val float64) (v []float64)

func GetColor

func GetColor(name ColorName) (c color.RGBA)

func GetMemUsage

func GetMemUsage() string

func IndexedAssign

func IndexedAssign(mI interface{}, I Index, ValI interface{}) (err error)

func NewSymTriDiagonal

func NewSymTriDiagonal(d0, d1 []float64) (Tri *mat.SymDense)

func POW

func POW(x float64, pp int) (y float64)

func ParseDim

func ParseDim(dimI interface{}, max int) (i1, i2 int)

func RowMajorToColMajor

func RowMajorToColMajor(nr, nc, ind int) (cind int)

func SleepFor

func SleepFor(milliseconds int)

func Split1D

func Split1D(iMax, numThreads, threadNum int) (istart, iend int)

func Split1DMaxChunk

func Split1DMaxChunk(iMax, numThreads int) (maxChunk int)

Types

type BlockMatrix

type BlockMatrix struct {
	M      [][]Matrix // First slice points to rows of matrices - Note, the Matrix type allows for scalar matrices
	Nr, Nc int        // number of rows, columns in the square block matrix consisting of a sub-matrix in each cell
	P      []int      // Permutation "matrix", created during an LUP decomposition, otherwise nil
	Pcount int        // count of number of pivots, used in determining sign of determinant
	// contains filtered or unexported fields
}

func NewBlockMatrix

func NewBlockMatrix(Nr, Nc int) (R BlockMatrix)

func NewBlockMatrixFromScalar

func NewBlockMatrixFromScalar(A Matrix) (R BlockMatrix)

func (BlockMatrix) Add

func (bm BlockMatrix) Add(ba BlockMatrix)

func (BlockMatrix) Copy

func (bm BlockMatrix) Copy() (R BlockMatrix)

func (BlockMatrix) GetTol

func (bm BlockMatrix) GetTol() (tol float64)

func (BlockMatrix) IsSquare

func (bm BlockMatrix) IsSquare() bool

func (*BlockMatrix) LUPDecompose

func (bm *BlockMatrix) LUPDecompose() (err error)

func (BlockMatrix) LUPDeterminant

func (bm BlockMatrix) LUPDeterminant() (det float64, err error)

func (BlockMatrix) LUPInvert

func (bm BlockMatrix) LUPInvert() (R BlockMatrix, err error)

func (BlockMatrix) LUPSolve

func (bm BlockMatrix) LUPSolve(b []Matrix) (Bx BlockMatrix, err error)

func (BlockMatrix) Mul

func (bm BlockMatrix) Mul(ba BlockMatrix) (R BlockMatrix)

func (BlockMatrix) Print

func (bm BlockMatrix) Print() (out string)

func (BlockMatrix) Scale

func (bm BlockMatrix) Scale(val float64) (R BlockMatrix)

func (BlockMatrix) Transpose

func (bm BlockMatrix) Transpose() (R BlockMatrix)

type CSR

type CSR struct {
	M *sparse.CSR
	// contains filtered or unexported fields
}

func NewCSR

func NewCSR(nr, nc int) (R CSR)

func (CSR) Assign

func (m CSR) Assign(I Index, AI interface{}) CSR

func (CSR) At

func (m CSR) At(i, j int) float64

func (CSR) Data

func (m CSR) Data() []float64

func (CSR) Dims

func (m CSR) Dims() (r, c int)

Dims, At and T minimally satisfy the mat.Matrix interface.

func (CSR) Equate

func (m CSR) Equate(ValuesI interface{}, RangeO ...interface{})

func (CSR) IndexedAssign

func (m CSR) IndexedAssign(I Index, ValI interface{}) (err error)

func (CSR) RawMatrix

func (m CSR) RawMatrix() *blas.SparseMatrix

func (CSR) T

func (m CSR) T() mat.Matrix

type ColorName

type ColorName uint8
const (
	White ColorName = iota
	Blue
	Red
	Green
	Black
)

type DOK

type DOK struct {
	M *sparse.DOK
	// contains filtered or unexported fields
}

func NewDOK

func NewDOK(nr, nc int) (R DOK)

func (DOK) Assign

func (m DOK) Assign(I Index, AI interface{}) DOK

func (DOK) At

func (m DOK) At(i, j int) float64

func (DOK) Data

func (m DOK) Data() []float64

func (DOK) Dims

func (m DOK) Dims() (r, c int)

Dims, At and T minimally satisfy the mat.Matrix interface.

func (DOK) Equate

func (m DOK) Equate(ValuesI interface{}, RangeO ...interface{})

func (DOK) IndexedAssign

func (m DOK) IndexedAssign(I Index, ValI interface{}) (err error)

func (DOK) RawMatrix

func (m DOK) RawMatrix() *blas.SparseMatrix

func (DOK) T

func (m DOK) T() mat.Matrix

func (DOK) ToCSR

func (m DOK) ToCSR() CSR

type EvalOp

type EvalOp uint8
const (
	Equal EvalOp = iota
	Less
	Greater
	LessOrEqual
	GreaterOrEqual
)

type Index

type Index []int

func NewFromFloat

func NewFromFloat(IF []float64) (r Index)

func NewIndex

func NewIndex(N int, ValIO ...interface{}) (I Index)

Chainable methods

func NewOnes

func NewOnes(N int) (r Index)

func NewRange

func NewRange(rmin, rmax int) (r Index)

func NewRangeInclusive

func NewRangeInclusive(rmin, rmax int) (r Index)

func NewRangeOffset

func NewRangeOffset(rmin, rmax int) (r Index)

func (Index) Add

func (I Index) Add(val int) Index

func (Index) Apply

func (I Index) Apply(f func(val int) int) Index

func (Index) Compare

func (I Index) Compare(op EvalOp, Values Index) (J Index)

func (Index) Copy

func (I Index) Copy() (r Index)

func (*Index) IndexedAssign

func (I *Index) IndexedAssign(J, Val Index) (err error)

func (Index) Outer

func (I Index) Outer(J Index) (A Matrix)

Non chainable methods

func (Index) RowMajorToColumnMajor

func (I Index) RowMajorToColumnMajor(nr, nc int) Index

func (Index) Subset

func (I Index) Subset(J Index) (r Index)

func (Index) ToMatrix

func (I Index) ToMatrix(nr, nc int) (R Matrix)

func (Index) ToMatrixReversed

func (I Index) ToMatrixReversed(nr, nc int) (R Matrix)

type Index2D

type Index2D struct {
	// Ind is the combined index in column-major format
	RI, CI, Ind Index
	Len         int
}

func MatFind

func MatFind(MI mat.Matrix, op EvalOp, val float64) (I Index2D)

func NewIndex2D

func NewIndex2D(nr, nc int, RI, CI Index, permuteO ...bool) (I2 Index2D, err error)

func (*Index2D) ToIndex

func (i2 *Index2D) ToIndex() (I Index)

type LineChart

type LineChart struct {
	Chart    *chart2d.Chart2D
	ColorMap *utils2.ColorMap
}

func NewLineChart

func NewLineChart(width, height int, xmin, xmax, fmin, fmax float64) (lc *LineChart)

func (*LineChart) Plot

func (lc *LineChart) Plot(graphDelay time.Duration, x, f []float64, lineColor float64, lineName string)

type Matrix

type Matrix struct {
	M *mat.Dense

	DataP []float64
	// contains filtered or unexported fields
}
var (
	I, Zero Matrix
)

func NewDiagMatrix

func NewDiagMatrix(nr int, data []float64, scalarO ...float64) (R Matrix)

func NewMatrix

func NewMatrix(nr, nc int, dataO ...[]float64) (R Matrix)

func (Matrix) Add

func (m Matrix) Add(A Matrix, RO ...Matrix) Matrix

func (Matrix) AddScalar

func (m Matrix) AddScalar(a float64) Matrix

func (Matrix) Apply

func (m Matrix) Apply(f func(float64) float64) Matrix

func (Matrix) Apply2

func (m Matrix) Apply2(A Matrix, f func(float64, float64) float64) Matrix

func (Matrix) Apply3

func (m Matrix) Apply3(A, B Matrix, f func(float64, float64, float64) float64) Matrix

func (Matrix) Apply3Parallel

func (m Matrix) Apply3Parallel(A, B Matrix, f func(float64, float64, float64) float64, nP int) Matrix

func (Matrix) Apply4

func (m Matrix) Apply4(A, B, C Matrix, f func(float64, float64, float64, float64) float64) Matrix

func (Matrix) Apply4Parallel

func (m Matrix) Apply4Parallel(A, B, C Matrix, f func(float64, float64, float64, float64) float64, nP int) Matrix

func (Matrix) Apply5Parallel

func (m Matrix) Apply5Parallel(A, B, C, D Matrix, f func(float64, float64, float64, float64, float64) float64, nP int) Matrix

func (Matrix) Apply8

func (m Matrix) Apply8(A, B, C, D, E, F, G Matrix, f func(float64, float64, float64, float64, float64, float64, float64, float64) float64) Matrix

func (Matrix) Assign

func (m Matrix) Assign(I Index, AI interface{}) Matrix

func (Matrix) AssignColumns

func (m Matrix) AssignColumns(I Index, A Matrix) Matrix

func (Matrix) AssignScalar

func (m Matrix) AssignScalar(I Index, val float64) Matrix

func (Matrix) AssignVector

func (m Matrix) AssignVector(I Index, AI interface{}) Matrix

func (m Matrix) AssignVector(I Index, Ainv Vector) Matrix { // Changes receiver

func (Matrix) At

func (m Matrix) At(i, j int) float64

func (Matrix) Avg

func (m Matrix) Avg() (avg float64)

func (Matrix) Col

func (m Matrix) Col(j int) Vector

func (Matrix) Copy

func (m Matrix) Copy(RO ...Matrix) (R Matrix)

func (Matrix) Data

func (m Matrix) Data() []float64

func (Matrix) Dims

func (m Matrix) Dims() (r, c int)

Dims, At and T minimally satisfy the mat.Matrix interface.

func (Matrix) ElDiv

func (m Matrix) ElDiv(A Matrix) Matrix

func (Matrix) ElMul

func (m Matrix) ElMul(A Matrix, RO ...Matrix) (R Matrix)

func (Matrix) Equate

func (m Matrix) Equate(ValuesI interface{}, RangeO ...interface{})

func (Matrix) Find

func (m Matrix) Find(op EvalOp, val float64, abs bool) (I Index)

func (Matrix) IndexedAssign

func (m Matrix) IndexedAssign(I Index, ValI interface{}) (err error)

func (Matrix) Inverse

func (m Matrix) Inverse(RO ...Matrix) (R Matrix, err error)

func (Matrix) Inverse2

func (m Matrix) Inverse2(iPiv []int, RO ...Matrix) (R Matrix, err error)

func (*Matrix) InverseWithCheck

func (m *Matrix) InverseWithCheck() (R Matrix)

func (*Matrix) IsEmpty

func (m *Matrix) IsEmpty() bool

Utility

func (Matrix) IsScalar

func (m Matrix) IsScalar() bool

Non chainable methods

func (Matrix) LUSolve

func (m Matrix) LUSolve(b Matrix) (X Matrix)

func (Matrix) Max

func (m Matrix) Max() (max float64)

func (Matrix) Min

func (m Matrix) Min() (min float64)

func (Matrix) Mul

func (m Matrix) Mul(A Matrix, RO ...Matrix) (R Matrix)

func (Matrix) MulParallel

func (m Matrix) MulParallel(A Matrix, nP int) (R Matrix)

func (Matrix) POW

func (m Matrix) POW(p int) Matrix

func (Matrix) Print

func (m Matrix) Print(msgI ...string) (o string)

func (Matrix) Range

func (m Matrix) Range(RangeO ...interface{}) (r []float64)

func (Matrix) RawMatrix

func (m Matrix) RawMatrix() blas64.General

func (Matrix) Row

func (m Matrix) Row(i int) Vector

func (Matrix) Scale

func (m Matrix) Scale(a float64) Matrix

func (Matrix) Set

func (m Matrix) Set(i, j int, val float64) Matrix

func (Matrix) SetCol

func (m Matrix) SetCol(j int, data []float64) Matrix

func (Matrix) SetColFrom

func (m Matrix) SetColFrom(col, rowFrom int, data []float64) Matrix

func (Matrix) SetRange

func (m Matrix) SetRange(i1, i2, j1, j2 int, val float64) Matrix

func (*Matrix) SetReadOnly

func (m *Matrix) SetReadOnly(name ...string) Matrix

Chainable methods (extended)

func (*Matrix) SetWritable

func (m *Matrix) SetWritable() Matrix

func (Matrix) Slice

func (m Matrix) Slice(I, K, J, L int) (R Matrix)

func (Matrix) SliceCols

func (m Matrix) SliceCols(I Index) (R Matrix)

func (Matrix) SliceRows

func (m Matrix) SliceRows(I Index) (R Matrix)

func (Matrix) Subset

func (m Matrix) Subset(I Index, newDims ...int) (R Matrix)

func (Matrix) SubsetVector

func (m Matrix) SubsetVector(I Index) (V Vector)

func (Matrix) Subtract

func (m Matrix) Subtract(A Matrix, RO ...Matrix) Matrix

func (Matrix) SumCols

func (m Matrix) SumCols() (V Vector)

func (Matrix) SumRows

func (m Matrix) SumRows() (V Vector)

func (Matrix) T

func (m Matrix) T() mat.Matrix

func (Matrix) Transpose

func (m Matrix) Transpose() (R Matrix)

type R1

type R1 struct {
	Max  int
	Data []int
}

func NewR1

func NewR1(imax int) R1

func (R1) Range

func (r R1) Range(dimI interface{}) Index

type R2

type R2 struct {
	Ir, Jr R1
	Data   []int
}

func NewR2

func NewR2(imax, jmax int) R2

func (*R2) Assign

func (r *R2) Assign(dimI, dimJ interface{}, V Index) (err error)

func (R2) Dims

func (r R2) Dims() (ni, nj int)

func (*R2) Get

func (r *R2) Get(dimI, dimJ interface{}) (V Index)

func (*R2) Index

func (r *R2) Index() (V Index)

func (R2) Range

func (r R2) Range(dimI, dimJ interface{}) (I Index)

type R3

type R3 struct {
	Ir, Jr, Kr R1
	Data       []int
}

func NewR3

func NewR3(imax, jmax, kmax int) R3

func (*R3) Assign

func (r *R3) Assign(dimI, dimJ, dimK interface{}, V Index) (err error)

func (R3) Dims

func (r R3) Dims() (ni, nj, nk int)

func (*R3) Get

func (r *R3) Get(dimI, dimJ, dimK interface{}) (V Index)

func (*R3) Index

func (r *R3) Index() (V Index)

func (R3) Range

func (r R3) Range(dimI, dimJ, dimK interface{}) (I Index)

type SurfacePlot

type SurfacePlot struct {
	Chart        *chart2d.Chart2D
	ColorMap     *utils2.ColorMap
	GraphicsMesh *graphics2D.TriMesh
}

func NewSurfacePlot

func NewSurfacePlot(width, height int, xmin, xmax, ymin, ymax float64,
	gm *graphics2D.TriMesh) (sp *SurfacePlot)

func (*SurfacePlot) AddColorMap

func (sp *SurfacePlot) AddColorMap(fmin, fmax float64)

func (*SurfacePlot) AddFunctionSurface

func (sp *SurfacePlot) AddFunctionSurface(field []float32)

type Vector

type Vector struct {
	V     *mat.VecDense
	DataP []float64
}

func NewVector

func NewVector(n int, dataO ...[]float64) Vector

func NewVectorConstant

func NewVectorConstant(n int, val float64) Vector

func (Vector) Add

func (v Vector) Add(a Vector) Vector

func (Vector) AddScalar

func (v Vector) AddScalar(a float64) Vector

func (Vector) Apply

func (v Vector) Apply(f func(float64) float64) Vector

func (Vector) At

func (v Vector) At(i, j int) float64

func (Vector) AtVec

func (v Vector) AtVec(i int) float64

func (Vector) Concat

func (v Vector) Concat(w Vector) (r Vector)

func (Vector) Copy

func (v Vector) Copy() Vector

func (Vector) Data

func (v Vector) Data() []float64

func (Vector) Dims

func (v Vector) Dims() (r, c int)

Dims, At and T minimally satisfy the mat.Matrix interface.

func (Vector) Dot

func (v Vector) Dot(a Vector) (res float64)

func (Vector) ElDiv

func (v Vector) ElDiv(a Vector) Vector

func (Vector) ElMul

func (v Vector) ElMul(a Vector) Vector

func (Vector) Find

func (v Vector) Find(op EvalOp, target float64, abs bool) (r Vector)

func (Vector) FindOr

func (v Vector) FindOr(op EvalOp, target float64, abs bool, A Vector) (r Vector)

func (Vector) Len

func (v Vector) Len() int

func (Vector) Linspace

func (v Vector) Linspace(begin, end float64) Vector

Chainable (extended) methods

func (Vector) Max

func (v Vector) Max() (max float64)

func (Vector) Min

func (v Vector) Min() (min float64)

func (Vector) Minmod

func (v Vector) Minmod() (val float64)

func (Vector) Mul

func (v Vector) Mul(w Vector) (A Matrix)

func (Vector) Outer

func (v Vector) Outer(w Vector) (R Matrix)

func (Vector) POW

func (v Vector) POW(p int) Vector

func (Vector) Print

func (v Vector) Print(msgI ...string) (o string)

func (Vector) RawVector

func (v Vector) RawVector() blas64.Vector

func (Vector) Scale

func (v Vector) Scale(a float64) Vector

func (Vector) Set

func (v Vector) Set(a float64) Vector

func (Vector) SubVec

func (v Vector) SubVec(a, b Vector)

func (Vector) Subset

func (v Vector) Subset(i1, i2 int) Vector

func (Vector) SubsetIndex

func (v Vector) SubsetIndex(I Index) Vector

func (Vector) Subtract

func (v Vector) Subtract(a Vector) Vector

func (Vector) T

func (v Vector) T() mat.Matrix

func (Vector) ToIndex

func (v Vector) ToIndex() (I Index)

func (Vector) ToMatrix

func (v Vector) ToMatrix() Matrix

func (Vector) Transpose

func (v Vector) Transpose() Matrix

Non Chainable methods

func (Vector) Zip

func (v Vector) Zip(op EvalOp, abs bool, A Vector) (R Vector)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL