Skip to content

Instantly share code, notes, and snippets.

View mihaitodor's full-sized avatar
:shipit:
Shipit!

Mihai Todor mihaitodor

:shipit:
Shipit!
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/* Naive (conditional) and optimized (branchless) absolute value */
#include <ctime>
#include <iostream>
#include <functional>
using namespace std;
int abs_naive(const int i) {
return i < 0 ? -i : i;
#include <cmath>
#include <iostream>
using std::cout;
using std::endl;
float quake3_hack(float number) {
float x2 = number * 0.5f;
float y = number;
long i = *(long*) & y;
def find_ngrams(input_list, max_n):
return [map(lambda x: list(x), zip(*[input_list[i:] for i in range(n)])) for n in range(1, max_n+1)]
.global _start
_start:
LDR R0,=matrix0
LDR R1,=matrix1
LDR R2,=matrix2
LDR R3,=matrix3
@ Load Q0-Q3 with the data
# Find the location on the pythonpath from which
# the package was imported. This helps debug pythonpath
# priority-related conflicts.
def pkg_loc(module_name):
module = __import__(module_name, globals(), locals(), [], -1)
return module.__file__
# The two-pass and Welford's method implementations were taken
# verbatim from Wikipedia:
#
# https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
#
# Note that in addition to the numerical stability benefits of Welford's
# algorithm, the other benefit is that it's an online algorithm, so
# variance update with additional data has an incremental cost,
# without the need to recompute on all the data.
#
import ctypes as C
from ctypes.util import find_library
cuda = C.cdll.LoadLibrary(find_library("cudart"))
dev_ct = C.c_int()
dev_ct_addr = C.addressof(dev_ct)
dev_ct_ptr = C.cast(dev_ct_addr, C.POINTER(C.c_int))
error_t = cuda.cudaGetDeviceCount(dev_ct_ptr)
def static_var(name, value):
def helper(fun):
setattr(fun, name, value)
return fun
return helper
@static_var("my_var", 0)
@static_var("my_other_var", "HAL")
def foo():
import mxnet as mx
from mxnet.gluon.model_zoo import vision
import os
import time
batch_shape = (1, 3, 224, 224)
resnet18 = vision.resnet18_v2(pretrained=True)
resnet18.hybridize()
resnet18.forward(mx.nd.zeros(batch_shape))
resnet18.export('resnet18_v2')