tiny linear interpolation library for go (factored out from https://github.com/sgreben/yeetgif)

piecewiselinear

gocover.io Build

A tiny library for linear interpolation. O(log(N)) per evaluation for N control points.

import "github.com/sgreben/piecewiselinear"

Get it

go get -u "github.com/sgreben/piecewiselinear"

Use it

import "github.com/sgreben/piecewiselinear"

func main() {
    f := piecewiselinear.Function{Y:[]float64{0,1,0}} // range: "hat" function
    f.X = piecewiselinear.Span(0, 1, len(f.Y)) // domain: equidistant points along X axis
    fmt.Println(
		f.At(0), // f.At(x) evaluates f at x
		f.At(0.25),
		f.At(0.5),
		f.At(0.75),
		f.At(1.0),
		f.At(123.0),  // outside its domain X the function is constant 0
		f.At(-123.0), //
	)
    // Output:
    // 0 0.5 1 0.5 0 0 0
}
Owner
Sergey Grebenshchikov
non-stop through desert, salisbury steak sweater
Sergey Grebenshchikov
Similar Resources

*DEPRECATED* Please use https://gopkg.in/redsync.v1 (https://github.com/go-redsync/redsync)

Redsync.go This package is being replaced with https://gopkg.in/redsync.v1. I will continue to maintain this package for a while so that its users do

Nov 20, 2022

Image resizing for the Go programming language with common interpolation methods

This package is no longer being updated! Please look for alternatives if that bothers you. Resize Image resizing for the Go programming language with

Dec 14, 2021

Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://developer.github.com/v4/).

githubv4 Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql). If you're looking for a client

Dec 26, 2022

In 'n Out - See what goes in and comes out of PEs/DLLs

In 'n Out Parse and return PE information ino -v comsvcs.dll { "Name": "string", "Path": "string", "Type": "string file|directory", "Im

Dec 16, 2022

Go language bindings for the COIN-OR Linear Programming library

clp Description The clp package provides a Go interface to the COIN-OR Linear Programming (CLP) library, part of the COIN-OR (COmputational INfrastruc

Nov 9, 2022

Tiny-HTTPS protocol implementation (experiment purpose.)

thttps Basic TLS implementation in Go, written as a learning project. Most components are forked from Go version 1.7 tiny-HTTPS is not suitable for re

Mar 7, 2022

Machine Learning libraries for Go Lang - Linear regression, Logistic regression, etc.

package ml - Machine Learning Libraries ###import "github.com/alonsovidales/go_ml" Package ml provides some implementations of usefull machine learnin

Nov 10, 2022

Go implementation of BLAS (Basic Linear Algebra Subprograms)

Go implementation of BLAS (Basic Linear Algebra Subprograms) Any function is implemented in generic Go and if it is justified, it is optimized for AMD

Dec 11, 2022

Sparse matrix formats for linear algebra supporting scientific and machine learning applications

Sparse matrix formats Implementations of selected sparse matrix formats for linear algebra supporting scientific and machine learning applications. Co

Dec 12, 2022

Sparse matrix formats for linear algebra supporting scientific and machine learning applications

Sparse matrix formats Implementations of selected sparse matrix formats for linear algebra supporting scientific and machine learning applications. Co

Jan 8, 2023

Fast (linear time) implementation of the Gaussian Blur algorithm in Go.

Fast (linear time) implementation of the Gaussian Blur algorithm in Go.

Song2 Fast (linear time) implementation of the Gaussian Blur algorithm in Go.

Oct 25, 2022

A pluggable linear task engine

noscript A pluggable linear task engine. Great for providing flexible configuration pattern to end users or providing scripting-like functionality to

Oct 23, 2021

Simple, fast and safe cross-platform linear binary stream communication protocol. AES key exchange based on ecc secp256k1

FFAX Protocol 2 dev 简体中文 Welcome to FFAX Protocol v2 Quick start go get github.com/RealFax/FFAX func example() { listener, err := net.Listen("tcp",

Mar 21, 2022

LFSR - Linear Feedback Shift Register

LFSR - Linear Feedback Shift Register A linear feedback shift register is a collection of bits that shifts when triggered, and the next state is a lin

Mar 3, 2022

go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config

HOCON (Human-Optimized Config Object Notation) Configuration library for working with the Lightbend's HOCON format. HOCON is a human-friendly JSON sup

Dec 3, 2022

A Go library for an efficient implementation of a skip list: https://godoc.org/github.com/MauriceGit/skiplist

A Go library for an efficient implementation of a skip list: https://godoc.org/github.com/MauriceGit/skiplist

Fast Skiplist Implementation This Go-library implements a very fast and efficient Skiplist that can be used as direct substitute for a balanced tree o

Dec 30, 2022

Cap'n Proto library and parser for go. This is go-capnproto-1.0, and does not have rpc. See https://github.com/zombiezen/go-capnproto2 for 2.0 which has rpc and capabilities.

Version 1.0 vs 2.0 Update 2015 Sept 20: Big news! Version 2.0 of the go-bindings, authored by Ross Light, is now released and newly available! It feat

Nov 29, 2022

Go wrapper library for "Dear ImGui" (https://github.com/ocornut/imgui)

Go wrapper library for

Dear ImGui for Go This library is a Go wrapper for Dear ImGui. This wrapper started as a special-purpose wrapper for use within InkyBlackness. However

Jan 2, 2023

Go-github-actions - `go-github-actions` is a package for developing GitHub Actions

go-github-actions go-github-actions is a package for developing GitHub Actions.

Feb 6, 2022
Comments
  • IsInterpolatedAt() to enable checking to see if a given value is within the points array

    IsInterpolatedAt() to enable checking to see if a given value is within the points array

    @sgreben I looked at creating a IsInRange like function but the effort to determine if the value is in the range is nearly the same operation as finding the value and it seemed wasteful to duplicate most of the At() function. I decided to preserve the At() function and insert an extended version, poorly but perhaps sufficiently named AtExtended() method.

    Thoughts?

  • Way to indicate out of range?

    Way to indicate out of range?

    Would a pull request to modify At() to return (float64, error) be accepted? In my use case I'd prefer not to rely on a magic value of 0 to indicate not found but would propose instead we returned something like 0, fmt.Errorf("value out of range") so the user could decide how to handle those cases?

  • Zero on start X value

    Zero on start X value

    Hello! I've tried to run simple example before using in project:

    f := piecewiselinear.Function{Y: []float64{100, 105, 120}} f.X = piecewiselinear.Span(10, 16, len(f.Y)) fmt.Println(f.X) fmt.Println(f.Y) fmt.Println( f.At(10), // f.At(x) evaluates f at x f.At(11), f.At(12), f.At(13), f.At(14), f.At(15), f.At(16), )

    And I've got the output: [10 13 16] [100 105 120] 0 101.66666666666667 103.33333333333334 105 110.00000000000001 115 120

    Everything is fine except zero on defined X value.

    Thank you

Sparse matrix formats for linear algebra supporting scientific and machine learning applications

Sparse matrix formats Implementations of selected sparse matrix formats for linear algebra supporting scientific and machine learning applications. Co

Jan 8, 2023
Calendar heatmap inspired by Github contribution activity
Calendar heatmap inspired by Github contribution activity

Self-contained, plain Go implementation of calendar heatmap inspired by Github contribution activity. $ go build $ echo '{ "2020-05-16": 8, "2

Dec 25, 2022
GoStats is a go library for math statistics mostly used in ML domains, it covers most of the statistical measures functions.

GoStats GoStats is an Open Source Go library for math statistics mostly used in Machine Learning domains, it covers most of the Statistical measures f

Nov 10, 2022
An ordinary differential equation solving library in golang.

ode An ordinary differential equation solving library in golang. Features Multi-dimensional state vector (i.e. extended states) Channel based stopping

Oct 19, 2022
PiHex Library, written in Go, generates a hexadecimal number sequence in the number Pi in the range from 0 to 10,000,000.

PiHex PiHex Library generates a hexadecimal number sequence in the number Pi in the range from 0 to 1.0e10000000. To calculate using "Bailey-Borwein-P

Nov 18, 2022
A well tested and comprehensive Golang statistics library package with no dependencies.

Stats - Golang Statistics Package A well tested and comprehensive Golang statistics library / package / module with no dependencies. If you have any s

Dec 26, 2022
2D triangulation library. Allows translating lines and polygons (both based on points) to the language of GPUs.
2D triangulation library. Allows translating lines and polygons (both based on points) to the language of GPUs.

triangolatte 2D triangulation library. Allows translating lines and polygons (both based on points) to the language of GPUs. Features normal and miter

Dec 23, 2022
Dec 28, 2022
Open-in-linear - A tool provides a shortcut to opening a linear issue in the desktop app or browser

This tool provides a shortcut to opening a linear issue in the desktop app or browser.

Jan 25, 2022
This project is an implementation of Fermat's factorization method in which multiples of prime numbers are factored into their constituent primes

This project is an implementation of Fermat's factorization method in which multiples of prime numbers are factored into their constituent primes. It is a vanity attempt to break RSA Encryption which relies on prime multiples for encryption.

Jun 3, 2022