numgo

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

numgo

N-dimensional arrays with NumPy semantics for Go.

CI Go License Dependencies

中文文档 · Website

Why numgo

  • NumPy semantics, Go ergonomics. Broadcasting rules, type promotion, NaN/Inf propagation, axis handling, and even error-message wording match NumPy — while the API uses Go idioms: generics for dtype dispatch, explicit conversion, views as first-class values.
  • Zero dependencies. go.mod contains only the Go standard library. LAPACK, FFT, random, and the math kernels are implemented in-tree; no cgo, no BLAS.
  • Reproducible random streams. SeedSequence + MT19937/PCG64 are exact ports: for identical seeds, distributions that don't depend on libm produce bit-identical streams to NumPy; libm-sensitive distributions are ULP-close via Go's stdlib math.
  • Two build modes. A default pure-Go build, and an opt-in GOEXPERIMENT=simd build that accelerates hot paths (with documented last-ULP notes). Results contracts hold in both.

Install

go get github.com/aixfoundry/numgo

Requires Go 1.27 or later.

Quick start

package main

import (
	"os"

	"github.com/aixfoundry/numgo"
)

func main() {
	a := numgo.Arange(0.0, 6.0, 1.0).Reshape(2, 3)    // [[0 1 2], [3 4 5]]
	b := numgo.Ones[float64](1, 3)                     // broadcast add (2,3)+(1,3)
	c := a.Add(b)                                      // pure operation: new data

	m := numgo.Ones[float64](3, 2)
	p := c.Matmul(m)                                   // (2,3) @ (3,2) → (2,2)

	numgo.SaveFile("a.npy", a)                         // .npy write/read
	if v, err := numgo.LoadFile("a.npy"); err == nil {
		arr := v.AsFloat64()
		_ = arr.Sum()                                  // 15
	}
	_ = p
	os.Remove("a.npy")
}

Packages

Package Contents
numgo (root) Array[T] views/constructors, ufuncs, reductions, sorting, manipulation, dot products, einsum, IO (.npy/.npz/txt), interop
numgo/linalg numpy.linalg: solve, least squares, SVD/QR/Cholesky/eigen decompositions, norms (pure-Go LAPACK kernels)
numgo/fft numpy.fft: mixed-radix FFT/inverse/rfft families + fftshift, three norm modes
numgo/random numpy.random: SeedSequence + MT19937/PCG64 + Generator distributions (streams match NumPy: libm-free paths bit-identical, libm-sensitive distributions ULP-close via Go stdlib math)
numgo/polynomial numpy.polynomial: Polynomial/Chebyshev/Legendre/Laguerre/Hermite/HermiteE
numgo/strings numpy.strings: vectorized string operations on StrArray (upper/split/replace/…)
numgo/ma numpy.ma: MaskedArray = data + mask with mask-propagating operations
numgo/emath numpy.emath: scimath functions that promote to complex outside the real domain
numgo/assert numpy.testing: AssertAllClose/AssertArrayEqual and friends, for downstream tests

Performance

  • Faster than NumPy on small-matrix Solve (24×) and Inv (4.6×), StandardNormal, StandardGamma, and element-level At/Set (12×).
  • Near parity on einsum, cumsum, and masked-array arithmetic.
  • Single-threaded elementwise and reductions currently trail NumPy's vectorized kernels by 3–21×.
  • The opt-in GOEXPERIMENT=simd build turns Matmul 4.2× faster and makes SumAll/SumAxis0 faster than NumPy.

Full methodology and tables: docs/performance.md.

NumPy parity

numgo tracks NumPy 2.x semantics module by module, verified against golden fixtures generated from NumPy. Some surfaces are intentionally skipped (recarrays, np.matrix, legacy RandomState), and some behavior deviates by design (explicit AsType instead of implicit promotion, panics instead of exceptions).

Per-module list, accuracy claims, and deviations: docs/numpy-parity.md. Design and contracts: docs/architecture.md. What's next: docs/roadmap.md.

Contributing

See CONTRIBUTING.md for development setup, test commands, and PR expectations.

License

Apache-2.0, Copyright 2024-2026 kaisawind. Zero third-party dependencies; the math is based on the pure-Go standard library. This product includes software translated from NumPy (BSD-3-Clause); see NOTICE and LICENSES/ for details.

Documentation

Overview

Package numgo is a numpy-compatible N-dimensional array library for float32/float64/complex64/complex128 element types. Binary IO covers .npy streams and .npz zip archives; PackBits/UnpackBits are pending integer dtype support.

Text IO with missing-value handling (numpy genfromtxt, simplified to uniform float columns — no structured dtypes, converters, usecols or masking; missing/failed-parse fields become the filling value and jagged rows are errors, like LoadTxt).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyInto

func CopyInto[T Number](dst, src *Array[T])

CopyInto mutates dst by filling it with src broadcast to dst's shape. This is the Into-style mutation primitive later operations build on.

func Histogram2D

func Histogram2D[T Number](x, y *Array[T], bins int) (*Array[float64], *Array[float64], *Array[float64])

Histogram2D histograms paired samples: returns the counts H (x bins × y bins, H[i][j] counts x in bin i and y in bin j) then the x and y edges. x and y are read flattened and must have equal length; defaults follow numpy histogram2d (range min..max per axis, last edge inclusive).

func LoadNpz

func LoadNpz(r io.Reader) (map[string]AnyArray, error)

LoadNpz reads every .npy member of an npz zip archive, keyed by member name with the .npy suffix stripped (np.load's NpzFile mapping). Non-.npy members are ignored; an archive without any .npy member is an error.

func LoadNpzFile

func LoadNpzFile(path string) (map[string]AnyArray, error)

LoadNpzFile reads path as an .npz archive.

func NormalizeRange

func NormalizeRange(r Range, dim int) (start, n, step int)

NormalizeRange exposes range normalization for subpackages that build views from numgo.Range values (numgo/strings).

func Save

func Save[T Number](w io.Writer, a *Array[T]) error

Save writes a as a NumPy .npy 1.0 stream (2.0 only if the header length field would overflow uint16). Data is written C-order (fortran_order false); non-contiguous input is raveled first, matching numpy's save of a strided view.

func SaveFile

func SaveFile[T Number](path string, a *Array[T]) error

SaveFile writes a to path as .npy, appending the .npy suffix when missing (numpy np.save).

func SaveTxt

func SaveTxt[T Number](w io.Writer, a *Array[T], format string) error

SaveTxt writes a row per line with space-delimited format-formatted values (numpy savetxt defaults: delimiter ' ', fmt '%g'). Rank above 2 panics.

func SaveTxtFile

func SaveTxtFile[T Number](path string, a *Array[T], format string) error

SaveTxtFile writes a to path as text; an empty format means "%g".

func SaveZ

func SaveZ(w io.Writer, arrays map[string]AnyArray) error

SaveZ writes arrays as an uncompressed .npz zip archive (numpy savez): one "name.npy" member per map entry, each a plain .npy stream written by Save. Member order follows Go's randomized map order; numpy tolerates any order.

func SaveZCompressed

func SaveZCompressed(w io.Writer, arrays map[string]AnyArray) error

SaveZCompressed writes arrays as a deflate-compressed .npz archive (numpy savez_compressed).

func SaveZFile

func SaveZFile(path string, compressed bool, arrays map[string]AnyArray) error

SaveZFile writes arrays to path as .npz, appending the suffix when missing (numpy savez); compressed selects savez_compressed over savez.

Types

type AnyArray

type AnyArray struct {
	F64   *Array[float64]
	F32   *Array[float32]
	C128  *Array[complex128]
	C64   *Array[complex64]
	Shape []int
	Descr string
}

AnyArray is the dynamic-dtype result of Load: exactly one typed field is non-nil and matches Shape. Use AsFloat64/AsComplex128 to unwrap.

func AnyOf

func AnyOf[T Number](a *Array[T]) AnyArray

AnyOf builds the tagged AnyArray for a so arrays of different dtypes can be mixed in one SaveZ map. Descr is the little-endian descriptor Save writes.

func Load

func Load(r io.Reader) (AnyArray, error)

Load reads a NumPy .npy stream. Supported dtypes: float32/float64/ complex64/complex128, either endianness. fortran_order data is transposed into C order on read.

func LoadFile

func LoadFile(path string) (AnyArray, error)

LoadFile reads path as .npy; a zip-magic file (.npz) is an error pointing at LoadNpzFile, since archives hold multiple arrays.

func (AnyArray) AsComplex128

func (a AnyArray) AsComplex128() *Array[complex128]

AsComplex128 returns the loaded complex array; it panics on real data.

func (AnyArray) AsFloat64

func (a AnyArray) AsFloat64() *Array[float64]

AsFloat64 returns the loaded real array; it panics on complex data.

type Array

type Array[T Number] struct {
	// contains filtered or unexported fields
}

Array is an N-dimensional strided view over a flat data slice. Strides are in element units. Views share data; use Copy for an independent array.

func AbsToReal

func AbsToReal[F Number, P Float](a *Array[F]) *Array[P]

AbsToReal is the package-level element-wise modulus with an explicit float result type P (methods cannot add type parameters): for complex input it is |z| as P; for real input it is the absolute value converted to P. P cannot be inferred, so callers must name both types, e.g. AbsToReal[complex128, float64](a).

func Arange

func Arange[T Number](start, stop, step T) *Array[T]

Arange returns evenly spaced values in [start, stop), stepping by step. Complex operands are ordered by their real part.

func AsArray

func AsArray[T Number](data []T, shape ...int) *Array[T]

AsArray returns a new array holding a copy of data, shaped as given. It is numpy's asarray naming for FromSlice.

func AsType

func AsType[F, P Number](a *Array[F]) *Array[P]

AsType returns a new array with every element converted to P. Real values converted to a complex type get a zero imaginary part; a complex value converted to a real type drops its imaginary part.

The conversion dispatches once per call on the concrete slice type and runs a typed copy loop (compiler-vectorizable); named types under Number keep the generic parts/scalarFromParts path. Same conversions as the generic path — bit-identical by construction.

func BorrowSlice

func BorrowSlice[T Number](data []T, shape ...int) *Array[T]

BorrowSlice wraps a caller-owned slice ZERO-COPY (numpy asarray semantics — the one explicit exception to the constructors-copy rule, named Borrow* to flag the aliasing). Mutations through the array write through to the slice and vice versa. The caller guarantees the slice is not resized or reused for the array's lifetime. With no shape the result is 1-D.

func BroadcastArrays

func BroadcastArrays[T Number](as ...*Array[T]) []*Array[T]

BroadcastArrays returns views of all inputs expanded to their common broadcast shape (stride-0 dimensions, numpy broadcast_arrays). Incompatible shapes panic. The views share each input's data.

func Concatenate

func Concatenate[T Number](axis int, as ...*Array[T]) *Array[T]

Concatenate joins arrays along axis (negative allowed). All dimensions except axis must match exactly. The result is new data.

func CorrCoef

func CorrCoef[T Number](a, b *Array[T]) *Array[float64]

CorrCoef returns the Pearson correlation coefficients of the variables in a's rows (b's rows appended, as with Cov): Cov normalized by the outer product of the per-variable standard deviations, clipped to [-1, 1].

func Cov

func Cov[T Number](a, b *Array[T]) *Array[float64]

Cov returns the covariance matrix of the variables in a's rows, with b's rows appended as further variables when given — numpy cov with rowvar=true, bias=false (ddof=1). Every row must hold the same number of observations. Complex arrays panic: the float64 result cannot represent complex covariance (numpy's result is complex there).

func Einsum

func Einsum[T Number](subscript string, as ...*Array[T]) *Array[T]

Einsum evaluates the Einstein summation convention on one or more arrays.

Grammar (numpy np.einsum subset):

	subscript := operand ("," operand)* ("->" output)?
	operand   := (letter | "...")*
	output    := (letter | "...")*

  - Explicit output after "->"; or implicit (no "->"): labels occurring
    exactly once across all operands, sorted alphabetically, with "..."
    placed before the free labels when any operand has one ("ij,jk" is
    "ik"; "i...j" yields shape [ellipsis, i, j] like numpy).
  - "..." stands for the operand's remaining dimensions (explicit labels
    take axes from the front and back around it); the operands' ellipsis
    dimensions broadcast together, so "...ij,...jk->...ik" batches. An
    explicit output lacking "..." sums the broadcast tail away.
  - A label repeated within ONE operand takes the diagonal of its axes
    ("ii->i" main diagonal, bare "ii" the trace); "...ii" traces the last
    two axes per batch. A non-square diagonal takes the min dimension.
  - Output labels must each appear once and be present in some input.

Unsupported relative to numpy: integer dtypes (Number excludes them); the grammar above is otherwise complete. Deliberate deviations: non-square diagonals take the min dimension (numpy einsum errors; np.diagonal agrees with us), an explicit output without "..." sums the ellipsis tail (numpy errors), and scalar results are one-element arrays (the package has no 0-d arrays).

Pure: returns new data; operands are never written.

With two or more operands the contraction runs as a left fold of dense matmuls (einsumMatmul in einsum_matmul.go, on dot.go's matmulKernel): each step flattens the pair's shared labels to K in sorted order — the same ascending order the generic path sums in, so results are bit-identical — with the left's remaining output labels as M and the right's as N. Anything the pattern cannot express falls back to the generic transpose-broadcast-multiply-sum path below.

func Eye

func Eye[T Number](n int) *Array[T]

Eye returns the n-by-n identity matrix.

func Flip

func Flip[T Number](a *Array[T], axes ...int) *Array[T]

Flip reverses the order of elements along axes (default: all axes). The result is new data; a negative-stride view is deliberately not attempted.

func FromByteSlice

func FromByteSlice[T Number](b []byte, shape ...int) *Array[T]

FromByteSlice reinterprets raw LITTLE-ENDIAN bytes as T elements (numpy frombuffer semantics). When len(b) is a multiple of sizeof(T) AND b is suitably aligned for T, it is a zero-copy reinterpretation that ALIASES b (mutations flow both ways); misaligned input is silently copied into aligned storage instead, so sharing only holds on the aligned path. Panics when len(b) is not a sizeof(T) multiple or product(shape) mismatches the element count.

func FromFunction

func FromFunction[T Number](shape []int, f func(coords ...int) T) *Array[T]

FromFunction fills a new array in C order, calling f with the coordinates of each element.

func FromRegex

func FromRegex(r io.Reader, regex string) (*Array[float64], error)

FromRegex parses every regex match's capture groups as float columns (numpy fromregex, with all groups taken as numeric fields).

func FromSlice

func FromSlice[T Number](data []T, shape ...int) *Array[T]

FromSlice returns a new array holding a copy of data. With no shape the result is 1-D; otherwise the element count must match.

func Full

func Full[T Number](v T, shape ...int) *Array[T]

Full returns a new array of the given shape filled with v.

func GenFromTxt

func GenFromTxt(r io.Reader, cfg GenConfig) (*Array[float64], []string, error)

GenFromTxt reads delimited float text with missing-value handling (numpy genfromtxt port, float columns only). It returns the data array and the column names — nil unless configured via Names or UseHeaderNames. A field equal to Missing (or empty) or one that fails float parsing becomes FillingValues; after that, a row with a different field count is an error.

func Identity

func Identity[T Number](n int) *Array[T]

Identity returns the n-by-n matrix with ones on the diagonal. Eye with a single argument; no Empty constructor exists because Go's make already zeroes.

func Interp

func Interp[T Number](x, xp, fp *Array[T]) *Array[T]

Interp linearly interpolates fp (sampled at the increasing abscissae xp) at each point of x: values below xp[0] clamp to fp[0] and above xp[-1] to fp[-1] (numpy interp with left/right defaulted to the endpoints). x keeps its shape; xp and fp are read flattened, must have equal length, and x/xp compare by real part; fp may be complex. xp with duplicate abscissae resolves to the last of them, as numpy's search does.

func Linspace

func Linspace[T Number](start, stop T, num int) *Array[T]

Linspace returns num evenly spaced values from start to stop inclusive.

func LoadTxt

func LoadTxt(r io.Reader) (*Array[float64], error)

LoadTxt parses whitespace-delimited float text (numpy loadtxt defaults). Blank lines are skipped; the first data row fixes the column count. A ragged file is an error, not a panic — IO failures are returned.

func LoadTxtFile

func LoadTxtFile(path string) (*Array[float64], error)

LoadTxtFile reads path as whitespace-delimited float text.

func MeshGrid

func MeshGrid[T Number](as ...*Array[T]) []*Array[T]

MeshGrid returns len(as) arrays with 'ij' (matrix) indexing semantics: result[k] has shape len(as[0]) × … × len(as[n-1]) and varies only along dimension k, taking as[k]'s values there.

func New1DArray

func New1DArray[T Number](data []T) *Array[T]

New1DArray returns a new 1-D array holding a copy of data.

func New2DArray

func New2DArray[T Number](rows [][]T) *Array[T]

New2DArray returns a new 2-D array holding a copy of rows; it panics on jagged input.

func Ones

func Ones[T Number](shape ...int) *Array[T]

Ones returns a new array of the given shape filled with ones.

func Pad

func Pad[T Number](a *Array[T], pads [][2]int, mode PadMode, constantValue T) *Array[T]

Pad returns a new array grown by pads[ax] = {before, after} along each axis, filled per mode. pads must have one entry per axis and no negative widths.

func Repeat

func Repeat[T Number](a *Array[T], count int, axis int) *Array[T]

Repeat repeats each element count times along axis (negative allowed). The result is new data.

func Roll

func Roll[T Number](a *Array[T], shift int, axes ...int) *Array[T]

Roll shifts elements by shift along axes (default: the flattened array in C order). Negative shifts roll backwards, wrapping around. The result is new data.

func Split

func Split[T Number](a *Array[T], indices []int, axis int) []*Array[T]

Split slices a at the given ascending boundaries along axis into len(indices)+1 views sharing data with a. Indices may equal the axis size.

func Stack

func Stack[T Number](axis int, as ...*Array[T]) *Array[T]

Stack joins same-shaped arrays along a new axis (negative allowed, ndim+1 positions valid). The result is new data.

func Tile

func Tile[T Number](a *Array[T], reps ...int) *Array[T]

Tile repeats a along each axis by reps, right-aligned like numpy.tile (shorter reps are padded with leading ones; a longer reps list prepends size-1 axes to a). The result is new data.

func Zeros

func Zeros[T Number](shape ...int) *Array[T]

Zeros returns a new array of the given shape filled with zeros.

func (*Array[T]) Abs

func (a *Array[T]) Abs() *Array[T]

Abs returns the element-wise absolute value. For real T this is the magnitude; for complex T the result is real and not representable in Array[T], so it panics and points at AbsToReal.

func (*Array[T]) Acos

func (a *Array[T]) Acos() *Array[T]

Acos returns the element-wise arccosine.

func (*Array[T]) Acosh

func (a *Array[T]) Acosh() *Array[T]

Acosh returns the element-wise inverse hyperbolic cosine.

func (*Array[T]) Add

func (a *Array[T]) Add(b *Array[T]) *Array[T]

Add returns a new array with the element-wise sum of a and b, broadcasting both operands with full numpy right-alignment.

func (*Array[T]) AddInto

func (a *Array[T]) AddInto(dst *Array[T], b *Array[T]) *Array[T]

AddInto writes the broadcast sum of a and b into dst and returns dst. dst must already have the broadcast result shape.

func (*Array[T]) AddValue

func (a *Array[T]) AddValue(v T) *Array[T]

AddValue returns a new array with v added to every element.

func (*Array[T]) All

func (a *Array[T]) All() bool

All reports whether every element is nonzero. The zero-size array is vacuously all-nonzero.

func (*Array[T]) Any

func (a *Array[T]) Any() bool

Any reports whether any element is nonzero.

func (*Array[T]) ArgMax

func (a *Array[T]) ArgMax(axis int) []int

ArgMax returns the coordinate of each maximum along axis (first occurrence wins ties), one entry per kept slot in C order. It returns a plain []int: index results are not element data, and Array's Number constraint excludes integer element types.

func (*Array[T]) ArgMin

func (a *Array[T]) ArgMin(axis int) []int

ArgMin returns the coordinate of each minimum along axis (first occurrence wins ties), one entry per kept slot in C order.

func (*Array[T]) ArgPartition

func (a *Array[T]) ArgPartition(kth int, axis int) []int

ArgPartition returns the indices that would partition each channel along axis, as a flat []int (same shortcut and stability as Argsort).

shortcut: O(n log n) sort-based partition, upgrade to introselect if profiling needs O(n).

func (*Array[T]) Argsort

func (a *Array[T]) Argsort(axis int) []int

Argsort returns the coordinates that would sort each channel along axis as a flat []int (one entry per element, kept slots in C order). The order is STABLE: equal values keep their original order, a Go-friendly superset of numpy's non-stable quicksort default. Negative axes resolve.

func (*Array[T]) AsStrided

func (a *Array[T]) AsStrided(shape, strides []int) *Array[T]

AsStrided builds a low-level view with explicit shape and strides over a's data starting at a's offset (numpy as_strided). SAFER than numpy: every reachable element position is validated against [0, len(a.data)) — numpy silently reads out of bounds, this panics. Negative strides are allowed; shape entries must be non-negative. The result shares data with no aliasing protection.

func (*Array[T]) Asin

func (a *Array[T]) Asin() *Array[T]

Asin returns the element-wise arcsine.

func (*Array[T]) Asinh

func (a *Array[T]) Asinh() *Array[T]

Asinh returns the element-wise inverse hyperbolic sine.

func (*Array[T]) At

func (a *Array[T]) At(coords ...int) T

At returns the element at coords. It panics if the rank or index is invalid.

func (*Array[T]) Atan

func (a *Array[T]) Atan() *Array[T]

Atan returns the element-wise arctangent.

func (*Array[T]) Atanh

func (a *Array[T]) Atanh() *Array[T]

Atanh returns the element-wise inverse hyperbolic tangent.

func (*Array[T]) BroadcastTo

func (a *Array[T]) BroadcastTo(shape ...int) *Array[T]

BroadcastTo expands the array to shape with stride-0 dimensions. The shape must be right-align-compatible: every trailing dimension is equal to the input's or the input dimension is one. The result shares data, and writes through it alias across expanded slots — numpy's broadcast_to is read-only, but this package cannot enforce that, so treat the result as read-only.

func (*Array[T]) ByteSize

func (a *Array[T]) ByteSize() uintptr

ByteSize returns the number of bytes from UnsafeData to the end of the VIEW: Size()·sizeof(T) — NOT the size of the whole backing store, which may be longer (a view starting at offset > 0 covers less than len(data)).

func (*Array[T]) Cbrt

func (a *Array[T]) Cbrt() *Array[T]

Cbrt returns the element-wise cube root. Complex elements get the real cube root applied per-component (math/cmplx has no Cbrt).

func (*Array[T]) Ceil

func (a *Array[T]) Ceil() *Array[T]

Ceil returns the element-wise ceiling, per-component on complex elements.

func (*Array[T]) Compress

func (a *Array[T]) Compress(mask []bool, axis int) *Array[T]

Compress selects the entries of a along axis where mask is true. The result shape is a's with the axis dimension replaced by the number of true entries (possibly zero); the result is new data.

func (*Array[T]) Conj

func (a *Array[T]) Conj() *Array[T]

Conj returns the element-wise complex conjugate; a real array is copied unchanged.

func (*Array[T]) Copy

func (a *Array[T]) Copy() *Array[T]

Copy returns an independent, C-order compact copy of the array.

func (*Array[T]) Cos

func (a *Array[T]) Cos() *Array[T]

Cos returns the element-wise cosine.

func (*Array[T]) Cosh

func (a *Array[T]) Cosh() *Array[T]

Cosh returns the element-wise hyperbolic cosine.

func (*Array[T]) CumProd

func (a *Array[T]) CumProd(axes ...int) *Array[T]

CumProd prefixes products along axes (no axes = C-order prefix over the raveled array). The result has the input's shape.

func (*Array[T]) CumSum

func (a *Array[T]) CumSum(axes ...int) *Array[T]

CumSum prefixes sums along axes (no axes = C-order prefix over the raveled array, numpy's cumsum default). The result has the input's shape.

func (*Array[T]) Data

func (a *Array[T]) Data() []T

Data returns the underlying storage starting at the view offset. For contiguous arrays it reads in C order; for non-contiguous views the element order does NOT match C order — use Ravel().Data() instead. Mutating it affects every array sharing the storage.

func (*Array[T]) Div

func (a *Array[T]) Div(b *Array[T]) *Array[T]

Div returns a new array with the element-wise quotient of a and b. Division by zero follows IEEE (Inf/NaN), never panics.

func (*Array[T]) DivInto

func (a *Array[T]) DivInto(dst *Array[T], b *Array[T]) *Array[T]

DivInto writes the broadcast quotient of a and b into dst and returns dst.

func (*Array[T]) DivValue

func (a *Array[T]) DivValue(v T) *Array[T]

DivValue returns a new array with every element divided by v. Division by zero follows IEEE (Inf/NaN), never panics.

func (*Array[T]) Dot

func (a *Array[T]) Dot(b *Array[T]) *Array[T]

Dot dispatches exactly like numpy's dot (PyArray_MatrixProduct_int in numpy/_core/src/multiarray/multiarraymodule.c): 1-D·1-D gives the scalar product as a one-element array; otherwise the last axis of a contracts with the second-to-last axis of b (axis 0 when b is 1-D). The result shape is a.shape[:-1] ++ b.shape[:b.ndim-2] ++ b.shape[-1:]: b's leading dimensions become MIDDLE dimensions of the result (an outer product of batches, not matmul's broadcasting — numpy deprecates this placement for a.ndim>=2 with b.ndim>2 and suggests tensordot), and b is shared whenever b is 1-D or 2-D. Inner dimension mismatches panic.

func (*Array[T]) Exp

func (a *Array[T]) Exp() *Array[T]

Exp returns the element-wise exponential.

func (*Array[T]) Exp2

func (a *Array[T]) Exp2() *Array[T]

Exp2 returns the element-wise base-2 exponential, 2**x. Complex elements use exp(x·ln2).

func (*Array[T]) ExpandDims

func (a *Array[T]) ExpandDims(axis int) *Array[T]

ExpandDims inserts a size-1 dimension at axis (negative counts from the end). The result shares data.

func (*Array[T]) Expm1

func (a *Array[T]) Expm1() *Array[T]

Expm1 returns e**x - 1, accurate near zero. Complex elements use Exp(x)-1.

func (*Array[T]) Floor

func (a *Array[T]) Floor() *Array[T]

Floor returns the element-wise floor, per-component on complex elements (numpy applies to both parts).

func (*Array[T]) Gradient

func (a *Array[T]) Gradient() []*Array[float64]

Gradient returns one float64 array per axis with numpy's default gradient: second-order central differences in the interior and first-order one-sided differences at the edges, unit spacing. Every axis must have at least two elements (numpy raises for fewer).

func (*Array[T]) Histogram

func (a *Array[T]) Histogram(bins int) (*Array[float64], *Array[float64])

Histogram counts the raveled values of a into bins equal-width bins over [min, max] — numpy's histogram defaults: the last edge is inclusive and out-of-range values (NaN included) are dropped. Returns the counts then the edges.

func (*Array[T]) HistogramBinEdges

func (a *Array[T]) HistogramBinEdges(bins int) *Array[float64]

HistogramBinEdges returns the bins+1 equal-width edges numpy's histogram would use: linspace over [min, max] of the raveled values, widened by 0.5 on both sides when min == max and [0, 1] when a is empty.

func (*Array[T]) HistogramDD

func (a *Array[T]) HistogramDD(bins []int, ranges ...[2]float64) (*Array[float64], []*Array[float64])

HistogramDD counts a's points into bins[d] equal-width bins per dimension: a's last axis holds the D coordinates of each point (numpy's sample of shape (N, D) with the points along the leading axes). Optional ranges override the autodetected [min, max] per dimension. Returns the counts array of shape bins and one edges array per dimension.

func (*Array[T]) Idx

func (a *Array[T]) Idx(coords ...int) int

Idx returns the linear position of coords in the backing data.

func (*Array[T]) Imag

func (a *Array[T]) Imag() *Array[float64]

Imag returns the element-wise imaginary parts as float64. Real element types yield all zeros (documented numpy behavior: .imag of a real array is zeros).

func (*Array[T]) Index

func (a *Array[T]) Index(idx ...[]int) *Array[T]

Index gathers elements of a by integer fancy indexing on the leading axes: each list is a 1-d index array, the lists broadcast to one common length k, and the result shape is (k,) ++ a's trailing axes. Negative indices count from the end, repeats allowed; the result is new data. With no lists Index returns a Copy.

func (*Array[T]) IsContiguous

func (a *Array[T]) IsContiguous() bool

IsContiguous reports whether the array is laid out in C order.

func (*Array[T]) IsIn

func (a *Array[T]) IsIn(testElements *Array[T], invert bool) []bool

IsIn tests every element of testElements against a's flattened unique values (numpy isin, Unique-based) and returns a []bool in C order of testElements. NaN only matches NaN. invert swaps the membership test. The result is a plain []bool because bool is not a Number element type.

func (*Array[T]) Log

func (a *Array[T]) Log() *Array[T]

Log returns the natural logarithm; Log(0) is -Inf (IEEE).

func (*Array[T]) Log1p

func (a *Array[T]) Log1p() *Array[T]

Log1p returns log(1+x), accurate near zero. Complex elements use Log(1+x).

func (*Array[T]) Log2

func (a *Array[T]) Log2() *Array[T]

Log2 returns the element-wise base-2 logarithm. Complex elements use Log(x)/ln2.

func (*Array[T]) Log10

func (a *Array[T]) Log10() *Array[T]

Log10 returns the element-wise base-10 logarithm. Complex elements use Log(x)/ln10.

func (*Array[T]) MaskSelect

func (a *Array[T]) MaskSelect(mask []bool) *Array[T]

MaskSelect selects every element whose flattened C-order position has mask true (numpy a[mask] for the whole array). The result is a new 1-d array.

func (*Array[T]) Matmul

func (a *Array[T]) Matmul(b *Array[T]) *Array[T]

Matmul returns the numpy matmul product: the last two dimensions are the matrix dimensions (M,K)@(K,N), leading dimensions broadcast. A 1-D left operand is treated as a (1,K) row and a 1-D right operand as a (K,1) column, that dimension dropped from the result. Two 1-D operands panic (use Vdot). Incompatible inner dimensions panic.

func (*Array[T]) Max

func (a *Array[T]) Max(axes ...int) *Array[T]

Max folds max along axes (no axes = whole array, [1]). The zero-size identity is -Inf: every element compares greater, so the fold adopts the first element and the empty result stays -Inf.

func (*Array[T]) MaxKeepdims

func (a *Array[T]) MaxKeepdims(axes ...int) *Array[T]

MaxKeepdims folds max along axes, keeping reduced axes as size 1.

func (*Array[T]) Mean

func (a *Array[T]) Mean(axes ...int) *Array[T]

Mean divides the sum along axes by the reduced element count. It accumulates in T (documented); the zero-size identity is NaN.

func (*Array[T]) MeanKeepdims

func (a *Array[T]) MeanKeepdims(axes ...int) *Array[T]

MeanKeepdims folds the mean along axes, keeping reduced axes as size 1.

func (*Array[T]) Median

func (a *Array[T]) Median(axes ...int) *Array[T]

Median computes the median along axes (linear interpolation between the two middle values for even counts). A channel containing NaN yields NaN for it; an empty channel yields NaN (numpy raises).

func (*Array[T]) Min

func (a *Array[T]) Min(axes ...int) *Array[T]

Min folds min along axes (no axes = whole array, [1]). The zero-size identity is +Inf: every element compares less, so the fold adopts the first element and the empty result stays +Inf.

func (*Array[T]) MinKeepdims

func (a *Array[T]) MinKeepdims(axes ...int) *Array[T]

MinKeepdims folds min along axes, keeping reduced axes as size 1.

func (*Array[T]) Mul

func (a *Array[T]) Mul(b *Array[T]) *Array[T]

Mul returns a new array with the element-wise product of a and b.

func (*Array[T]) MulInto

func (a *Array[T]) MulInto(dst *Array[T], b *Array[T]) *Array[T]

MulInto writes the broadcast product of a and b into dst and returns dst.

func (*Array[T]) MulValue

func (a *Array[T]) MulValue(v T) *Array[T]

MulValue returns a new array with every element multiplied by v.

func (*Array[T]) NanArgMax

func (a *Array[T]) NanArgMax(axis int) []int

NanArgMax returns the coordinate of each maximum along axis, skipping NaNs (first occurrence wins ties among non-NaN values), one entry per kept slot in C order. A slice holding only NaNs panics, as numpy's nanargmax raises.

func (*Array[T]) NanArgMin

func (a *Array[T]) NanArgMin(axis int) []int

NanArgMin returns the coordinate of each minimum along axis, skipping NaNs (first occurrence wins ties among non-NaN values), one entry per kept slot in C order. A slice holding only NaNs panics.

func (*Array[T]) NanCumProd

func (a *Array[T]) NanCumProd(axes ...int) *Array[T]

NanCumProd prefixes NaN-free products along axes (no axes = C-order prefix over the raveled array): NaN contributes 1, mirroring numpy's nancumprod.

func (*Array[T]) NanCumSum

func (a *Array[T]) NanCumSum(axes ...int) *Array[T]

NanCumSum prefixes NaN-free sums along axes (no axes = C-order prefix over the raveled array, like CumSum): NaN contributes 0, mirroring numpy's nancumsum.

func (*Array[T]) NanMax

func (a *Array[T]) NanMax(axes ...int) *Array[T]

NanMax folds max along axes, skipping NaNs; a slice with no non-NaN values (including an empty one) yields NaN.

func (*Array[T]) NanMaxKeepdims

func (a *Array[T]) NanMaxKeepdims(axes ...int) *Array[T]

NanMaxKeepdims folds the NaN-skipping max along axes, keeping reduced axes as size 1.

func (*Array[T]) NanMean

func (a *Array[T]) NanMean(axes ...int) *Array[T]

NanMean averages the non-NaN values along axes; a slice without non-NaN values yields NaN.

func (*Array[T]) NanMeanKeepdims

func (a *Array[T]) NanMeanKeepdims(axes ...int) *Array[T]

NanMeanKeepdims folds the NaN-skipping mean along axes, keeping reduced axes as size 1.

func (*Array[T]) NanMedian

func (a *Array[T]) NanMedian(axes ...int) *Array[T]

NanMedian computes the median of the non-NaN values along axes (linear interpolation between the two middle values for even counts); a slice without non-NaN values yields NaN.

func (*Array[T]) NanMedianKeepdims

func (a *Array[T]) NanMedianKeepdims(axes ...int) *Array[T]

NanMedianKeepdims folds the NaN-skipping median along axes, keeping reduced axes as size 1.

func (*Array[T]) NanMin

func (a *Array[T]) NanMin(axes ...int) *Array[T]

NanMin folds min along axes, skipping NaNs; a slice with no non-NaN values (including an empty one) yields NaN.

func (*Array[T]) NanMinKeepdims

func (a *Array[T]) NanMinKeepdims(axes ...int) *Array[T]

NanMinKeepdims folds the NaN-skipping min along axes, keeping reduced axes as size 1.

func (*Array[T]) NanProd

func (a *Array[T]) NanProd(axes ...int) *Array[T]

NanProd folds multiplication along axes, treating NaN as 1 (numpy nanprod; an all-NaN slice therefore multiplies to 1).

func (*Array[T]) NanProdKeepdims

func (a *Array[T]) NanProdKeepdims(axes ...int) *Array[T]

NanProdKeepdims folds the NaN-skipping product along axes, keeping reduced axes as size 1.

func (*Array[T]) NanStd

func (a *Array[T]) NanStd(axes ...int) *Array[T]

NanStd computes the NaN-skipping standard deviation along axes with ddof=0.

func (*Array[T]) NanStdDDof

func (a *Array[T]) NanStdDDof(ddof int, axes ...int) *Array[T]

NanStdDDof computes the NaN-skipping standard deviation along axes with the given delta degrees of freedom.

func (*Array[T]) NanStdKeepdims

func (a *Array[T]) NanStdKeepdims(axes ...int) *Array[T]

NanStdKeepdims folds the NaN-skipping standard deviation along axes, keeping reduced axes as size 1.

func (*Array[T]) NanSum

func (a *Array[T]) NanSum(axes ...int) *Array[T]

NanSum folds addition along axes, treating NaN as 0 (numpy nansum; an all-NaN slice therefore sums to 0).

func (*Array[T]) NanSumKeepdims

func (a *Array[T]) NanSumKeepdims(axes ...int) *Array[T]

NanSumKeepdims folds the NaN-skipping sum along axes, keeping reduced axes as size 1.

func (*Array[T]) NanToNum

func (a *Array[T]) NanToNum(nan, posinf, neginf T) *Array[T]

NanToNum replaces NaN with nan and ±Inf with posinf/neginf element-wise (numpy nan_to_num). For complex elements each component is replaced independently; replacing a component leaves the other intact, so a complex NaN-replacement writes NaN+0i parts as (nan value, 0).

func (*Array[T]) NanToNumDefault

func (a *Array[T]) NanToNumDefault() *Array[T]

NanToNumDefault is NanToNum with numpy's defaults: NaN becomes 0 and ±Inf become the largest/smallest finite values of the element type (math.MaxFloat64 for float64; float32 elements use math.MaxFloat32).

func (*Array[T]) NanVar

func (a *Array[T]) NanVar(axes ...int) *Array[T]

NanVar computes the NaN-skipping population variance (ddof=0) along axes. Complex arrays panic as with Var. A slice with fewer non-NaN values than ddof+1 yields NaN.

func (*Array[T]) NanVarDDof

func (a *Array[T]) NanVarDDof(ddof int, axes ...int) *Array[T]

NanVarDDof computes the NaN-skipping variance along axes with the given delta degrees of freedom.

func (*Array[T]) NanVarKeepdims

func (a *Array[T]) NanVarKeepdims(axes ...int) *Array[T]

NanVarKeepdims folds the NaN-skipping variance along axes, keeping reduced axes as size 1.

func (*Array[T]) Ndim

func (a *Array[T]) Ndim() int

Ndim returns the number of dimensions.

func (*Array[T]) Partition

func (a *Array[T]) Partition(kth int, axis int) *Array[T]

Partition returns a new array where the element at position kth (negative counts from the end) along each channel of axis is in its sorted place, with smaller elements left and larger right (numpy partition).

shortcut: O(n log n) sort-based partition, upgrade to introselect if profiling needs O(n).

func (*Array[T]) Percentile

func (a *Array[T]) Percentile(q float64, axes ...int) *Array[float64]

Percentile computes the q-th percentile (q in [0, 100]) along axes with numpy's linear interpolation method — the only method implemented. The result is always float64: percentiles of complex values are not representable here (numpy raises TypeError). A channel containing NaN yields NaN for it.

func (*Array[T]) Prod

func (a *Array[T]) Prod(axes ...int) *Array[T]

Prod folds multiplication along axes (no axes = whole array, [1]).

func (*Array[T]) ProdKeepdims

func (a *Array[T]) ProdKeepdims(axes ...int) *Array[T]

ProdKeepdims folds multiplication along axes, keeping reduced axes as size 1.

func (*Array[T]) Put

func (a *Array[T]) Put(indices []int, axis int, values *Array[T]) *Array[T]

Put mutates the receiver by writing values at the given indices along axis (negative indices count from the end, repeats allowed). values broadcast against the gathered shape (a's shape with the axis dimension replaced by len(indices)). Returns the receiver for chaining.

func (*Array[T]) PutIndices

func (a *Array[T]) PutIndices(values *Array[T], idx ...[]int) *Array[T]

PutIndices mutates the receiver by assigning values at the positions selected by integer fancy indexing (same rules as Index): values are broadcast against the gathered shape. Returns the receiver for chaining.

func (*Array[T]) Quantile

func (a *Array[T]) Quantile(q float64, axes ...int) *Array[float64]

Quantile is Percentile with numpy's quantile scale: q in [0, 1].

func (*Array[T]) Ravel

func (a *Array[T]) Ravel() *Array[T]

Ravel flattens to 1-D in C order. A contiguous array returns a view sharing data; a non-contiguous array is copied first, so sharing is not guaranteed.

func (*Array[T]) Real

func (a *Array[T]) Real() *Array[float64]

Real returns the element-wise real parts as float64. Real element types are converted (float32 widens to float64); complex elements drop the imaginary part.

func (*Array[T]) RealIfClose

func (a *Array[T]) RealIfClose(tol float64) *Array[float64]

RealIfClose returns Real unless a is complex with any |imag| >= tol, where it panics. tol is a multiple of the machine epsilon (numpy real_if_close); tol <= 1 uses the absolute value as the tolerance, matching numpy's "if the tolerance is <=1, use the absolute tolerance". Documented deviation: numpy returns the COMPLEX array unchanged in that case; this package panics because the caller asked for real values that cannot be given losslessly.

func (*Array[T]) Reshape

func (a *Array[T]) Reshape(shape ...int) *Array[T]

Reshape views the array with a new shape when the data is contiguous; a non-contiguous array is copied first, so the result may not share data. At most one dimension may be -1 and is inferred.

func (*Array[T]) Round

func (a *Array[T]) Round() *Array[T]

Round returns the element-wise round-half-to-even (numpy's round), per-component on complex elements.

func (*Array[T]) Set

func (a *Array[T]) Set(coords []int, v T) *Array[T]

Set writes v at coords in place and returns a for chaining.

func (*Array[T]) SetMask

func (a *Array[T]) SetMask(mask []bool, v T) *Array[T]

SetMask mutates the receiver by assigning v to every element whose flattened C-order position has mask true (numpy a[mask] = v flat semantics). Returns the receiver for chaining.

func (*Array[T]) Shape

func (a *Array[T]) Shape() []int

Shape returns a copy of the array's dimensions.

func (*Array[T]) Sin

func (a *Array[T]) Sin() *Array[T]

Sin returns the element-wise sine.

func (*Array[T]) Sinh

func (a *Array[T]) Sinh() *Array[T]

Sinh returns the element-wise hyperbolic sine.

func (*Array[T]) Size

func (a *Array[T]) Size() int

Size returns the total number of elements.

func (*Array[T]) Slice

func (a *Array[T]) Slice(rs ...Range) *Array[T]

Slice views a strided sub-array. Ranges cover the leading axes; trailing axes not mentioned are taken whole (numpy a[:2] semantics), so a zero Range or a missing axis means the entire axis. The result shares data. Bounds follow numpy: negative indices count from the end and a negative Step reverses the axis.

func (*Array[T]) SlidingWindowView

func (a *Array[T]) SlidingWindowView(windowShape ...int) *Array[T]

SlidingWindowView appends len(windowShape) window axes to a trimmed copy of a's shape: view.shape = trimmed + window, where trimmed[k] = shape[k] - (window[k] - 1). The window axes run over ALL of a's axes in order, so len(windowShape) must equal a.Ndim() (numpy's axis=None branch; there is no last-k-axes default in numpy either). The result shares data and the same element is reachable from many window slots, so writes alias — treat the result as read-only like numpy's default writeable=False.

func (*Array[T]) Sort

func (a *Array[T]) Sort(axes ...int) *Array[T]

Sort returns a new array with each channel along the given axes sorted ascending; with no axes the LAST axis is sorted (numpy axis=-1). Each listed axis is sorted independently, one pass per axis in the order given. NaN sorts last. Negative axes resolve.

func (*Array[T]) SortInto

func (a *Array[T]) SortInto(axes ...int) *Array[T]

SortInto sorts the receiver's channels in place (same semantics as Sort) and returns it.

func (*Array[T]) Sqrt

func (a *Array[T]) Sqrt() *Array[T]

Sqrt returns the element-wise square root: the math/cmplx square root (principal branch; real Sqrt(-1) is NaN).

func (*Array[T]) Squeeze

func (a *Array[T]) Squeeze(axes ...int) *Array[T]

Squeeze drops size-1 dimensions. With no axes all size-1 dimensions are dropped; named axes must have size one. The result shares data.

func (*Array[T]) Std

func (a *Array[T]) Std(axes ...int) *Array[T]

Std computes the standard deviation along axes with ddof=0.

func (*Array[T]) StdDDof

func (a *Array[T]) StdDDof(ddof int, axes ...int) *Array[T]

StdDDof computes the standard deviation along axes with the given delta degrees of freedom.

func (*Array[T]) StdKeepdims

func (a *Array[T]) StdKeepdims(axes ...int) *Array[T]

StdKeepdims folds the standard deviation along axes, keeping reduced axes as size 1.

func (*Array[T]) Sub

func (a *Array[T]) Sub(b *Array[T]) *Array[T]

Sub returns a new array with the element-wise difference of a and b.

func (*Array[T]) SubInto

func (a *Array[T]) SubInto(dst *Array[T], b *Array[T]) *Array[T]

SubInto writes the broadcast difference of a and b into dst and returns dst.

func (*Array[T]) SubValue

func (a *Array[T]) SubValue(v T) *Array[T]

SubValue returns a new array with v subtracted from every element.

func (*Array[T]) Sum

func (a *Array[T]) Sum(axes ...int) *Array[T]

Sum folds addition along axes (no axes = whole array, result shape [1]). Negative axes resolve as axis+ndim; invalid axes panic.

func (*Array[T]) SumKeepdims

func (a *Array[T]) SumKeepdims(axes ...int) *Array[T]

SumKeepdims folds addition along axes, keeping reduced axes as size 1.

func (*Array[T]) SwapAxes

func (a *Array[T]) SwapAxes(i, j int) *Array[T]

SwapAxes exchanges dimensions i and j (negative allowed). The result shares data.

func (*Array[T]) Take

func (a *Array[T]) Take(indices []int, axis int) *Array[T]

Take gathers the elements of a at indices along axis (negative indices count from the end, repeats allowed). The result shape is a's with the axis dimension replaced by len(indices); the result is new data.

func (*Array[T]) Tan

func (a *Array[T]) Tan() *Array[T]

Tan returns the element-wise tangent.

func (*Array[T]) Tanh

func (a *Array[T]) Tanh() *Array[T]

Tanh returns the element-wise hyperbolic tangent.

func (*Array[T]) Transpose

func (a *Array[T]) Transpose(axes ...int) *Array[T]

Transpose views the array with its axes permuted. With no axes it reverses them (numpy .T). The result shares data.

func (*Array[T]) Trunc

func (a *Array[T]) Trunc() *Array[T]

Trunc returns the element-wise integer part, per-component on complex elements.

func (*Array[T]) Unique

func (a *Array[T]) Unique() *Array[T]

Unique returns the flattened (C-order ravel) unique values, sorted. NaN — compared by real part — groups into a single NaN placed last, as complex values order by (real, imag).

func (*Array[T]) UniqueCounts

func (a *Array[T]) UniqueCounts() (*Array[T], []int)

UniqueCounts returns Unique's values together with each value's occurrence count.

func (*Array[T]) UnsafeData

func (a *Array[T]) UnsafeData() unsafe.Pointer

UnsafeData hands the array's backing storage to foreign code (cgo, syscalls, binary decoders) — the Go-side analog of numpy's __array_interface__ / ctypeslib. This is the ONLY way this package aliases caller memory: every constructor otherwise copies its input.

cgo example (a is *Array[float64], C-order contiguous):

p := (*C.double)(a.UnsafeData())
C.process(p, C.int(a.Size())) // ByteSize() bytes, C float64 == Go float64

The pointer stays valid while a is reachable (the GC keeps the backing array alive) and its data is not resized.

func (*Array[T]) Var

func (a *Array[T]) Var(axes ...int) *Array[T]

Var computes the population variance (ddof=0) along axes. The result is real-valued: Var/Std of complex arrays are not representable in T and panic (numpy raises TypeError for the same reason). The zero-size identity is NaN.

func (*Array[T]) VarDDof

func (a *Array[T]) VarDDof(ddof int, axes ...int) *Array[T]

VarDDof computes the variance along axes with the given delta degrees of freedom.

func (*Array[T]) VarKeepdims

func (a *Array[T]) VarKeepdims(axes ...int) *Array[T]

VarKeepdims folds the variance along axes, keeping reduced axes as size 1.

func (*Array[T]) Vdot

func (a *Array[T]) Vdot(b *Array[T]) T

Vdot returns the conjugate dot product of the flattened operands: sum(conj(a[i]) * b[i]). Sizes must match.

type Float

type Float interface {
	~float32 | ~float64
}

Float is the real-valued subset of Number: the result element type of operations whose value is real even for complex input (Abs).

type GenConfig

type GenConfig struct {
	Delimiter      string   // "" splits on any run of whitespace; otherwise a literal separator
	SkipHeader     int      // lines skipped at the start, before names detection
	SkipFooter     int      // data rows dropped from the end
	Comments       []string // lines starting with any entry are skipped (default "#")
	Names          []string // explicit column names to return
	UseHeaderNames bool     // the first non-skipped row supplies the names
	FillingValues  float64  // substituted for missing/failed-parse fields (default NaN)
	Missing        string   // a field equal to this string counts as missing ("" is always missing)
}

GenConfig configures GenFromTxt; zero values match numpy's defaults except FillingValues, which defaults to NaN (numpy's fill for float columns).

type Number

type Number interface {
	~float32 | ~float64 | ~complex64 | ~complex128
}

Number is the element type constraint for Array. Integers are excluded: Mean/Div would silently truncate without numpy-style dtype promotion.

type PadMode

type PadMode int

PadMode selects how Pad fills the padded area.

const (
	PadConstant  PadMode = iota // fill with the given constant value
	PadEdge                     // repeat the edge value
	PadReflect                  // reflect about the edge, edge value NOT repeated
	PadSymmetric                // reflect including the edge value
	PadWrap                     // circular shift (numpy wrap)
	PadEmpty                    // leave Go zero values: numpy's uninitialized

)

type Range

type Range struct {
	Start, Stop, Step int
}

Range is one slice axis. A zero Range means the whole axis. Step 0 is treated as 1. Negative Start/Stop count from the end. With a negative Step and no bounds, the whole axis is reversed (Range{Step: -1}).

func From

func From(start int) Range

From builds a Range from start to the end of the axis with step 1. Stop uses an explicit sentinel because a zero Stop would be ambiguous with an explicit 0.

func R

func R(start, stop, step int) Range

R builds a Range with explicit start, stop and step.

func To

func To(stop int) Range

To builds a Range from 0 up to stop (exclusive) with step 1.

Directories

Path Synopsis
Package assert provides numpy.testing-style assertions for numgo arrays, for use in downstream tests.
Package assert provides numpy.testing-style assertions for numgo arrays, for use in downstream tests.
Package emath ports numpy.emath (lib.scimath): math functions that return mathematically valid answers in the complex domain instead of NaN.
Package emath ports numpy.emath (lib.scimath): math functions that return mathematically valid answers in the complex domain instead of NaN.
Package fft provides numpy.fft-semantics discrete Fourier transforms over numgo arrays, backed by an own FFT: mixed-radix Cooley-Tukey + Bluestein for large primes.
Package fft provides numpy.fft-semantics discrete Fourier transforms over numgo arrays, backed by an own FFT: mixed-radix Cooley-Tukey + Bluestein for large primes.
internal
fixtures
Package fixtures provides golden-data helpers for numpy comparison tests.
Package fixtures provides golden-data helpers for numpy comparison tests.
lapack
Package lapack provides pure-Go numeric kernels for the linalg package: dense LU, Cholesky, Householder QR, one-sided Jacobi SVD, cyclic-Jacobi symmetric eigendecomposition, and general eigenvalues via Hessenberg reduction plus shifted QR iteration.
Package lapack provides pure-Go numeric kernels for the linalg package: dense LU, Cholesky, Householder QR, one-sided Jacobi SVD, cyclic-Jacobi symmetric eigendecomposition, and general eigenvalues via Hessenberg reduction plus shifted QR iteration.
nditer
Package nditer is the single place where strided index arithmetic lives.
Package nditer is the single place where strided index arithmetic lives.
simdvec
Package simdvec holds vectorized inner loops for per-element, order-free operations (a[i]+b[i], dtype conversion, matmul inner kernel, sum reduction).
Package simdvec holds vectorized inner loops for per-element, order-free operations (a[i]+b[i], dtype conversion, matmul inner kernel, sum reduction).
Package linalg provides numpy.linalg-semantics dense linear algebra over numgo arrays.
Package linalg provides numpy.linalg-semantics dense linear algebra over numgo arrays.
Package ma provides numpy.ma-style masked arrays over numgo.Array (numpy/ma/core.py semantics; see docs/architecture.md).
Package ma provides numpy.ma-style masked arrays over numgo.Array (numpy/ma/core.py semantics; see docs/architecture.md).
Package polynomial is a Go port of numpy.polynomial: the six polynomial classes sharing the ABCPolyBase API (numpy _polybase.py), each with its own basis arithmetic ported from the corresponding numpy module.
Package polynomial is a Go port of numpy.polynomial: the six polynomial classes sharing the ABCPolyBase API (numpy _polybase.py), each with its own basis arithmetic ported from the corresponding numpy module.
Package random is the numgo equivalent of numpy.random: SeedSequence + bit-generator engines + the Generator distribution layer, ported for bit-exact agreement with numpy 2.x for identical seeds.
Package random is the numgo equivalent of numpy.random: SeedSequence + bit-generator engines + the Generator distribution layer, ported for bit-exact agreement with numpy 2.x for identical seeds.
Package strings ports numpy.strings: elementwise string operations over an N-dimensional array of Go strings.
Package strings ports numpy.strings: elementwise string operations over an N-dimensional array of Go strings.

Jump to

Keyboard shortcuts

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