Skip to content

Instantly share code, notes, and snippets.

"""Converts between the RGB and CIECAM02 color spaces."""
from collections import namedtuple
from functools import partial
import colour
from colour.utilities import tsplit, tstack
import numpy as np
from scipy.optimize import fmin_l_bfgs_b
import pyparsing as pp
from pyparsing import pyparsing_common as ppc
from repl import repl
variables = {}
var = ppc.identifier.copy()
def do_var(t):
import pyparsing as pp
from pyparsing import pyparsing_common as ppc
from repl import repl
class Node:
def __init__(self, name, *args):
self.name = name
self.items = args
@crowsonkb
crowsonkb / ewma.py
Last active September 30, 2018 19:00
import numpy as np
class EWMA:
"""An exponentially weighted moving average with initialization bias correction."""
def __init__(self, shape=(), dtype=np.float64, beta=0.9, correct_bias=True):
self.beta = beta
self.beta_accum = 1 if correct_bias else 0
self.value = np.zeros(shape, dtype)
@crowsonkb
crowsonkb / capture.py
Created December 16, 2018 03:14
Captures and returns an argument passed to a lambda expression.
"""Captures and returns an argument passed to a lambda expression."""
class Capture:
"""Captures and returns an argument passed to a lambda expression.
:param fn: The lambda expression.
:type fn: function
:Example:
import inspect
import typing
from typing import get_type_hints, TypeVar, Any, AnyStr, Generic, Union
from sphinx.util import logging
from sphinx.util.inspect import Signature
try:
from typing_extensions import Protocol
except ImportError:
@crowsonkb
crowsonkb / format_fragments.py
Created January 6, 2019 05:50
The prompt-toolkit utility function format_fragments().
"""The prompt-toolkit utility function :func:`format_fragments`."""
from prompt_toolkit.formatted_text import FormattedText
def format_fragments(fragments, *args, **kwargs):
"""Applies :meth:`str.format` to each text fragment in `fragments`.
Args:
fragments (FormattedText): The input list of text fragments.
@crowsonkb
crowsonkb / benchmark.py
Last active January 27, 2019 00:01
A with-statement context manager to benchmark code.
"""A with-statement context manager to benchmark code."""
import time
__all__ = ['Benchmark']
class Benchmark:
"""A with-statement context manager to benchmark code."""
def __init__(self, timer=time.perf_counter):
name: "thing"
layer {
name: "data"
type: "Data"
top: "big_data"
top: "label"
include { phase: TRAIN }
transform_param {
mean_value: 103.939
mean_value: 116.779
@crowsonkb
crowsonkb / site.cfg
Last active July 25, 2019 11:31
site.cfg for building scipy against MKL on macOS
# This file provides configuration information about non-Python dependencies for
# numpy.distutils-using packages. Create a file like this called "site.cfg" next
# to your package's setup.py file and fill in the appropriate sections. Not all
# packages will use all sections so you should leave out sections that your
# package does not use.
# To assist automatic installation like easy_install, the user's home directory
# will also be checked for the file ~/.numpy-site.cfg .
# The format of the file is that of the standard library's ConfigParser module.