This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// bucket_stats.cpp | |
#include <array> | |
#include <vector> | |
#include <unordered_map> | |
#include <random> | |
#include <iostream> | |
#include <algorithm> | |
#include <chrono> | |
#include <cstdint> | |
#include <numeric> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <vector> | |
#include <unordered_map> | |
#include <random> | |
#include <iostream> | |
#include <limits> | |
#include <cstdint> | |
#include <chrono> | |
constexpr size_t DIM = 128; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <cstdint> | |
#include <iostream> | |
#include <vector> | |
#include <random> | |
#include <chrono> | |
constexpr size_t NUM_BYTES = 1024; | |
constexpr int N = 10'000'000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <chrono> | |
#include <iostream> | |
#include <cstdint> | |
// -------------------------------------- | |
// Byte-based 256-bit bitset | |
// -------------------------------------- | |
struct ConstexprBitset256 { | |
std::array<uint8_t, 32> blocks{}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <arm_neon.h> | |
#include <array> | |
#include <cstdint> | |
#include <iostream> | |
#include <random> | |
#include <chrono> | |
struct ConstexprBitset256 { | |
uint8_t data[32]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <cmath> | |
#include <cstddef> | |
#include <algorithm> | |
#include <iostream> | |
// helper to compute ceiling of log2 at runtime | |
constexpr int ceil_log2(float x) { | |
return static_cast<int>(std::ceil(-std::log2(x))); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
⚡ Bit Operations Mini-Cheat Sheet | |
1️⃣ Integer division and modulo with powers of two | |
Operation Bit trick Explanation | |
x / 2 x >> 1 Right shift divides by 2 | |
x / 4 x >> 2 Right shift divides by 4 | |
x / 8 x >> 3 Right shift divides by 8 | |
x % 2 x & 1 Bitwise AND with 2^n - 1 for modulo | |
x % 4 x & 3 3 = 0b11 → remainder when dividing by 4 | |
x % 8 x & 7 7 = 0b111 → remainder when dividing by 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <array> | |
#include <cstdint> | |
#include <cstddef> | |
// ---------- ConstexprBitset ---------- | |
template<std::size_t N> | |
struct ConstexprBitset { | |
static constexpr std::size_t numBlocks = (N + 63) / 64; | |
std::array<uint64_t, numBlocks> blocks{}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <bitset> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
class HammingNeighborIterator { | |
public: | |
HammingNeighborIterator(uint16_t code, int numBits) | |
: code(code), numBits(numBits), radius(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <cstdint> | |
#include <iostream> | |
#include <cmath> | |
#include <numeric> | |
#include <bitset> | |
uint16_t quantizeVectorToBits(const std::vector<float>& vec, | |
int numBits, | |
bool useGlobalMean = false, |
NewerOlder