Skip to content

Instantly share code, notes, and snippets.

#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/arrayobject.h>
#include <iostream>
static PyObject* create_zero_array(PyObject* self, PyObject* args);
static PyMethodDef NpMethods[] = {
{"create_zero_array", create_zero_array, METH_VARARGS, "create zero array of specified size"},
cmake_minimum_required(VERSION 3.13)
project(np_test)
execute_process(
COMMAND "python3" -c "import numpy; print(numpy.get_include(), end='')"
OUTPUT_VARIABLE NUMPY_INCLUDE_DIRS
RESULT_VARIABLE NUMPY_NOTFOUND)
find_package(PythonLibs 3 REQUIRED)
import bisect
import random
import pytest
import numpy as np
from quantize import quantize
from time import time
def quantize_slow(x, n):
def test_shape():
arr = np.random.normal(size=(2,1,2,3,1,4,5))
boundaries, quantized = quantize(arr, 20)
assert np.all(quantized.shape == arr.shape)
boundaries_slow, quantized_slow = quantize_slow(arr.reshape(-1), 20)
boundaries_slow = boundaries_slow.reshape(boundaries.shape)
quantized_slow = quantized_slow.reshape(quantized.shape)
(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
#include <array>
#include <type_traits>
#include <cstddef>
template <class ValueType, bool is_const>
class ContiguousContainerView {
using CQualValueType = std::conditional_t<is_const, const ValueType, ValueType>;
public:
using DerefT = CQualValueType&;
using PointerT = CQualValueType*;
#include <type_traits>
#include <iostream>
// Template magic to test if class has .METHOD
#define ENABLEHASMETHOD(METHOD) \
template <class T__> \
struct Has_##METHOD { \
template <class U__, class = decltype(&(U__::METHOD))> \
static const std::true_type Tester(U__*); \
\
#include <type_traits>
#include <cassert>
template <class T>
struct Clone {
template <class Dummy = void>
auto operator()(const T& val) const {
static_assert(!std::is_same_v<Dummy, void>, "Clone trait not implemented");
}
};
@npetrenko
npetrenko / BaseConcept.hpp
Last active September 24, 2019 16:35
Using concepts for matching CRTP inheritance
#include <type_traits>
template <class Derived>
class Base {
public:
int Create() const {
return static_cast<const Derived&>(*this).CreateImpl();
}
};
#include <benchmark/benchmark.h>
void LockedAdd(benchmark::State& state) {
unsigned int val;
while (state.KeepRunning()) {
asm volatile("lock addl $1, %[val]" : [val] "=m"(val));
benchmark::DoNotOptimize(val);
}
}