Skip to content

Instantly share code, notes, and snippets.

Avatar

Bryan Catanzaro bryancatanzaro

View GitHub Profile
View get_optional.cpp
template<typename T>
struct get_optional_visit {
template<typename U>
std::optional<T> operator()(U) const {
return std::optional<T>();
}
std::optional<T> operator()(const T& t) const {
return std::optional<T>(t);
}
@bryancatanzaro
bryancatanzaro / apply_tuple_to_function.cpp
Last active Mar 4, 2016
Call a function by expanding a tuple as its arguments.
View apply_tuple_to_function.cpp
#include <iostream>
#include <tuple>
/******************
* Implementation *
******************/
//If you're using C++14, just use std::integer_sequence
//instead of all this index_seq stuff
template<unsigned... Indices>
View log_linear.cpp
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <cmath>
std::vector<float> make_log_linear(size_t n,
int linear,
int subbin) {
std::vector<float> result;
@bryancatanzaro
bryancatanzaro / count.py
Last active Dec 29, 2015
A simple script for counting recurring sentences.
View count.py
import sys
import re
import operator
if __name__ == '__main__':
filename = sys.argv[1]
f = open(filename, 'r')
sentences = {}
current_sentence = ''
@bryancatanzaro
bryancatanzaro / test.cu
Created Jul 20, 2012
Using uniform_sequence
View test.cu
#include <iostream>
#include <prelude/sequences/uniform_sequence.h>
#include <prelude/runtime/tags.h>
#include <thrust/host_vector.h>
#include <thrust/copy.h>
#include <thrust/iterator/counting_iterator.h>
typedef copperhead::cpp_tag Tag;
@bryancatanzaro
bryancatanzaro / gist:3146033
Created Jul 19, 2012
Simple sequential thrust program
View gist:3146033
//Define the system to be OpenMP to remove all CUDA references
#define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_OMP
#include <thrust/host_vector.h>
#include <thrust/fill.h>
#include <thrust/reduce.h>
#include <iostream>
template<typename T>
struct my_reduction {
typedef T result_type;
@bryancatanzaro
bryancatanzaro / thrust_demo.py
Created May 22, 2012
PyCUDA/Thrust interop
View thrust_demo.py
import pycuda
import pycuda.autoinit
import pycuda.gpuarray as gpuarray
import numpy as np
from codepy.cgen import *
from codepy.bpl import BoostPythonModule
from codepy.cuda import CudaModule
#Make a host_module, compiled for CPU
You can’t perform that action at this time.