def test_size(n: int = 10): a = np.ones(n) b = np.ones(n) c = np.ones(n) d = np.ones(n) assert size(a, b, c, d) == n
def test_size_error(): x = np.ones(10) y = np.ones(10) z = np.ones(5) with pytest.raises(ValueError): n = size(x, y, z)
def grad(self, predicted: Tensor, target: Tensor) -> float: n = size(predicted, target) return 2 * (predicted - target) / n
def loss(self, predicted: Tensor, target: Tensor) -> float: n = size(predicted, target) return np.sum((predicted - target)**2) / n
def test_size_one(n: int = 10): x = np.ones(n) assert size(x) == n
def test_size_no_args(): with pytest.raises(ValueError): n = size()