Skip to content

Instantly share code, notes, and snippets.

@luoyetx
luoyetx / get_logger.py
Created August 3, 2017 12:02
get logger in python
import logging
def get_logger(name=None):
"""return a logger
"""
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
sh = logging.StreamHandler()
sh.setLevel(logging.INFO)
@luoyetx
luoyetx / recdb.py
Last active July 12, 2017 02:27
RecordDb is an esay interface to save (image, label) data to `mx.record`
"""RecordDb is an esay interface to save (image, label) data to `mx.record`
"""
import random
import mxnet as mx
class RecDb(object):
"""Interface to save (image, label) to `mx.record`
"""
@luoyetx
luoyetx / dmr.py
Created November 7, 2016 11:52
a simple map-reduce for data processing pipeline
import multiprocessing as mp
class Job(object):
'''Job present a data processing pipeline with mapper and reducer
'''
def __init__(self, name, mapper, reducer, worker_n):
'''initialize Job object with given mapper and reducer
Parameters
@luoyetx
luoyetx / reduce.cu
Created October 24, 2016 15:44
simple Reduce && Scan in CUDA
__global__ void reduce_kernel(float* d_in, int n, float* d_out) {
extern __shared__ float shared_mem[];
int tid = threadIdx.x;
int i = threadIdx.x + blockDim.x * blockIdx.x;
if (i < len) {
shared_mem[tid] = d_in[i];
}
else {
shared_mem[tid] = 0;
@luoyetx
luoyetx / CMakeLists.txt
Created October 7, 2016 12:11
CMakeLists.txt for CUDA
### CMakeLists.txt for CUDA
cmake_minimum_required(VERSION 2.8)
find_package(CUDA QUIET REQUIRED)
# Pass options to NVCC
set(
CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-O3 -gencode arch=compute_22,code=sm_22
@luoyetx
luoyetx / a.py
Created September 5, 2016 07:18
solve an email address
import math
ps = [
0.0000008110673199286165000000000000000000,
0.0000162907226016170940000000000000000000,
0.0024177576053697383000000000000000000000,
0.0000000054649286143693143000000000000000,
0.0003272079103201879800000000000000000000,
0.0000000148552161462659780000000000000000,
{
"color_scheme": "Packages/Theme - Afterglow/Afterglow.tmTheme",
"default_line_ending": "system",
"font_size": 14,
"ignored_packages":
[
"Vintage"
],
"tab_size": 2,
"tabs_medium": true,
#ifdef DEBUG
#define cudaCheckError(ans) { cudaAssert((ans), __FILE__, __LINE__); }
inline void cudaAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
fprintf(stderr, "CUDA Error: %s at %s:%d\n",
cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
@luoyetx
luoyetx / LOG.c
Created August 2, 2016 02:47
logging
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
void LOG(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
char msg[256];
vsprintf(msg, fmt, args);
va_end(args);
@luoyetx
luoyetx / timer.h
Last active February 28, 2023 10:37
macros for time evaluation
#include <chrono>
/*! \brief Timer */
class Timer {
using Clock = std::chrono::high_resolution_clock;
public:
/*! \brief start or restart timer */
inline void Tic() {
start_ = Clock::now();
}