Skip to content

Instantly share code, notes, and snippets.

View DannyWeitekamp's full-sized avatar

DannyWeitekamp

  • Carnegie Mellon University
  • Pittsburgh, PA
View GitHub Profile
@DannyWeitekamp
DannyWeitekamp / str_float.py
Created October 21, 2023 02:40
Implementing str(float) in numba
import numba
import numpy as np
import numba
from numba import types, jit,njit, generated_jit
from numba import deferred_type, optional
from numba import void,b1,u1,u2,u4,u8,i1,i2,i4,i8,f4,f8,c8,c16
from numba.typed import List, Dict
from numba.types import ListType, unicode_type, UnicodeType
from numba.cpython.unicode import _empty_string, _set_code_point, _get_code_point, PY_UNICODE_1BYTE_KIND
from numba.extending import overload, overload_method
@DannyWeitekamp
DannyWeitekamp / numba_fast_func_calls.py
Last active November 17, 2022 19:26
Examples of how to speed up python execution of numba compiled functions
from numba import njit, cfunc
from numba.types import unicode_type, i8
import time
class PrintElapse():
def __init__(self, name):
self.name = name
def __enter__(self):
self.t0 = time.time_ns()/float(1e6)
def __exit__(self,*args):
@DannyWeitekamp
DannyWeitekamp / Numba_Iterator.py
Created September 4, 2022 22:59
Example of writing an iterator for Interval() struct shown in the numba docs
from numba import njit, f8
from numba.typed import List
from numba.extending import models, register_model
class Interval(object):
"""
A half-open interval on the real number line.
"""
def __init__(self, lo, hi):
self.lo = lo
from numba import njit, f8
from numba.typed import List
from numba.extending import models, register_model
class Interval(object):
"""
A half-open interval on the real number line.
"""
# Chris Questions:
# Calling all inputs and outputs 'foas' is a little confusing?
# In training why does HowSearch run at the beginning and then only get used when there are no explanations?
# Nitty Gritty Questions:
# Does the when learner need to include foas & selection in search?
# -How do we support the possibility that it does/doesn't
# -are there accuracy/opp differences if only operating on the state without expanding / querying over all the foas/selections?
@DannyWeitekamp
DannyWeitekamp / javaBrdsToHTML.py
Last active January 15, 2019 02:27
Turns BRDs built for java CTAT to BRDs for html
import sys, glob, os, re
print(len(sys.argv))
if(len(sys.argv) < 3):
print("Proper Usage:")
print("%s <input.brd or folder w/ .brds> <output file or folder>" % sys.argv[0])
exit()
inp = os.path.abspath(sys.argv[1]);
out = os.path.abspath(sys.argv[2]);
@DannyWeitekamp
DannyWeitekamp / Attention.py
Created July 12, 2017 09:25 — forked from cbaziotis/Attention.py
Keras Layer that implements an Attention mechanism for temporal data. Supports Masking. Follows the work of Raffel et al. [https://arxiv.org/abs/1512.08756]
class Attention(Layer):
def __init__(self,
W_regularizer=None, b_regularizer=None,
W_constraint=None, b_constraint=None,
bias=True, **kwargs):
"""
Keras Layer that implements an Attention mechanism for temporal data.
Supports Masking.
Follows the work of Raffel et al. [https://arxiv.org/abs/1512.08756]
# Input shape
@DannyWeitekamp
DannyWeitekamp / AttentionWithContext.py
Created July 12, 2017 09:25 — forked from cbaziotis/AttentionWithContext.py
Keras Layer that implements an Attention mechanism, with a context/query vector, for temporal data. Supports Masking. Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] "Hierarchical Attention Networks for Document Classification"
class AttentionWithContext(Layer):
"""
Attention operation, with a context/query vector, for temporal data.
Supports Masking.
Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf]
"Hierarchical Attention Networks for Document Classification"
by using a context vector to assist the attention
# Input shape
3D tensor with shape: `(samples, steps, features)`.
# Output shape