Skip to content

Instantly share code, notes, and snippets.

View cgarciae's full-sized avatar

Cristian Garcia cgarciae

View GitHub Profile
@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 / 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
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 / 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
@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 / 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 / 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 / task_pool.py
Last active June 6, 2019 18:57
task_pool.py
import asyncio
class TaskPool(object):
def __init__(self, workers):
self._semaphore = asyncio.Semaphore(workers)
self._tasks = set()
async def put(self, coro):
@cgarciae
cgarciae / client-async-as-completed.py
Last active September 23, 2018 15:21
client-async-as-completed.py
# client-async-as-completed.py
from aiohttp import ClientSession, TCPConnector
import asyncio
from itertools import islice
import sys
def limited_as_completed(coros, limit):
futures = [
asyncio.ensure_future(c)
@cgarciae
cgarciae / client-async-sem.py
Last active May 9, 2022 00:28
client-async-sem.py
# client-async-sem.py
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
limit = 1000
async def fetch(url, session):
async with session.get(url) as response: