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 flags
// type ExistentialFlag provides a common interface for Who's On First -style "existential" flags where 1 represents true, 0 represents false and -1 represents unknown or to be determined.
type ExistentialFlag interface {
StringFlag() string
Flag() int64
// Return a boolean value indicating whether th... | flags.go | 0.805403 | 0.478529 | flags.go | starcoder |
package storetest
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
)
func TestTermsOfServiceStore(t *testing.T, ss store.Store) {
t.Run("TestSaveTermsOfService", ... | store/storetest/terms_of_service_store.go | 0.632616 | 0.411111 | terms_of_service_store.go | starcoder |
package value
import (
"math/big"
)
func sinh(c Context, v Value) Value {
return evalFloatFunc(c, v, floatSinh)
}
func cosh(c Context, v Value) Value {
return evalFloatFunc(c, v, floatCosh)
}
func tanh(c Context, v Value) Value {
return evalFloatFunc(c, v, floatTanh)
}
// floatSinh computes sinh(x) = (e**x - ... | value/sinh.go | 0.76145 | 0.460653 | sinh.go | starcoder |
package _8_String_to_Integer_atoi_
/*https://leetcode.com/problems/string-to-integer-atoi/
Implement atoi which converts a string to an integer.
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optio... | 8_String_to_Integer_atoi/solution.go | 0.892199 | 0.707758 | solution.go | starcoder |
package common
import (
"engo.io/engo"
"engo.io/engo/math"
"engo.io/gl"
)
const (
orth = "orthogonal"
iso = "isometric"
)
// Level is a parsed TMX level containing all layers and default Tiled attributes
type Level struct {
// Orientation is the parsed level orientation from the TMX XML, like orthogonal, isom... | common/level.go | 0.736211 | 0.562237 | level.go | starcoder |
package rgo
// dotProduct calculates the dot product of two vectors. It is used to make matrix multiplication easier.
func dotProduct(a, b []float64) (f float64, err error) {
if len(a) != len(b) {
return f, SizeMismatch
}
for i, av := range a {
f += av * b[i]
}
return f, nil
}
// MatrixMultiply performs a m... | matrixMath.go | 0.85344 | 0.658328 | matrixMath.go | starcoder |
package rules
import "github.com/butuzov/mirror/internal/checker"
func NewStringsChecker() *checker.Checker {
return checker.New("strings").
WithFunctions(StringFunctions).
WithStructMethods("strings.Builder", StringsBuilderMethods)
}
var (
StringFunctions = map[string]checker.Violation{
"Compare": {
Type... | internal/rules/strings.go | 0.674158 | 0.488588 | strings.go | starcoder |
package main
import (
"time"
)
// Calculates and returns the date on which the given holiday
// date is actually observed. In the US, if a designated
// holiday falls on a Saturday, then the preceding Friday is
// taken as the "observed" holiday - a non-working day.
// If the designated holiday falls on a Sunday, it... | definitions.go | 0.637144 | 0.652608 | definitions.go | starcoder |
package starlark
import (
"fmt"
"math"
"math/big"
"github.com/glycerine/monty/syntax"
)
// Int is the type of a Starlark int.
type Int struct{ bigint *big.Int }
// MakeInt returns a Starlark int for the specified signed integer.
func MakeInt(x int) Int { return MakeInt64(int64(x)) }
// MakeInt64 returns a Sta... | starlark/int.go | 0.703142 | 0.444444 | int.go | starcoder |
package resourcemanagers
import (
"github.com/determined-ai/determined/master/internal/sproto"
"github.com/determined-ai/determined/master/pkg/actor"
"github.com/determined-ai/determined/master/pkg/check"
cproto "github.com/determined-ai/determined/master/pkg/container"
"github.com/determined-ai/determined/master... | master/internal/resourcemanagers/agent.go | 0.710628 | 0.416975 | agent.go | starcoder |
package datachannel
import (
"fmt"
"io"
)
/*
* Type Defs
*/
type Data float64
type Dchan chan Data
type Filter func(Data) Data
//filterpipe: a struct matching a filter to a channel for the output.
type Filterpipe struct {
Filt Filter
Pipe Dchan
}
type FilterpipeI interface {
Read() Data
Write(Data)
Filt() F... | dataflow/datachannel/datachannel.go | 0.657428 | 0.439266 | datachannel.go | starcoder |
package opr
import (
"github.com/FactomProject/factom"
"github.com/pegnet/pegnet/common"
)
// EntryBlockSync has the current eblock synced to, and the target Eblock
// It also has the blocks in between in order. This makes it so traversing only needs to happen once
type EntryBlockSync struct {
ChainID str... | opr/entryblocksync.go | 0.52756 | 0.420064 | entryblocksync.go | starcoder |
package counts
import (
"fmt"
)
// Humanable is a quantity that can be made human-readable using
// `Humaner.Format()`.
type Humanable interface {
// ToUint64 returns the value as a uint64, and a boolean telling
// whether it overflowed.
ToUint64() (uint64, bool)
}
// Humaner is an object that can format a Human... | counts/human.go | 0.877345 | 0.475849 | human.go | starcoder |
package gedcom
import (
"fmt"
"io"
"strings"
)
// A Decoder reads and decodes GEDCOM objects from an input stream.
type Decoder struct {
r io.Reader
parsers []parser
refs map[string]interface{}
bufferSize int
}
// NewDecoder returns a new decoder that reads r.
func NewDecoder(r io.Reader) *D... | decoder.go | 0.584745 | 0.51013 | decoder.go | starcoder |
package parser
import . "github.com/jotaen/klog/src"
// Style describes the general styling and formatting preferences of a record.
type Style struct {
lineEnding string
lineEndingSet bool
indentation string
indentationSet bool
spacingInRange string // Example: `8:00 - 9:00` vs. `8:00-9:00`
spacingIn... | src/parser/style.go | 0.678966 | 0.431345 | style.go | starcoder |
package bag
import (
"github.com/danielvaughan/scrabtris/pkg/tile"
"math/rand"
"time"
)
//Bag holds tiles to randomly pick from.
type Bag struct {
tiles []tile.Tile
tilePicked chan tile.Tile
rng *rand.Rand
}
//tileCount specifies a number of tiles to add to a bag
type tileCount struct {
number int... | pkg/bag/bag.go | 0.689933 | 0.41401 | bag.go | starcoder |
package stdlib
import (
"fmt"
"time"
"github.com/vida-lang/vida/vida"
)
// Durations models Go's Duration type derived from int64
type Duration struct {
Value time.Duration
}
// Interface Value
func (d Duration) TypeName() string {
return "Duration"
}
func (d Duration) Description() string {
return fmt.Sprin... | stdlib/time.go | 0.79999 | 0.511595 | time.go | starcoder |
package immutable
import (
"fmt"
"github.com/m4gshm/gollections/c"
"github.com/m4gshm/gollections/it/impl/it"
"github.com/m4gshm/gollections/notsafe"
"github.com/m4gshm/gollections/op"
"github.com/m4gshm/gollections/slice"
)
//NewVector creates the Vector and copies elements to it.
func NewVector[T any](elemen... | immutable/vector.go | 0.818447 | 0.590573 | vector.go | starcoder |
package index
import (
"fmt"
"image"
"math/rand"
"sort"
"github.com/disintegration/imaging"
"github.com/timwu/mosaicer/storage"
"github.com/timwu/mosaicer/util"
)
type inMemoryIndex struct {
keyToID map[string]int
idToKey []string
multiple int
fuzziness int
// all the sample data, maps from aspect ... | index/in_memory.go | 0.604632 | 0.439507 | in_memory.go | starcoder |
package plaid
import (
"encoding/json"
)
// Total An object representing both the current pay period and year to date amount for a category.
type Total struct {
// Commonly used term to describe the line item.
CanonicalDescription NullableString `json:"canonical_description,omitempty"`
// Text of the line item a... | plaid/model_total.go | 0.783823 | 0.466177 | model_total.go | starcoder |
package platform
// Some of the code in the package and all of the inspiration for this comes from <https://github.com/containerd/containerd>.
// Their license is included here:
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file excep... | types/platform/platform.go | 0.714528 | 0.416085 | platform.go | starcoder |
package main
import (
"fmt"
"os"
"strconv"
"time"
)
/*
-- Sort.go --
The goal of this is to take a list of numbers in the terminal and sorts them from low to high. It does this using Selection Sort.
In essence what it's going to do is take an array of x numbers and with those x numbers it recursively ... | Selection Sort/sort.go | 0.522446 | 0.468912 | sort.go | starcoder |
package machine
import (
"fmt"
"math/rand"
"time"
)
const alphabetSize = 26
// Machine represents a xenigma encryption machine. Machine's components are
// electric pathways, reflector, plugboard, and rotors.
type Machine struct {
rotors *Rotors
plugboard *Plugboard
reflector *Reflector
}
// New creates an... | pkg/machine/machine.go | 0.801276 | 0.459986 | machine.go | starcoder |
package goop2
// LinearExpr represents a linear general expression of the form
// c0 * x0 + c1 * x1 + ... + cn * xn + k where ci are coefficients and xi are
// variables and k is a constant
type LinearExpr struct {
variables []uint64
coefficients []float64
constant float64
}
// NewLinearExpr returns a new e... | linear_expr.go | 0.864668 | 0.799677 | linear_expr.go | starcoder |
package nmeaais
import (
"math"
)
func asBool(b uint) bool {
return b == 1
}
func latlon(l int) float64 {
return float64(l) / 600000
}
func latlonShort(l int) float64 {
return float64(l) / 600
}
func rateOfTurn(rot int) float64 {
floatified := float64(rot)
if rot == 128 || rot == 127 || rot == -127 {
retur... | type_common.go | 0.658088 | 0.513607 | type_common.go | starcoder |
package codegen
import (
"llvm/bindings/go/llvm"
)
// Cast casts the value v to the type ty.
func (v *Value) Cast(ty Type) *Value {
srcTy, dstTy := v.Type(), ty
if srcTy == dstTy {
return v // No-op
}
if IsVector(srcTy) != IsVector(dstTy) {
fail("Cannot cast between vector and non-vector types. (%v -> %v)",... | core/codegen/cast.go | 0.642545 | 0.425486 | cast.go | starcoder |
package model
import (
"errors"
"github.com/sirupsen/logrus"
)
// Context is intended to handle two types of object and make them available to various parts of the suite including
// testcases. The first set are objects created as a result of the discovery phase, which capture discovery model
// information like e... | pkg/model/context.go | 0.698535 | 0.462655 | context.go | starcoder |
package datalist
import (
"math"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
func floatApproxEquals(a, b float64) bool {
return math.Abs(a-b) < 0.000001
}
func valueMatches(s *schema.Schema, value interface{}, filterValue string) bool {
switch s.Type {
case schema.TypeStri... | vendor/github.com/terraform-providers/terraform-provider-digitalocean/internal/datalist/values.go | 0.620162 | 0.417925 | values.go | starcoder |
package main
import (
"fmt"
"regexp"
"strconv"
"strings"
)
var sample = `
light red bags contain 1 bright white bag, 2 muted yellow bags.
dark orange bags contain 3 bright white bags, 4 muted yellow bags.
bright white bags contain 1 shiny gold bag.
muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
s... | aoc/2020/07/main/main.go | 0.537041 | 0.452838 | main.go | starcoder |
package battleship
import (
"bytes"
"errors"
"fmt"
"strconv"
"strings"
)
/*
Since it was not specifically mentioned in the problem as to how the coordinate system of the
board works. Hence, we are assuming that (0,0) lies in the top left corner and (m,m) in bottom right
Final depiction of the board looks as foll... | game.go | 0.678966 | 0.487124 | game.go | starcoder |
package containers
import (
"golang.org/x/exp/slices"
)
type Slice[T any] struct {
d []T
}
func NewSlice[T any](v ...T) *Slice[T] {
return &Slice[T]{d: v}
}
func (p *Slice[T]) Reset() {
p.d = []T{}
}
func (p *Slice[T]) Append(v T) *Slice[T] {
p.d = append(p.d, v)
return p
}
func (p *Slice[T]) Prepend(v T) *... | slice.go | 0.644225 | 0.534552 | slice.go | starcoder |
package svg
import (
"github.com/goki/ki/ki"
"github.com/goki/ki/kit"
"github.com/goki/mat32"
)
// Polyline is a SVG multi-line shape
type Polyline struct {
NodeBase
Points []mat32.Vec2 `xml:"points" desc:"the coordinates to draw -- does a moveto on the first, then lineto for all the rest"`
}
var KiT_Polyline ... | svg/polyline.go | 0.588889 | 0.465327 | polyline.go | starcoder |
package exec
import (
"encoding/binary"
"fmt"
"math"
"os"
)
var ErrLimitExceeded = fmt.Errorf("memory limit exceeded")
// Memory is a WASM linear memory.
type Memory struct {
min, max uint32
bytes []byte
}
// NewMemory creates a new linear memory with the given limits.
func NewMemory(min, max uint32) Memo... | exec/memory_trace.go | 0.85747 | 0.431105 | memory_trace.go | starcoder |
package gpxgo
import (
"math"
)
const (
// One degree in meters:
ONE_DEGREE = 1000. * 10000.8 / 90.
EARTH_RADIUS = 6371 * 1000
)
type LocationDelta struct {
Distance float64
Angle float64
}
type Location struct {
Latitude float64
Longitude float64
Elevation float64
}
/*==============================... | geo.go | 0.778018 | 0.581392 | geo.go | starcoder |
package main
import (
"math"
"math/rand"
"time"
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"
)
/*
It is not easy, to create this file to follow only one function set.
Let's say: tank.moveForward(angle float64) -> this seems to be taking the tank pointer, and change it's angle.
But in my case, ... | old/tank.go | 0.63409 | 0.497925 | tank.go | starcoder |
package instrument
// OPL2OperatorData is the operator data for an OPL2/Adlib instrument
type OPL2OperatorData struct {
// KeyScaleRateSelect returns true if the modulator's envelope scales with keys
// If enabled, the envelopes of higher notes are played more quickly than those of lower notes.
KeyScaleRateSelect b... | internal/song/instrument/instrument_opl2.go | 0.775095 | 0.686038 | instrument_opl2.go | starcoder |
package billdsv
import (
"bytes"
"io"
"github.com/pkg/errors"
)
// Reader implements a DSV reader that reads the pipe separated values
// that Bill outputs.
type Reader struct {
Separator byte
SkipHeading bool
BufferSize int
r io.Reader
fields int
rdBuffer []byte
wrBuffer []byte
rowBuffer... | reader.go | 0.680666 | 0.50116 | reader.go | starcoder |
package integration
import (
"net"
"testing"
. "github.com/onsi/gomega"
"github.com/dnsdb/go-dnsdb/pkg/dnsdb"
)
func SummarizeRRSet(t *testing.T, c dnsdb.SummarizeClient) {
name := "farsightsecurity.com."
qf := func() dnsdb.Query { return c.SummarizeRRSet(name) }
bailiwick := "com."
rrtype := "NS"
t.Run(... | test/integration/summarize.go | 0.502441 | 0.406803 | summarize.go | starcoder |
package vincenty
import "math"
//https://en.wikipedia.org/wiki/Vincenty%27s_formulae
// Fins the ellipsoidal distance between two coordinates.
func InverseProblem(latitude1, longitude1, latitude2, longitude2 float64) (float64, float64, float64) {
f := 1.0 / 298.257223563
a := 6378137.0
b := (1.0 - f) * a
phi1 :... | vincenty.go | 0.804291 | 0.654784 | vincenty.go | starcoder |
package edges
func (d *Detector) applyVerticalISEF(A, B [][]float32) {
var b1 float32 = (1.0 - d.smoothingFactor) / (1.0 + d.smoothingFactor)
b2 := d.smoothingFactor * b1
x := d.buffer
y := d.smoothed
rect := d.workRect
// compute boundary conditions
for col := rect.Min.X; col < rect.Max.X; col++ {
// bounda... | smoothing.go | 0.63023 | 0.4881 | smoothing.go | starcoder |
package executor
import (
"github.com/RoaringBitmap/roaring"
"meerkat/internal/storage"
)
// NewBinaryBitmapOperator creates a new bitmap binary operator.
func NewIndexScanOperator(ctx Context, op ComparisonOperation, value interface{}, fieldName string) BitmapOperator {
return &IndexScanOperator{
ctx: ctx,
... | internal/executor/index_scan_operator.go | 0.745861 | 0.598518 | index_scan_operator.go | starcoder |
package govert
import (
"errors"
"reflect"
"strconv"
"strings"
"encoding/json"
)
var errInvalidOutputType = errors.New("output data type is not i simple type")
func getElemKind(i interface{}) reflect.Kind {
return reflect.TypeOf(i).Elem().Kind()
}
// This converts it's first parameter's value to type of it's ... | main.go | 0.517327 | 0.420659 | main.go | starcoder |
package storage
import (
"math"
"github.com/daniel-dsouza/hexago/coordinate"
)
// GeoStorage is a wrapper to add points based on lat/lon
type GeoStorage struct {
lat float64
lon float64
a11, a12, a21, a22 float64 // hex -> cartesian offset
b11, b12, b21, b22 float64 // cartesian o... | storage/geostorage.go | 0.745861 | 0.500122 | geostorage.go | starcoder |
package check
import (
"fmt"
"time"
)
// Time is the type of a check function which takes an time.Time
// parameter and returns an error or nil if the check passes
type Time func(d time.Time) error
// TimeEQ returns a function that will check that the time is equal to the
// value of the t parameter
func TimeEQ(t ... | check/time.go | 0.707304 | 0.644938 | time.go | starcoder |
package discrete
import (
"math"
"github.com/kzahedi/goent/sm"
)
// Empirical1D is an empirical estimator for a one-dimensional
// probability distribution
func Empirical1D(d []int) []float64 {
max := 0
for _, v := range d {
if v > max {
max = v
}
}
max++
p := make([]float64, max, max)
for _, v := ... | discrete/ProbabilityEstimator.go | 0.745584 | 0.500427 | ProbabilityEstimator.go | starcoder |
package redis_rate
import (
"fmt"
"time"
"github.com/go-redis/redis/v7"
"golang.org/x/time/rate"
)
const redisPrefix = "rate"
type rediser interface {
Del(...string) *redis.IntCmd
Pipelined(func(pipe redis.Pipeliner) error) ([]redis.Cmder, error)
}
// Limiter controls how frequently events are allowed to hap... | vendor/github.com/go-redis/redis_rate/v7/rate.go | 0.803559 | 0.408749 | rate.go | starcoder |
package ltparse
import (
"fmt"
"io"
"text/template"
"github.com/pkg/errors"
"github.com/mattermost/mattermost-load-test/loadtest"
)
var (
funcMap = template.FuncMap{
"percent": func(x float64) string {
return fmt.Sprintf("%.2f%%", float64(x)*100.0)
},
"compareInt64": func(a, b int64) string {
delt... | ltparse/markdown.go | 0.747432 | 0.473901 | markdown.go | starcoder |
package schema
import (
"cloud.google.com/go/bigquery"
"github.com/m-lab/go/cloud/bqx"
"time"
)
// Sample is an individual measurement taken by DISCO.
// NOTE: the types of the fields in this struct differ from the types used
// natively by the structs in DISCOv2. In DiSCOv2 Value is a uint64, but must
// be a f... | schema/switch_schema.go | 0.691497 | 0.411643 | switch_schema.go | starcoder |
package main
import (
"strconv"
"github.com/TomasCruz/projecteuler"
)
/*
Problem 32; Pandigital products
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once;
for example, the 5-digit number, 15234, is 1 through 5 pandigital.
The product 7254 is unusual, as the ... | 001-100/031-040/032/main.go | 0.608245 | 0.563918 | main.go | starcoder |
package cast
import (
"errors"
"fmt"
"strconv"
)
// ErrUintBelowZero defines the error returned when attempting to cast a
// negative value as a uint.
var ErrUintBelowZero = errors.New("cannot cast negative value as uint")
// ToUint casts an interface to a uint type, discarding any errors.
func ToUint(i interface... | uint.go | 0.692122 | 0.439266 | uint.go | starcoder |
package p488
/**
Think about Zuma Game. You have a row of balls on the table, colored red(R), yellow(Y), blue(B), green(G), and white(W). You also have several balls in your hand.
Each time, you may choose a ball in your hand, and insert it into the row (including the leftmost place and rightmost place). Then, if the... | algorithms/p488/488.go | 0.76533 | 0.691849 | 488.go | starcoder |
package graph
import (
"bytes"
"errors"
"fmt"
"io"
"strconv"
)
// Digraph is a directed graph implementation using an adjacency list
type Digraph struct {
v int
e *int
adj [][]int
}
// NewDigraph returns a digraph with v vertices, all disconnected
func NewDigraph(v int) Digraph {
return Digraph{
v: ... | digraph.go | 0.840095 | 0.436202 | digraph.go | starcoder |
package bloom
import (
"github.com/spaolacci/murmur3"
"math"
)
type BloomFilter struct {
numOfHashFunctions int
bitArray *BitArray
}
/**
Create new BloomFilter with approximate unique keys insertion count and tolerated false positive probability
*/
func New(insertionCount uint64, falsePositiveProbabili... | bloom/bloomfilter.go | 0.744935 | 0.482856 | bloomfilter.go | starcoder |
package gost3410
import (
"errors"
"math/big"
"github.com/bi-zone/ruwireguard-go/crypto/gost/gost34112012256"
"github.com/bi-zone/ruwireguard-go/crypto/gost/gost34112012512"
)
var (
zero *big.Int = big.NewInt(0)
bigInt1 *big.Int = big.NewInt(1)
bigInt2 *big.Int = big.NewInt(2)
bigInt3 *big.Int = big.NewI... | crypto/gost/gost3410/curve.go | 0.642545 | 0.490968 | curve.go | starcoder |
package dna
// compareBases returns an integer related to the lexographical order of nucleotides.
// i.e. A < C < a < c < Dot < Gap
func compareBases(alpha Base, beta Base, ignoreCase bool) int {
if ignoreCase {
alpha = ToUpper(alpha)
beta = ToUpper(beta)
}
if alpha < beta {
return -1
} else if alpha > beta ... | dna/compare.go | 0.7865 | 0.599837 | compare.go | starcoder |
package align
import (
"fmt"
"github.com/vertgenlab/gonomics/dna"
"github.com/vertgenlab/gonomics/fasta"
"log"
)
// the trace data structure is a 3d slice where the first index is 0,1,2 and represents the match, gap in x (first seq), and gap in y (second seq).
// m used to have the same data structure as trace, b... | align/affineGap.go | 0.530236 | 0.470615 | affineGap.go | starcoder |
package build
// Join joins g1 to g2 by adding edges from vertices in g1 to
// vertices in g2. Only the edges in the bridge are added.
// The vertices of g2 are renumbered before the operation:
// vertex v ∊ g2 becomes v + g1.Order() in the new graph.
func (g1 *Virtual) Join(g2 *Virtual, bridge EdgeSet) *Virtual {
n ... | build/join.go | 0.663342 | 0.470676 | join.go | starcoder |
package gomosaic
import (
"fmt"
"io"
"strconv"
"strings"
log "github.com/sirupsen/logrus"
)
const (
// Debug is true if code should be compiled in debug mode, printing
// more stuff and performing checks.
Debug = true
// Version is the version of gomosaic.
Version = "1.1"
)
var (
// BufferSize is the (... | utils.go | 0.631481 | 0.438124 | utils.go | starcoder |
package search
import (
"github.com/jtejido/golucene/core/index"
"github.com/jtejido/golucene/core/util"
)
// search/similarities/Similarity.java
/*
Similarity defines the components of Lucene scoring.
Expert: Scoring API.
This is a low-level API, you should only extend this API if you want
to implement an infor... | core/search/similarity.go | 0.767341 | 0.5794 | similarity.go | starcoder |
package dataset
import (
"math"
"math/rand"
"time"
)
func MakeDoubleArray(rows, cols int) [][]float64 {
data := make([][]float64, rows)
for i := 0; i < rows; i++ {
data[i] = make([]float64, cols)
}
return data
}
func ShuffleArray(data []float64) []float64 {
rows := len(data)
newData := make([]float64, ro... | ml/dataset/util.go | 0.507568 | 0.640608 | util.go | starcoder |
package metric
import (
"errors"
"math"
"time"
)
type MetricCalculator struct {
portfolio, bench []float64
dates []time.Time
vectorCache map[string][]float64
scalarCache map[string]float64
period float64
}
func NewMetricCalculator(portfolio, bench []float64, dates []time.Time) ... | metric/interface.go | 0.73431 | 0.440469 | interface.go | starcoder |
// Note that I do these exercises to LEARN Go; don't judge.
package main
/*
The exercise:
It is well known that if the square root of a natural number is not an integer, then it is irrational. The decimal expansion of such square roots is infinite without any repeating pattern at all.
The square root of two is 1.4... | 80/main.go | 0.634204 | 0.707758 | main.go | starcoder |
package number
import (
"fmt"
"math"
"regexp"
"strconv"
"strings"
)
// arithmetic operator
// +, -(u), -(b), *, /, //(IDIV), %, ^
// 除法和乘方运算先转换为 floating point,再进行运算,计算结果也是 floating point
// 其他先判断操作数是否都为整数,如果是,进行整数运算;否则,转换为 floating point
// 乘方运算为右结合,比如 4^3^2 == 4^(3^2)
// IFloorDiv is integer floor division
f... | number/math.go | 0.512937 | 0.431285 | math.go | starcoder |
package polyhedra
import (
"fmt"
"github.com/MichaelMauderer/polyhedra/r3"
)
// Vertex represents a point within a Polyhedron where edges meet.
type Vertex uint
// vertexID is the global id counter that is used to generate unique ids fo vertices.
var vertexID Vertex
// vertexPositions contains the position for ea... | polyhedra/vertices.go | 0.854171 | 0.659679 | vertices.go | starcoder |
package entity
import (
"github.com/galaco/kero/framework/graphics"
"github.com/galaco/kero/framework/graphics/mesh"
"github.com/galaco/source-tools-common/entity"
"github.com/go-gl/mathgl/mgl32"
)
// IEntity
type IEntity interface {
// Classname is the entity type
Classname() string
// Targetname is the name.... | framework/entity/entity.go | 0.821975 | 0.41484 | entity.go | starcoder |
package mandel
import (
"image"
"image/color"
"math"
"sync"
"github.com/karlek/vanilj/fractal"
"github.com/lucasb-eyer/go-colorful"
)
func Smooth(f *fractal.Fractal) {
h := float64(f.Src.Bounds().Size().Y)
wg := new(sync.WaitGroup)
// For each row.
for y := 0.0; y < h; y++ {
wg.Add(1)
go func(f *fract... | fractal/mandel/draw.go | 0.723114 | 0.427098 | draw.go | starcoder |
package js
// Object is a container for a native JavaScript object. Calls to its methods are treated specially by GopherJS and translated directly to their JavaScript syntax.
type Object interface {
// Get returns the object's property with the given name.
Get(name string) Object
// Set assigns the value to the o... | gopherjs/js/js.go | 0.833731 | 0.443058 | js.go | starcoder |
package config
import (
"math"
"math/rand"
)
type CPU struct {
MaxExecStackSize int `usage:"the maximum size of the exec stack. If set to 0, will be set to critterSize"`
MaxStepsPerInput float64 `usage:"governs how many steps per each input item each individual can run. For example, for an input of length 5 a... | pkg/config/conf.go | 0.852537 | 0.639525 | conf.go | starcoder |
package curve1174
import (
"fmt"
"math/big"
)
//P is order of F_p, 2^251-9
var P, _ = new(big.Int).SetString("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7", 16)
//Base is base point of curve in affine coordinates (Base.Z == 1)
var Base = &Point{
X: FieldElement{0x16123f27bce29eda, 0xc021d96a492... | curve1174.go | 0.619471 | 0.457197 | curve1174.go | starcoder |
package scc
import (
"sort"
)
// Edge is a directed one, which represents T -> H.
type Edge struct {
T int
H int
}
// SCC computes strongly connected components and returns sizes of the SCCs in decreasing order.
func SCC(edges []Edge) []int {
leaderMap := SCC2(edges)
sccs := make(map[int]int)
for _, v := range... | scc/scc.go | 0.74872 | 0.410402 | scc.go | starcoder |
package mvt
import (
"fmt"
vt "github.com/buckhx/diglet/mbt/mvt/vector_tile"
"github.com/buckhx/diglet/util"
)
type Shape struct {
points []Point
curType CursorType
geomType vt.Tile_GeomType
}
func NewShape(geomType vt.Tile_GeomType, points ...Point) *Shape {
return &Shape{points: points, curType: AbsCur}... | mbt/mvt/shape.go | 0.62601 | 0.55929 | shape.go | starcoder |
package nntbs
import (
"strconv"
flatbuffers "github.com/google/flatbuffers/go"
)
type NumericValueT struct {
Type NumericValue
Value interface{}
}
func NumericValuePack(builder *flatbuffers.Builder, t *NumericValueT) flatbuffers.UOffsetT {
if t == nil {
return 0
}
switch t.Type {
case NumericValueIntVa... | vendor/github.com/circonus-labs/gosnowth/fb/nntbs/nntbs_generated.go | 0.573678 | 0.436142 | nntbs_generated.go | starcoder |
package money
type currency struct {
alphaCode string
numericCode string
decimalDigits int
}
func (c currency) AlphaCode() string {
return c.alphaCode
}
func (c currency) NumericCode() string {
return c.numericCode
}
func (c currency) DecimalDigits() int {
return c.decimalDigits
}
func (c currency) Str... | money/currency.go | 0.742422 | 0.551151 | currency.go | starcoder |
package plural
import (
"fmt"
"math"
"strconv"
"golang.org/x/text/language"
)
func mod(x, y float64) float64 {
return math.Mod(x, y)
}
func float(v interface{}) float64 {
switch v.(type) {
case int:
return float64(v.(int))
case int64:
return float64(v.(int64))
case float64:
return v.(float64)
ca... | plural/func.go | 0.705582 | 0.447943 | func.go | starcoder |
package skiplists
import "math/rand"
const (
maxLevel int = 16 // Should be enough for 2^16 elements
p float32 = 0.25
)
// Element is an Element of a skiplist.
type Node struct {
Score float64
Value interface{}
forward []*Node
}
func newElement(score float64, value interface{}, level int) *Nod... | skiplists/SkipLists.go | 0.68595 | 0.446676 | SkipLists.go | starcoder |
package ads126x
//Opcodes - Commands are used to access the configuration and data registers and also to control the ADC. Many of the ADC commands are stand-alone (that is, single-byte). The register write and register read commands, however, are multibyte, consisting of two opcode bytes plus the register data byte or... | ads126x/constants.go | 0.570212 | 0.644085 | constants.go | starcoder |
package encoder
import (
"errors"
)
type boundingBox struct {
MaxLatitude float64
MinLatitude float64
MaxLongitude float64
MinLongitude float64
}
func EncodeWithPrecision(lat, lng float64, precision int) (hash uint64, err error) {
bounds := boundingBox{MaxLatitude: 90, MaxLongitude: 180, MinLatitude: -90, Mi... | encoder/encoder.go | 0.742982 | 0.534612 | encoder.go | starcoder |
package graph
type Node struct {
Key int
Left *Node
Right *Node
}
func Breadth(n *Node) []int {
var result []int
visit := []*Node{n}
for len(visit) > 0 {
currentNode := visit[0]
result = append(result, currentNode.Key)
visit = visit[1:]
if currentNode.Left != nil {
visit = append(visit, currentNod... | graph/binaryTrees.go | 0.531696 | 0.487734 | binaryTrees.go | starcoder |
The z80 package implements a Zilog Z80 emulator.
*/
package z80
import (
_ "fmt"
)
// The flags
const FLAG_C = 0x01
const FLAG_N = 0x02
const FLAG_P = 0x04
const FLAG_V = FLAG_P
const FLAG_3 = 0x08
const FLAG_H = 0x10
const FLAG_5 = 0x20
const FLAG_Z = 0x40
const FLAG_S = 0x80
var (
OpcodesMap [1536]func(z80 *Z... | z80.go | 0.559531 | 0.406567 | z80.go | starcoder |
// Package takuzu provides functions to solve, build or validate takuzu
// puzzles.
package takuzu
import (
"bytes"
"fmt"
"math"
"github.com/pkg/errors"
)
// Cell is a single cell of a Takuzu game board
type Cell struct {
Defined bool
Value int
}
// Takuzu is a Takuzu game board (Size x Size)
type Takuzu s... | takuzu.go | 0.673729 | 0.462048 | takuzu.go | starcoder |
package types
import (
"bytes"
"errors"
"fmt"
"math"
"regexp"
"strconv"
"strings"
"github.com/attic-labs/noms/go/d"
"github.com/attic-labs/noms/go/hash"
)
var annotationRe = regexp.MustCompile("^@([a-z]+)")
// A Path is an address to a Noms value - and unlike hashes (i.e. #abcd...) they can address inline... | go/types/path.go | 0.794505 | 0.417331 | path.go | starcoder |
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"strings"
)
type Point struct {
X int
Y int
}
type Line struct {
A Point
B Point
Meta string
}
func (p Point) Name() string {
return strconv.Itoa(p.X) + ":" + strconv.Itoa(p.Y)
}
func (l Line) IsHorizontal() bool {
return l.A.Y == l.B.Y
}
... | 2019/go/09.1 Sensor Boost/aoc_common.go | 0.549882 | 0.408454 | aoc_common.go | starcoder |
package output
import (
"github.com/Jeffail/benthos/v3/internal/docs"
"github.com/Jeffail/benthos/v3/lib/log"
"github.com/Jeffail/benthos/v3/lib/message/roundtrip"
"github.com/Jeffail/benthos/v3/lib/metrics"
"github.com/Jeffail/benthos/v3/lib/types"
)
//-----------------------------------------------------------... | lib/output/sync_response.go | 0.599485 | 0.65486 | sync_response.go | starcoder |
package goji
import (
"fmt"
"math/rand"
"sort"
"strings"
)
// Min returns the smaller of x or y.
func Min(x, y int) int {
if x < y {
return x
}
return y
}
// Max returns the larger of x or y.
func Max(x, y int) int {
if x > y {
return x
}
return y
}
// Range creates a range of numbers progressing from... | goji.go | 0.852997 | 0.566558 | goji.go | starcoder |
package pixelpusher
// Functions for sorting, clamping, finding minimum and maximum etc.
// The default type for these functions is int32.
// Functions that deals with bytes instead are postfixed with "Byte".
// Functions that deals with ints should go elsewhere.
// Functions that deals with floats should go elsewhere... | maths.go | 0.794505 | 0.600276 | maths.go | starcoder |
package backendbase
import (
"image"
"image/color"
"math"
)
// Backend is used by the canvas to actually do the final
// drawing. This enables the backend to be implemented by
// various methods (OpenGL, but also other APIs or software)
type Backend interface {
Size() (int, int)
LoadImage(img image.Image) (Imag... | backend/backendbase/base.go | 0.681939 | 0.440168 | base.go | starcoder |
package gohorizon
import (
"encoding/json"
)
// DesktopPoolProvisioningStatusData Provisioning status data about this automated desktop pool.
type DesktopPoolProvisioningStatusData struct {
// Applicable To: instant clone automated desktop pools.<br>This represents the state of the current image of this instant cl... | model_desktop_pool_provisioning_status_data.go | 0.657209 | 0.489748 | model_desktop_pool_provisioning_status_data.go | starcoder |
package onshape
import (
"encoding/json"
)
// BTPExpressionVarReference245 struct for BTPExpressionVarReference245
type BTPExpressionVarReference245 struct {
BTPExpression9
BtType *string `json:"btType,omitempty"`
Name *BTPName261 `json:"name,omitempty"`
}
// NewBTPExpressionVarReference245 instantiates a new BT... | onshape/model_btp_expression_var_reference_245.go | 0.662906 | 0.488893 | model_btp_expression_var_reference_245.go | starcoder |
package iso20022
// Provides information about the rates related to securities movement.
type RateDetails2 struct {
// Rate used for additional tax that cannot be categorised.
AdditionalTax *RateAndAmountFormat5Choice `xml:"AddtlTax,omitempty"`
// Rate used to calculate the amount of the charges/fees that cannot ... | RateDetails2.go | 0.845496 | 0.610395 | RateDetails2.go | starcoder |
package iso20022
// Information about a securities account and its characteristics.
type InvestmentAccount51 struct {
// Name of the account. It provides an additional means of identification, and is designated by the account servicer in agreement with the account owner.
Name *Max35Text `xml:"Nm,omitempty"`
// Su... | InvestmentAccount51.go | 0.773901 | 0.47171 | InvestmentAccount51.go | starcoder |
package astits
import (
"fmt"
"github.com/asticode/go-astikit"
)
// PIDs
const (
PIDPAT = 0x0 // Program Association Table (PAT) contains a directory listing of all Program Map Tables.
PIDCAT = 0x1 // Conditional Access Table (CAT) contains a directory listing of all ITU-T Rec. H.222 entitlement manageme... | data.go | 0.561455 | 0.410993 | data.go | starcoder |
package widgets
import (
"strconv"
"github.com/gdamore/tcell/v2"
)
var (
columnStyle = tcell.StyleDefault.Background(tcell.ColorBlack).Bold(true)
rowCountStyle = tcell.StyleDefault.Foreground(tcell.ColorSlateGray).Background(tcell.ColorBlack)
primaryKeyStyle = tcell.StyleDefault.Foreground(tcell.ColorAqu... | pkg/widgets/data_table.go | 0.577734 | 0.543772 | data_table.go | starcoder |
package rbtree
import (
"bytes"
"fmt"
"math"
"strconv"
)
type color bool
func (c color) String() string {
if c == black {
return "black"
}
return "red"
}
const black color = false
const red color = true
// A red-black tree has the following properties:
// Property 1: every node is red or black
// Property... | rbtree.go | 0.772788 | 0.442396 | rbtree.go | starcoder |
package kdtree
import (
"container/heap"
"github.com/hongshibao/go-algo"
)
type Point interface {
// Return the total number of dimensions
Dim() int
// Return the value X_{dim}, dim is started from 0
GetValue(dim int) float64
// Return the distance between two points
Distance(p Point) float64
// Return the ... | kdtree.go | 0.756717 | 0.483161 | kdtree.go | starcoder |
package main
import (
. "github.com/mmcloughlin/avo/build"
. "github.com/mmcloughlin/avo/operand"
. "github.com/mmcloughlin/avo/reg"
)
func AVX() {
// Lay out the prime constant in memory, copy it so no unpack is needed.
primeData := GLOBL("prime_avx", RODATA|NOPTR)
for i := 0; i < 32; i += 8 {
DATA(i, U32(26... | avo/avx.go | 0.501465 | 0.400661 | avx.go | starcoder |
package geometry
import (
"math"
"github.com/go-gl/mathgl/mgl32"
)
type LineSegment struct {
start mgl32.Vec2
end mgl32.Vec2
}
// Returns the % multiplier to intersect both vectors. Vectors do NOT need to be normalized.
func intersectionImplementation(first, second Vector) (float32, float32) {
// first.pos +... | voxelli/geometry/lineSegment.go | 0.900197 | 0.682841 | lineSegment.go | starcoder |
package block
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/entity"
"github.com/df-mc/dragonfly/server/world"
"math/rand"
)
// Farmland is a block that crops are grown on. Farmland is created by interacting with a grass or dirt block using a
// hoe. Farmland can be hyd... | server/block/farmland.go | 0.737158 | 0.485966 | farmland.go | starcoder |
package main
import (
"github.com/pkg/errors"
"gorgonia.org/gorgonia"
"gorgonia.org/tensor"
)
// FeedForward Forward pass
func (tiny *TinyYOLOv2Net) FeedForward(g *gorgonia.ExprGraph, x *gorgonia.Node) (err error) {
// 0 conv 16 3 x 3/ 1 416 x 416 x 3 -> 416 x 416 x 16
var conv0, bias0, leaky0... | examples/tiny-yolo-v2-coco/feedforward.go | 0.518302 | 0.506225 | feedforward.go | starcoder |
package bsoncore
import (
"bytes"
"fmt"
"io"
"strconv"
)
// NewArrayLengthError creates and returns an error for when the length of an array exceeds the
// bytes available.
func NewArrayLengthError(length, rem int) error {
return lengthError("array", length, rem)
}
// Array is a raw bytes representation of a B... | bsoncore/array.go | 0.72331 | 0.441011 | array.go | starcoder |
package merkle
import (
"bytes"
"errors"
"fmt"
)
// RootMismatchError occurs when an inclusion proof fails.
type RootMismatchError struct {
ExpectedRoot []byte
CalculatedRoot []byte
}
func (e RootMismatchError) Error() string {
return fmt.Sprintf("calculated root:\n%v\n does not match expected root:\n%v", e... | merkle/log_verifier.go | 0.760651 | 0.523725 | log_verifier.go | starcoder |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.