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 os | |
| import psutil | |
| from time import time | |
| import numpy as np | |
| import blosc2 | |
| # --- Experiment Setup --- | |
| n_frames = 1000 # Raise this for more frames | |
| width, height = np.array((n_frames, n_frames)) # Size of the grid |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| area_circle = ia.nansum(circle) | |
| area_square = ia.nansum(square) | |
| print(f"PI estimate: {4 * area_circle / area_square}") |
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
| expr = ia.expr_from_udf(filter_func, | |
| [rand_data], | |
| [shape[0], shape[1], True]) | |
| circle = expr.eval() |
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
| expr = ia.expr_from_udf(filter_func, | |
| [rand_data], | |
| [shape[0], shape[1], False]) | |
| square = expr.eval() |
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
| @udf.jit() | |
| def filter_func(out: udf.Array(udf.float32, 2), | |
| vals: udf.Array(udf.float32, 2), | |
| nrows: udf.int64, ncols: udf.int64, | |
| iscircle: udf.bool) -> udf.int32: | |
| 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): |
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
| @udf.scalar() | |
| def square_filter(val: udf.float32) -> udf.float32: | |
| if val >= 0.5: | |
| return 1. | |
| return math.nan |
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 iarray as ia | |
| shape = (40_000, 40_000) | |
| ia.set_config_defaults(dtype=np.float32, fp_mantissa_bits=15) | |
| rand_data = ia.random.random_sample(shape) |
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
| @udf.scalar() | |
| def circle_filter(val: udf.float32, row: udf.int64, col: udf.int64, | |
| nrows: udf.int64, ncols: udf.int64) -> udf.float32: | |
| x = (2. * row / nrows) - 1. | |
| y = (2. * col / ncols) - 1. | |
| if ((x ** 2 + y ** 2) <= 1) and val >= 0.5: | |
| return 1. | |
| return math.nan |
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
| @udf.scalar() | |
| def circle_filter(val: udf.float32, row: udf.int64, col: udf.int64, | |
| nrows: udf.int64, ncols: udf.int64) | |
| -> udf.float32: | |
| x = (2. * row / nrows) - 1. | |
| y = (2. * col / ncols) - 1. | |
| if ((x ** 2 + y ** 2) <= 1) and val >= 0.5: | |
| return 1. | |
| return math.nan |
NewerOlder