-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumpy_test2.py
More file actions
46 lines (36 loc) · 1.68 KB
/
numpy_test2.py
File metadata and controls
46 lines (36 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import numpy as np
import time
def test_numpy_installation():
print(f"--- NumPy Sanity Check ---")
print(f"Version: {np.__version__}")
assert np.__version__ == "1.26.4", f"Version mismatch! Found {np.__version__}"
try:
# 1. Test basic array creation and math
print("\n1. Testing array creation and broadcasting...")
a = np.arange(10)
b = a * 2 + 1
expected = np.array([1, 3, 5, 7, 9, 11, 13, 15, 17, 19])
np.testing.assert_array_equal(b, expected)
print(" -> Array math OK")
# 2. Test Random Number Generation (uses bit generators in 1.26+)
print("2. Testing random number generation...")
rng = np.random.default_rng(seed=42)
rand_matrix = rng.random((500, 500))
print(f" -> Generated 500x500 random matrix. Mean: {rand_matrix.mean():.4f} (Expected ~0.5)")
# 3. Test Linear Algebra (verifies BLAS/LAPACK linking)
print("3. Testing Linear Algebra (Matrix Multiplication & Eigenvalues)...")
start_time = time.time()
# Matrix multiplication
c = rand_matrix @ rand_matrix.T
# Eigenvalue decomposition (computationally heavy)
eigenvalues, _ = np.linalg.eigh(c)
elapsed = time.time() - start_time
print(f" -> LinAlg operations completed in {elapsed:.4f} seconds")
print(f" -> Max eigenvalue: {eigenvalues.max():.4f}")
print("\n NumPy 1.26.4 is installed and functioning correctly!")
except AssertionError as e:
print(f"\nL Test Failed: {e}")
except Exception as e:
print(f"\nL Unexpected Error: {e}")
if __name__ == "__main__":
test_numpy_installation()