mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2025-12-05 19:17:52 -06:00
Fix integration tests: Dense -> Linear alias
This commit is contained in:
@@ -20,7 +20,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import numpy as np
|
||||
from tinytorch.core.tensor import Tensor
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.activations import ReLU
|
||||
from tinytorch.core.training import CrossEntropyLoss
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import numpy as np
|
||||
from tinytorch.core.tensor import Tensor
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.activations import ReLU
|
||||
from tinytorch.core.training import CrossEntropyLoss
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import numpy as np
|
||||
from tinytorch.core.tensor import Tensor
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.activations import ReLU
|
||||
|
||||
# Try to import transformer components
|
||||
|
||||
@@ -172,7 +172,7 @@ def test_modern_api_integration():
|
||||
# Test 5: Backward compatibility integration
|
||||
try:
|
||||
# Test old names still work
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.spatial import MultiChannelConv2D
|
||||
|
||||
dense = Dense(5, 3)
|
||||
|
||||
@@ -24,7 +24,7 @@ def test_layers_integration():
|
||||
print("Test 1: Layer + Tensor integration")
|
||||
try:
|
||||
from tinytorch.core.tensor import Tensor
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
|
||||
layer = Dense(3, 2)
|
||||
x = Tensor(np.random.randn(5, 3))
|
||||
|
||||
@@ -18,12 +18,12 @@ class TestDenseModuleExports:
|
||||
|
||||
def test_dense_class_exports(self):
|
||||
"""Test Dense class exports from layers module."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
assert Dense is not None, "Dense class should be exported"
|
||||
|
||||
def test_dense_is_callable(self):
|
||||
"""Test Dense can be instantiated."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
layer = Dense(10, 5)
|
||||
assert layer is not None, "Should create Dense layer instance"
|
||||
assert hasattr(layer, 'forward'), "Dense should have forward method"
|
||||
@@ -34,7 +34,7 @@ class TestDenseLayerFunctionality:
|
||||
|
||||
def test_dense_forward_pass(self):
|
||||
"""Test Dense layer forward pass produces correct shape."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
# Create layer
|
||||
@@ -53,7 +53,7 @@ class TestDenseLayerFunctionality:
|
||||
|
||||
def test_dense_with_bias(self):
|
||||
"""Test Dense layer with bias enabled."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
layer = Dense(10, 5, bias=True)
|
||||
@@ -66,7 +66,7 @@ class TestDenseLayerFunctionality:
|
||||
|
||||
def test_dense_without_bias(self):
|
||||
"""Test Dense layer with bias disabled."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
layer = Dense(10, 5, bias=False)
|
||||
@@ -78,7 +78,7 @@ class TestDenseLayerFunctionality:
|
||||
|
||||
def test_dense_callable_interface(self):
|
||||
"""Test Dense layer can be called directly."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
layer = Dense(10, 5)
|
||||
@@ -109,7 +109,7 @@ class TestNetworkComposition:
|
||||
|
||||
def test_multi_layer_network(self):
|
||||
"""Test building a multi-layer network."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.activations import ReLU, Sigmoid
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
@@ -141,7 +141,7 @@ class TestXORCapability:
|
||||
|
||||
def test_xor_network_structure(self):
|
||||
"""Test building XOR network structure."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.activations import ReLU, Sigmoid
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ def test_autograd_integration():
|
||||
print("Test 1: Gradient flow through layers")
|
||||
try:
|
||||
from tinytorch.core.tensor import Tensor
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.training import MeanSquaredError
|
||||
|
||||
# Create simple network
|
||||
|
||||
@@ -104,7 +104,7 @@ def test_layer_integration():
|
||||
|
||||
def test_dense_integration():
|
||||
"""Test Dense layer integration with Tensor."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.tensor import Tensor
|
||||
import numpy as np
|
||||
|
||||
@@ -119,7 +119,7 @@ def test_dense_integration():
|
||||
|
||||
def test_dense_with_tensor():
|
||||
"""Test that Dense properly uses Tensor for weights/bias."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
layer = Dense(10, 5, use_bias=True)
|
||||
@@ -133,7 +133,7 @@ def test_dense_with_tensor():
|
||||
|
||||
def test_dense_with_activations():
|
||||
"""Test Dense layer works with activation functions."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.activations import ReLU, Sigmoid
|
||||
from tinytorch.core.tensor import Tensor
|
||||
import numpy as np
|
||||
@@ -163,7 +163,7 @@ def test_dense_with_activations():
|
||||
|
||||
def test_multi_layer_network():
|
||||
"""Test building multi-layer networks with Dense."""
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.tensor import Tensor
|
||||
import numpy as np
|
||||
|
||||
@@ -269,7 +269,7 @@ def test_autograd_integration():
|
||||
def test_optimizer_integration():
|
||||
"""Test optimizers work with layers."""
|
||||
from tinytorch.core.optimizers import SGD
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
|
||||
layer = Dense(10, 5)
|
||||
optimizer = SGD(learning_rate=0.01)
|
||||
@@ -282,7 +282,7 @@ def test_optimizer_integration():
|
||||
def test_training_loop_integration():
|
||||
"""Test training loop integrates optimizer and autograd."""
|
||||
from tinytorch.core.training import Trainer
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.layers import Linear as Dense
|
||||
from tinytorch.core.optimizers import SGD
|
||||
from tinytorch.core.losses import MSELoss
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
Reference in New Issue
Block a user