Skip to content

Instantly share code, notes, and snippets.

View inoryy's full-sized avatar
:octocat:

Roman Ring inoryy

:octocat:
View GitHub Profile
import tensorflow as tf
class TfCategorical:
def __init__(self, logits):
self.logits = logits
self.probs = tf.nn.softmax(logits)
def sample(self):
u = tf.random_uniform(tf.shape(self.logits))
#!/home/inoryy/anaconda3/bin/python
import sys, time
from math import sqrt, acos, pi, cos, sin
from decimal import Decimal, ROUND_HALF_UP
class Point(object):
__slots__ = 'x', 'y'
def __init__(self, x, y):
@inoryy
inoryy / mcts.cpp
Last active January 25, 2019 10:29
Node* mcts(Node* root) {
save();
while (true) {
if (TIME >= TIME_LIMIT) break;
// select
Node* node = root;
while (!isTerminal() && node->isExpanded()) {
node = node->uctChild();
apply(node->action);
@inoryy
inoryy / pnorm.py
Created March 16, 2016 17:35
Normal Distribution via Box–Muller transform
from random import random
from math import log, cos, sin, sqrt, pi
# Implementation of Box-Muller transform to
# generate two random numbers from N(mu, sigma) distribution
def pnorm(mu = 0, sigma = 1):
r = sqrt(-2*log(random()))
a = 2*pi*random()
return sigma*r*cos(a) + mu, sigma*r*sin(a) + mu
#!/usr/bin/env python
import sys, re, os
DEFAULT_MAIN = 'main.cpp'
DEFAULT_OUT = 'arena.cpp'
BUNDLE_SYM = '// ###'
def bundle(flname, main = False):
base = os.path.dirname(flname)
@inoryy
inoryy / _results.md
Last active December 28, 2022 07:54
Fixing MKL on AMD Zen CPU.

Fixing MKL on AMD Zen CPU

As per discussion on Reddit, it seems a workaround for the Intel MKL's notorious SIMD throttling of AMD Zen CPUs is as simple a setting MKL_DEBUG_CPU_TYPE=5 environment variable.

Benchmarks

All three scripts are executed in the same Python 3.7 environment on a first-gen AMD Zen CPU (1950x).
The difference will be even bigger on newer models as first-gen Zen resolves 256-bit AVX2 in two 128-bit instructions.