code stringlengths 114 1.05M | path stringlengths 3 312 | quality_prob float64 0.5 0.99 | learning_prob float64 0.2 1 | filename stringlengths 3 168 | kind stringclasses 1
value |
|---|---|---|---|---|---|
package imageutil
import "image"
// ResizeNearestNeighbor returns a new NRGBA image with the given width and
// height created by resizing the given image using the nearest neighbor
// algorithm.
func ResizeNearestNeighbor(img image.Image, newWidth, newHeight int) *image.NRGBA {
w := img.Bounds().Max.X
h := img.Bou... | resize.go | 0.689201 | 0.646028 | resize.go | starcoder |
package gofun
import "fmt"
// List represents value lists.
type List struct {
isCons bool
head interface{}
tail *List
}
// ListOrElse returns x if x is List pointer, otherwise y.
func ListOrElse(x interface{}, y *List) *List {
z, isOk := x.(*List)
if isOk {
return z
} else {
re... | list.go | 0.836955 | 0.442817 | list.go | starcoder |
package bgls
import (
"bytes"
"fmt"
"math/big"
"github.com/dchest/blake2b"
"github.com/ethereum/go-ethereum/crypto/bn256/cloudflare"
gosha3 "github.com/ethereum/go-ethereum/crypto/sha3"
"golang.org/x/crypto/sha3"
)
type altbn128 struct {
}
type altbn128Point1 struct {
point *bn256.G1
}
type altbn128Point2... | alt_bn128.go | 0.725746 | 0.496643 | alt_bn128.go | starcoder |
package blueprint
import (
"encoding/json"
"fmt"
"testing"
"github.com/ingrammicro/cio/api/types"
"github.com/ingrammicro/cio/utils"
"github.com/stretchr/testify/assert"
)
// TODO exclude from release compile
// ListTemplatesMocked test mocked function
func ListTemplatesMocked(t *testing.T, templatesIn []*ty... | api/blueprint/templates_api_mocked.go | 0.520984 | 0.469338 | templates_api_mocked.go | starcoder |
package perfcounters
import (
"fmt"
"math"
"sync"
"time"
)
/*
RateOfCountsPerSecond32
A difference counter that shows the average number of operations completed during each second of the sample interval. Counters of this type measure time in ticks of the system clock.
Formula: (N 1 - N 0) / ((D 1 -D 0) / F), wh... | perfcounters/rateofcountspersecond32.go | 0.804675 | 0.746486 | rateofcountspersecond32.go | starcoder |
package cluster
import (
"fmt"
"math"
"math/rand"
"sort"
"time"
"gonum.org/v1/gonum/mat"
)
// KV is a structure that holds key-value pairs of type float64.
type KV struct {
Key float64
Value float64
}
// InitHuang implements initialization of cluster centroids based on the
// frequency of attributes as de... | cluster/init_functions.go | 0.729616 | 0.507385 | init_functions.go | starcoder |
package collection
import (
"github.com/deatil/lakego-admin/lakego/support/collection"
)
/**
* Collect
*
* @create 2021-7-3
* @author deatil
*/
// Collect transforms src into Collection. The src could be json string, []string,
// []map[string]interface{}, map[string]interface{}, []int, []int16, []int32, []in... | pkg/lakego-admin/lakego/collection/collection.go | 0.848565 | 0.644756 | collection.go | starcoder |
package gini
import (
"fmt"
"github.com/shuLhan/numerus"
"github.com/shuLhan/tekstus"
"os"
"strconv"
)
var (
// DEBUG debug level, set from environment.
DEBUG = 0
)
/*
Gini contain slice of sorted index, slice of partition values, slice of Gini
index, Gini value for all samples.
*/
type Gini struct {
// Skip... | gain/gini/gini.go | 0.511961 | 0.463444 | gini.go | starcoder |
package iso3166
import (
"fmt"
"strconv"
)
// Country is a representation of a country.
type Country uint16
// Alpha2 returns the ISO 3166-1 two-letter alphabetic code.
func (c Country) Alpha2() string { return countries[c].alpha2 }
// Alpha3 returns the ISO 3166-1 three-letter alphabetic code.
func (c Country) A... | country.go | 0.846514 | 0.565179 | country.go | starcoder |
package pure
import (
"fmt"
"time"
"github.com/itchyny/timefmt-go"
"github.com/rickb777/date/period"
"github.com/benthosdev/benthos/v4/internal/bloblang/query"
"github.com/benthosdev/benthos/v4/public/bloblang"
)
func asDeprecated(s *bloblang.PluginSpec) *bloblang.PluginSpec {
tmpSpec := *s
newSpec := &tmpS... | internal/impl/pure/bloblang_time.go | 0.758511 | 0.499451 | bloblang_time.go | starcoder |
package openapi
import (
"encoding/json"
)
// AccountRouting struct for AccountRouting
type AccountRouting struct {
// The routing number used for US ACH payments. Only appears if `bank_countries` contains `US`. Value may be masked, in which case only the last four digits are returned.
AchRoutingNumber *string `... | synctera/model_account_routing.go | 0.837421 | 0.418222 | model_account_routing.go | starcoder |
package pedersen
import (
"encoding/binary"
"errors"
"io"
ristretto "github.com/bwesterb/go-ristretto"
generator "github.com/dusk-network/dusk-blockchain/pkg/crypto/rangeproof/generators"
)
// Pedersen represents a pedersen struct which holds
// the necessary information to commit a vector or a scalar to a poin... | pkg/crypto/rangeproof/pedersen/pedersen.go | 0.727589 | 0.446495 | pedersen.go | starcoder |
package render
import (
goimage "image"
"image/color"
"math"
"photofield/internal/image"
"github.com/tdewolff/canvas"
"golang.org/x/image/draw"
"golang.org/x/image/math/f64"
)
func getRGBA(col color.Color) color.RGBA {
r, g, b, a := col.RGBA()
return color.RGBA{uint8(r >> 8), uint8(g >> 8), uint8(b >> 8), u... | internal/render/bitmap.go | 0.556641 | 0.40392 | bitmap.go | starcoder |
package hand
import (
"fmt"
"log"
"time"
"github.com/aamcrae/config"
"github.com/aamcrae/gpio"
"github.com/aamcrae/gpio/action"
)
// Configuration data for the clock hand, usually read from a configuration file.
type ClockConfig struct {
Name string // Name of the hand
Gpio []int // Out... | hand/config.go | 0.568536 | 0.460713 | config.go | starcoder |
package evaluator
import (
"time"
"github.com/sonirico/datetoken.go/models"
"github.com/sonirico/datetoken.go/ast"
"github.com/sonirico/datetoken.go/lexer"
"github.com/sonirico/datetoken.go/parser"
"github.com/sonirico/datetoken.go/token"
)
// Evaluator takes a token payload to eval. Handles lexing and parsin... | evaluator/evaluator.go | 0.711932 | 0.482551 | evaluator.go | starcoder |
package bites
import "unicode/utf8"
// Bites' purpose is to give byte slices some useful methods.
// The Get methods snip things off the front, and return the remainder of the slice.
// The Expect methods do a Get, and then compare it to the provided value.
// If there is not enough space for a Get, or if the Expect ... | get.go | 0.71403 | 0.480844 | get.go | starcoder |
package spoe
import (
"encoding/binary"
"fmt"
"net"
"unsafe"
"github.com/pkg/errors"
)
type dataType byte
const (
dataTypeNull dataType = 0
dataTypeBool dataType = 1
dataTypeInt32 dataType = 2
dataTypeUInt32 dataType = 3
dataTypeInt64 dataType = 4
dataTypeUInt64 dataType = 5
dataTypeIPV4 dataTyp... | encoding.go | 0.607081 | 0.497376 | encoding.go | starcoder |
package main
import (
"fmt"
"math"
)
type Point struct {
X, Y float64
}
// Declare an Abs method for the Point struct.
// Abs has a value receiver, which means that it operates
// on a copy of the original Point value
func (p Point) Abs() float64 {
return math.Sqrt(p.X*p.X + p.Y*p.Y)
}
// The Scale method has a... | go-code-examples/methods-interfaces/methods/methods.go | 0.727104 | 0.440168 | methods.go | starcoder |
package invasion
import (
"fmt"
"io/ioutil"
"log"
"math/rand"
"time"
"strings"
"errors"
"github.com/davecgh/go-spew/spew"
)
// City represents a City with Name and 4 possible roads to neighbour cities
// North, East, South, West is either nil or a string to neighbour cities
// Alien s... | src/invasion/invasion.go | 0.535341 | 0.430327 | invasion.go | starcoder |
package hraft
const peersInfoContent = `
As of Consul 0.7.0, the peers.json file is only used for recovery
after an outage. The format of this file depends on what the server has
configured for its Raft protocol version. Please see the agent configuration
page at https://www.consul.io/docs/agent/options.html#_raft_pro... | hashicorp-raft/hraft/peers-info.go | 0.609292 | 0.469946 | peers-info.go | starcoder |
package benchmarking
import (
"github.com/nathanhack/errorcorrectingcodes/linearblock/messagepassing/bec"
mat "github.com/nathanhack/sparsemat"
mat2 "gonum.org/v1/gonum/mat"
"math"
"math/rand"
)
//RandomMessage creates a random message of length len.
func RandomMessage(len int) mat.SparseVector {
message := mat... | benchmarking/randomdata.go | 0.675229 | 0.409723 | randomdata.go | starcoder |
package hraftd
import "reflect"
// DistributedApplier is the data applier with NodeID.
type DistributedApplier interface {
Distribute(NodeID NodeID, item Identifier)
}
// Identifier gives the ID getter.
type Identifier interface {
ID() string
}
// Distributor is the role to charge the distribution among the hraft... | distribute.go | 0.507568 | 0.42925 | distribute.go | starcoder |
package goraph
import (
"sort"
)
// Graph is implemented by all of the graph types. All of the graph
// algorithms use this data type instead of the concrete types.
type Graph interface {
// AddVertex creates an returns a new vertex in the graph.
AddVertex() Vertex
// RemoveVertex permanently removes a vertex fr... | graph.go | 0.86031 | 0.638849 | graph.go | starcoder |
package contact
import (
"math"
"github.com/hueypark/physics/core/body"
"github.com/hueypark/physics/core/math/rotator"
"github.com/hueypark/physics/core/math/vector"
"github.com/hueypark/physics/core/shape"
"github.com/hueypark/physics/core/shape/circle"
"github.com/hueypark/physics/core/shape/convex"
)
func... | core/contact/detect_collision.go | 0.738103 | 0.545649 | detect_collision.go | starcoder |
package iso20022
// Set of characteristics that apply to the the direct debit transaction(s).
type DirectDebitTransactionInformation2 struct {
// Set of elements to reference a payment instruction.
PaymentIdentification *PaymentIdentification2 `xml:"PmtId"`
// Set of elements used to further specify the type of t... | DirectDebitTransactionInformation2.go | 0.77343 | 0.647109 | DirectDebitTransactionInformation2.go | starcoder |
package binmani
const bitsPerByte int = 8
// Bit manipulation functions
// GetMask creates a bitmask of size shifted left index bits.
// GetMask(4, 1) -> 0b0000000000010000
// GetMask(2, 3) -> 0b0000000000011100
// GetMask(0, 8) -> 0b0000000011111111
// GetMask(3, 8) -> 0b0000011111111000
func GetMask(index, siz... | binmani.go | 0.703957 | 0.668143 | binmani.go | starcoder |
package gen
import (
"fmt"
"math/rand"
)
// CityStateZipGenerator generates a City state zip line in the form: City, ST 99999
func CityStateZipGenerator() string {
var state = StateNameGenerator()
return fmt.Sprintf("%s, %s %s", CityNameGenerator(), state, ZipcodeGenerator(state))
}
// CityStateZipGenerator2 gen... | gen/city_state_zip_names.go | 0.503174 | 0.42925 | city_state_zip_names.go | starcoder |
package shapes
import (
"math"
"sort"
"github.com/factorion/graytracer/pkg/primitives"
)
// MinMax Sort an array of floats and return the minimum and maximum values
func MinMax(values []float64) (float64, float64) {
sort.Float64s(values)
return values[0], values[len(values) - 1]
}
// CombineBounds Combine a sli... | pkg/shapes/bounds.go | 0.799677 | 0.545104 | bounds.go | starcoder |
package unicornify
import (
. "github.com/drbrain/go-unicornify/unicornify/core"
"math"
"sort"
)
type tv struct {
t float64
v float64
}
type tvSorter struct {
tvs []tv
}
func (s tvSorter) Len() int {
return len(s.tvs)
}
func (s tvSorter) Less(i, j int) bool {
return s.tvs[i].t < s.tvs[j].t
}
func (s tvSor... | unicornify/pose.go | 0.666062 | 0.448909 | pose.go | starcoder |
package rangesum
/*
* @lc app=leetcode id=304 lang=golang
*
* [304] Range Sum Query 2D - Immutable
*
* https://leetcode.com/problems/range-sum-query-2d-immutable/description/
*
* algorithms
* Medium (31.68%)
* Total Accepted: 68.7K
* Total Submissions: 213.6K
* Testcase Example: '["NumMatrix","sumRegion... | 304-rangesumquery/304.range-sum-query-2d-immutable.go | 0.9069 | 0.501648 | 304.range-sum-query-2d-immutable.go | starcoder |
package client
import (
"os"
"github.com/charmbracelet/lipgloss"
"golang.org/x/term"
)
const (
// In real life situations we'd adjust the document to fit the width we've
// detected. In the case of this example we're hardcoding the width, and
// later using the detected width only to truncate in order to avoid... | client/viewStyle.go | 0.588061 | 0.439627 | viewStyle.go | starcoder |
package internal
import (
"errors"
"fmt"
"math"
"reflect"
"sort"
"github.com/lyraproj/dgo/dgo"
"github.com/lyraproj/dgo/util"
)
type (
array struct {
slice []dgo.Value
frozen bool
}
// defaultArrayType is the unconstrained array type
defaultArrayType int
// sizedArrayType represents array with ele... | internal/array.go | 0.696991 | 0.57069 | array.go | starcoder |
package vector
import (
"math"
)
// Finds angle relative to the y-axis.
// Clockwise is positive and Counterclockwise is negative.
func Angle(v Vector2D) float64 {
x, y := Components(v)
rotation := math.Pi / 2
theta := math.Atan2(-y, x)
return -1*theta + rotation
}
// Finds standard angle
func A... | vector/vector.go | 0.801975 | 0.592637 | vector.go | starcoder |
package blockchain
import (
"bytes"
"crypto/sha256"
"log"
"math"
"math/big"
"github.com/neil-berg/blockchain/util"
)
// Difficulty is a static number here, but would be dynamically changing in
// reality to regulate block rates.
const Difficulty = 12
// ProofOfWork is the shape of a block's proof of work
type... | blockchain/proof.go | 0.719876 | 0.47025 | proof.go | starcoder |
package remotewrite
import (
"fmt"
"github.com/prometheus/prometheus/pkg/timestamp"
"github.com/prometheus/prometheus/prompb"
"go.k6.io/k6/stats"
)
// Note: k6 Registry is not used here since Output is getting
// samples only from k6 engine, hence we assume they are already vetted.
// metricsStorage is an in-me... | pkg/remotewrite/metrics.go | 0.82379 | 0.404478 | metrics.go | starcoder |
package bits
import (
"io"
)
type BitWriter interface {
// Write a single bit out to the byte stream.
// Args:
// is_one: 1 for writing a '1' else 0 for writing a '0'
// Return:
// error: Return an error if something failed to write
Write(is_one int) error
// BitWriter can only write at a byte level gran... | bits/bit_writer.go | 0.724188 | 0.431584 | bit_writer.go | starcoder |
package tests
import (
"bytes"
"reflect"
"testing"
)
func isZeroOfUnderlyingType(x interface{}) bool {
if x == nil {
return true
}
if _, ok := x.([]string); ok {
return true
}
return x == reflect.Zero(reflect.TypeOf(x)).Interface()
}
func objEq(expected, actual interface{}) bool {
if expected == nil ||... | tests/integration/v2/assert.go | 0.51879 | 0.632673 | assert.go | starcoder |
package datastore
import (
"bytes"
"encoding/binary"
"fmt"
"math"
"time"
"code.google.com/p/log4go"
"github.com/influxdb/influxdb/common"
)
const maxSeqNumber = (1 << 64) - 1
// storageKey is the key that we use to store values in our key/value
// store engine. The key contains the field id, timestamp and s... | datastore/storage_key.go | 0.757974 | 0.428771 | storage_key.go | starcoder |
package uid12
// Q: Why not use base32.StdEncoding?
// A: The uid12 encoder is more terse, as it can make assumptions
// about the size and shape of the value to encode. It also implements
// aliases like I and 1, and O and 0, at no extra cost.
// Benchmarks show ~2x improvement on encode and ~10x improvement... | base32.go | 0.642208 | 0.442817 | base32.go | starcoder |
package linear
import (
"bytes"
"errors"
"strconv"
)
// Heap represents a min heap backed backed by a slice
type Heap struct {
array []int
count int
}
// NewHeap returns a new empty heap
func NewHeap() *Heap {
heap := new(Heap)
heap.array = make([]int, 20)
heap.count = 0
return heap
}
func (H *Heap) String... | data/linear/heap.go | 0.668123 | 0.411111 | heap.go | starcoder |
package primitives
import (
"bytes"
"fmt"
)
type Sha256 []byte
func (x Sha256) String() string {
return fmt.Sprintf("%x", []byte(x))
}
func (x Sha256) Equal(y Sha256) bool {
return bytes.Equal(x, y)
}
func (x Sha256) KeyForMap() string {
return string(x)
}
type Keccak256 []byte
func (x Keccak256) String() s... | types/go/primitives/crypto.mb.go | 0.658088 | 0.483526 | crypto.mb.go | starcoder |
package scene
import (
"fmt"
"github.com/andrepxx/sydney/color"
"github.com/andrepxx/sydney/coordinates"
"image"
"math"
)
/*
* A scene is a plane onto which points are drawn.
*/
type Scene interface {
Aggregate(data []coordinates.Cartesian)
Clear()
Render(mapping color.Mapping) (*image.NRGBA, error)
Spread... | scene/scene.go | 0.690872 | 0.466056 | scene.go | starcoder |
package bitarray
import (
"math"
"math/bits"
)
type Bit = uint64
const (
Zero = Bit(iota)
One
)
// BitArray is an array data structure that compactly stores bits.
// Bits externally represented as `bool` are stored internally as `uint64`s.
// The total number of bits stored is set at creation and is immutable.
... | ba.go | 0.757525 | 0.518241 | ba.go | starcoder |
package misc
import (
"github.com/dreading/gospecfunc/integrals/internal/toms"
)
// Abramowitz computes the Abramowitz function
// ∫ 0 to ∞ of t^order exp( -t*t - x/t ) dt
func Abramowitz(order int, x float64) float64 {
switch order {
case 0:
return toms.ABRAM0(x)
case 1:
return toms.ABRAM1(x)
case 2:
... | integrals/integrals.go | 0.718496 | 0.700267 | integrals.go | starcoder |
package main
import (
"fmt"
"math"
"math/bits"
"sort"
"github.com/pointlander/datum/iris"
)
// RealLayer is a neural network layer
type RealLayer struct {
Columns int
Weights []float32
Biases []float32
Rand Rand
}
// RealNetwork is a neural network
type RealNetwork []RealLayer
// Inference performs i... | real.go | 0.545044 | 0.551876 | real.go | starcoder |
package hashsets
// New factory that creates a hash set
func New[T comparable](values ...T) *HashSet[T] {
set := HashSet[T]{data: make(map[T]struct{}, len(values))}
set.Add(values...)
return &set
}
// HashSet datastructure
type HashSet[T comparable] struct {
data map[T]struct{}
}
// Add adds values to the set
fu... | datastructures/sets/hashsets/hash_set.go | 0.804252 | 0.615059 | hash_set.go | starcoder |
package generator
import (
"math"
"math/rand"
"time"
"github.com/kwoodhouse93/audio-playground/source"
"github.com/kwoodhouse93/audio-playground/types"
"github.com/kwoodhouse93/audio-playground/utils"
)
// UniformNoiseM returns a mono uniform noise generator
func UniformNoiseM() source.Source {
r := rand.New(... | generator/generator.go | 0.898805 | 0.428413 | generator.go | starcoder |
package graph
import (
"sort"
"github.com/Tom-Johnston/mamba/ints"
"github.com/Tom-Johnston/mamba/sortints"
)
//NumberOfCycles returns a slice where the ith element contains the number of cycles of length i.
//Any cycle is contained in a biconnected component so the algorithm first splits the graph into biconnect... | graph/subgraph.go | 0.59843 | 0.615088 | subgraph.go | starcoder |
package sexpr
import (
"fmt"
"io/ioutil"
)
// ParseFile processes the given file and stores all the nodes it finds in
// the given AST instance. The parser uses the given syntax rule set to
// perform the parsing.
func ParseFile(ast *AST, file string, syntax *Syntax) (err error) {
fileindex, new := ast.addFile(fi... | parse.go | 0.615666 | 0.454593 | parse.go | starcoder |
package polynomial
import (
"log"
)
type Polynomial struct {
c []float64 // Coefficients : a + bx + cx^2 + dx^3 -> {a, b, c, d}
}
// Create New object of Polynomial
func NewPolynomial(c []float64) (p Polynomial) {
p.c = c
return
}
func (p Polynomial) Coefficients() []float64 {
return p.c
}
func (p Polynomial)... | polynomial/polynomial.go | 0.667039 | 0.678017 | polynomial.go | starcoder |
package data
// ConditionParams contains settings for one portion of a Run. A ConditionParams refers to a single ConditionParams, along with
// other information such as the number of times to run each instantiated Block. A single Block can be referenced by many RunBlocks.
type ConditionParams struct {
Nm ... | ch7/pvlv/data/condition_params.go | 0.704364 | 0.546073 | condition_params.go | starcoder |
package token
import (
"unicode"
"github.com/gnames/bayes"
gner "github.com/gnames/gner/ent/token"
"github.com/gnames/gnfinder/io/dict"
)
// tokenSN represents a word separated by spaces in a text. Words that are
// split by new lines are concatenated.
type tokenSN struct {
gner.TokenNER
// features is a coll... | ent/token/token.go | 0.753285 | 0.464841 | token.go | starcoder |
package stream
import "golang.org/x/exp/slices"
// SliceComparableStream Generics constraints based on comparable
type SliceComparableStream[E comparable] struct {
SliceStream[E]
}
// NewSliceByComparable new stream instance, generics constraints based on comparable
func NewSliceByComparable[E comparable](source [... | slice_comparable.go | 0.863837 | 0.408867 | slice_comparable.go | starcoder |
package holee
import (
"math"
"math/rand"
"time"
"github.com/konimarti/fixedincome/pkg/term"
)
// HoLee implements the Ho-Lee interest rate model
type HoLee struct {
// R0 is the initial rate (known today)
R0 float64
// Sigma is the standard deviation of the short term interest rate
Sigma float64
// T is th... | pkg/mc/model/holee/holee.go | 0.74382 | 0.639947 | holee.go | starcoder |
package continuous
import (
"github.com/jtejido/stats"
"github.com/jtejido/stats/err"
"math"
"math/rand"
)
// Pareto type-II
// At μ = 0, see https://en.wikipedia.org/wiki/Lomax_distribution
// https://reference.wolfram.com/language/ref/ParetoDistribution.html
type ParetoType2 struct {
xmin, shape, location floa... | dist/continuous/pareto_type_2.go | 0.785103 | 0.584923 | pareto_type_2.go | starcoder |
package proxyproto
import "encoding/binary"
// parseTLVs processes the Type-Length-Value bits for Proxy Protocol V2
// the buffer is expected to only include the TLV portion of the payload
// it can also be used to process the SSL sub-TLVs by passing that buffer
// into this function
func parseTLVs(buf []byte) map[TL... | parsetlvs.go | 0.608245 | 0.455986 | parsetlvs.go | starcoder |
package main
//@danielmatthewsgrout
//A very basic Self Organising Map implementation with limited parallelism
import (
"math"
"math/rand"
"sync"
)
//DistanceFunction a function to measure distance between 2 vectors of same len
type DistanceFunction func(a1, a2 []float64) float64
//InitFunction - the function u... | basicsom.go | 0.53437 | 0.526769 | basicsom.go | starcoder |
package models
// TableAdd defines the table to be added to an existing keyspace
type TableAdd struct {
Name string `validate:"required"`
// Attempting to create an existing table returns an error unless the IF NOT EXISTS option is used. If the option is
// used, the statement if a no-op is the table already exist... | rest/models/model_table_add.go | 0.804329 | 0.412353 | model_table_add.go | starcoder |
package objects
import (
"errors"
"io"
"math/rand"
)
// A simple two dimensional grid
type Grid struct {
Cells []bool
Width int
Height int
}
// Creates and returns a Grid of specified size
func MakeGrid(width int, height int) Grid {
g := Grid{
Cells: make([]bool, width*height),
Width: width,
Height:... | objects/grid.go | 0.812198 | 0.515742 | grid.go | starcoder |
package a2l
import (
"errors"
"strconv"
"github.com/rs/zerolog/log"
)
/*Description of rescaling the axis values of an adjustable object. A rescale axis consists
mainly of a number of rescaling axis points pairs (axis i , virtual i ) which describe a rescale
mapping between the axis points and a virtual axis that... | a2l/axis_rescale_x.go | 0.562417 | 0.787646 | axis_rescale_x.go | starcoder |
package world
import (
"errors"
"math"
)
const degreeToRad = math.Pi / 180
const radToDegree = 180 / math.Pi
type LatLonToGameFunc func(lat, lon float64) (x, y int)
type GameToLatLonFunc func(x, y int) (lat, lon float64)
// Creates functions for converting into and out of game pixels
func CreateConverters(metadat... | world/projection.go | 0.851058 | 0.543469 | projection.go | starcoder |
package frontend
type FieldType uint64
const (
FieldTypeBoolean FieldType = iota
FieldTypeInteger
FieldTypeString
FieldTypeFloat
FieldTypeNull
)
func (f FieldType) String() string {
switch f {
case FieldTypeBoolean:
return "boolean"
case FieldTypeInteger:
return "integer"
case FieldTypeString:
retur... | pkg/frontend/types.go | 0.837554 | 0.448426 | types.go | starcoder |
package placement
import (
"math"
"sort"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/tikv/pd/server/core"
)
// RegionFit is the result of fitting a region's peers to rule list.
// All peers are divided into corresponding rules according to the matching
// rules, and the remaining Peers are placed in the... | server/schedule/placement/fit.go | 0.814791 | 0.47792 | fit.go | starcoder |
package math
import (
"github.com/gopherjs/gopherjs/js"
)
var math = js.Global.Get("Math")
var zero float64 = 0
var posInf = 1 / zero
var negInf = -1 / zero
var nan = 0 / zero
func Acos(x float64) float64 {
return math.Call("acos", x).Float()
}
func Acosh(x float64) float64 {
return math.Call("acosh", x).Float(... | vendor/github.com/gopherjs/gopherjs/compiler/natives/src/math/math.go | 0.78403 | 0.649162 | math.go | starcoder |
package m32
import "math"
const (
E = float32(2.71828182845904523536028747135266249775724709369995957496696763) // https://oeis.org/A001113
Pi = float32(3.14159265358979323846264338327950288419716939937510582097494459) // https://oeis.org/A000796
Phi = float32(1.6180339887498948482045868343656381177203091798057... | m32/m32.go | 0.817429 | 0.584834 | m32.go | starcoder |
// Package skiplist is an implementation of a skiplist to store elements in increasing order. 递增排序
// It allows finding, insertion and deletion operations in approximately O(n log(n)).
// Additionally, there are methods for retrieving the next and previous element as well as changing the actual value
// without the ne... | MauriceGit_skiplist/skiplist.go | 0.682256 | 0.627124 | skiplist.go | starcoder |
package elliptic
import (
nativeelliptic "crypto/elliptic"
"encoding/hex"
"errors"
"fmt"
"math/big"
)
// Point represents a point on an EllipticCurve.
type Point struct {
X *big.Int
Y *big.Int
}
/* y**2 = x**3 + a*x + b % p */
// Curve represents the parameters of a short Weierstrass equation elliptic curve.... | pkg/crypto/elliptic/elliptic.go | 0.706494 | 0.504883 | elliptic.go | starcoder |
Component of Slice:
1. Pointer - The pointer is used to points to the first element of the array
that is accessible through the slice. Here, it is not necessary that the pointed
element is the first element of the array.
2. Length - The length is the total number of elements present in the array.
3. Capa... | day-13/Sanskriti/day13.go | 0.672439 | 0.733822 | day13.go | starcoder |
package sif
import (
"fmt"
"time"
)
// String will return a string corresponding to the Datatype.
func (d Datatype) String() string {
switch d {
case DataDeffile:
return "Def.FILE"
case DataEnvVar:
return "Env.Vars"
case DataLabels:
return "JSON.Labels"
case DataPartition:
return "FS"
case DataSignat... | pkg/sif/fmt.go | 0.598782 | 0.409693 | fmt.go | starcoder |
package canvas
import (
"strconv"
)
//Canvas Represents a canvas of pixels (colors) of size width X height
type Canvas struct {
Width, Height int
Pixels [][]*Color
}
//NewCanvas returns a new Canvas with given width and height
func NewCanvas(width, height int) *Canvas {
pixels := make([][]*Color, 0, 0)
f... | pkg/canvas/canvas.go | 0.86164 | 0.510435 | canvas.go | starcoder |
package board
import "errors"
// These two variables allow for conversion of each square status to
// the status string and vice-versa. This allows for statuses to be stored
// as integers for faster lookup and comparison.
var (
values = map[string]int{
"Empty": 0, "Miss": 1, "Destroyer": 2, "Submarine": 3,
"Cru... | pkg/board/board.go | 0.862656 | 0.575648 | board.go | starcoder |
package xrand
import (
"encoding/binary"
"fmt"
"math"
"math/bits"
"time"
)
// https://prng.di.unimi.it/xoroshiro1024plusplus.c
type Xoroshiro1024pp struct {
s [16]uint64
p int
}
func NewXoroshiro1024pp(seed int64) *Xoroshiro1024pp {
x := Xoroshiro1024pp{}
x.Seed(seed)
return &x
}
func (x Xoroshiro1024pp)... | xoroshiro1024pp.go | 0.547464 | 0.405302 | xoroshiro1024pp.go | starcoder |
package chart
import (
"math"
"sort"
)
// Return p percentil of pre-sorted integer data. 0 <= p <= 100.
func PercentilInt(data []int, p int) int {
n := len(data)
if n == 0 {
return 0
}
if n == 1 {
return data[0]
}
pos := float64(p) * float64(n+1) / 100
fpos := math.Floor(pos)
intPos := int(fpos)
dif :... | stat.go | 0.645232 | 0.561936 | stat.go | starcoder |
package main
import (
"fmt"
"flag"
"image/color"
"math"
"math/big"
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
"gonum.org/v1/plot/vg"
)
// // https://projecteuler.net/problem=25
func getDigitLengthBinet(n int) int {
// We use a reverse implementation of the Binet formula
... | Problem_25_Euler/main.go | 0.680135 | 0.528838 | main.go | starcoder |
package naive_bayesian
import "math"
var (
shape = map[string]int{"irregular": 1, "round": 2, "oval": 3}
color = map[string]int{"red": 1, "orange": 2, "green": 3}
grain = map[string]int{"noGrain": 1, "grain": 2}
weight = map[string]int{"0-200": 1, "200-500": 2, "500>1000": 3}
grip = map[string]int{"hard": 1... | pkg/naive_bayesian/naive_beyesian.go | 0.673406 | 0.50354 | naive_beyesian.go | starcoder |
package sip
import ()
/**
* This interface represents a unique IP network listening point,
* which consists of port and transport. A ListeningPoint is a Java
* representation of the port that a SipProvider messaging entity uses to send
* and receive messages.
* <p>
* For any address and port that a server liste... | sip/ListeningPoint.go | 0.886174 | 0.407392 | ListeningPoint.go | starcoder |
package cube
import (
"github.com/bahadrix/cardinalitycube/cube/pb"
"sync"
)
// Board is a table like data structure which consists of rows.
// It is of course thread safe.
type Board struct {
cube *Cube
rowMap map[string]*Row
rowLock sync.RWMutex
cellLock sync.Mutex
}
// A BoardSnapshot contains rows d... | cube/board.go | 0.696681 | 0.401923 | board.go | starcoder |
package sheetfile
import (
"fmt"
"github.com/fourstring/sheetfs/master/config"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"strings"
"text/template"
)
/*
Cell
Represent a cell of a sheet.
Every Cell is stored in a Chunk, starting at a fixed offset(see SheetFile),
and every Chunk contains multiple Cells. The number of ... | master/sheetfile/cell.go | 0.610453 | 0.55447 | cell.go | starcoder |
package common
import (
"fmt"
"log"
"math/rand"
"strconv"
"time"
)
//RngSeed sets the rand seed global variable using the randSeed and setSeed arguments
func RngSeed(randSeed bool, setSeed int64) {
if randSeed && setSeed != -1 {
log.Fatalf("Cannot use a set seed and also a random seed.")
}
if randSeed {
r... | common/math.go | 0.547706 | 0.447641 | math.go | starcoder |
package main
import (
"math/rand"
"os"
"github.com/nate-anderson/traffic-simulator"
)
/*
Simulate an intersection of two roads, each with two lanes passing each direction.
*/
// a traffic signal to alternate between north-south and east-west traffic
type alternatingTrafficSignal struct {
northSouth bool
}
func... | demos/fourway.go | 0.722821 | 0.482246 | fourway.go | starcoder |
package geometry
import (
"github.com/g3n/engine/gls"
"github.com/g3n/engine/math32"
"math"
)
// NewDisk creates a disk (filled circle) geometry with the specified
// radius and number of radial segments/triangles (minimum 3).
func NewDisk(radius float64, segments int) *Geometry {
return NewDiskSector(radius, se... | geometry/disk.go | 0.796728 | 0.575499 | disk.go | starcoder |
package d3
import (
"strconv"
"strings"
"github.com/adamcolton/geom/angle"
"github.com/adamcolton/geom/calc/cmpr"
"github.com/adamcolton/geom/geomerr"
)
// T is a 3D transform.
type T [4][4]float64
/*
| x | | a b c d |
| y | * | e f g h | = | ax+by+cz+d ex+fy+gz+h ix+jy+kz+l mx+ny+pz+q |
| z | | i j k l |... | d3/t.go | 0.625552 | 0.623635 | t.go | starcoder |
package main
import "fmt"
type point struct {
x, y float64
}
type circle struct {
x, y, r float64
}
type printer interface {
print()
}
func (p *point) print() {
fmt.Println(p.x, p.y)
}
func (c *circle) print() {
fmt.Println(c.x, c.y, c.r)
}
func main() {
var i printer // polymorphic variable
i ... | tasks/Polymorphism/polymorphism.go | 0.623606 | 0.407923 | polymorphism.go | starcoder |
package collections
import (
"github.com/freetaxii/libstix2/objects/bundle"
"github.com/freetaxii/libstix2/resources/manifest"
"github.com/freetaxii/libstix2/resources/properties"
)
// ----------------------------------------------------------------------
// Define Message Type
// --------------------------------... | resources/collections/collections.go | 0.625667 | 0.41834 | collections.go | starcoder |
package binary_tree
import "github.com/99_problems/go/src/data_structures"
type Comparable interface {
LessThan(value data_structures.Any) bool
GreaterThan(value data_structures.Any) bool
}
type Tree interface {
Add(any Comparable)
AddAll(any ...Comparable)
Remove(any Comparable) bool
Contains(any Comparable) ... | go/src/data_structures/binary_tree/binary_tree.go | 0.855369 | 0.470737 | binary_tree.go | starcoder |
package stack
import (
"eslang/core"
"fmt"
)
// StackValue interface Represents a value in the stack.
type StackValue interface {
Type() core.Type
Value() any
TestTruthy() (bool, error)
}
// Stack struct Represents a stack of elements.
type Stack struct {
// TODO: considering to use liked list instead ... | interpreter/stack/stack.go | 0.557123 | 0.503418 | stack.go | starcoder |
package txscript
import (
"sync"
"github.com/p9c/p9/pkg/chainhash"
"github.com/p9c/p9/pkg/ecc"
)
// sigCacheEntry represents an entry in the SigCache. Entries within the SigCache are keyed according to the sigHash of
// the signature. In the scenario of a cache-hit (according to the sigHash), an additional compa... | pkg/txscript/sigcache.go | 0.681939 | 0.460046 | sigcache.go | starcoder |
package interpreter
import (
"errors"
"fmt"
)
// A type that contains information about values in a given scope
type Environment map[string]Value
/**
* Simply determines if an S-Expression is one of the supported special forms by checking
* the name of the function/form to evaulate.
*/
func isSpecialForm(formNa... | src/interpreter/evaluator.go | 0.695545 | 0.496155 | evaluator.go | starcoder |
package argparse
import "github.com/skillian/errors"
// Namespace maps argument destination names with their values. Values
// are of the type the Argument's Type function converts them to (string, by
// default). If an argument's Nargs are >1, then the value is a slice of
// interface{} with the elements being the... | namespace.go | 0.678007 | 0.518241 | namespace.go | starcoder |
package taxi
// Data file contains sample data obtained from google big query.
// Dataset: bigquery-public-data.new_york.tlc_yellow_trips_2015.
// Development to be done using sample data before calling the big query api.
// Tests are also ran using this file.
// Data: sample for fare amount and pickup locations
// F... | taxi/data.go | 0.538741 | 0.523725 | data.go | starcoder |
package distuvx
import (
"golang.org/x/exp/rand"
"gonum.org/v1/gonum/stat/distuv"
)
// PERT represents a PERT distribution, which is a four parameter Beta
// distribution described by the parameters min, max, and mode, as well as the
// requirement that the mean = (max + 4 * mod + min) / 6.
// (https://en.wikiped... | pert.go | 0.89197 | 0.464902 | pert.go | starcoder |
package dsl
import "fmt"
var helpText = `keybite
A flexible, serverless key-value store
USAGE:
keybite (keybite will start in standalone server mode when started with no args)
keybite [command] [index] [options] [data]
FLAGS:
-h, --help
Display this help text.
QUERY COMMANDS:
- Auto-incrementing indexes (keybit... | dsl/help.go | 0.672439 | 0.444866 | help.go | starcoder |
package pnm
import (
"fmt"
"image"
"io"
"math"
"strings"
)
type PNMType int
// Known PNM file types.
const (
BitmapAscii PNMType = iota
BitmapBinary
GraymapAscii
GraymapBinary
PixmapAscii
PixmapBinary
)
// Encode writes the Image m to w in PPM format.
// The type of output file is determined by the given... | encode.go | 0.614047 | 0.464416 | encode.go | starcoder |
package crypto
import (
"crypto/cipher"
"fmt"
"github.com/turtledex/errors"
"github.com/turtledex/fastrand"
//lint:ignore SA1019 keeping for compatibility
"golang.org/x/crypto/twofish"
)
const (
// twofishOverhead is the number of bytes added by EncryptBytes.
twofishOverhead = 28
)
var (
// ErrInsufficien... | crypto/twofish.go | 0.743913 | 0.41739 | twofish.go | starcoder |
package vile
import (
"bytes"
)
// VectorEqual - return true of the two vectors are equal, i.e. the same length and
// all the elements are also equal
func VectorEqual(v1 *Object, v2 *Object) bool {
el1 := v1.elements
el2 := v2.elements
count := len(el1)
if count != len(el2) {
return false
}
for i := 0; i < ... | src/vector.go | 0.761095 | 0.529689 | vector.go | starcoder |
package nn
import (
"encoding/json"
"fmt"
"os"
tsr "../tensor"
)
// NeuralNetwork is a basic neural network that can handle multiple layer types.
type NeuralNetwork struct {
layers []Layer
}
// NewNeuralNetwork Creates a new instance of a NeuralNetwork.
func NewNeuralNetwork() *NeuralNetwork {
return &NeuralN... | nn/neuralNetwork.go | 0.827689 | 0.549641 | neuralNetwork.go | starcoder |
package partitioner
import "github.com/Shopify/sarama"
// Murmur2Partitioner is a matching implemention for the current (10.1) kafka partitioner. It will generate the same partition ID's a the default Kafka client and hence can be as a replacement with correct inter op
type Murmur2Partitioner struct {
random sarama.... | kafka/vendor/github.com/movio/go-kafka/partitioner/murmur2.go | 0.670824 | 0.445952 | murmur2.go | starcoder |
package render
import (
"github.com/emily33901/lambda-core/core/mesh"
"github.com/emily33901/lambda-core/core/mesh/util"
"github.com/go-gl/mathgl/mgl32"
)
type Composition struct {
Vertices []float32
Normals []float32
UVs []float32
Tangents []float32
Light... | render/compositor.go | 0.778228 | 0.41941 | compositor.go | starcoder |
package processor
import (
"context"
"fmt"
"github.com/benthosdev/benthos/v4/internal/bloblang/field"
"github.com/benthosdev/benthos/v4/internal/component/metrics"
"github.com/benthosdev/benthos/v4/internal/component/processor"
"github.com/benthosdev/benthos/v4/internal/docs"
"github.com/benthosdev/benthos/v4/... | internal/old/processor/group_by_value.go | 0.681303 | 0.446253 | group_by_value.go | starcoder |
package wallGenerator
import (
"fmt"
)
// LineSegment - segment of line
type LineSegment struct {
BeginPosition float64
EndPosition float64
Thk float64
}
// Line - array of position of X
type Line []LineSegment
// NewLine - create new line
func NewLine(lenght float64, thk float64) (line Line) {
l :... | wallGenerator/line.go | 0.54819 | 0.416144 | line.go | starcoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.