pfutil

package
v0.0.0-...-6493f53 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blur

func Blur(data MutableSlice, domainSize []int, kernel BlurKernel)

Blur applies a blurring kernel to the data. domainSize specifies the size of the domain in each direction. Thus, if domain size is []int{5, 5}, the length of data must be 25 and it is assumed that it represents a 5x5 domain. kernel is a blurring kernel.

func Clear

func Clear(data []complex128)

Clear sets all elements in the slice to zero

func CmplxEqualApprox

func CmplxEqualApprox(a []complex128, b []complex128, tol float64) bool

CmplxEqualApprox returns true if to complex arrays are equal within the passed tolerance

func DivRealScalar

func DivRealScalar(data []complex128, factor float64) []complex128

DivRealScalar divides each element in the comlex array by a real scalar

func Dot

func Dot(a []float64, b []float64) float64

Dot calculates the dot product between two slices

func Draw

func Draw(shape Shape, grid *Grid, transformation *Affine, value float64)

Draw draws the shape onto the passed grid. The passed transfformations is applied to the shape prior to drawing. Note that the transformation is applied to the pixel position in the destination image. If a point is inside the passed shape, the value of that grid point will be set to value

func ElemwiseAdd

func ElemwiseAdd(dst []complex128, data []complex128)

ElemwiseAdd adds dst and data and places the result in dst

func ElemwiseMul

func ElemwiseMul(dst []complex128, data []complex128)

ElemwiseMul multiplies dst and data and places the result in dst.

func MaxReal

func MaxReal(data []complex128) float64

MaxReal calculates the maximum real part

func MinReal

func MinReal(data []complex128) float64

MinReal returns the minimum real-part value

func NodeIdx

func NodeIdx(domainSize []int, idx []int) int

NodeIdx returns the index of the node corresponding to a given typle of index

func Pos

func Pos(domainSize []int, nodeNum int) []int

Pos converts the node number to position

func ProdInt

func ProdInt(a []int) int

ProdInt calculates the product of all the elements in the passed sequence

func Voronoi

func Voronoi(pts []int, data []int, domainSize []int)

Voronoi assigns each pixel/voxel of the data array to the closest points amongst the generating points in pts. Domain size is an array that specifies the sizes in X, Y (and Z iif 3D) direction

func Wrap

func Wrap(pos []int, domainSize []int)

Wrap wrap pos such that it is inside the box defined by domainsize

Types

type Affine

type Affine struct {
	Mat *mat.Dense
}

Affine is a type used to represent affine transformations. The transformation itself is stored as a 4x4 matrix

func Identity

func Identity() Affine

Identity initializes a new identity transformation

func NewAffine

func NewAffine() Affine

NewAffine initializes a new empty transformation

func RotX

func RotX(angle float64) Affine

RotX returns the rotation transformation corresponding to a rotation about th x-axis c = cos angle, s = sin angle ** ** * 1 0 0 * * 0 c -s * * 0 s c * ** **

func RotY

func RotY(angle float64) Affine

RotY the rotation transformation an angle about the y-axis c = cos angle, s = sin angle ** ** * c 0 s * * 0 1 0 * * -s 0 c * ** **

func RotZ

func RotZ(angle float64) Affine

RotZ returns the rotation transformation corresonding to rotation about the z-axis by an angle alpha. c = cos alpha, s = sin alpha, the matrix is ** ** * c -s 0 * * s c 0 * * 0 0 1 * ** **

func Scaling

func Scaling(vec []float64) Affine

Scaling returns a new scaling transformation

func Translation

func Translation(vec []float64) Affine

Translation initializes a new translation transformation

func (*Affine) Append

func (a *Affine) Append(other Affine)

Append applies the passed transformation after the current. If the receiver's transformation is A and other's transformation matrix is B, the updated transformation matrix is given by A <- B*A

func (*Affine) Apply

func (a *Affine) Apply(pos []float64)

Apply applies the transformation to the passed position vector.

type Ball

type Ball struct {
	Radius float64
}

Ball represents a ball in n dimensions. In 2D this is a circle and in 3D this is a sphere

func (*Ball) BBox

func (b *Ball) BBox() BoundingBox

BBox returns the bounding box

func (*Ball) InteriorPoint

func (b *Ball) InteriorPoint(pos []float64) bool

InteriorPoint returns true if the passed point is inside the ball

type BlurKernel

type BlurKernel interface {
	// Value returns the value of the kernel
	Value(x []int) float64

	// Cutoff returns a value beyond which the kernel is zero
	// (e.g. the kernel is assumed to be zero outisde the box
	// -Cutoff() < x < Cutoff() )
	Cutoff() int
}

BlurKernel is an interfae for kernel functions used for blurring

type BoundingBox

type BoundingBox struct {
	Min []int
	Max []int
}

BoundingBox represents the bounding box for the shape

type Box

type Box struct {
	Diagonal []float64
}

Box represents a rectangle in 2D and a box in 3D

func (*Box) BBox

func (b *Box) BBox() BoundingBox

BBox returns the bounding box of the shape

func (*Box) InteriorPoint

func (b *Box) InteriorPoint(pos []float64) bool

InteriorPoint returns true if the passed point is inside the box

type BoxKernel

type BoxKernel struct {
	Width int
}

BoxKernel returns a blurring kernel that is 1 inside a box and zero outside

func (*BoxKernel) Cutoff

func (bk *BoxKernel) Cutoff() int

Cutoff the half-width of the box

func (*BoxKernel) Value

func (bk *BoxKernel) Value(x []int) float64

Value returns the box kernel

type FFTWWrapper

type FFTWWrapper struct {
	PlanFFT    fftw.Plan
	PlanIFFT   fftw.Plan
	Data       []complex128
	Dimensions []int
}

FFTWWrapper implemente the FourierTransform interface

func NewFFTW

func NewFFTW(n []int) *FFTWWrapper

NewFFTW returns a new FFTWWrapper

func (*FFTWWrapper) ConjugateNode

func (fw *FFTWWrapper) ConjugateNode(i int) int

ConjugateNode returns the node that corresponds to the negative frequency of the node being passed

func (*FFTWWrapper) FFT

func (fw *FFTWWrapper) FFT(data []complex128) []complex128

FFT performs forward fourier transform

func (*FFTWWrapper) Freq

func (fw *FFTWWrapper) Freq(i int) []float64

Freq returns the frequency corresponding to site i

func (*FFTWWrapper) IFFT

func (fw *FFTWWrapper) IFFT(data []complex128) []complex128

IFFT performs inferse fourier transform

type Grid

type Grid struct {
	Dims []int
	Data []float64
}

Grid is a type that represents a computatoinal grid

func NewGrid

func NewGrid(dims []int) Grid

NewGrid initializes a new grid type

func (Grid) Copy

func (g Grid) Copy() Grid

Copy returns a copy of the grid

func (*Grid) FromComplex

func (g *Grid) FromComplex(carray []complex128)

FromComplex extracts the real part of a complex array

func (Grid) Get

func (g Grid) Get(pos []int) float64

Get gets a value at the given position

func (Grid) Index

func (g Grid) Index(pos []int) int

Index returnds the underlying index corresponding to the point

func (Grid) Pos

func (g Grid) Pos(i int) []int

Pos returns the positions that corresponds to index i

func (*Grid) Rotate2D

func (g *Grid) Rotate2D(angle float64)

Rotate2D rotates 2D grids about the center. Angle is the rotation angle in radians.

func (Grid) SaveCsv

func (g Grid) SaveCsv(fname string)

SaveCsv stores the grid in a text file format. The format of the produced file is 1. For 2D grids x, y, value 2. For 3D grids x, y, z, value

func (*Grid) Set

func (g *Grid) Set(pos []int, value float64)

Set sets a value

func (Grid) ToComplex

func (g Grid) ToComplex() []complex128

ToComplex converts the underlying data array to a complex array. The data is inserted as the real part and the imaginary part is zero.

type ImmutableSlice

type ImmutableSlice interface {
	Get(i int) float64
	Len() int
}

ImmutableSlice is a type for wrapping slices that can be accessed, but not altered slices

type MutableSlice

type MutableSlice interface {
	ImmutableSlice
	Set(i int, v float64)
}

MutableSlice is an interface for slice wrapeprs where the underlying data array can be both accessed and altered

type Product

type Product struct {
	End     []int
	Current []int
	// contains filtered or unexported fields
}

Product implements a generic product. It can be used to loop over all combinations Example: The following is equivalent to a double for loo from 0 to 3

prod := NewProduct([]{3, 3})

for idx := prod.Current; prod.Next() != nil; idx = prod.Current {
		Do something
}

func NewProduct

func NewProduct(end []int) Product

NewProduct returns a new product iterator.

func (*Product) Next

func (p *Product) Next() []int

Next returns the next integer set

type RealPartSlice

type RealPartSlice struct {
	Data []complex128
}

RealPartSlice implements the MutableSlice interface. It only operates on the real part of the underlying complex array

func (*RealPartSlice) Get

func (rps *RealPartSlice) Get(i int) float64

Get returns the value at position i

func (*RealPartSlice) Len

func (rps *RealPartSlice) Len() int

Len returns the length of the underlying data array

func (*RealPartSlice) Set

func (rps *RealPartSlice) Set(i int, v float64)

Set sets the real part at position i to the new value

type RealSlice

type RealSlice struct {
	Data []float64
}

RealSlice implements the MutableSlice interface when the underlying data is a real array

func (*RealSlice) Get

func (rs *RealSlice) Get(i int) float64

Get returns the value at position i

func (*RealSlice) Len

func (rs *RealSlice) Len() int

Len returns the length of the underlying data array

func (*RealSlice) Set

func (rs *RealSlice) Set(i int, v float64)

Set sets the value at index i equal to v

type Shape

type Shape interface {
	// InteriorPoint returns true if the passed point is inside the shape
	InteriorPoint(pos []float64) bool

	// BBox returns the bounding box of the shape
	BBox() BoundingBox
}

Shape is represents a generic interface to represent geometrical shapes

Jump to

Keyboard shortcuts

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