Skip to content

Instantly share code, notes, and snippets.

View Enet4's full-sized avatar

Eduardo Pinho Enet4

View GitHub Profile
@Enet4
Enet4 / rpn.rs
Created February 25, 2016 11:22
// A simple RPN calculator
use std::env;
fn main() {
let args = env::args().skip(1).collect::<Vec<String>>();
let mut stack:Vec<f64> = vec![];
for token in args {
match token.as_ref() {
"+" => add(&mut stack),
"-" => sub(&mut stack),

Keybase proof

I hereby claim:

  • I am Enet4 on github.
  • I am e_net4 (https://keybase.io/e_net4) on keybase.
  • I have a public key whose fingerprint is B218 D92A A7CF F49A 0342 F859 EA9F 08ED 7359 D0E9

To claim this, I am signing this object:

.
├── AutoTune.h
├── AuxIndexStructures.h
├── Clustering.h
├── FaissException.h
├── IndexFlat.h
├── Index.h
├── IndexIVFFlat.h
├── IndexIVF.h
├── IndexIVFPQ.h
/// Opaque type for IndexFlat
typedef FaissIndex_H FaissIndexFlat;
/// Default constructor
int faiss_IndexFlat_new(FaissIndexFlat** p_index);
/// Constructor with dimensionality and distance metric parameters
int faiss_IndexFlat_new_with(FaissIndexFlat** index, idx_t d, FaissMetricType metric);
/// attempt a dynamic cast to a flat index
/// Declare an opaque type for a class type `clazz`.
#define FAISS_DECLARE_CLASS(clazz) \
typedef struct Faiss ## clazz ## _H Faiss ## clazz;
/// Declare an opaque type for a class type `clazz`, while
/// actually aliasing it to an existing parent class type `parent`.
#define FAISS_DECLARE_CLASS_INHERITED(clazz, parent) \
typedef struct Faiss ## parent ## _H Faiss ## clazz;
/// Declare a getter for the field `name` in class `clazz`,
int faiss_IndexFlat_new_with(FaissIndexFlat** p_index, idx_t d, FaissMetricType metric) {
try {
IndexFlat* index = new IndexFlat(d, static_cast<faiss::MetricType>(metric));
*p_index = reinterpret_cast<FaissIndexFlat*>(index);
return 0;
} catch (faiss::FaissException& e) {
// ... handle error?
return -2;
} catch (std::exception& e) {
return -4;
int faiss_Index_search(const FaissIndex* index, idx_t n, const float* x, idx_t k,
float* distances, idx_t* labels) {
try {
reinterpret_cast<const faiss::Index*>(index)->search(n, x, k, distances, labels);
} CATCH_AND_HANDLE
}
// ------------ in error_c.h ----------------
/**
* Get the error message of the last failed operation performed by Faiss.
* The given pointer is only valid until another Faiss function is called.
*/
const char* faiss_get_last_error();
// ------------ in error_impl.cpp --------------
@Enet4
Enet4 / faiss_c_snippet.mk
Created March 31, 2018 15:10
Faiss C API Makefile snippet
# Build dynamic library
$(CLIBNAME).$(SHAREDEXT): $(LIBCOBJ) ../$(LIBNAME).a
$(CXX) $(LDFLAGS) $(FAISSSHAREDFLAGS) -o $@ \
-Wl,--whole-archive $^ $(BLASLDFLAGS) -Wl,--no-whole-archive -static-libstdc++
@Enet4
Enet4 / build.rs
Created April 8, 2018 23:12
faiss-sys build script
#[cfg(feature = "gpu")]
const LIBNAME: &str = "gpufaiss_c";
#[cfg(not(feature = "gpu"))]
const LIBNAME: &str = "faiss_c";
fn main() {
println!("cargo:rustc-link-lib={}", LIBNAME);
}