Module sied

sied - SIMD operations for Erlang.

Description

sied - SIMD operations for Erlang

High-performance vectorized operations using SIMD instructions via Rust NIF with simdeez. Provides runtime SIMD detection and automatic dispatch to SSE2, SSE4.1, AVX2, or NEON instructions.

Function Index

abs_f32/1Compute absolute value of an f32 vector.
abs_f64/1Compute absolute value of an f64 vector.
add_f32/2Element-wise addition of two f32 vectors.
add_f64/2Element-wise addition of two f64 vectors.
cosine_similarity_batch_f32/2Batch cosine similarity: one f32 query against many f32 vectors.
cosine_similarity_batch_f64/2Batch cosine similarity: one f64 query against many f64 vectors.
cosine_similarity_f32/2Cosine similarity between two f32 vectors: dot(A,B) / (|A| * |B|).
cosine_similarity_f64/2Cosine similarity between two f64 vectors.
divide_f32/2Element-wise division of two f32 vectors.
divide_f64/2Element-wise division of two f64 vectors.
dot_product_batch_f32/2Compute dot product of Query against every vector in Vecs.
dot_product_batch_f32_bin/2Dot product of a query f32 binary against a list of f32 binaries.
dot_product_batch_f64/2Compute dot product of Query against every f64 vector in Vecs.
dot_product_f32/2Compute dot product of two f32 vectors Computes the scalar product: sum(A[i] * B[i]).
dot_product_f64/2Compute dot product of two f64 vectors Computes the scalar product: sum(A[i] * B[i]).
dot_product_topk_flat/4Dot-product scoring of selected vectors from a flat f32 binary.
hamming_distance_batch/2Batch hamming distance between a query binary and a list of binaries.
hamming_topk_flat/4Hamming top-K from a flat binary buffer (all vectors concatenated).
l2_norm_f32/1L2 (Euclidean) norm of an f32 vector.
l2_norm_f64/1L2 (Euclidean) norm of an f64 vector.
l2_normalize_batch_f32/1L2-normalize a batch of f32 vectors.
l2_normalize_batch_f64/1L2-normalize a batch of f64 vectors.
l2_normalize_f32/1L2-normalize an f32 vector to unit length.
l2_normalize_f64/1L2-normalize an f64 vector to unit length.
max_elementwise_f32/2Element-wise maximum of two f32 vectors.
max_elementwise_f64/2Element-wise maximum of two f64 vectors.
max_f32/1Find maximum value in an f32 vector.
max_f64/1Find maximum value in an f64 vector.
mean_f32/1Compute arithmetic mean of an f32 vector.
mean_f64/1Compute arithmetic mean of an f64 vector.
min_elementwise_f32/2Element-wise minimum of two f32 vectors.
min_elementwise_f64/2Element-wise minimum of two f64 vectors.
min_f32/1Find minimum value in an f32 vector.
min_f64/1Find minimum value in an f64 vector.
multiply_f32/2Element-wise multiplication of two f32 vectors.
multiply_f64/2Element-wise multiplication of two f64 vectors.
negate_f32/1Negate an f32 vector (multiply by -1).
negate_f64/1Negate an f64 vector (multiply by -1).
sqrt_f32/1Compute square root of an f32 vector.
sqrt_f64/1Compute square root of an f64 vector.
std_dev_f32/1Compute standard deviation of an f32 vector.
std_dev_f64/1Compute standard deviation of an f64 vector.
subtract_f32/2Element-wise subtraction of two f32 vectors.
subtract_f64/2Element-wise subtraction of two f64 vectors.
sum_f32/1Compute sum of all elements in an f32 vector.
sum_f64/1Compute sum of all elements in an f64 vector.
to_binary_f32/11-bit quantize an f32 vector.
to_binary_f32_bin/1Like to_binary_f32/1 but accepts a little-endian f32 binary instead of a float list.
variance_f32/1Compute variance of an f32 vector.
variance_f64/1Compute variance of an f64 vector.

Function Details

abs_f32/1

abs_f32(A::[float()]) -> {ok, [float()]} | {error, term()}

A: List of floats

returns: {ok, Result} | {error, Reason}

Compute absolute value of an f32 vector

abs_f64/1

abs_f64(A::[float()]) -> {ok, [float()]} | {error, term()}

A: List of doubles

returns: {ok, Result} | {error, Reason}

Compute absolute value of an f64 vector

add_f32/2

add_f32(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of floats
B: Second list of floats (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise addition of two f32 vectors

add_f64/2

add_f64(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of doubles
B: Second list of doubles (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise addition of two f64 vectors

cosine_similarity_batch_f32/2

cosine_similarity_batch_f32(Query::[float()], Vecs::[[float()]]) -> {ok, [float()]} | {error, term()}

Batch cosine similarity: one f32 query against many f32 vectors.

cosine_similarity_batch_f64/2

cosine_similarity_batch_f64(Query::[float()], Vecs::[[float()]]) -> {ok, [float()]} | {error, term()}

Batch cosine similarity: one f64 query against many f64 vectors.

cosine_similarity_f32/2

cosine_similarity_f32(A::[float()], B::[float()]) -> {ok, float()} | {error, term()}

Cosine similarity between two f32 vectors: dot(A,B) / (|A| * |B|). Returns a value in [-1.0, 1.0].

cosine_similarity_f64/2

cosine_similarity_f64(A::[float()], B::[float()]) -> {ok, float()} | {error, term()}

Cosine similarity between two f64 vectors.

divide_f32/2

divide_f32(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of floats (numerators)
B: Second list of floats (denominators, must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise division of two f32 vectors

divide_f64/2

divide_f64(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of doubles (numerators)
B: Second list of doubles (denominators, must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise division of two f64 vectors

dot_product_batch_f32/2

dot_product_batch_f32(Query::[float()], Vecs::[[float()]]) -> {ok, [float()]} | {error, term()}

Compute dot product of Query against every vector in Vecs. Returns {ok, [Score]} in input order. One NIF call for the whole batch.

dot_product_batch_f32_bin/2

dot_product_batch_f32_bin(Query::binary(), Vecs::[binary()]) -> {ok, [float()]} | {error, term()}

Dot product of a query f32 binary against a list of f32 binaries. Binaries are little-endian IEEE 754 f32 (4 bytes per element). Avoids Erlang float-list marshalling — use with kvex f32-binary storage.

dot_product_batch_f64/2

dot_product_batch_f64(Query::[float()], Vecs::[[float()]]) -> {ok, [float()]} | {error, term()}

Compute dot product of Query against every f64 vector in Vecs.

dot_product_f32/2

dot_product_f32(A::[float()], B::[float()]) -> {ok, float()} | {error, term()}

A: First vector
B: Second vector (must be same length)

returns: {ok, Scalar} | {error, Reason}

Compute dot product of two f32 vectors Computes the scalar product: sum(A[i] * B[i])

dot_product_f64/2

dot_product_f64(A::[float()], B::[float()]) -> {ok, float()} | {error, term()}

A: First vector
B: Second vector (must be same length)

returns: {ok, Scalar} | {error, Reason}

Compute dot product of two f64 vectors Computes the scalar product: sum(A[i] * B[i])

dot_product_topk_flat/4

dot_product_topk_flat(Query::binary(), FlatF32::binary(), VecByteLen::pos_integer(), Indices::[non_neg_integer()]) -> {ok, [{float(), non_neg_integer()}]} | {error, term()}

Dot-product scoring of selected vectors from a flat f32 binary. indices: list produced by hamming_topk_flat. Returns {ok, [{Score, Idx}]} sorted by descending score.

hamming_distance_batch/2

hamming_distance_batch(Query::binary(), Vecs::[binary()]) -> {ok, [non_neg_integer()]} | {error, term()}

Batch hamming distance between a query binary and a list of binaries. Returns {ok, [Distance]} where lower distance means more similar. Uses u64 POPCNT for speed. Intended for the first phase of two-phase ANN search: hamming_distance_batch → filter top-N → dot_product_batch.

hamming_topk_flat/4

hamming_topk_flat(Query::binary(), FlatVecs::binary(), VecLen::pos_integer(), TopK::pos_integer()) -> {ok, [non_neg_integer()]} | {error, term()}

Hamming top-K from a flat binary buffer (all vectors concatenated). Returns {ok, [Idx]} — the indices of the top_k closest vectors, sorted ascending by Hamming distance. O(N) partition + O(K log K) sort, no per-element Erlang overhead.

l2_norm_f32/1

l2_norm_f32(A::[float()]) -> {ok, float()} | {error, term()}

L2 (Euclidean) norm of an f32 vector

l2_norm_f64/1

l2_norm_f64(A::[float()]) -> {ok, float()} | {error, term()}

L2 (Euclidean) norm of an f64 vector

l2_normalize_batch_f32/1

l2_normalize_batch_f32(Vecs::[[float()]]) -> {ok, [[float()]]} | {error, term()}

L2-normalize a batch of f32 vectors.

l2_normalize_batch_f64/1

l2_normalize_batch_f64(Vecs::[[float()]]) -> {ok, [[float()]]} | {error, term()}

L2-normalize a batch of f64 vectors.

l2_normalize_f32/1

l2_normalize_f32(A::[float()]) -> {ok, [float()]} | {error, term()}

L2-normalize an f32 vector to unit length. Returns the original vector if its norm is zero.

l2_normalize_f64/1

l2_normalize_f64(A::[float()]) -> {ok, [float()]} | {error, term()}

L2-normalize an f64 vector to unit length.

max_elementwise_f32/2

max_elementwise_f32(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of floats
B: Second list of floats (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise maximum of two f32 vectors

max_elementwise_f64/2

max_elementwise_f64(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of doubles
B: Second list of doubles (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise maximum of two f64 vectors

max_f32/1

max_f32(A::[float()]) -> {ok, float()} | {error, term()}

A: List of floats

returns: {ok, Max} | {error, Reason}

Find maximum value in an f32 vector

max_f64/1

max_f64(A::[float()]) -> {ok, float()} | {error, term()}

A: List of doubles

returns: {ok, Max} | {error, Reason}

Find maximum value in an f64 vector

mean_f32/1

mean_f32(A::[float()]) -> {ok, float()} | {error, term()}

A: List of floats

returns: {ok, Mean} | {error, Reason}

Compute arithmetic mean of an f32 vector

mean_f64/1

mean_f64(A::[float()]) -> {ok, float()} | {error, term()}

A: List of doubles

returns: {ok, Mean} | {error, Reason}

Compute arithmetic mean of an f64 vector

min_elementwise_f32/2

min_elementwise_f32(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of floats
B: Second list of floats (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise minimum of two f32 vectors

min_elementwise_f64/2

min_elementwise_f64(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of doubles
B: Second list of doubles (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise minimum of two f64 vectors

min_f32/1

min_f32(A::[float()]) -> {ok, float()} | {error, term()}

A: List of floats

returns: {ok, Min} | {error, Reason}

Find minimum value in an f32 vector

min_f64/1

min_f64(A::[float()]) -> {ok, float()} | {error, term()}

A: List of doubles

returns: {ok, Min} | {error, Reason}

Find minimum value in an f64 vector

multiply_f32/2

multiply_f32(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of floats
B: Second list of floats (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise multiplication of two f32 vectors

multiply_f64/2

multiply_f64(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of doubles
B: Second list of doubles (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise multiplication of two f64 vectors

negate_f32/1

negate_f32(A::[float()]) -> {ok, [float()]} | {error, term()}

A: List of floats

returns: {ok, Result} | {error, Reason}

Negate an f32 vector (multiply by -1)

negate_f64/1

negate_f64(A::[float()]) -> {ok, [float()]} | {error, term()}

A: List of doubles

returns: {ok, Result} | {error, Reason}

Negate an f64 vector (multiply by -1)

sqrt_f32/1

sqrt_f32(A::[float()]) -> {ok, [float()]} | {error, term()}

A: List of floats (must be non-negative)

returns: {ok, Result} | {error, Reason}

Compute square root of an f32 vector

sqrt_f64/1

sqrt_f64(A::[float()]) -> {ok, [float()]} | {error, term()}

A: List of doubles (must be non-negative)

returns: {ok, Result} | {error, Reason}

Compute square root of an f64 vector

std_dev_f32/1

std_dev_f32(A::[float()]) -> {ok, float()} | {error, term()}

A: List of floats

returns: {ok, StdDev} | {error, Reason}

Compute standard deviation of an f32 vector

std_dev_f64/1

std_dev_f64(A::[float()]) -> {ok, float()} | {error, term()}

A: List of doubles

returns: {ok, StdDev} | {error, Reason}

Compute standard deviation of an f64 vector

subtract_f32/2

subtract_f32(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of floats
B: Second list of floats (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise subtraction of two f32 vectors

subtract_f64/2

subtract_f64(A::[float()], B::[float()]) -> {ok, [float()]} | {error, term()}

A: First list of doubles
B: Second list of doubles (must be same length)

returns: {ok, Result} | {error, Reason}

Element-wise subtraction of two f64 vectors

sum_f32/1

sum_f32(A::[float()]) -> {ok, float()} | {error, term()}

A: List of floats to sum

returns: {ok, Sum} | {error, Reason}

Compute sum of all elements in an f32 vector

sum_f64/1

sum_f64(A::[float()]) -> {ok, float()} | {error, term()}

A: List of doubles to sum

returns: {ok, Sum} | {error, Reason}

Compute sum of all elements in an f64 vector

to_binary_f32/1

to_binary_f32(Vec::[float()]) -> {ok, binary()} | {error, term()}

1-bit quantize an f32 vector. Each element becomes 1 if above mean, else 0. Returns a packed binary: 128 dims → 16 bytes. Use hamming_distance_batch/2 to search over quantized vectors.

to_binary_f32_bin/1

to_binary_f32_bin(Data::binary()) -> {ok, binary()} | {error, term()}

Like to_binary_f32/1 but accepts a little-endian f32 binary instead of a float list. Zero-copy path when the vector is already stored as a binary (e.g. in kvex ETS).

variance_f32/1

variance_f32(A::[float()]) -> {ok, float()} | {error, term()}

A: List of floats

returns: {ok, Variance} | {error, Reason}

Compute variance of an f32 vector

variance_f64/1

variance_f64(A::[float()]) -> {ok, float()} | {error, term()}

A: List of doubles

returns: {ok, Variance} | {error, Reason}

Compute variance of an f64 vector


Generated by EDoc