Download app_cpppy/test.py from xtumu/vm: direct link, hf CLI and curl.
- Browser
- Download file 828 Bytes
-
https://huggingface.co/spaces/xtumu/vm/resolve/main/app_cpppy/test.py
- Command line
-
hf download hf://spaces/xtumu/vm/app_cpppy/test.py
-
curl -L -o test.py https://huggingface.co/spaces/xtumu/vm/resolve/main/app_cpppy/test.py
828 Bytes
| import numpy as np | |
| import time | |
| import os | |
| import sys | |
| import app_cpppy # 导入C++扩展 | |
| def python_matmul(x, y): | |
| return np.dot(x, y) | |
| size = 1000 | |
| a = np.random.rand(size, size).astype(np.float64) | |
| b = np.random.rand(size, size).astype(np.float64) | |
| try: | |
| # 测试C++扩展 | |
| start = time.time() | |
| cpp_result = app_cpppy.matrix_multiply(a, b) | |
| cpp_time = time.time() - start | |
| except Exception as e: | |
| cpp_time = time.time() - start | |
| cpp_result = f'❌ Import failed: {e}' | |
| # 测试Python实现 | |
| start = time.time() | |
| py_result = python_matmul(a, b) | |
| py_time = time.time() - start | |
| # 验证结果一致性 | |
| diff = np.abs(cpp_result - py_result).max() | |
| res = { | |
| "cpp_time": cpp_time, | |
| "python_time": py_time, | |
| "speedup": py_time / cpp_time if cpp_time > 0 else 0, | |
| "max_difference": diff, | |
| "matrix_size": size | |
| } | |
| print(res) | |