sied (sied v0.2.6)

View Source

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.

Summary

Functions

Compute absolute value of an f32 vector

Compute absolute value of an f64 vector

Element-wise addition of two f32 vectors

Element-wise addition of two f64 vectors

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

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

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

Cosine similarity between two f64 vectors.

Element-wise division of two f32 vectors

Element-wise division of two f64 vectors

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 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.

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

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

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

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.

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 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 (Euclidean) norm of an f32 vector

L2 (Euclidean) norm of an f64 vector

L2-normalize a batch of f32 vectors.

L2-normalize a batch of f64 vectors.

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

L2-normalize an f64 vector to unit length.

Element-wise maximum of two f32 vectors

Element-wise maximum of two f64 vectors

Find maximum value in an f32 vector

Find maximum value in an f64 vector

Compute arithmetic mean of an f32 vector

Compute arithmetic mean of an f64 vector

Element-wise minimum of two f32 vectors

Element-wise minimum of two f64 vectors

Find minimum value in an f32 vector

Find minimum value in an f64 vector

Element-wise multiplication of two f32 vectors

Element-wise multiplication of two f64 vectors

Negate an f32 vector (multiply by -1)

Negate an f64 vector (multiply by -1)

Compute square root of an f32 vector

Compute square root of an f64 vector

Compute standard deviation of an f32 vector

Compute standard deviation of an f64 vector

Element-wise subtraction of two f32 vectors

Element-wise subtraction of two f64 vectors

Compute sum of all elements in an f32 vector

Compute sum of all elements in an f64 vector

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.

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).

Compute variance of an f32 vector

Compute variance of an f64 vector

Functions

abs_f32(A)

-spec abs_f32([float()]) -> {ok, [float()]} | {error, term()}.

Compute absolute value of an f32 vector

abs_f64(A)

-spec abs_f64([float()]) -> {ok, [float()]} | {error, term()}.

Compute absolute value of an f64 vector

add_f32(A, B)

-spec add_f32([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise addition of two f32 vectors

add_f64(A, B)

-spec add_f64([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise addition of two f64 vectors

cosine_similarity_batch_f32(Query, Vecs)

-spec cosine_similarity_batch_f32([float()], [[float()]]) -> {ok, [float()]} | {error, term()}.

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

cosine_similarity_batch_f64(Query, Vecs)

-spec cosine_similarity_batch_f64([float()], [[float()]]) -> {ok, [float()]} | {error, term()}.

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

cosine_similarity_f32(A, B)

-spec cosine_similarity_f32([float()], [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(A, B)

-spec cosine_similarity_f64([float()], [float()]) -> {ok, float()} | {error, term()}.

Cosine similarity between two f64 vectors.

divide_f32(A, B)

-spec divide_f32([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise division of two f32 vectors

divide_f64(A, B)

-spec divide_f64([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise division of two f64 vectors

dot_product_batch_f32(Query, Vecs)

-spec dot_product_batch_f32([float()], [[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(Query, Vecs)

-spec dot_product_batch_f32_bin(binary(), [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(Query, Vecs)

-spec dot_product_batch_f64([float()], [[float()]]) -> {ok, [float()]} | {error, term()}.

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

dot_product_f32(A, B)

-spec dot_product_f32([float()], [float()]) -> {ok, float()} | {error, term()}.

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

dot_product_f64(A, B)

-spec dot_product_f64([float()], [float()]) -> {ok, float()} | {error, term()}.

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

dot_product_topk_flat(Query, FlatF32, VecByteLen, Indices)

-spec dot_product_topk_flat(binary(), binary(), pos_integer(), [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(Query, Vecs)

-spec hamming_distance_batch(binary(), [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(Query, FlatVecs, VecLen, TopK)

-spec hamming_topk_flat(binary(), binary(), pos_integer(), 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(A)

-spec l2_norm_f32([float()]) -> {ok, float()} | {error, term()}.

L2 (Euclidean) norm of an f32 vector

l2_norm_f64(A)

-spec l2_norm_f64([float()]) -> {ok, float()} | {error, term()}.

L2 (Euclidean) norm of an f64 vector

l2_normalize_batch_f32(Vecs)

-spec l2_normalize_batch_f32([[float()]]) -> {ok, [[float()]]} | {error, term()}.

L2-normalize a batch of f32 vectors.

l2_normalize_batch_f64(Vecs)

-spec l2_normalize_batch_f64([[float()]]) -> {ok, [[float()]]} | {error, term()}.

L2-normalize a batch of f64 vectors.

l2_normalize_f32(A)

-spec l2_normalize_f32([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(A)

-spec l2_normalize_f64([float()]) -> {ok, [float()]} | {error, term()}.

L2-normalize an f64 vector to unit length.

max_elementwise_f32(A, B)

-spec max_elementwise_f32([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise maximum of two f32 vectors

max_elementwise_f64(A, B)

-spec max_elementwise_f64([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise maximum of two f64 vectors

max_f32(A)

-spec max_f32([float()]) -> {ok, float()} | {error, term()}.

Find maximum value in an f32 vector

max_f64(A)

-spec max_f64([float()]) -> {ok, float()} | {error, term()}.

Find maximum value in an f64 vector

mean_f32(A)

-spec mean_f32([float()]) -> {ok, float()} | {error, term()}.

Compute arithmetic mean of an f32 vector

mean_f64(A)

-spec mean_f64([float()]) -> {ok, float()} | {error, term()}.

Compute arithmetic mean of an f64 vector

min_elementwise_f32(A, B)

-spec min_elementwise_f32([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise minimum of two f32 vectors

min_elementwise_f64(A, B)

-spec min_elementwise_f64([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise minimum of two f64 vectors

min_f32(A)

-spec min_f32([float()]) -> {ok, float()} | {error, term()}.

Find minimum value in an f32 vector

min_f64(A)

-spec min_f64([float()]) -> {ok, float()} | {error, term()}.

Find minimum value in an f64 vector

multiply_f32(A, B)

-spec multiply_f32([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise multiplication of two f32 vectors

multiply_f64(A, B)

-spec multiply_f64([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise multiplication of two f64 vectors

negate_f32(A)

-spec negate_f32([float()]) -> {ok, [float()]} | {error, term()}.

Negate an f32 vector (multiply by -1)

negate_f64(A)

-spec negate_f64([float()]) -> {ok, [float()]} | {error, term()}.

Negate an f64 vector (multiply by -1)

sqrt_f32(A)

-spec sqrt_f32([float()]) -> {ok, [float()]} | {error, term()}.

Compute square root of an f32 vector

sqrt_f64(A)

-spec sqrt_f64([float()]) -> {ok, [float()]} | {error, term()}.

Compute square root of an f64 vector

std_dev_f32(A)

-spec std_dev_f32([float()]) -> {ok, float()} | {error, term()}.

Compute standard deviation of an f32 vector

std_dev_f64(A)

-spec std_dev_f64([float()]) -> {ok, float()} | {error, term()}.

Compute standard deviation of an f64 vector

subtract_f32(A, B)

-spec subtract_f32([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise subtraction of two f32 vectors

subtract_f64(A, B)

-spec subtract_f64([float()], [float()]) -> {ok, [float()]} | {error, term()}.

Element-wise subtraction of two f64 vectors

sum_f32(A)

-spec sum_f32([float()]) -> {ok, float()} | {error, term()}.

Compute sum of all elements in an f32 vector

sum_f64(A)

-spec sum_f64([float()]) -> {ok, float()} | {error, term()}.

Compute sum of all elements in an f64 vector

to_binary_f32(Vec)

-spec to_binary_f32([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(Data)

-spec to_binary_f32_bin(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(A)

-spec variance_f32([float()]) -> {ok, float()} | {error, term()}.

Compute variance of an f32 vector

variance_f64(A)

-spec variance_f64([float()]) -> {ok, float()} | {error, term()}.

Compute variance of an f64 vector