SimSIMD icon indicating copy to clipboard operation
SimSIMD copied to clipboard

Sample program error

Open EricZequan opened this issue 1 year ago • 1 comments

Describe the bug

In the C program sample code in the readme:

#include <simsimd/simsimd.h>

int main() {
    simsimd_flush_denormals(); // Optional, to avoid performance penalties on denormal numbers

    simsimd_f32_t vector_a[1536];
    simsimd_f32_t vector_b[1536];
    simsimd_kernel_punned_t distance_function = simsimd_metric_punned(
        simsimd_metric_cos_k,   // Metric kind, like the angular cosine distance
        simsimd_datatype_f32_k, // Data type, like: f16, f32, f64, i8, b8, and complex variants
        simsimd_cap_any_k);     // Which CPU capabilities are we allowed to use
    simsimd_distance_t distance;
    distance_function(vector_a, vector_b, 1536, &distance);
    return 0;
}

it will throw a error : error: too many arguments to function call, expected 1, have 4 and I find the simsimd_kernel_punned_t:

/**
 *  @brief  Type-punned function pointer for a SimSIMD public interface.
 *
 *  Can be a `simsimd_metric_dense_punned_t`, `simsimd_metric_sparse_punned_t`, `simsimd_metric_curved_punned_t`,
 *  `simsimd_kernel_fma_punned_t`, or `simsimd_kernel_wsum_punned_t`.
 */
typedef void (*simsimd_kernel_punned_t)(void *);

I think it should be written like this?

simsimd_kernel_punned_t distance_function = simsimd_metric_punned(
        simsimd_metric_cos_k,   // Metric kind, like the angular cosine distance
        simsimd_datatype_f32_k, // Data type, like: f16, f32, f64, i8, b8, and complex variants
        simsimd_cap_any_k);     // Which CPU capabilities are we allowed to use
simsimd_distance_t distance;
metric = reinterpret_cast<simsimd_metric_dense_punned_t>(distance_function);
metric(vector_a, vector_b, 1536, &distance);

I don't know if it's a problem with my code or the readme document has not been updated. Could you please check it?

Steps to reproduce

Sample code issues

Expected behavior

run code successfully

SimSIMD version

v6.2.3

Operating System

macOS

Hardware architecture

Arm

Which interface are you using?

C implementation

Contact Details

No response

Are you open to being tagged as a contributor?

  • [x] I am open to being mentioned in the project .git history as a contributor

Is there an existing issue for this?

  • [x] I have searched the existing issues

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

EricZequan avatar Apr 21 '25 07:04 EricZequan

Yes, you are right, @EricZequan! Can you please submit a patch as a PR?

ashvardanian avatar Apr 24 '25 17:04 ashvardanian