Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion recipes/recipes_emscripten/numpy/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ rm -r -f branding

export CFLAGS="$CFLAGS -Wno-return-type -Wno-implicit-function-declaration"
export MESON_CROSS_FILE=$RECIPE_DIR/emscripten.meson.cross
export LDFLAGS="$LDFLAGS -sWASM_BIGINT"
export LDFLAGS="$LDFLAGS -sWASM_BIGINT -sEXPORTED_FUNCTIONS=['_init_numpy'] -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=['sin','cos','exp','log']"



cp $RECIPE_DIR/config/config.h.in numpy/_core/config.h.in
#
Expand Down
2 changes: 1 addition & 1 deletion recipes/recipes_emscripten/numpy/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source:
url: https://github.com/numpy/numpy/releases/download/v${{ version }}/numpy-${{ version }}.tar.gz
sha256: e0486a11ec30cdecb53f184d496d1c6a20786c81e55e41640270130056f8ee48
build:
number: 0
number: 1

requirements:
build:
Expand Down
32 changes: 29 additions & 3 deletions recipes/recipes_emscripten/numpy/test_numpy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
def test_numpy():
import numpy
import numpy as np

ones = numpy.ones(shape=[2,3])
assert ones.shape == (2,3)
ones = np.ones(shape=[2,3])
assert ones.shape == (2,3)



# 1. Array creation & dtype
a = np.arange(6).reshape(2, 3)
print("Array a:\n", a, "dtype:", a.dtype)

# 2. Elementwise ops & broadcasting
b = np.ones((2, 1))
print("a + b (broadcasted):\n", a + b)

# 3. Reduction
print("Sum of a:", np.sum(a))

# 4. Matrix multiplication (BLAS check)
c = np.array([[1, 2], [3, 4]])
d = np.array([[5, 6], [7, 8]])
print("Matrix product c @ d:\n", c @ d)

# 5. Linear algebra (LAPACK check)
eigvals, eigvecs = np.linalg.eig(c)
print("Eigenvalues of c:", eigvals)

# 6. Random numbers
rng = np.random.default_rng(42)
print("Random sample:", rng.random(3))
Loading