Skip to content

Instantly share code, notes, and snippets.

View FrancescAlted's full-sized avatar

Francesc Alted FrancescAlted

View GitHub Profile
# Examples on getting orthogonal slices
import iarray as ia
import numpy as np
dtype = np.float32
ia.set_config_defaults(dtype=dtype)
@FrancescAlted
FrancescAlted / udf_expr.py
Created May 10, 2022 10:54
Calling UDFs from expressions
# Calling scalar UDFs from expressions.
# This is for 1-dim arrays.
from time import time
import numpy as np
import iarray as ia
from iarray import udf
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from iarray.udf import jit, Array, float64, int64
# Create second array via an UDF
@jit()
def tri(out: Array(float64, 2), x: Array(float64, 2), k: int64) -> int64:
n = out.window_shape[0]
m = out.window_shape[1]
row_start = out.window_start[0]
col_start = out.window_start[1]
for i in range(n):
c = ia.matmul(am, bm)
@FrancescAlted
FrancescAlted / ia-matmul-excerpt2.py
Created March 15, 2022 08:24
Actual iarray matmul call
# Random values with lossy compression to get some decent compression ratio
am = ia.random.normal(amshape, 3, 2, chunks=amchunks, blocks=amblocks, urlpath=filename, fp_mantissa_bits=10)
@FrancescAlted
FrancescAlted / ia-matmul-excerpt1.py
Last active March 15, 2022 08:20
Matmul with ironArray (preparation)
nrows = 100_000 # number of rows in matrix am
ncols = 25000 # number of columns in first matrix
ncols2 = 1000 # number of columns in second matrix
shape = (nrows, ncols, ncols2)
amshape = (shape[0], shape[1])
bmshape = (shape[1], shape[2])
# Obtain optimal chunk and block shapes
mparams = ia.matmul_params(amshape, bmshape, dtype=np.float64)
precip_trans_expr = ia.tan(precip1) * (ia.sin(precip1) * ia.sin(precip2) + ia.cos(precip2)) + ia.sqrt(precip3) * 2
precip_trans = precip_trans_expr.eval(urlpath="trans-3m.iarr", mode="w")
@FrancescAlted
FrancescAlted / out-of-core-eval.py
Created January 28, 2022 09:54
Example of an out-of-core evaluation
precip_expr = ia.expr_from_string("(p1 + p2 + p3) / 3",
{'p1': precip1, 'p2': precip2, 'p3': precip3},
)
precip_mean = precip_expr.eval(urlpath="mean-3m.iarr", mode="w")