Skip to main content
topk-js / data

Functions

binaryVector()

function binaryVector(values: number[]): List;
Creates a List type containing a binary vector. This function is an alias for binaryList(). Example:
import { binaryVector } from "topk-js/data";

binaryVector([0, 1, 1, 0])
Parameters
ParameterType
valuesnumber[]
Returns List

bytes()

function bytes(buffer: number[] | Buffer<ArrayBufferLike>): Buffer;
Creates a List type containing bytes data. Example:
import { bytes } from "topk-js/data";

bytes([0, 1, 1, 0])
Parameters
ParameterType
buffernumber[] | Buffer<ArrayBufferLike>
Returns Buffer

f32List()

function f32List(values: number[]): List;
Creates a List type containing a list of 32-bit floating point numbers. Example:
import { f32List } from "topk-js/data";

f32List([0.12, 0.67, 0.82, 0.53])
Parameters
ParameterType
valuesnumber[]
Returns List

f32SparseVector()

function f32SparseVector(vector: Record<number, number>): SparseVector;
Creates a SparseVector type containing a sparse vector of 32-bit floats. This function is an alias for f32SparseList(). Example:
import { f32SparseVector } from "topk-js/data";

f32SparseVector({0: 0.12, 6: 0.67, 17: 0.82, 97: 0.53})
Parameters
ParameterType
vectorRecord<number, number>
Returns SparseVector

f32Vector()

function f32Vector(values: number[]): List;
Creates a List type containing a 32-bit float vector. This function is an alias for f32List(). Example:
import { f32Vector } from "topk-js/data";

f32Vector([0.12, 0.67, 0.82, 0.53])
Parameters
ParameterType
valuesnumber[]
Returns List

f64List()

function f64List(values: number[]): List;
Creates a List type containing a list of 64-bit floating point numbers. Example:
import { f64List } from "topk-js/data";

f64List([0.12, 0.67, 0.82, 0.53])
Parameters
ParameterType
valuesnumber[]
Returns List

i32List()

function i32List(values: number[]): List;
Creates a List type containing a list of 32-bit signed integers. Example:
import { i32List } from "topk-js/data";

i32List([0, 1, 2, 3])
Parameters
ParameterType
valuesnumber[]
Returns List

i64List()

function i64List(values: number[]): List;
Creates a List type containing a list of 64-bit signed integers. Example:
import { i64List } from "topk-js/data";

i64List([0, 1, 2, 3])
Parameters
ParameterType
valuesnumber[]
Returns List

i8Vector()

function i8Vector(values: number[]): List;
Creates a List type containing an 8-bit signed integer vector. This function is an alias for i8List(). Example:
import { i8Vector } from "topk-js/data";

i8Vector([-128, 127, -1, 0, 1])
Parameters
ParameterType
valuesnumber[]
Returns List

matrix()

function matrix(values: number[][], valueType?: MatrixValueType): Matrix;
Create a Matrix type containing matrix values. The values parameter must be an array of number arrays. When passing an array of number arrays, the optional valueType parameter specifies the matrix type. If valueType is not provided, the matrix defaults to f32.
import { matrix } from "topk-js/data";

// Array of number arrays with explicit type
matrix([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], "f32")

// Array of number arrays defaults to f32
matrix([[1.0, 2.0], [3.0, 4.0]])
Parameters
ParameterType
valuesnumber[][]
valueType?MatrixValueType
Returns Matrix

stringList()

function stringList(values: string[]): List;
Creates a List type containing a list of strings. Example:
import { stringList } from "topk-js/data";

stringList(["foo", "bar", "baz"])
Parameters
ParameterType
valuesstring[]
Returns List

u32List()

function u32List(values: number[]): List;
Creates a List type containing a list of 32-bit unsigned integers. Example:
import { u32List } from "topk-js/data";

u32List([0, 1, 2, 3])
Parameters
ParameterType
valuesnumber[]
Returns List

u8SparseVector()

function u8SparseVector(vector: Record<number, number>): SparseVector;
Creates a SparseVector type containing a sparse vector of 8-bit unsigned integers. This function is an alias for u8SparseList(). Example:
import { u8SparseVector } from "topk-js/data";

u8SparseVector({0: 12, 6: 67, 17: 82, 97: 53})
Parameters
ParameterType
vectorRecord<number, number>
Returns SparseVector

u8Vector()

function u8Vector(values: number[]): List;
Creates a List type containing an 8-bit unsigned integer vector. This function is an alias for u8List(). Example:
import { u8Vector } from "topk-js/data";

u8Vector([0, 255, 1, 2, 3])
Parameters
ParameterType
valuesnumber[]
Returns List

Classes

List

Internal Instances of the List class are used to represent lists of values in TopK. Usually created using data constructors such as f32_list(), i32_list(), etc.

Matrix

Internal Instances of the Matrix class are used to represent matrices in TopK. Usually created using data constructors such as matrix().

SparseVector

Internal Instances of the SparseVector class are used to represent sparse vectors in TopK. Usually created using data constructors such as f32_sparse_vector() or u8_sparse_vector().

Type Aliases

MatrixValueType

type MatrixValueType = "f32" | "f16" | "f8" | "u8" | "i8";
Matrix element value type.