Skip to content

Instantly share code, notes, and snippets.

View snk4tr's full-sized avatar
👨‍💻
Building predictive models

Sergey Kastryulin snk4tr

👨‍💻
Building predictive models
View GitHub Profile
@snk4tr
snk4tr / functional_df_bench.py
Last active March 1, 2019 14:51
Benchmark of PyFunctional library in compression with procedural approach when applied to map/reduce on Pandas DataFrame
import pandas as pd
import numpy as np
from itertools import product
from time import time
from functional import seq, pseq
from pipe import *
from typing import Callable
@snk4tr
snk4tr / benchmark.py
Created February 25, 2019 15:55 — forked from RomanSteinberg/benchmark.py
Benchmark parallel execution
from multiprocessing import Process, Queue, Event
from queue import Empty as QueueEmpty
from random import randint, seed
from time import monotonic as now
from datetime import timedelta
TASKS_COUNT = 12
ARRAY_SIZE = 2_000_000
POOL_SIZE = 2
import functools
import cv2
from skimage import io
from PIL import Image
def time_logger(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
@snk4tr
snk4tr / functional_wrapper.py
Last active July 31, 2018 07:47
This gist shows the way to reduce python code size and complexity with some elements of functional programming.
class FunctionalWrapper(object):
def __init__(self, data):
self.data = data
def map(self, function):
"""Call `map` on the items in `data` using the provided `function`"""
return FunctionalWrapper(list(map(function, self.data)))
def reduce(self, function):
"""Call `reduce` on the items in `data` using the provided `function`"""
return list(reduce(function, self.data))
def filter(self, function):
#A plain vanilla BST
class BSTNode(object):
"""A node in the vanilla BST tree."""
def __init__(self, parent, k):
"""Creates a node.
Args:
parent: The node's parent.