Skip to content

Instantly share code, notes, and snippets.

View raghavrv's full-sized avatar

(Venkat) Raghav, Rajagopalan raghavrv

View GitHub Profile
@raghavrv
raghavrv / undecorate_python.py
Last active June 27, 2017 11:54
Undecorate an object python2.7 or 3.5
from types import FunctionType
import inspect
def undecorate(func):
funcs = []
# python 3.5
if hasattr(func, '__wrapped__'):
while hasattr(func, '__wrapped__'):
func = func.__wrapped__
@raghavrv
raghavrv / struct_member_ptr.pyx
Created May 16, 2017 11:08
Advance a pointer by sizeof(struct) for a struct member in an array of struct
%%cython
# cython: wraparound=False
# cython: boundscheck=False
# cython: cdivision=True
# cython: nonecheck=False
# cython: profile=False
cimport numpy as np
import numpy as np
@raghavrv
raghavrv / cython_numpy_struct.pyx
Created May 1, 2017 13:11
cython struct interplaying with numpy struct without memory reallocation
from cpython cimport Py_INCREF, PyObject
from libc.stdlib cimport malloc, free, calloc, realloc
import numpy as np
cimport numpy as np
np.import_array()
from sklearn.externals import joblib
@raghavrv
raghavrv / split_record.pyx
Created April 30, 2017 22:40
The new SplitRecord
cdef struct SplitRecord:
# Data to track sample splitting process
# This structure also store the best split found so far
SIZE_t feature # Which feature to split on.
SIZE_t start
SIZE_t end
SIZE_t pos # Split samples array at the given position,
# i.e. count of samples below threshold for feature.
# pos is >= end if the node is a leaf.
@raghavrv
raghavrv / new_tree.md
Last active April 30, 2017 22:50
New tree builder classes

New structure of tree builders/splitter/criterion

So right now what I've come up with is this:

A new criterion (only for mse) which will compute the stats for all the nodes. The criterion design will be as much similar as possible to the old one.

Two important data structures -

  • (node_stats numpy double array)
@raghavrv
raghavrv / extra_trees_memory_leak_check.md
Created March 24, 2017 23:43
I don't think this is a memory leak either. The residual is due to OS's mem. caching - Ref: http://stackoverflow.com/a/35121766
import os, time, gc, psutil
from pympler import tracker

import numpy as np
from sklearn.ensemble import ExtraTreesClassifier

tracker.memory_tracker = tracker.SummaryTracker()
def get_mem():
    return "{:.0f}MB".format(p.memory_info().rss / 1e6)
@raghavrv
raghavrv / random_forest_memory_leak_check.md
Created March 24, 2017 23:42
Nopes. No memory leaks...
import os, time, gc, psutil
from pympler import tracker

import numpy as np
from sklearn.ensemble import RandomForestRegressor

tracker.memory_tracker = tracker.SummaryTracker()
def get_mem():
    return "{:.0f}MB".format(p.memory_info().rss / 1e6)
@raghavrv
raghavrv / logistic_regression_memory_test.md
Created March 24, 2017 23:15
This ain't memory leak (I think)

Test script

import os, time, gc, psutil
from pympler import tracker

import numpy as np
from sklearn.linear_model import LogisticRegression

tracker.memory_tracker = tracker.SummaryTracker()
@raghavrv
raghavrv / url_in_title.js
Last active March 16, 2017 13:12
Greasemonkey script to add URL to end of current page title
// ==UserScript==
// @name URL in title
// @version 0.1
// @description try to take over the world!
// @author Raghav RV
// @updateURL https://gist.githubusercontent.com/raghavrv/eb2f44b43ef7d3287327a5fd5e3ee205/raw/url_in_title.js
// @downloadURL https://gist.githubusercontent.com/raghavrv/eb2f44b43ef7d3287327a5fd5e3ee205/raw/url_in_title.js
// @include http://*/*
// @include https://*/*
// @grant unsafeWindow
@raghavrv
raghavrv / keybase.md
Created March 14, 2017 14:10
Keybase

Keybase proof

I hereby claim:

  • I am raghavrv on github.
  • I am raghavrv (https://keybase.io/raghavrv) on keybase.
  • I have a public key whose fingerprint is B127 1CD1 4F49 36C3 2FD0 2992 E301 E3AA 24EB 94A7

To claim this, I am signing this object: