This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <thread> | |
#include <chrono> | |
#include <atomic> | |
int message = 1; | |
std::atomic<int> sync_dummy{0}; | |
void Write() { | |
message = 0; | |
sync_dummy.fetch_add(0, std::memory_order_relaxed); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
template <class Derived> | |
class Base { | |
public: | |
int Create() const { | |
return static_cast<const Derived&>(*this).CreateImpl(); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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__*); \ | |
\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bisect | |
import random | |
import pytest | |
import numpy as np | |
from quantize import quantize | |
from time import time | |
def quantize_slow(x, n): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder