Start by systematically reviewing each function to identify bugs, then fix them while ensuring correct behavior for edge cases like aliasing and non-divisible chunks. Finally, write comprehensive tests that cover the specified scenarios, demonstrating thoroughness and attention to detail.
Pro tip: When fixing bugs, consider not just the immediate issue but also potential aliasing problems and shape mismatches that could arise in real-world ML pipelines. Writing tests first can help clarify expected behavior and prevent regressions.
Read the provided tensor utility library carefully, noting the expected behavior for matrix initialization, array conversion, and chunk splitting. Identify the specific requirements: aliasing, shape correctness, and non-divisible chunk sizes.
For each function, trace through the logic to find bugs. Common issues include incorrect shape handling, aliasing (e.g., returning views instead of copies), and off-by-one errors in chunk splitting. Fix them while preserving intended functionality.
Create tests that cover aliasing (modifying the output should not affect the input), shape correctness (output shapes match expectations), and non-divisible chunk sizes (last chunk may be smaller). Include both typical and edge cases.
Run the tests to ensure all pass. Refactor code if needed for clarity and efficiency, ensuring fixes are robust and don't introduce new issues.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.