Skip to content

Instantly share code, notes, and snippets.

View csullivan's full-sized avatar

Chris Sullivan csullivan

  • NVIDIA
  • Portland
View GitHub Profile
@csullivan
csullivan / least_squares.ipynb
Last active October 9, 2017 00:50
Least squares using QR, and L2 regularization
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@csullivan
csullivan / qr_decomp.ipynb
Created October 1, 2017 22:06
Matrix QR Decompositions
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@csullivan
csullivan / CM2Lab.ipynb
Last active September 15, 2017 18:42
Center of Mass to Lab frame conversion
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@csullivan
csullivan / cereal_polymorphic_serialization.cc
Last active March 13, 2025 22:44
polymorphic data serialization example with cereal
#include <iostream>
#include <vector>
#include <memory>
#include <cereal/archives/binary.hpp>
#include <cereal/types/vector.hpp>
#include <cereal/types/string.hpp>
#include <cereal/types/base_class.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/access.hpp>
@csullivan
csullivan / CRTP.cc
Created June 27, 2017 19:26
Compile time polymorphism: avoiding the short commings of virtual functions with the curiously recursive template pattern.
#include <iostream>
class Base {
public:
Base() { ; }
~Base() { ; }
};
template <typename Derived>
@csullivan
csullivan / range_map.hh
Created May 9, 2017 21:20
A simple key-range containter. If a key is within a range, the corresponding value is returned. O(log n)
template<typename KeyType, typename ValueType>
class range_map {
public:
range_map() { ; }
range_map(std::initializer_list<std::pair<KeyType,ValueType>> list) {
for (auto& pair : list) {
keys.push_back(pair.first);
values.push_back(pair.second);
}
}
@csullivan
csullivan / duck_typing_with_recursive_templates.cc
Last active February 20, 2017 15:28
Example showing how something like duck typing can be resolved by the compiler using the curiously recursive template pattern in C++14
#include <iostream>
#include <string>
#include <vector>
#include <set>
class Base {
};
template <typename T>
template<typename ...Args>
void hist(bool conditional, TRuntimeObjects& obj, Args&&... args) {
if (conditional) { obj.FillHistogram(std::forward<Args>(args)...); }
}
S - Set of all nodes with no inbound connections (NodeType::Input)
-- Enumerating all paths
paths = {}
for each node n in S do
visit(n,{})
function visit(node n, list l)
if n is not in l then
@csullivan
csullivan / constraint_template_example.cc
Last active July 28, 2016 16:04
An example using c++ constraints and concept templates
// Function template constraint (implicit or "ad-hoc")
template<typename T> requires
requires (T a) { a + a; } &&
requires (T b) { b * b; } &&
requires (T c) { sqrt(c); }
T Magnitude(vector<T>&& vec) {
T sum;
for (auto& const i : vec) { sum += i*i; }
return sqrt(sum);