Skip to content

Instantly share code, notes, and snippets.

View csullivan's full-sized avatar

Chris Sullivan csullivan

  • NVIDIA
  • Portland
View GitHub Profile
template<typename ...Args>
void hist(bool conditional, TRuntimeObjects& obj, Args&&... args) {
if (conditional) { obj.FillHistogram(std::forward<Args>(args)...); }
}
@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>
@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 / 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 / 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 / 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 / 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 / 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 / stability.ipynb
Created October 15, 2017 21:08
Exploring conditioning, floating point errors, and stability of algorithms
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@csullivan
csullivan / type_erasure.cc
Last active October 25, 2017 16:10
Example of type erasure with C++ templates
class Base {
public:
Base* interface_method(...) {
// this function could read in a file, and based on a
// a string determine the type that needs to be used
// and then the builder is set using set_builder<T>()
// now, internally you can use builder->build(...) to
// build the child that you want