Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 8 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# Temporarily disabled
# - repo: https://github.com/RobertCraigie/pyright-python
# rev: v1.1.404
# hooks:
# - id: pyright
# additional_dependencies:
# - pytest
# - hypothesis
13 changes: 12 additions & 1 deletion minitorch/tensor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand All @@ -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")


Expand All @@ -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")


Expand All @@ -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")


Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions minitorch/tensor_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions minitorch/tensor_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading