# [CS5871] Module 2 checks
# Table of Contents
1. [Code](#section_1)
1. [[TODO] Task 2.1 & 2.2: function signature incompatible with Python3.7](#1.1)
2. [[TODO] Task 2.3: Correct task number in the code](#1.2)
3. [[TODO] Task 2.3: Function to be implemented not mentioned in the assignment](#1.3)
4. [Import conflicts with scalar](#1.4)
5. [style errors on copy files](#1.5)
4. [Writeup](#section_2)
Related link:
- [How to check assignment (by Celine)](https://github.com/srush/miniTorch/blob/master/how_to_check_assignment.md)
- [Assignment Module 2](https://minitorch.github.io/module2/module2/#guides)
---
## 1. Code <a name="section_1"></a>
### 1.1 [TODO] Task 2.1 & 2.2: function signature incompatible with Python3.7<a name="1.1"></a>
**Issue**:
In [`tensor_ops.py`, L23](https://github.com/minitorch/Module-2/blob/master/minitorch/tensor_ops.py#L23), the notation
```
def __call__(self, x: Tensor, out: Optional[Tensor] = ..., /) -> Tensor:
...
```
will return `SyntaxError` when running `pytest -m task2_1` or `pytest -m task2_2` in Python3.7.
**Full error message**:
```
> pytest -m task2_1
================================================================================================================== test session starts ===================================================================================================================
platform darwin -- Python 3.7.13, pytest-7.1.2, pluggy-1.0.0
plugins: hypothesis-6.54.0, env-0.6.2
collected 0 items / 2 errors
========================================================================================================================= ERRORS =========================================================================================================================
_________________________________________________________________________________________________________ ERROR collecting tests/test_tensor.py __________________________________________________________________________________________________________
../mtmod2_py3.7/lib/python3.7/site-packages/_pytest/python.py:608: in _importtestmodule
mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
../mtmod2_py3.7/lib/python3.7/site-packages/_pytest/pathlib.py:533: in import_path
importlib.import_module(module_name)
../../.pyenv/versions/3.7.13/lib/python3.7/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1006: in _gcd_import
???
<frozen importlib._bootstrap>:983: in _find_and_load
???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:677: in _load_unlocked
???
../mtmod2_py3.7/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:168: in exec_module
exec(co, module.__dict__)
tests/test_tensor.py:7: in <module>
from minitorch import MathTestVariable, Tensor, grad_check, tensor
minitorch/__init__.py:3: in <module>
from .tensor import * # noqa: F401,F403
minitorch/tensor.py:15: in <module>
from .tensor_functions import (
minitorch/tensor_functions.py:16: in <module>
from .tensor_ops import SimpleBackend, TensorBackend
E File "/Users/hf/git_ta_cs5781/mle-module-2-annshin/minitorch/tensor_ops.py", line 23
E def __call__(self, x: Tensor, out: Optional[Tensor] = ..., /) -> Tensor: # = ..., /) -> Tensor:
E ^
E SyntaxError: invalid syntax
_______________________________________________________________________________________________________ ERROR collecting tests/test_tensor_data.py _______________________________________________________________________________________________________
../mtmod2_py3.7/lib/python3.7/site-packages/_pytest/python.py:608: in _importtestmodule
mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
../mtmod2_py3.7/lib/python3.7/site-packages/_pytest/pathlib.py:533: in import_path
importlib.import_module(module_name)
../../.pyenv/versions/3.7.13/lib/python3.7/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1006: in _gcd_import
???
<frozen importlib._bootstrap>:983: in _find_and_load
???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:677: in _load_unlocked
???
../mtmod2_py3.7/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:168: in exec_module
exec(co, module.__dict__)
tests/test_tensor_data.py:5: in <module>
import minitorch
minitorch/__init__.py:3: in <module>
from .tensor import * # noqa: F401,F403
minitorch/tensor.py:15: in <module>
from .tensor_functions import (
minitorch/tensor_functions.py:16: in <module>
from .tensor_ops import SimpleBackend, TensorBackend
E File "/Users/hf/git_ta_cs5781/mle-module-2-annshin/minitorch/tensor_ops.py", line 23
E def __call__(self, x: Tensor, out: Optional[Tensor] = ..., /) -> Tensor: # = ..., /) -> Tensor:
E ^
E SyntaxError: invalid syntax
================================================================================================================ short test summary info =================================================================================================================
ERROR tests/test_tensor.py
ERROR tests/test_tensor_data.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=================================================================================================================== 2 errors in 1.56s ====================================================================================================================
```
**Solution**:
Tell students to use Python3.8+ .
Alternatively, removing the slash `/` in the function signature allows compatibility with Python3.8:
```
def __call__(self, x: Tensor, out: Optional[Tensor] = ...) -> Tensor:
...
```
, but ^^ this solution causes style error failures.
```
minitorch/tensor_ops.py:135: error: Incompatible return value type (got "Callable[[Tensor, Optional[Tensor]], Tensor]", expected "MapProto")
24
minitorch/tensor_ops.py:135: note: "MapProto.__call__" has type "Callable[[Arg(Tensor, 'x'), DefaultArg(Optional[Tensor], 'out')], Tensor]"
```
### 1.2 [TODO] Task 2.3: Correct task number in the code<a name="1.2"></a>
**Issue**:
The functions to be modified for [Tasks 2.3 in the assignment](https://minitorch.github.io/module2/module2/#guides) are marked with Task 2.**2** [in the code](https://github.com/minitorch/Module-2/blob/master/minitorch/tensor_ops.py).
**Solution**:
- [L271-272, tensor_map](https://github.com/minitorch/Module-2/blob/master/minitorch/tensor_ops.py#L271):
Change from
```
# TODO: Implement for Task 2.2.
raise NotImplementedError("Need to implement for Task 2.2")
```
to:
```
# TODO: Implement for Task 2.3.
raise NotImplementedError("Need to implement for Task 2.3")
```
- Same for [L321-322, tensor_zip](https://github.com/minitorch/Module-2/blob/master/minitorch/tensor_ops.py#L321)
- Same for [L357-358, tensor_reduce](https://github.com/minitorch/Module-2/blob/master/minitorch/tensor_ops.py#L357)
### 1.3 [TODO] Task 2.3: Function to be implemented not mentioned in the assignment<a name="1.3"></a>
**Issue**: `IsClose()` in [`tensor_functions.py`](https://github.com/minitorch/Module-2/blob/master/minitorch/tensor_functions.py#L207) requires to be implemented, but it's not in the [assignment in minitorch.github.io](https://minitorch.github.io/module2/module2/#guides).
**Solution**: Adding `isClose()` to the assignment page.
### 1.4 import conflicts with tensor and scalar functios<a name="1.4"></a>
**Issue**: Incompatible imports of the EQ, LT, Add, Exp, Inv, Log, Mul, Neg, ReLU, Sigmoid functions. Erorr message:
```
minitorch/__init__.py:7: error: Incompatible import of "EQ" (imported name has type "Type[minitorch.tensor_functions.EQ]", local name has type "Type[minitorch.scalar_functions.EQ]")
31
minitorch/__init__.py:7: error: Incompatible import of "LT" (imported name has type "Type[minitorch.tensor_functions.LT]", local name has type "Type[minitorch.scalar_functions.LT]")
32
minitorch/__init__.py:7: error: Incompatible import of "Add" (imported name has type "Type[minitorch.tensor_functions.Add]", local name has type "Type[minitorch.scalar_functions.Add]")
33
minitorch/__init__.py:7: error: Incompatible import of "Exp" (imported name has type "Type[minitorch.tensor_functions.Exp]", local name has type "Type[minitorch.scalar_functions.Exp]")
34
minitorch/__init__.py:7: error: Incompatible import of "Inv" (imported name has type "Type[minitorch.tensor_functions.Inv]", local name has type "Type[minitorch.scalar_functions.Inv]")
35
minitorch/__init__.py:7: error: Incompatible import of "Log" (imported name has type "Type[minitorch.tensor_functions.Log]", local name has type "Type[minitorch.scalar_functions.Log]")
36
minitorch/__init__.py:7: error: Incompatible import of "Mul" (imported name has type "Type[minitorch.tensor_functions.Mul]", local name has type "Type[minitorch.scalar_functions.Mul]")
37
minitorch/__init__.py:7: error: Incompatible import of "Neg" (imported name has type "Type[minitorch.tensor_functions.Neg]", local name has type "Type[minitorch.scalar_functions.Neg]")
38
minitorch/__init__.py:7: error: Incompatible import of "ReLU" (imported name has type "Type[minitorch.tensor_functions.ReLU]", local name has type "Type[minitorch.scalar_functions.ReLU]")
39
minitorch/__init__.py:7: error: Incompatible import of "Sigmoid" (imported name has type "Type[minitorch.tensor_functions.Sigmoid]", local name has type "Type[minitorch.scalar_functions.Sigmoid]")
40
minitorch/__init__.py:9: error: Incompatible import of "Neg" (imported name has type "Type[minitorch.tensor_functions.Neg]", local name has type "Type[minitorch.scalar_functions.Neg]")
41
minitorch/__init__.py:9: error: Incompatible import of "Inv" (imported name has type "Type[minitorch.tensor_functions.Inv]", local name has type "Type[minitorch.scalar_functions.Inv]")
42
minitorch/__init__.py:9: error: Incompatible import of "Add" (imported name has type "Type[minitorch.tensor_functions.Add]", local name has type "Type[minitorch.scalar_functions.Add]")
43
minitorch/__init__.py:9: error: Incompatible import of "Mul" (imported name has type "Type[minitorch.tensor_functions.Mul]", local name has type "Type[minitorch.scalar_functions.Mul]")
44
minitorch/__init__.py:9: error: Incompatible import of "Sigmoid" (imported name has type "Type[minitorch.tensor_functions.Sigmoid]", local name has type "Type[minitorch.scalar_functions.Sigmoid]")
45
minitorch/__init__.py:9: error: Incompatible import of "ReLU" (imported name has type "Type[minitorch.tensor_functions.ReLU]", local name has type "Type[minitorch.scalar_functions.ReLU]")
46
minitorch/__init__.py:9: error: Incompatible import of "Log" (imported name has type "Type[minitorch.tensor_functions.Log]", local name has type "Type[minitorch.scalar_functions.Log]")
47
minitorch/__init__.py:9: error: Incompatible import of "Exp" (imported name has type "Type[minitorch.tensor_functions.Exp]", local name has type "Type[minitorch.scalar_functions.Exp]")
48
minitorch/__init__.py:9: error: Incompatible import of "LT" (imported name has type "Type[minitorch.tensor_functions.LT]", local name has type "Type[minitorch.scalar_functions.LT]")
49
minitorch/__init__.py:9: error: Incompatible import of "EQ" (imported name has type "Type[minitorch.tensor_functions.EQ]", local name has type "Type[minitorch.scalar_functions.EQ]")
```
**Solution**: comment out lines 6 and 7 in `minitorch/__init__.py`:
```
from .scalar import * # noqa: F401,F403
from .scalar_functions import * # noqa: F401,F403
```
### 1.5 style failures on `sync_previous_module.py` <a name="1.5"></a>
**Issues**:
```
sync_previous_module.py:41:15: F541 f-string is missing placeholders
sync_previous_module.py:47:1: F841 local variable 'e' is assigned to but never used
```
**Solutions**:
Line 41-> `print(f"Moving file : {file}")`
Line 49-> `f"Exception {e}:\nSomething went wrong! please check if the source and destination folders are present in same folder"`
---
## 2. Writeup <a name="section_2"></a>
### 2.1 Tensors page<a name="2.1"></a>
**Issue**: Typo in the shape of the 2-dimensional tensor.
**Solution**: The shape is (4,5) not (2,5). Also size is 20, not 10.
### 2.2 Broadcasting page<a name="2.2"></a>
**Issue**: Typo in the example for Rule 1.
**Solution**: The matrix is of shape (5,3) not (4,3).
**Issue**: Typo in the matrix multiplication example.
**Solution** A is (1x3x2) not just (3x2), and B is (2x1x2), not just (2x2)
### 2.3 Task 2.4<a name="2.3"></a>
**Issue**: Typo in the TODO.
**Solution**: Complete functions in minitorch/tensor_functions.py., not in tensor_ops.py