Skip to content

Instantly share code, notes, and snippets.

View maxwellpirtle's full-sized avatar

Maxwell Pirtle maxwellpirtle

View GitHub Profile
@maxwellpirtle
maxwellpirtle / ddt.hpp
Created January 13, 2024 00:52
An implementation of a double dispatch table in C++ that uses RTTI to dynamically dispatch calls to pointer-to-member functions
#pragma once
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
template <typename InterfaceType, typename FunctionType>
struct double_dispatch_member_function_table;
@maxwellpirtle
maxwellpirtle / iterative-subsets.py
Created February 15, 2023 12:40
A implementation to generate all possible subsets of size `k` of a collection of size `n` iteratively (i.e. without recursion)
def range_inclusive(start, stop, step=1):
"""A convenience function over Python's range which includes
the last element specified in the range
Python's range function excludes the `stop` element. In
general this is ok. But it's confusing enough with all of
the indices when iterating subsets that it's more intuitive
to have a range function that includes the final index
"""
return range(start, stop - 1, step) if step < 0 else range(start, stop + 1, step)
import sys
import math
try:
import numpy as np
print(f'Using numpy version {np.__version__}')
except:
print(f'Numpy is needed for this demo', file=sys.stderr)
exit(1)
ushort
divceil(ushort a, ushort b) {
return a % b == 0 ? a / b : a / b + 1;
}
/// Quickly samples a (2N + 1) x (2N + 1) region for each
/// thread
///
/// This is a generalization of the sampling
/// described in "Discover Advances in Metal for A15 Bionic"

Keybase proof

I hereby claim:

  • I am maxwellpirtle on github.
  • I am maxwellpirtle (https://keybase.io/maxwellpirtle) on keybase.
  • I have a public key ASA2JxKDCGWuknFRqavVw9Xee8ZnqYUxRGaStiiSTOMnFwo

To claim this, I am signing this object: