Skip to content

Commit e2dfd48

Browse files
chore: add dev requirements, pytest tests and compatibility docs
1 parent c9dd748 commit e2dfd48

5 files changed

Lines changed: 97 additions & 13 deletions

File tree

CONTRIBUTING.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Dependencias Python principales del proyecto:
3939
- setuptools
4040
- wheel
4141

42+
Compatibilidad probada:
43+
44+
- OS: Windows 10/11
45+
- Python: 3.12.x
46+
- CUDA Toolkit: 12.8
47+
- Visual Studio: 18 2026 (x64)
48+
- CMake: 3.18+
49+
4250
## Configuración rápida del entorno (Windows)
4351

4452
1. Haz fork del repositorio en GitHub.
@@ -55,6 +63,7 @@ python -m venv venv
5563
.\venv\Scripts\Activate.ps1
5664
python -m pip install --upgrade pip
5765
pip install .
66+
python -m pip install -r requirements-dev.txt
5867
```
5968

6069
## Verificación básica
@@ -82,7 +91,7 @@ Pruebas rápidas después del build:
8291
```powershell
8392
python -c "import ttensor; print('OK')"
8493
python examples/xor_cpu.py
85-
python -m unittest tests/test_import_smoke.py
94+
python -m pytest -q tests
8695
```
8796

8897
## Flujo recomendado para contribuir

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@ Nuestra meta es convertir a T-Tensor en un motor educativo de alto rendimiento.
6666

6767
## 2. Instalacion
6868

69+
### ✅ Compatibilidad probada
70+
71+
Estas combinaciones han sido verificadas en el proyecto:
72+
73+
| Componente | Versiones probadas |
74+
|---|---|
75+
| OS | Windows 10/11 |
76+
| Python | 3.12.x |
77+
| CUDA Toolkit | 12.8 |
78+
| Visual Studio | 18 2026 (x64) |
79+
| CMake | 3.18+ |
80+
81+
### 🧰 Entorno de desarrollo (contributors)
82+
83+
Para contribuir y ejecutar tests/lint localmente:
84+
85+
```powershell
86+
python -m pip install --upgrade pip
87+
python -m pip install -r requirements-dev.txt
88+
```
89+
6990
### 🔧 Desde el repositorio (compilacion desde fuente)
7091

7192
```bash
@@ -101,7 +122,7 @@ Smoke test recomendado:
101122
```powershell
102123
python -c "import ttensor; print('OK')"
103124
python examples/xor_cpu.py
104-
python -m unittest tests/test_import_smoke.py
125+
python -m pytest -q tests
105126
```
106127

107128
---

requirements-dev.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pytest>=8.2
2+
pytest-cov>=5.0
3+
black>=24.8
4+
ruff>=0.6
5+
mypy>=1.11
6+
cmake>=3.18
7+
pybind11>=2.11

tests/test_import_smoke.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
"""Smoke test basico para el paquete Python de T-Tensor."""
22

3-
import unittest
43

4+
def test_import_ttensor() -> None:
5+
import ttensor # noqa: F401
56

6-
class TestImportSmoke(unittest.TestCase):
7-
def test_import_ttensor(self) -> None:
8-
try:
9-
import ttensor # noqa: F401
10-
except Exception as exc:
11-
self.fail(f"No se pudo importar ttensor: {exc}")
12-
13-
14-
if __name__ == "__main__":
15-
unittest.main()

tests/test_tensor_core.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Pruebas unitarias base para operaciones de Tensor y autograd."""
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
7+
from ttensor import Device
8+
from ttensor import DeviceManager
9+
from ttensor import Tensor
10+
11+
12+
def _has_gpu() -> bool:
13+
try:
14+
DeviceManager.initialize()
15+
return DeviceManager.device_count() > 0
16+
except Exception:
17+
return False
18+
19+
20+
def test_tensor_add_cpu() -> None:
21+
a = Tensor.from_list([1.0, 2.0, 3.0, 4.0], rows=2, cols=2, device=Device.CPU, requires_grad=False)
22+
b = Tensor.from_list([10.0, 20.0, 30.0, 40.0], rows=2, cols=2, device=Device.CPU, requires_grad=False)
23+
24+
c = Tensor.add(a, b)
25+
26+
assert c.tolist() == [11.0, 22.0, 33.0, 44.0]
27+
28+
29+
def test_autograd_square_grad_cpu() -> None:
30+
x = Tensor.from_list([3.0], rows=1, cols=1, device=Device.CPU, requires_grad=True)
31+
32+
y = Tensor.mul(x, x) # f(x) = x^2
33+
y.backward()
34+
35+
assert x.grad is not None
36+
assert x.grad.item() == pytest.approx(6.0, rel=1e-6, abs=1e-6)
37+
38+
39+
def test_matmul_cpu_gpu_consistency() -> None:
40+
if not _has_gpu():
41+
pytest.skip("No hay GPU CUDA disponible en este entorno")
42+
43+
values_a = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
44+
values_b = [7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
45+
46+
a_cpu = Tensor.from_list(values_a, rows=2, cols=3, device=Device.CPU, requires_grad=False)
47+
b_cpu = Tensor.from_list(values_b, rows=3, cols=2, device=Device.CPU, requires_grad=False)
48+
out_cpu = Tensor.matmul(a_cpu, b_cpu).tolist()
49+
50+
a_gpu = Tensor.from_list(values_a, rows=2, cols=3, device=Device.GPU, requires_grad=False)
51+
b_gpu = Tensor.from_list(values_b, rows=3, cols=2, device=Device.GPU, requires_grad=False)
52+
out_gpu = Tensor.matmul(a_gpu, b_gpu).tolist()
53+
54+
assert len(out_cpu) == len(out_gpu)
55+
for cpu_v, gpu_v in zip(out_cpu, out_gpu):
56+
assert gpu_v == pytest.approx(cpu_v, rel=1e-5, abs=1e-5)

0 commit comments

Comments
 (0)