1+ #!/usr/bin/env python3
2+ """
3+ Test script for Pyroid
4+ """
5+
6+ import sys
7+ import os
8+
9+ # Add the project directory to the Python path
10+ sys .path .insert (0 , os .path .abspath ('.' ))
11+
12+ try :
13+ import pyroid
14+ print (f"Successfully imported pyroid version { pyroid .__version__ } " )
15+ except ImportError as e :
16+ print (f"Failed to import pyroid: { e } " )
17+ sys .exit (1 )
18+
19+ # Test vector operations
20+ try :
21+ v1 = pyroid .math .Vector ([1 , 2 , 3 ])
22+ v2 = pyroid .math .Vector ([4 , 5 , 6 ])
23+ v3 = v1 + v2
24+ print (f"Vector sum: { v3 } " )
25+ print (f"Dot product: { v1 .dot (v2 )} " )
26+ except Exception as e :
27+ print (f"Vector operations error: { e } " )
28+
29+ # Test matrix operations
30+ try :
31+ m1 = pyroid .math .Matrix ([[1 , 2 ], [3 , 4 ]])
32+ m2 = pyroid .math .Matrix ([[5 , 6 ], [7 , 8 ]])
33+ m3 = m1 * m2
34+ print (f"Matrix product: { m3 } " )
35+ except Exception as e :
36+ print (f"Matrix operations error: { e } " )
37+
38+ # Test statistical functions
39+ try :
40+ numbers = [1 , 2 , 3 , 4 , 5 ]
41+ mean = pyroid .math .stats .mean (numbers )
42+ median = pyroid .math .stats .median (numbers )
43+ std_dev = pyroid .math .stats .calc_std (numbers )
44+ print (f"Mean: { mean } , Median: { median } , StdDev: { std_dev } " )
45+ except Exception as e :
46+ print (f"Statistical functions error: { e } " )
47+
48+ # Test image operations
49+ try :
50+ img = pyroid .image .basic .create_image (100 , 100 , 3 )
51+ for x in range (50 ):
52+ for y in range (50 ):
53+ img .set_pixel (x , y , [255 , 0 , 0 ]) # Red square
54+ grayscale_img = img .to_grayscale ()
55+ print (f"Created image: { img .width } x{ img .height } with { img .channels } channels" )
56+ print (f"Grayscale image: { grayscale_img .width } x{ grayscale_img .height } with { grayscale_img .channels } channels" )
57+ except Exception as e :
58+ print (f"Image operations error: { e } " )
59+
60+ # Test ML operations
61+ try :
62+ data = [
63+ [1.0 , 2.0 ], [1.5 , 1.8 ], [5.0 , 8.0 ],
64+ [8.0 , 8.0 ], [1.0 , 0.6 ], [9.0 , 11.0 ]
65+ ]
66+ result = pyroid .ml .basic .kmeans (data , k = 2 )
67+ print (f"K-means centroids: { result ['centroids' ]} " )
68+ print (f"K-means clusters: { result ['clusters' ]} " )
69+ except Exception as e :
70+ print (f"ML operations error: { e } " )
71+
72+ print ("All tests completed." )
0 commit comments