Skip to content

Instantly share code, notes, and snippets.

View cgarciae's full-sized avatar

Cristian Garcia cgarciae

View GitHub Profile
@cgarciae
cgarciae / client-task-pool.py
Last active May 14, 2022 23:00
client-task-pool.py
# client-task-pool.py
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
from pypeln.task import TaskPool
limit = 1000
@cgarciae
cgarciae / client-pypeln-io.py
Last active July 6, 2020 16:32
client-pypeln-io.py
# client-pypeln-pl.task.py
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
import pypeln as pl
limit = 1000
urls = ("http://localhost:8080/{}".format(i) for i in range(int(sys.argv[1])))
@cgarciae
cgarciae / test.py
Last active April 26, 2020 14:46
python distance functions
import typing as tp
from jax import numpy as jnp
import jax
import numpy as np
import time
@jax.jit
def _distances_jax(data1, data2):
@cgarciae
cgarciae / test.jl
Last active April 26, 2020 04:36
julia distance function + python imports
using Base.Threads
using Distributions
using BenchmarkTools
ENV["PYCALL_JL_RUNTIME_PYTHON"] = Sys.which("python")
using PyCall
py"""
import sys
using Base.Threads
using LoopVectorization
using BenchmarkTools
const None = [CartesianIndex()]
function distances(data1, data2)
data1 = deg2rad.(data1)
data2 = deg2rad.(data2)
lat1 = @view data1[:, 1]
@cgarciae
cgarciae / erasure.nim
Last active December 16, 2022 21:38
Type Erasure in Nim
#-------------------------------------------------------------
# types
#-------------------------------------------------------------
type C = concept type C
proc name(x: C, msg: string): string
type AnyC = object
name: proc(msg: string): string # doesn't contain C
type A = object
@cgarciae
cgarciae / tabular.py
Last active June 2, 2020 00:14
Tablular Attention
def get_model(params) -> tf.keras.Model:
x0 = tf.keras.Input(shape=(1,), name="x0")
x1 = tf.keras.Input(shape=(1,), name="x1")
inputs = [x0, x1]
# x0 embeddings
@cgarciae
cgarciae / test.py
Last active June 12, 2020 14:34
simple pypeln test
import pypeln as pl
import time
from random import random
def slow_add1(x):
time.sleep(random()) # <= some slow computation
return x + 1
def slow_gt3(x):
time.sleep(random()) # <= some slow computation
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
import pypeln as pl
limit = 1000
urls = ("http://localhost:8080/{}".format(i) for i in range(int(sys.argv[1])))
@cgarciae
cgarciae / haiku-accuracy.py
Last active July 8, 2020 01:04
Simple cumulative accuracy metric using Haiku and Jax.
class Accuracy(hk.Module):
def __init__(self, y_true: jnp.ndarray, y_pred: jnp.ndarray) -> jnp.ndarray:
total = hk.get_state(
"total", shape=[], dtype=jnp.float32, init=hk.initializers.Constant(0)
)
count = hk.get_state(
"count", shape=[], dtype=jnp.int64, init=hk.initializers.Constant(0)
)