### Vectorized XOR operations for uint64 slices in Go Source: https://github.com/viant/vec/blob/main/bitwise/README.md Illustrates vectorized XOR operations on uint64 slices using the bitwise package. This includes examples for two-operand and three-operand XOR. The function requires the 'github.com/viant/vec/bitwise' package. ```go package mypkg; import "github.com/viant/vec/bitwise" func ExampleUint64s_XOr() { { out := bitwise.Uint64s(make([]uint64, 8)) v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} out.Xor(v1, v2) } { out := bitwise.Uint64s(make([]uint64, 8)) v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} v3 := []uint64{1, 1, 0, 4, 1, 6, 7, 2} out.XorV3(v1, v2, v3) } } ``` -------------------------------- ### Generate Assembler File using Clang and c2goasm Source: https://github.com/viant/vec/blob/main/search/cpp/README.md This snippet demonstrates the process of generating an assembler file. It first compiles a C++ file using clang with specific optimization flags and then uses c2goasm to convert the resulting assembly file into a format suitable for c2goasm. Ensure clang version 18.0.0 or later is installed. ```bash cd cpp clang -S -mavx2 -mfma -masm=intel -fno-asynchronous-unwind-tables -mstackrealign -Ofast file_name_1.cpp cd .. c2goasm -a -f cpp/file_name_1.s file_name1_2.s ``` -------------------------------- ### Vectorized AND operations for uint64 slices in Go Source: https://github.com/viant/vec/blob/main/bitwise/README.md Demonstrates vectorized AND operations on uint64 slices using the bitwise package. It includes examples for both two-operand and three-operand AND operations. This function requires the 'github.com/viant/vec/bitwise' package. ```go package mypkg; import "github.com/viant/vec/bitwise" func ExampleUint64s_And() { { out := bitwise.Uint64s(make([]uint64, 8)) v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} out.And(v1, v2) } { out := make([]uint64, 8) v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} v3 := []uint64{1, 1, 0, 4, 1, 6, 7, 2} bitwise.Uint64s(out).AndV3(v1, v2, v3) } } ``` -------------------------------- ### Assembly Code Snippet to Remove Source: https://github.com/viant/vec/blob/main/search/cpp/README.md This snippet shows assembly lines that may need to be removed from the generated assembler files. These lines relate to stack frame setup and are sometimes not handled correctly by c2 in earlier versions. This is a common post-processing step. ```assembly // push rbp // mov rbp, rsp // and rsp, -8 ``` -------------------------------- ### Perform SIMD-accelerated byte-level lookup transformations using Go Source: https://context7.com/viant/vec/llms.txt This snippet demonstrates how to use SIMD-accelerated lookup tables for fast byte-level transformations in Go. It covers creating a lookup table, applying it to input data, and performing subrange lookups for bucketing. Dependencies include the 'github.com/viant/vec/lut' package. ```Go package main import "github.com/viant/vec/lut" func main() { // Create lookup table (256 entries for all possible byte values) table := make([]byte, 256) for i := 0; i < 256; i++ { table[i] = byte(i ^ 0xFF) // Example: invert bits } // Input data input := make([]byte, 1024) for i := range input { input[i] = byte(i % 256) } // Allocate output output := make([]byte, len(input)) // Perform vectorized lookup lut.Lookup(input, table, &output) // Each input[i] is mapped to table[input[i]] // Subrange lookup for bucketing (max 16 ranges) rangeUpper := []byte{10, 20, 30, 50, 100, 200, 255} rangeLut := []byte{0, 1, 2, 3, 4, 5, 6} lut.LookupSubrange(input, rangeUpper, rangeLut, &output) // Maps inputs to range indices based on upper bounds } ``` -------------------------------- ### Perform Bitwise AND Operation on uint64 Slices in Go Source: https://github.com/viant/vec/blob/main/README.md This Go code snippet demonstrates how to perform a bitwise AND operation on two slices of uint64 using the viant/vec library. It requires the `bitwise` package from the library and takes two input slices (`v1`, `v2`) and an output slice (`out`) to store the result. The operation is performed in-place on the `out` slice. ```go package main import ( "github.com/viant/vec/bitwise" ) func main() { out := make([]uint64, 8) v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} bitwise.Uint64s(out).And(v1, v2) } ``` -------------------------------- ### Vectorized Bitwise AND Operations in Go Source: https://context7.com/viant/vec/llms.txt Performs vectorized binary AND operations on uint64 slices using the 'bitwise' package. Supports single and multi-operand (3-6 vectors) operations. Requires input slices of uint64 and an output slice of the same size. ```go package main import "github.com/viant/vec/bitwise" func main() { // Create output slice out := bitwise.Uint64s(make([]uint64, 8)) // Input vectors v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} // Perform vectorized AND out.And(v1, v2) // Result: [1, 2, 3, 4, 1, 6, 7, 0] // AND with multiple operands (3-6 vectors supported) v3 := []uint64{1, 1, 0, 4, 1, 6, 7, 2} out.AndV3(v1, v2, v3) // Result: [1, 0, 0, 4, 1, 6, 7, 0] } ``` -------------------------------- ### Lookup byte vector using subrange partitioning (Go) Source: https://github.com/viant/vec/blob/main/lut/README.md Maps an input byte vector to a collection of indexes using a subrange vector, then uses a 16-element lookup table to create the output vector. This is optimized for hardware vectorization. It requires the input byte vector, a sorted subrange limit vector, a 16-element lookup table, and an output byte vector. ```Go package mypkg; import ( "github.com/viant/vec/lut" ) func Example_LookupSubrange() { var rangeUpper = []byte{10, 20, 100, 250} var rangeTable = []byte{0, 42, 43, 240, 211, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} var input = []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 255, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 255} var output = make([]byte, len(input)) lut.LookupSubrange(input, rangeUpper, rangeTable, &output) } ``` -------------------------------- ### Compress sparse byte masks to uint64 representation in Go Source: https://context7.com/viant/vec/llms.txt This snippet illustrates byte mask compression in Go, shrinking sparse byte masks into a compact uint64 representation. It covers compressing masks, compressing values where non-zero bytes become bits, and expanding the compressed representation back into a byte array. The 'github.com/viant/vec/pack' package is utilized. ```Go package main import "github.com/viant/vec/pack" func main() { // Sparse byte mask (only specific bytes are non-zero) mask := make([]byte, 64) mask[0] = 1 mask[15] = 1 mask[31] = 1 mask[63] = 1 // Compress to single uint64 where each bit represents a byte var compressor pack.Uint64 compressed := compressor.Shrink(mask) // compressed is a uint64 with bits set at positions 0, 15, 31, 63 // Also works with values - shrinks non-zero bytes to bits values := make([]byte, 64) values[5] = 42 values[10] = 100 compressedVals := compressor.ShrinkValue(values) // Bits set at positions 5 and 10 // Expand back to byte array expanded := make([]byte, 64) pack.Uint64s([]uint64{compressed}).Expand(expanded) // expanded has bytes set at original positions } ``` -------------------------------- ### Populate Bit Positions from Int64 (Go) Source: https://github.com/viant/vec/blob/main/bits/README.md Populates a pre-allocated [64]int32 array with the bit positions of set bits in an int64 input. The 'Populate' method returns the index of the last populated element in the output array. This is useful for scenarios where you need to efficiently represent or process the positions of set bits. ```go package mypkg; import ( "fmt" "github.com/viant/vec/bits" "math/rand" "time" ) func Example_Count() { var out bits.Positions input := rand.New(rand.NewSource(time.Now().UnixNano())).Uint64() lastIndex := out.Populate(input) fmt.Println(out[0:lastIndex]) } ``` -------------------------------- ### Go Assembly: NEON Decompiler Output Transformation Source: https://github.com/viant/vec/blob/main/lut/cpp/README.md This snippet shows Go assembly code using the NEON instruction set. It demonstrates how to load input, output, and table data, perform bitwise operations, and use table lookups for data transformation. It's relevant for Go versions 1.17 and above, but also notes potential assembler inaccuracies. ```goasm TEXT ·_transform16_neon(SB), $0-32 MOVD input+0(FP), R0 MOVD output+8(FP), R1 MOVD table+16(FP), R2 MOVD chunks+24(FP),R3 CMPW $1, R3 BLT 27(PC) MOVW R3, R8 VMOVI $64, V0.B16 VMOVI $128, V1.B16 VMOVI $192, V2.B16 FLDPQ (R2), (F3, F4) FLDPQ 32(R2), (F5, F6) FMOVQ.P 16(R0), F7 FLDPQ 64(R2), (F16, F17) FLDPQ 96(R2), (F18, F19) VEOR V0.B16, V7.B16, V20.B16 FLDPQ 128(R2), (F21, F22) VTBL V20.B16, [V16.B16, V17.B16, V18.B16, V19.B16], V16.B16 FLDPQ 160(R2), (F23, F24) VEOR V1.B16, V7.B16, V17.B16 FLDPQ 192(R2), (F25, F26) VTBL V17.B16, [V21.B16, V22.B16, V23.B16, V24.B16], V17.B16 VTBL V7.B16, [V3.B16, V4.B16, V5.B16, V6.B16], V3.B16 FLDPQ 224(R2), (F27, F28) VEOR V2.B16, V7.B16, V4.B16 VTBL V4.B16, [V25.B16, V26.B16, V27.B16, V28.B16], V4.B16 VORR V3.B16, V16.B16, V3.B16 VORR V17.B16, V3.B16, V3.B16 VORR V4.B16, V3.B16, V3.B16 FMOVQ.P F3, 16(R1) SUBS $1, R8, R8 BNE -21(PC) RET ``` -------------------------------- ### Go Assembly: Transforming C Assembly with c2goasm Source: https://github.com/viant/vec/blob/main/lut/cpp/README.md This command uses the c2goasm tool to convert C assembly code into Go assembly format. The '-f' flag indicates force overwriting, and '-a' specifies the output file name. This process is crucial for integrating C-optimized assembly into Go projects. ```bash c2goasm -f -a cpp/lookup_512vbmi.s lookup_amd64.s ``` -------------------------------- ### Bitwise OR and XOR Operations Source: https://context7.com/viant/vec/llms.txt Provides vectorized bitwise OR and XOR operations on uint64 slices, with support for operations involving multiple operands. ```APIDOC ## Bitwise OR and XOR Operations ### Description Provides vectorized bitwise OR and XOR operations on uint64 slices, with support for operations involving multiple operands. ### Method Various (internal implementation using SIMD) ### Endpoint N/A (Library functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import "github.com/viant/vec/bitwise" func main() { out := bitwise.Uint64s(make([]uint64, 8)) v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} // Bitwise OR out.Or(v1, v2) // Result: [1, 7, 3, 4, 7, 6, 7, 10] // XOR operation out.Xor(v1, v2) // Result: [0, 5, 0, 0, 6, 0, 0, 10] // Multi-operand OR v3 := []uint64{1, 1, 0, 4, 1, 6, 7, 2} out.OrV3(v1, v2, v3) // Result combines all three vectors with OR } ``` ### Response #### Success Response (200) Modifies the output slice in-place with the result of the bitwise OR or XOR operation. #### Response Example (See Go code for example results) ``` -------------------------------- ### Vectorized Bitwise OR and XOR in Go Source: https://context7.com/viant/vec/llms.txt Implements vectorized bitwise OR and XOR operations for uint64 slices using the 'bitwise' package. Supports both two-operand and multi-operand (3-6 vectors) versions for OR. Input and output slices must be of type uint64. ```go package main import "github.com/viant/vec/bitwise" func main() { out := bitwise.Uint64s(make([]uint64, 8)) v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} // Bitwise OR out.Or(v1, v2) // Result: [1, 7, 3, 4, 7, 6, 7, 10] // XOR operation out.Xor(v1, v2) // Result: [0, 5, 0, 0, 6, 0, 0, 10] // Multi-operand OR v3 := []uint64{1, 1, 0, 4, 1, 6, 7, 2} out.OrV3(v1, v2, v3) // Result combines all three vectors with OR } ``` -------------------------------- ### Bit Counting and Position Finding in Go Source: https://context7.com/viant/vec/llms.txt Provides utilities for bit manipulation on uint64 vectors using the 'bits' package. Includes functions to count set bits ('Count'), find the least significant bit ('Lsb'), and the most significant bit ('Msb'). It also offers a 'Positions' struct to populate and store indices of set bits. ```go package main import "github.com/viant/vec/bits" func main() { vec := []uint64{0xF, 0xFF, 0xFFFF, 0xFFFFFFFF} // Count total set bits across all elements count := bits.Count(vec) // count = 4 + 8 + 16 + 32 = 60 // Find least significant bit position lsb := bits.Lsb(vec) // Returns position of first set bit // Find most significant bit position msb := bits.Msb(vec) // Returns position of last set bit // Populate bit positions from int64 var positions bits.Positions input := uint64(0b10110) lastIdx := positions.Populate(input) // Populates positions array with indices of set bits: [1, 2, 4] } ``` -------------------------------- ### Bit Counting and Position Finding Source: https://context7.com/viant/vec/llms.txt Utility functions for bit manipulation, including counting set bits and finding the positions of the least and most significant bits in uint64 vectors. ```APIDOC ## Bit Counting and Position Finding ### Description Utility functions for bit manipulation, including counting set bits and finding the positions of the least and most significant bits in uint64 vectors. ### Method Various (internal implementation) ### Endpoint N/A (Library functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import "github.com/viant/vec/bits" func main() { vec := []uint64{0xF, 0xFF, 0xFFFF, 0xFFFFFFFF} // Count total set bits across all elements count := bits.Count(vec) // count = 4 + 8 + 16 + 32 = 60 // Find least significant bit position lsb := bits.Lsb(vec) // Returns position of first set bit // Find most significant bit position msb := bits.Msb(vec) // Returns position of last set bit // Populate bit positions from int64 var positions bits.Positions input := uint64(0b10110) lastIdx := positions.Populate(input) // Populates positions array with indices of set bits: [1, 2, 4] } ``` ### Response #### Success Response (200) Returns the count of set bits, the position of the LSB/MSB, or populates a `Positions` struct with bit indices. #### Response Example (See Go code for example results) ``` -------------------------------- ### Intel Assembly: Compiling C code with AVX512VBMI Source: https://github.com/viant/vec/blob/main/lut/cpp/README.md This command demonstrates how to compile C code to Intel assembly using the clang compiler. It specifically targets the AVX512VBMI instruction set and optimizes for speed with '-Ofast'. The output is an assembly file suitable for further transformation. ```bash clang -mavx512vbmi -S -masm=intel -fno-asynchronous-unwind-tables lookup_512vbmi.cpp -Ofast ``` -------------------------------- ### Bitwise AND Operation Source: https://context7.com/viant/vec/llms.txt Performs vectorized binary AND operation on uint64 slices using SIMD instructions. Supports AND with two or multiple operands. ```APIDOC ## Bitwise AND Operation ### Description Performs vectorized binary AND operation on uint64 slices using SIMD instructions. Supports AND with two or multiple operands. ### Method Various (internal implementation using SIMD) ### Endpoint N/A (Library functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import "github.com/viant/vec/bitwise" func main() { // Create output slice out := bitwise.Uint64s(make([]uint64, 8)) // Input vectors v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} // Perform vectorized AND out.And(v1, v2) // Result: [1, 2, 3, 4, 1, 6, 7, 0] // AND with multiple operands (3-6 vectors supported) v3 := []uint64{1, 1, 0, 4, 1, 6, 7, 2} out.AndV3(v1, v2, v3) // Result: [1, 0, 0, 4, 1, 6, 7, 0] } ``` ### Response #### Success Response (200) Modifies the output slice in-place with the result of the bitwise AND operation. #### Response Example (See Go code for example results) ``` -------------------------------- ### Lookup byte vector using a table (Go) Source: https://github.com/viant/vec/blob/main/lut/README.md Maps an input byte vector to an output vector using a lookup table. This function is useful for transforming byte values based on a predefined mapping. It requires the input byte vector, the lookup table, and an output byte vector to store the results. ```Go package mypkg; import ( "github.com/viant/vec/lut" ) func Example_Lookup() { var table = make([]byte, 256) // .. populate the lookup table var input = make([]byte, 12345) // .. populate the input byte vector var output = make([]byte, len(input)) lut.Lookup(input, table, &output) } ``` -------------------------------- ### Compress and decompress integer arrays with variable bit-width encoding in Go Source: https://context7.com/viant/vec/llms.txt This code snippet shows how to compress and decompress integer arrays using variable bit-width encoding in Go. It calculates the minimum bits required, determines the packed size, packs the data, and then unpacks it back to the original values. It relies on the 'github.com/viant/vec/pack' package. ```Go package main import "github.com/viant/vec/pack" func main() { // Original data data := []uint32{ 20124, 8831, 2575, 1977, 15, 42441, 302690, 871222, 323452, 424532, 29434, 939141, 4244, 324314, 13, 1, } // Determine minimum bits needed to represent all values bits := pack.MaxBits(data) // bits = 20 (since max value is 939141) // Calculate packed size packedSize := pack.PackedUint32Count(uint32(len(data)), bits) packedData := pack.Uint32s(make([]uint32, packedSize)) // Pack data using determined bit width packedData.PackBits(data, int(bits)) // Data is now compressed to 20 bits per value // Unpack back to original values unpackedData := make([]uint32, len(data)) pack.Uint32s(unpackedData).UnpackBits(packedData, int(bits)) // unpackedData now equals original data } ``` -------------------------------- ### Implement delta encoding for time series data compression in Go Source: https://context7.com/viant/vec/llms.txt This Go snippet demonstrates delta encoding for compressing sequential or monotonic data. It shows how to convert an array of integers into an array of their differences (deltas) and then recover the original sequence from these deltas. The 'github.com/viant/vec/pack' package is used for these operations. ```Go package main import "github.com/viant/vec/pack" func main() { // Time series or monotonic data data := []int32{100, 105, 110, 112, 120, 125, 130} // Convert to deltas deltas := make([]int32, len(data)) pack.Int32s(deltas).Deltas(data) // deltas = [100, 5, 5, 2, 8, 5, 5] // Recover original from deltas recovered := make([]int32, len(deltas)) pack.Int32s(recovered).RecoverDeltas(deltas) // recovered = [100, 105, 110, 112, 120, 125, 130] } ``` -------------------------------- ### Shrink Byte Mask to Uint64 with Value Mapping (Go) Source: https://github.com/viant/vec/blob/main/pack/README.md Similar to Shrink, but maps a specific byte value within the uint64 vector to a '1' in the resulting bit pattern. Useful for creating bitmasks based on specific byte content. ```go package mypkg; import ( "github.com/viant/vec/pack" ) func Example_ShrinkValue() { var ints = []uint64{ 0x8000800080008000, 0x8000800080008000, 0x8000800080008000, 0x8000800080008000, 0x0080008000800080, 0x0080008000800080, 0x0080008000800080, 0x0080008000800080, } var shrunkValue = pack.Uint64(0) shrunkValue.ShrinkValue(0x80, ints) } ``` -------------------------------- ### Vectorized Add Operation for int32 Source: https://github.com/viant/vec/blob/main/blas/README.md Demonstrates how to perform a vectorized addition of two int32 vectors using the blas.Int32s function. This operation is optimized for performance. ```go package mypkg; import "github.com/viant/vec/blas" func ExampleInt32_Add() { v1 := []int32{1, 2, 3, 4, 5, 6, 7, 8} v2 := []int32{1, 7, 3, 4, 3, 6, 7, 2} out := blas.Int32s(make([]int32, 8)) out.AddInt32(v1, v2) } ``` -------------------------------- ### Float32 Arithmetic Operations with SIMD in Go Source: https://context7.com/viant/vec/llms.txt Provides element-wise arithmetic operations (Add, Sub, Mul, Div) for float32 slices, accelerated by SIMD instructions via the 'blas' package. Requires input slices of float32 and an output slice of the same size. ```go package main import "github.com/viant/vec/blas" func main() { // Create input data data1 := make([]float32, 255) data2 := make([]float32, 255) for i := 0; i < 255; i++ { data1[i] = float32(i) data2[i] = float32(2 * (i + 1)) } // Allocate output out := blas.Float32s(make([]float32, 255)) // Addition out.AddFloat32(data1, data2) // out[i] = data1[i] + data2[i] // Subtraction out.SubFloat32(data1, data2) // out[i] = data1[i] - data2[i] // Multiplication out.MulFloat32(data1, data2) // out[i] = data1[i] * data2[i] // Division out.DivFloat32(data1, data2) // out[i] = data1[i] / data2[i] } ``` -------------------------------- ### Detect and control CPU vectorization capabilities in Go Source: https://context7.com/viant/vec/llms.txt This Go code snippet focuses on CPU feature detection for vectorization. It shows how to explicitly disable certain instruction sets like AVX512 to fall back to others like AVX2, and how to check for support of specific architectures such as ARM SVE. The library automatically selects the best available instruction set. ```Go package main import "github.com/viant/vec/cpu" func main() { // Disable AVX512 to use AVX2 instead cpu.TryAVX512(false) // Check for ARM SVE support if cpu.CanUseSVE() { // Use SVE-optimized paths } // The library automatically detects and uses the best // available instruction set for the current CPU } ``` -------------------------------- ### Horizontal Sum, Min, and Max Operations Source: https://context7.com/viant/vec/llms.txt Provides reduce operations that compute aggregate values such as sum, minimum, and maximum across entire float32 and int32 vectors. ```APIDOC ## Horizontal Sum, Min, and Max Operations ### Description Provides reduce operations that compute aggregate values such as sum, minimum, and maximum across entire float32 and int32 vectors. ### Method Various (internal implementation using SIMD) ### Endpoint N/A (Library functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import "github.com/viant/vec/blas" func main() { data := []float32{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0} // Horizontal sum - adds all elements sum := blas.HsumFloat32(data) // sum = 36.0 // Horizontal maximum max := blas.HmaxFloat32(data) // max = 8.0 // Horizontal minimum min := blas.HminFloat32(data) // min = 1.0 // Works with int32 as well intData := []int32{10, 20, 30, 40, 50} intSum := blas.HsumInt32(intData) // intSum = 150 intMax := blas.HmaxInt32(intData) // intMax = 50 } ``` ### Response #### Success Response (200) Returns the computed aggregate value (sum, min, or max). #### Response Example (See Go code for example results) ``` -------------------------------- ### Shrink Byte Mask to Uint64 Bit Pattern (Go) Source: https://github.com/viant/vec/blob/main/pack/README.md Condenses a byte mask, stored as a uint64 vector (max 8 elements), into a single uint64 bit pattern. This is useful for space optimization. ```go package mypkg; import ( "github.com/viant/vec/pack" ) func Example_Shrink() { var ints = []uint64{ 0x8000800080008000, 0x8000800080008000, 0x8000800080008000, 0x8000800080008000, 0x0080008000800080, 0x0080008000800080, 0x0080008000800080, 0x0080008000800080, } var shrunkValue = pack.Uint64(0) shrunkValue.Shrink(ints) } ``` -------------------------------- ### Calculate cosine and Euclidean distance between float32 vectors in Go Source: https://context7.com/viant/vec/llms.txt This Go code calculates the cosine distance (1 - cosine similarity) and Euclidean distance between two float32 vectors. It shows both a basic calculation and an optimized version using pre-calculated magnitudes for cosine distance. The 'github.com/viant/vec/search' package is required. ```Go package main import "github.com/viant/vec/search" func main() { v1 := []float32{1, 2, 3, 4, 8} v2 := []float32{1, 2, 3, 4, 5} // Calculate cosine distance (1 - cosine similarity) vec := search.Float32s(v1) distance := vec.CosineDistance(v2) // distance ≈ 0.0265 (vectors are quite similar) // Optimized version with pre-calculated magnitudes mag1 := vec.Magnitude() mag2 := search.Float32s(v2).Magnitude() distanceOpt := vec.CosineDistanceWithMagnitude(v2, mag1, mag2) // Same result, faster when computing multiple distances // Euclidean distance euclidean := vec.EuclideanDistance(search.Float32s(v2)) // euclidean ≈ 3.0 (L2 distance) } ``` -------------------------------- ### Horizontal Sum, Min, Max for Float32/Int32 in Go Source: https://context7.com/viant/vec/llms.txt Performs horizontal reduction operations (sum, min, max) across entire float32 and int32 slices using the 'blas' package. These functions efficiently compute aggregate values from vector data, leveraging SIMD where available. ```go package main import "github.com/viant/vec/blas" func main() { data := []float32{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0} // Horizontal sum - adds all elements sum := blas.HsumFloat32(data) // sum = 36.0 // Horizontal maximum max := blas.HmaxFloat32(data) // max = 8.0 // Horizontal minimum min := blas.HminFloat32(data) // min = 1.0 // Works with int32 as well intData := []int32{10, 20, 30, 40, 50} intSum := blas.HsumInt32(intData) // intSum = 150 intMax := blas.HmaxInt32(intData) // intMax = 50 } ``` -------------------------------- ### Float32 Arithmetic Operations Source: https://context7.com/viant/vec/llms.txt Performs element-wise arithmetic operations (addition, subtraction, multiplication, division) on float32 slices with SIMD acceleration. ```APIDOC ## Float32 Arithmetic Operations ### Description Performs element-wise arithmetic operations (addition, subtraction, multiplication, division) on float32 slices with SIMD acceleration. ### Method Various (internal implementation using SIMD) ### Endpoint N/A (Library functions) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import "github.com/viant/vec/blas" func main() { // Create input data data1 := make([]float32, 255) data2 := make([]float32, 255) for i := 0; i < 255; i++ { data1[i] = float32(i) data2[i] = float32(2 * (i + 1)) } // Allocate output out := blas.Float32s(make([]float32, 255)) // Addition out.AddFloat32(data1, data2) // out[i] = data1[i] + data2[i] // Subtraction out.SubFloat32(data1, data2) // out[i] = data1[i] - data2[i] // Multiplication out.MulFloat32(data1, data2) // out[i] = data1[i] * data2[i] // Division out.DivFloat32(data1, data2) // out[i] = data1[i] / data2[i] } ``` ### Response #### Success Response (200) Modifies the output slice in-place with the result of the arithmetic operation. #### Response Example (See Go code for example results) ``` -------------------------------- ### Expand Uint64 Bit Pattern to Byte Mask (Go) Source: https://github.com/viant/vec/blob/main/pack/README.md Reverses the operation of ShrinkValue, expanding a single uint64 bit pattern back into a uint64 vector representing a byte mask. This reconstructs the original or a similar byte mask. ```go package mypkg; import ( "github.com/viant/vec/pack" ) func Example_Expand() { var shrunkValue = uint64(0x55555555aaaaaaaa) out := pack.Uint64s(make([]uint64, 8)) out.Expand(shrunkValue) } ``` -------------------------------- ### Vectorized OR operations for uint64 slices in Go Source: https://github.com/viant/vec/blob/main/bitwise/README.md Shows vectorized OR operations on uint64 slices using the bitwise package. It covers both two-operand and three-operand OR operations. This function depends on the 'github.com/viant/vec/bitwise' package. ```go package mypkg; import "github.com/viant/vec/bitwise" func ExampleUint64s_Or() { { out := make([]uint64, 8) v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} bitwise.Uint64s(out).Or(v1, v2) } { out := bitwise.Uint64s(make([]uint64, 8)) v1 := []uint64{1, 2, 3, 4, 5, 6, 7, 8} v2 := []uint64{1, 7, 3, 4, 3, 6, 7, 2} v3 := []uint64{1, 1, 0, 4, 1, 6, 7, 2} out.OrV3(v1, v2, v3) } } ``` -------------------------------- ### Delta Encode/Decode Int32 Vectors (Go) Source: https://github.com/viant/vec/blob/main/pack/README.md Implements delta encoding for int32 vectors and provides a function to recover the original data. This is useful for compressing sequential integer data. ```go package mypkg; import ( "github.com/viant/vec/pack" ) func Example_Deltas() { data := make([]int32, 1000) //... deltas := pack.Int32s(make([]int32, len(data))) deltas.Deltas(data) //... recoveredData := pack.Int32s(make([]int32, len(deltas))) recoveredData.RecoverDeltas(deltas) } ``` -------------------------------- ### Pack/Unpack Uint32 Vectors with Custom Bit Width (Go) Source: https://github.com/viant/vec/blob/main/pack/README.md Packs uint32 data into a more compact representation using a specified number of bits per element, determined by MaxBits. UnpackBits reverses this operation. ```go package mypkg; import ( "github.com/viant/vec/pack" ) func Example_PackBits() { data := []uint32{20124, 8831, 2575, 1977, 15, 42441, 302690, 871222, 323452, 424532, 29434, 939141, 4244, 324314, 13, 1, 874255, 20124, 8831, 2575, 1977, 15, 42441, 302690, 871222, 323452, 424532, 29434, 939141, 4244, 324314, 13, 1, 874255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42441, 302690, 871222, 323452, 424532, 29434, 939141, 4244, 324314, 13, 1, 874255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} b its := pack.MaxBits(data) packedData := pack.Uint32s(make([]uint32, pack.PackedUint32Count(uint32(len(data)), bits))) packedData.PackBits(data, int(bits)) unpackedData := make([]uint32, len(data)) pack.Uint32s(unpackedData).UnpackBits(packedData, int(bits)) } ``` -------------------------------- ### Vectorized Horizontal Sum for float32 Source: https://github.com/viant/vec/blob/main/blas/README.md Illustrates the usage of the blas.HsumFloat32 function to compute the horizontal sum of a slice of float32 values. This operation sums all elements within a single vector. ```go package mypkg; import ( "fmt" "github.com/viant/vec/blas" ) func ExampleInt32_HSum() { var data = make([]float32, 1000) //... sum := blas.HsumFloat32(data) fmt.Println(sum) } ``` -------------------------------- ### Count Set Bits in a Vector (Go) Source: https://github.com/viant/vec/blob/main/bits/README.md Counts the number of set (1) bits in a slice of uint64. This function is part of the 'bits' package and operates on a vector of unsigned 64-bit integers. It is useful for various bit manipulation tasks and performance-critical applications. ```go package mypkg; import ( "fmt" "github.com/viant/vec/bits" "math/rand" "time" ) func Example_Count() { rnd := rand.New(rand.NewSource(time.Now().UnixNano())) var vec = make([]uint64, 267) for i := range vec { vec[i] = rnd.Uint64() } cnt := bits.Count(vec) fmt.Println(cnt) } ``` -------------------------------- ### C function for NEON vectorized table lookup Source: https://github.com/viant/vec/blob/main/lut/cpp/README.md Implements a vectorized table lookup using ARM NEON intrinsics. It takes input data, output buffer, a lookup table, and the number of chunks as parameters. The function processes data in 16-byte chunks and utilizes `vqtbl4q_u8` for table lookups and `vorrq_u8` for combining results. ```c #include void lookup_neon(const uint8x16_t *input, uint8x16_t *output, const uint8x16x4_t *table, const int chunks) { for (int i = 0; i < chunks; i++) { const uint8x16_t t1 = vqtbl4q_u8(table[0], input[i]); const uint8x16_t t2 = vqtbl4q_u8(table[1], veorq_u8(input[i], vdupq_n_u8(0x40))); const uint8x16_t t3 = vqtbl4q_u8(table[2], veorq_u8(input[i], vdupq_n_u8(0x80))); const uint8x16_t t4 = vqtbl4q_u8(table[3], veorq_u8(input[i], vdupq_n_u8(0xc0))); output[i] = vorrq_u8(vorrq_u8(t1, t2), vorrq_u8(t3, t4)); } } ``` -------------------------------- ### Determine Max Bits for Int32 Vector (Go) Source: https://github.com/viant/vec/blob/main/pack/README.md A helper function to calculate the maximum number of bits required to represent any number within an int32 vector. This is used in bit packing operations. ```go package mypkg; import ( "fmt" "github.com/viant/vec/pack" ) func Example_MaxBits() { var data = make([]uint32, 1000) //.... bitwidth := pack.MaxBits(data) fmt.Println(bitwidth) } ``` -------------------------------- ### Disassembling ARM assembly code Source: https://github.com/viant/vec/blob/main/lut/cpp/README.md Disassembles an object file generated from C code into ARM assembly instructions. This step is crucial for understanding the low-level operations and preparing for manual assembly or verification. The output is a list of hexadecimal instruction codes and their corresponding assembly mnemonics. ```asm :0 0x0 7100047f CMPW $1 ``` -------------------------------- ### Find Least/Most Significant Bit Position in Vector (Go) Source: https://github.com/viant/vec/blob/main/bits/README.md Finds the position of the least significant bit (LSb) or most significant bit (MSb) in a vector of uint64. The 'Lsb' function returns the index of the least significant set bit. This operation is fundamental in various bitwise algorithms and data structure implementations. ```go package mypkg; import ( "fmt" "github.com/viant/vec/bits" "math/rand" "time" ) func Example_Lsb() { rnd := rand.New(rand.NewSource(time.Now().UnixNano())) var vec = make([]uint64, 267) for i := range vec { vec[i] = rnd.Uint64() } position := bits.Lsb(vec) fmt.Println(position)} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.