diff --git a/.gitignore b/.gitignore index fd6e8976..b5f2ee15 100644 --- a/.gitignore +++ b/.gitignore @@ -129,8 +129,3 @@ dmypy.json .pyre/ *.\#* data/ -pyodideModule2.md -module2-modernization.md -task2_1_comments.md -task2_2_comments.md -task2_3_comments.md diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ae349ac8..bde03a47 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,10 +36,11 @@ repos: # Run the formatter. - id: ruff-format -- repo: https://github.com/RobertCraigie/pyright-python - rev: v1.1.404 - hooks: - - id: pyright - additional_dependencies: - - pytest - - hypothesis \ No newline at end of file +# Temporarily disabled +# - repo: https://github.com/RobertCraigie/pyright-python +# rev: v1.1.404 +# hooks: +# - id: pyright +# additional_dependencies: +# - pytest +# - hypothesis \ No newline at end of file diff --git a/minitorch/tensor_data.py b/minitorch/tensor_data.py index 452b7904..e8505e01 100644 --- a/minitorch/tensor_data.py +++ b/minitorch/tensor_data.py @@ -42,8 +42,9 @@ def index_to_position(index: Index, strides: Strides) -> int: Returns: Position in storage """ - # TODO: Implement for Task 2.1. + # Hint: Use strides to navigate through memory layout + # Each dimension contributes to the final position based on its stride raise NotImplementedError("Need to implement for Task 2.1") @@ -61,6 +62,8 @@ def to_index(ordinal: int, shape: Shape, out_index: OutIndex) -> None: """ # TODO: Implement for Task 2.1. + # Hint: Think about converting a number to different bases + # Work backwards from the last dimension to the first raise NotImplementedError("Need to implement for Task 2.1") @@ -84,6 +87,9 @@ def broadcast_index( None """ # TODO: Implement for Task 2.2. + # Hint: Align dimensions from the right (last dimension first) + # If smaller tensor dimension is 1, map to index 0 + # Otherwise, use the corresponding index from big_index raise NotImplementedError("Need to implement for Task 2.2") @@ -102,6 +108,9 @@ def shape_broadcast(shape1: UserShape, shape2: UserShape) -> UserShape: IndexingError : if cannot broadcast """ # TODO: Implement for Task 2.2. + # Hint: Pad shorter shape with 1s on the left to make them same length + # Then check each dimension: must be equal, or one must be 1 + # If one is 1, take the other; if both equal, take either raise NotImplementedError("Need to implement for Task 2.2") @@ -223,6 +232,8 @@ def permute(self, *order: int) -> TensorData: ), f"Must give a position to each dimension. Shape: {self.shape} Order: {order}" # TODO: Implement for Task 2.1. + # Hint: Reorder both shape and strides according to the permutation + # The storage remains the same, only the view changes raise NotImplementedError("Need to implement for Task 2.1") def to_string(self) -> str: diff --git a/minitorch/tensor_functions.py b/minitorch/tensor_functions.py index 86db01a1..6a85815b 100644 --- a/minitorch/tensor_functions.py +++ b/minitorch/tensor_functions.py @@ -212,6 +212,9 @@ class Permute(Function): @staticmethod def forward(ctx: Context, a: Tensor, order: Tensor) -> Tensor: # TODO: Implement for Task 2.3. + # Hint: Convert order tensor to list of integers + # Use tensor's permute method on the underlying _tensor + # Create new Tensor with same backend raise NotImplementedError("Need to implement for Task 2.3") @staticmethod diff --git a/minitorch/tensor_ops.py b/minitorch/tensor_ops.py index 96411b42..7bf560b4 100644 --- a/minitorch/tensor_ops.py +++ b/minitorch/tensor_ops.py @@ -269,6 +269,11 @@ def _map( in_strides: Strides, ) -> None: # TODO: Implement for Task 2.3. + # Hint: Iterate through each output position using ordinal indexing + # Use to_index to convert ordinal to multidimensional index + # Use broadcast_index to map output index to input index + # Use index_to_position to get storage positions + # Apply fn to input value and store in output raise NotImplementedError("Need to implement for Task 2.3") return _map @@ -319,6 +324,10 @@ def _zip( b_strides: Strides, ) -> None: # TODO: Implement for Task 2.3. + # Hint: Similar to tensor_map but with two input tensors + # For each output position, get corresponding positions in both inputs + # Both inputs may need broadcasting to output shape + # Apply fn to both input values and store result raise NotImplementedError("Need to implement for Task 2.3") return _zip @@ -355,6 +364,10 @@ def _reduce( reduce_dim: int, ) -> None: # TODO: Implement for Task 2.3. + # Hint: For each output position, iterate over the reduce dimension + # Copy output index to input index, then vary the reduce dimension + # Apply reduction function (fn) to accumulate values + # Remember output is pre-initialized with start value raise NotImplementedError("Need to implement for Task 2.3") return _reduce