Nune-go - High-performance numerical engine based on generic tensors

Nune (v0.1)

Numerical engine is a library for performing numerical computation in Go, relying on generic tensors.

Table of contents

Installation

Nune requires Go v1.18 as it heavily relies on generics in order to achieve a flexible interface. Go v1.18 is currently only available in beta version, which can be downloaded here.

Design

Nune follows Go's principles and design philosophies of simplicity and minimalism. Therefore, going forward, Nune will always be a compact library providing only the minimal and foundational functions to deal with numerical data and computation.

Usage

Creating tensors was never easier:

package main

import (
	"github.com/lordlarker/nune/tensor"
)

func  main() {
	// Nune can create tensors of any shapes.
	_ = tensor.Zeros[int](5, 5) // create a 5x5 tensor
	_ = tensor.Ones[int](5, 10, 5, 25) // or a weird one
	_ = tensor.Full[int](4, []int{5, 2}) // (value, shape)

	// From a range?
	_ = tensor.Range[uint](0, 100, 2) // (start, end, step)
	// Maybe in reverse?
	_ = tensor.Range[uint](100, 0, -1)

	// Even a geometrical space?
	_ = tensor.Linspace[float32](-10, 10, 5) // (start, end, size)
	_ = tensor.Logspace[float32](2, 0, 1, 20) // (base, start, end, size)

	// Random facilities as well?
	_ = tensor.Rand[float64](3, 3, 3) // (shape ...int)
	_ = tensor.RandRange[float64](10, 100, []int{4, 4}) // (start, end, shape)

	// In fact Nune can create tensors from (almost) anything.
	_ = tensor.From[int](5)
	_ = tensor.From[float32]([]int{1, 2, 3}) // implicitly casts the type
	_ = tensor.From[float64]("nune") // even strings

	type Point int
	_ = tensor.From[Point](3) // or custom types

	// It can also take any n-dimensional array/slice.
	// The tensor will implicitly have a shape of (2, 2).
	_ = tensor.From[byte]([][]uint{{1, 2}, {3, 4}})
}

Or performing parallel operations with multithreaded math:

package main

import (
	"math"
	"github.com/lordlarker/nune/tensor"
)

func main() {
	t := tensor.Range[float64](-100, 100, 1).Reshape(2, 4, 25)
	
	// Built in methods of various kinds
	_ = t.Abs()
	_ = t.Sum()
	_ = t.Add(t.Copy())
	
	_ = t.Sqrt().Floor()

	_, _, _ = t.Min(), t.Max(), t.Mean()
	_, _, _ = t.Sin(), t.Cos(), t.Tan()
	
	// Or make your own, and automatically
	// get parallelization on the way
	_ = t.PwiseOp(func(x float64) float64 {
		return 1 / (1 + math.Exp(-x)) // parallel sigmoid function
	})
}

And what's better than some fancy terminal output:

package main

import (
	"fmt"
	"github.com/lordlarker/nune"
	"github.com/lordlarker/nune/tensor"
)

func main() {
	scalar := tensor.From[int](5)
	fmt.Println(scalar)
	// Prints:
	// 
	// Tensor(5)

	nune.FmtConfig.Precision = 2 // number of decimal points
	t := tensor.Range[float32](-5, 5, 1).Reshape(2, 5)
	fmt.Println(t)
	// Prints:
	//
	// Tensor([[-5.00, -4.00, -3.00, -2.00, -1.00]
	//         [ 0.00,  1.00,  2.00,  3.00,  4.00]])

	nune.FmtConfig.Excerpt = 4 // number of elements shown per axis
	t = tensor.Range[float32](0, 256, 1).Reshape(16, 16)
	fmt.Println(t)
	// Prints:
	//
	//  Tensor([[  0.00,   1.00, ...,  14.00,  15.00]
        //          [ 16.00,  17.00, ...,  30.00,  31.00]
        //          ...,
        //          [224.00, 225.00, ..., 238.00, 239.00]
        //          [240.00, 241.00, ..., 254.00, 255.00]])
	
	nune.FmtConfig.Btoa = true // bytes to ASCII
	b := tensor.From[byte]("nune")
	fmt.Println(b)
	// Prints:
	//
	// Tensor([n, u, n, e])
}

Roadmap

Since Nune will always be designed to provide only the minimal foundational numerical computing facilities, the roadmap isn't that long, and Nune already is close to stabilizing. Things that still need work before this is a rock-stable library are the following, in order:

  • Create a backend to handle all the tensor manipulation routines and managing layout and memory.
  • Optimize the API for maximum performance.
  • Rigorously test the API.
  • Stabilize the API.
  • Write examples to ease the use of this library.

License

Nune has a BSD-style license, as found in the LICENSE file.

Owner
Lord Larker
The name suffices.
Lord Larker
Similar Resources

Generic-list-go - Go container/list but with generics

generic-list-go Go container/list but with generics. The code is based on contai

Dec 7, 2022

Go language interface to the PAPI performance API

go-papi Description go-papi provides a Go interface to PAPI, the Performance Application Programming Interface. PAPI provides convenient access to har

Dec 22, 2022

🦔 semver and constraint parsing with a focus on performance

semver 🦔 semver and constraint parsing with a focus on performance semver provides semantic version and constraint parsing, comparison, and testing.

Dec 1, 2021

Exercise for solve problem data processing, performance and something wrong in passing data

Citcall Exercise Exercise for solve problem data processing, performance and something wrong in passing data Pengolahan data data processing - Readme

Nov 25, 2021

wkhtmltopdf Go bindings and high level interface for HTML to PDF conversion

wkhtmltopdf Go bindings and high level interface for HTML to PDF conversion

wkhtmltopdf Go bindings and high level interface for HTML to PDF conversion. Implements wkhtmltopdf Go bindings. It can be used to convert HTML docume

Dec 17, 2022

The High Code Framework (low-code for devs)

hof - the high code framework The hof tool tries to remove redundent development activities by using high level designs, code generation, and diff3 wh

Dec 24, 2022

Assembly syntax that makes you feel like you're writing code in a high-level language.

shasm Assembly syntax that makes you feel like you're writing code in a high-level language. Shasm is not an Assembler. Shasm simply compiles Shasm sy

Jun 5, 2021

other glyph sets for high-dpi 1-bit monochrome

hd1b_other other glyph sets for high-dpi 1-bit monochrome Currently included glyph sets: Hangul (Korean): U+1100..U+11FF, U+3131..U+318E, U+AC00..U+D7

Aug 29, 2022

community search engine

Lieu an alternative search engine Created in response to the environs of apathy concerning the use of hypertext search and discovery.

Dec 24, 2022
Comments
  • dir structure: Use of internal package not allowed

    dir structure: Use of internal package not allowed

    I copied some examples from the readme as below and tried running go run ./main.go.

    package main
    
    import "github.com/lordlarker/nune-go/tensor"
    
    func main() {
    	// t := tensor.Full[int](4, []int{5, 2})
    	t := tensor.From[byte]("nune")
    	println(t.Prod())
    	println(t.Sum())
    }
    

    errors:

    package github.com/kendfss/larking
    	imports github.com/lordlarker/nune-go/tensor
    	../../lordlarker/nune-go/tensor/ops.go:8:2: use of internal package github.com/lordlarker/nune/internal/cpd not allowed
    package github.com/kendfss/larking
    	imports github.com/lordlarker/nune-go/tensor
    	../../lordlarker/nune-go/tensor/attr.go:10:2: use of internal package github.com/lordlarker/nune/internal/slice not allowed
    package github.com/kendfss/larking
    	imports github.com/lordlarker/nune-go/tensor
    	../../lordlarker/nune-go/tensor/attr.go:11:2: use of internal package github.com/lordlarker/nune/internal/utils not allowed
    

    looking it up took me to this thread https://stackoverflow.com/questions/41060764/how-to-disable-use-of-internal-package-not-allowed

    So, if this package is supposed to be used by third parties the types should be aliased into the root directory or, ideally, rename the internal directory to something like api|core|lib|utils. Or, coincidentally, I have some generic libraries forked from exp/constraints|slices|maps. and could refactor. Would give me a nice excuse to publish something.

    Otherwise, looking good as far as I can tell.

Go-generic-unboxing - A quick ready to ship demo for go generic using the official example

Go generic This repo contain basic demo for installing and running go1.18beta1 v

Feb 1, 2022
Generic - Golang generic example

泛型 场景 假设需要写一个列表总数计算的函数,根据不同数据类型,我们可能分别要写 SumInts(data []int),SumFloats(data []fl

Jan 27, 2022
elPrep: a high-performance tool for analyzing sequence alignment/map files in sequencing pipelines.
elPrep: a high-performance tool for analyzing sequence alignment/map files in sequencing pipelines.

Overview elPrep is a high-performance tool for analyzing .sam/.bam files (up to and including variant calling) in sequencing pipelines. The key advant

Nov 2, 2022
a generic object pool for golang

Go Commons Pool The Go Commons Pool is a generic object pool for Golang, direct rewrite from Apache Commons Pool. Features Support custom PooledObject

Jan 5, 2023
Optimistic rollup tech, minimal and generic.

Opti Optimistic rollup tech, minimal and generic. VERY experimental, just exploratory code, question is: 1:1 EVM rollup with interactive fraud proof p

Aug 30, 2022
Generic mapStringInterface tool for extracting of data for CSV output

Generic mapStringInterface tool for extracting of data for CSV output

Nov 2, 2021
Generic slices for Go 1.8+

Slice A simple package that makes working with slices a little bit easier with the help of generics. Install go get github.com/twharmon/slice Example

Nov 1, 2022
Generic tools for go 1.18+

Gtools Generic tools for go 1.18+ FT (func tools) Provide func tools over iterators Iterators for functions like Filter, Map, Reduce, etc solve 3 main

Jan 12, 2022
Ecsgo - Cache friendly, Multi threading Entity Component System in Go (with Generic)

ECSGo ECSGo is an Entity Component System(ECS) in Go. This is made with Generic

Oct 19, 2022
Go-generic - A collection of experiments using Go Generics coming out in Go 1.18

Go Generic - experiments with Go 1.18 beta Data structures: iter.Iter[T any] - l

Aug 15, 2022