This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------- | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Base.Threads | |
using LoopVectorization | |
using BenchmarkTools | |
const None = [CartesianIndex()] | |
function distances(data1, data2) | |
data1 = deg2rad.(data1) | |
data2 = deg2rad.(data2) | |
lat1 = @view data1[:, 1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Base.Threads | |
using Distributions | |
using BenchmarkTools | |
ENV["PYCALL_JL_RUNTIME_PYTHON"] = Sys.which("python") | |
using PyCall | |
py""" | |
import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# client-task-pool.py | |
from aiohttp import ClientSession, TCPConnector | |
import asyncio | |
import sys | |
from pypeln.task import TaskPool | |
limit = 1000 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
class TaskPool(object): | |
def __init__(self, workers): | |
self._semaphore = asyncio.Semaphore(workers) | |
self._tasks = set() | |
async def put(self, coro): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |