{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "42dbbbcf",
   "metadata": {
    "cell_marker": "\"\"\""
   },
   "source": [
    "\n",
    "# Tensor - Core Data Structure\n",
    "\n",
    "Welcome to the Tensor module! This is where TinyTorch really begins. You'll implement the fundamental data structure that powers all ML systems.\n",
    "\n",
    "## Learning Goals\n",
    "- Understand tensors as N-dimensional arrays with ML-specific operations\n",
    "- Implement a complete Tensor class with arithmetic operations\n",
    "- Handle shape management, data types, and memory layout\n",
    "- Build the foundation for neural networks and automatic differentiation\n",
    "- Master the NBGrader workflow with comprehensive testing\n",
    "\n",
    "## Build → Use → Understand\n",
    "1. **Build**: Create the Tensor class with core operations\n",
    "2. **Use**: Perform tensor arithmetic and transformations\n",
    "3. **Understand**: How tensors form the foundation of ML systems"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "876dd108",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "tensor-imports",
     "locked": false,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "#| default_exp core.tensor\n",
    "\n",
    "#| export\n",
    "import numpy as np\n",
    "import sys\n",
    "from typing import Union, List, Tuple, Optional, Any"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a189cf93",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "tensor-setup",
     "locked": false,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "print(\"🔥 TinyTorch Tensor Module\")\n",
    "print(f\"NumPy version: {np.__version__}\")\n",
    "print(f\"Python version: {sys.version_info.major}.{sys.version_info.minor}\")\n",
    "print(\"Ready to build tensors!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ea0df97",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "## Where This Code Lives in the Final Package\n",
    "\n",
    "**Learning Side:** You work in `modules/source/02_tensor/tensor_dev.py`  \n",
    "**Building Side:** Code exports to `tinytorch.core.tensor`\n",
    "\n",
    "```python\n",
    "# Final package structure:\n",
    "from tinytorch.core.tensor import Tensor  # The foundation of everything!\n",
    "from tinytorch.core.activations import ReLU, Sigmoid, Tanh\n",
    "from tinytorch.core.layers import Dense, Conv2D\n",
    "```\n",
    "\n",
    "**Why this matters:**\n",
    "- **Learning:** Focused modules for deep understanding\n",
    "- **Production:** Proper organization like PyTorch's `torch.Tensor`\n",
    "- **Consistency:** All tensor operations live together in `core.tensor`\n",
    "- **Foundation:** Every other module depends on Tensor"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2c72aaa7",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "## Mathematical Foundation: From Scalars to Tensors\n",
    "\n",
    "Understanding tensors requires building from mathematical fundamentals:\n",
    "\n",
    "### Scalars (Rank 0)\n",
    "- **Definition**: A single number with no direction\n",
    "- **Examples**: Temperature (25°C), mass (5.2 kg), probability (0.7)\n",
    "- **Operations**: Addition, multiplication, comparison\n",
    "- **ML Context**: Loss values, learning rates, regularization parameters\n",
    "\n",
    "### Vectors (Rank 1)\n",
    "- **Definition**: An ordered list of numbers with direction and magnitude\n",
    "- **Examples**: Position [x, y, z], RGB color [255, 128, 0], word embedding [0.1, -0.5, 0.8]\n",
    "- **Operations**: Dot product, cross product, norm calculation\n",
    "- **ML Context**: Feature vectors, gradients, model parameters\n",
    "\n",
    "### Matrices (Rank 2)\n",
    "- **Definition**: A 2D array organizing data in rows and columns\n",
    "- **Examples**: Image (height × width), weight matrix (input × output), covariance matrix\n",
    "- **Operations**: Matrix multiplication, transpose, inverse, eigendecomposition\n",
    "- **ML Context**: Linear layer weights, attention matrices, batch data\n",
    "\n",
    "### Higher-Order Tensors (Rank 3+)\n",
    "- **Definition**: Multi-dimensional arrays extending matrices\n",
    "- **Examples**: \n",
    "  - **3D**: Video frames (time × height × width), RGB images (height × width × channels)\n",
    "  - **4D**: Image batches (batch × height × width × channels)\n",
    "  - **5D**: Video batches (batch × time × height × width × channels)\n",
    "- **Operations**: Tensor products, contractions, decompositions\n",
    "- **ML Context**: Convolutional features, RNN states, transformer attention"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d84445e",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "## Why Tensors Matter in ML: The Computational Foundation\n",
    "\n",
    "### Unified Data Representation\n",
    "Tensors provide a consistent way to represent all ML data:\n",
    "```python\n",
    "# All of these are tensors with different shapes\n",
    "scalar_loss = Tensor(0.5)              # Shape: ()\n",
    "feature_vector = Tensor([1, 2, 3])      # Shape: (3,)\n",
    "weight_matrix = Tensor([[1, 2], [3, 4]]) # Shape: (2, 2)\n",
    "image_batch = Tensor(np.random.rand(32, 224, 224, 3)) # Shape: (32, 224, 224, 3)\n",
    "```\n",
    "\n",
    "### Efficient Batch Processing\n",
    "ML systems process multiple samples simultaneously:\n",
    "```python\n",
    "# Instead of processing one image at a time:\n",
    "for image in images:\n",
    "    result = model(image)  # Slow: 1000 separate operations\n",
    "\n",
    "# Process entire batch at once:\n",
    "batch_result = model(image_batch)  # Fast: 1 vectorized operation\n",
    "```\n",
    "\n",
    "### Hardware Acceleration\n",
    "Modern hardware (GPUs, TPUs) excels at tensor operations:\n",
    "- **Parallel processing**: Multiple operations simultaneously\n",
    "- **Vectorization**: SIMD (Single Instruction, Multiple Data) operations\n",
    "- **Memory optimization**: Contiguous memory layout for cache efficiency\n",
    "\n",
    "### Automatic Differentiation\n",
    "Tensors enable gradient computation through computational graphs:\n",
    "```python\n",
    "# Each tensor operation creates a node in the computation graph\n",
    "x = Tensor([1, 2, 3])\n",
    "y = x * 2          # Node: multiplication\n",
    "z = y + 1          # Node: addition\n",
    "loss = z.sum()     # Node: summation\n",
    "# Gradients flow backward through this graph\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1f3b6191",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "## Real-World Examples: Tensors in Action\n",
    "\n",
    "### Computer Vision\n",
    "- **Grayscale image**: 2D tensor `(height, width)` - `(28, 28)` for MNIST\n",
    "- **Color image**: 3D tensor `(height, width, channels)` - `(224, 224, 3)` for RGB\n",
    "- **Image batch**: 4D tensor `(batch, height, width, channels)` - `(32, 224, 224, 3)`\n",
    "- **Video**: 5D tensor `(batch, time, height, width, channels)`\n",
    "\n",
    "### Natural Language Processing\n",
    "- **Word embedding**: 1D tensor `(embedding_dim,)` - `(300,)` for Word2Vec\n",
    "- **Sentence**: 2D tensor `(sequence_length, embedding_dim)` - `(50, 768)` for BERT\n",
    "- **Batch of sentences**: 3D tensor `(batch, sequence_length, embedding_dim)`\n",
    "\n",
    "### Audio Processing\n",
    "- **Audio signal**: 1D tensor `(time_steps,)` - `(16000,)` for 1 second at 16kHz\n",
    "- **Spectrogram**: 2D tensor `(time_frames, frequency_bins)`\n",
    "- **Batch of audio**: 3D tensor `(batch, time_steps, features)`\n",
    "\n",
    "### Time Series\n",
    "- **Single series**: 2D tensor `(time_steps, features)`\n",
    "- **Multiple series**: 3D tensor `(batch, time_steps, features)`\n",
    "- **Multivariate forecasting**: 4D tensor `(batch, time_steps, features, predictions)`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e87f556",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "## Why Not Just Use NumPy?\n",
    "\n",
    "While we use NumPy internally, our Tensor class adds ML-specific functionality:\n",
    "\n",
    "### ML-Specific Operations\n",
    "- **Gradient tracking**: For automatic differentiation (coming in Module 7)\n",
    "- **GPU support**: For hardware acceleration (future extension)\n",
    "- **Broadcasting semantics**: ML-friendly dimension handling\n",
    "\n",
    "### Consistent API\n",
    "- **Type safety**: Predictable behavior across operations\n",
    "- **Error checking**: Clear error messages for debugging\n",
    "- **Integration**: Seamless work with other TinyTorch components\n",
    "\n",
    "### Educational Value\n",
    "- **Conceptual clarity**: Understand what tensors really are\n",
    "- **Implementation insight**: See how frameworks work internally\n",
    "- **Debugging skills**: Trace through tensor operations step by step\n",
    "\n",
    "### Extensibility\n",
    "- **Future features**: Ready for gradients, GPU, distributed computing\n",
    "- **Customization**: Add domain-specific operations\n",
    "- **Optimization**: Profile and optimize specific use cases"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ab0774c1",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "## Performance Considerations: Building Efficient Tensors\n",
    "\n",
    "### Memory Layout\n",
    "- **Contiguous arrays**: Better cache locality and performance\n",
    "- **Data types**: `float32` vs `float64` trade-offs\n",
    "- **Memory sharing**: Avoid unnecessary copies\n",
    "\n",
    "### Vectorization\n",
    "- **SIMD operations**: Single Instruction, Multiple Data\n",
    "- **Broadcasting**: Efficient operations on different shapes\n",
    "- **Batch operations**: Process multiple samples simultaneously\n",
    "\n",
    "### Numerical Stability\n",
    "- **Precision**: Balancing speed and accuracy\n",
    "- **Overflow/underflow**: Handling extreme values\n",
    "- **Gradient flow**: Maintaining numerical stability for training"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "31c02235",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "# CONCEPT\n",
    "Tensors are N-dimensional arrays that carry data through neural networks.\n",
    "Think NumPy arrays with ML superpowers - same math, more capabilities."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "18f4c5db",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "# CODE STRUCTURE\n",
    "```python\n",
    "class Tensor:\n",
    "    def __init__(self, data):     # Create from any data type\n",
    "    def __add__(self, other):     # Enable tensor + tensor\n",
    "    def __mul__(self, other):     # Enable tensor * tensor\n",
    "    # Properties: .shape, .size, .dtype, .data\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6c97001",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "# CONNECTIONS\n",
    "- torch.Tensor (PyTorch) - same concept, production optimized\n",
    "- tf.Tensor (TensorFlow) - distributed computing focus\n",
    "- np.ndarray (NumPy) - we wrap this with ML operations"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ba04fac",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "# CONSTRAINTS\n",
    "- Handle broadcasting (auto-shape matching for operations)\n",
    "- Support multiple data types (float32, int32, etc.)\n",
    "- Efficient memory usage (copy only when necessary)\n",
    "- Natural math notation (tensor + tensor should just work)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c7626a9",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "# CONTEXT\n",
    "Every ML operation flows through tensors:\n",
    "- Neural networks: All computations operate on tensors\n",
    "- Training: Gradients flow through tensor operations  \n",
    "- Hardware: GPUs optimized for tensor math\n",
    "- Production: Millions of tensor ops per second in real systems\n",
    "\n",
    "**You're building the universal language of machine learning.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c390d7f",
   "metadata": {
    "deletable": false,
    "lines_to_next_cell": 1,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "c025281d54c1f95fef2dc7e91d11255a",
     "grade": false,
     "grade_id": "tensor-class",
     "locked": false,
     "schema_version": 3,
     "solution": true,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "#| export\n",
    "class Tensor:\n",
    "    \"\"\"\n",
    "    TinyTorch Tensor: N-dimensional array with ML operations.\n",
    "    \n",
    "    The fundamental data structure for all TinyTorch operations.\n",
    "    Wraps NumPy arrays with ML-specific functionality.\n",
    "    \"\"\"\n",
    "    \n",
    "    def __init__(self, data: Union[int, float, List, np.ndarray], dtype: Optional[str] = None):\n",
    "        \"\"\"\n",
    "        Create a new tensor from data.\n",
    "        \n",
    "        Args:\n",
    "            data: Input data (scalar, list, or numpy array)\n",
    "            dtype: Data type ('float32', 'int32', etc.). Defaults to auto-detect.\n",
    "            \n",
    "        TODO: Implement tensor creation with proper type handling.\n",
    "        \n",
    "        STEP-BY-STEP:\n",
    "        1. Check if data is a scalar (int/float) - convert to numpy array\n",
    "        2. Check if data is a list - convert to numpy array  \n",
    "        3. Check if data is already a numpy array - use as-is\n",
    "        4. Apply dtype conversion if specified\n",
    "        5. Store the result in self._data\n",
    "        \n",
    "        EXAMPLE:\n",
    "        Tensor(5) → stores np.array(5)\n",
    "        Tensor([1, 2, 3]) → stores np.array([1, 2, 3])\n",
    "        Tensor(np.array([1, 2, 3])) → stores the array directly\n",
    "        \n",
    "        HINTS:\n",
    "        - Use isinstance() to check data types\n",
    "        - Use np.array() for conversion\n",
    "        - Handle dtype parameter for type conversion\n",
    "        - Store the array in self._data\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "\n",
    "    @property\n",
    "    def data(self) -> np.ndarray:\n",
    "        \"\"\"\n",
    "        Access underlying numpy array.\n",
    "        \n",
    "        TODO: Return the stored numpy array.\n",
    "        \n",
    "        HINT: Return self._data (the array you stored in __init__)\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "    \n",
    "    @property\n",
    "    def shape(self) -> Tuple[int, ...]:\n",
    "        \"\"\"\n",
    "        Get tensor shape.\n",
    "        \n",
    "        TODO: Return the shape of the stored numpy array.\n",
    "        \n",
    "        HINT: Use .shape attribute of the numpy array\n",
    "        EXAMPLE: Tensor([1, 2, 3]).shape should return (3,)\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "    \n",
    "    @property\n",
    "    def size(self) -> int:\n",
    "        \"\"\"\n",
    "        Get total number of elements.\n",
    "        \n",
    "        TODO: Return the total number of elements in the tensor.\n",
    "        \n",
    "        HINT: Use .size attribute of the numpy array\n",
    "        EXAMPLE: Tensor([1, 2, 3]).size should return 3\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "    \n",
    "    @property\n",
    "    def dtype(self) -> np.dtype:\n",
    "        \"\"\"\n",
    "        Get data type as numpy dtype.\n",
    "        \n",
    "        TODO: Return the data type of the stored numpy array.\n",
    "        \n",
    "        HINT: Use .dtype attribute of the numpy array\n",
    "        EXAMPLE: Tensor([1, 2, 3]).dtype should return dtype('int32')\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "    \n",
    "    def __repr__(self) -> str:\n",
    "        \"\"\"\n",
    "        String representation.\n",
    "        \n",
    "        TODO: Create a clear string representation of the tensor.\n",
    "        \n",
    "        APPROACH:\n",
    "        1. Convert the numpy array to a list for readable output\n",
    "        2. Include the shape and dtype information\n",
    "        3. Format: \"Tensor([data], shape=shape, dtype=dtype)\"\n",
    "        \n",
    "        EXAMPLE:\n",
    "        Tensor([1, 2, 3]) → \"Tensor([1, 2, 3], shape=(3,), dtype=int32)\"\n",
    "        \n",
    "        HINTS:\n",
    "        - Use .tolist() to convert numpy array to list\n",
    "        - Include shape and dtype information\n",
    "        - Keep format consistent and readable\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "\n",
    "    def add(self, other: 'Tensor') -> 'Tensor':\n",
    "        \"\"\"\n",
    "        Add two tensors element-wise.\n",
    "        \n",
    "        TODO: Implement tensor addition.\n",
    "        \n",
    "        APPROACH:\n",
    "        1. Add the numpy arrays using +\n",
    "        2. Return a new Tensor with the result\n",
    "        3. Handle broadcasting automatically\n",
    "        \n",
    "        EXAMPLE:\n",
    "        Tensor([1, 2]) + Tensor([3, 4]) → Tensor([4, 6])\n",
    "        \n",
    "        HINTS:\n",
    "        - Use self._data + other._data\n",
    "        - Return Tensor(result)\n",
    "        - NumPy handles broadcasting automatically\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "\n",
    "    def multiply(self, other: 'Tensor') -> 'Tensor':\n",
    "        \"\"\"\n",
    "        Multiply two tensors element-wise.\n",
    "        \n",
    "        TODO: Implement tensor multiplication.\n",
    "        \n",
    "        APPROACH:\n",
    "        1. Multiply the numpy arrays using *\n",
    "        2. Return a new Tensor with the result\n",
    "        3. Handle broadcasting automatically\n",
    "        \n",
    "        EXAMPLE:\n",
    "        Tensor([1, 2]) * Tensor([3, 4]) → Tensor([3, 8])\n",
    "        \n",
    "        HINTS:\n",
    "        - Use self._data * other._data\n",
    "        - Return Tensor(result)\n",
    "        - This is element-wise, not matrix multiplication\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "\n",
    "    def __add__(self, other: Union['Tensor', int, float]) -> 'Tensor':\n",
    "        \"\"\"\n",
    "        Addition operator: tensor + other\n",
    "        \n",
    "        TODO: Implement + operator for tensors.\n",
    "        \n",
    "        APPROACH:\n",
    "        1. If other is a Tensor, use tensor addition\n",
    "        2. If other is a scalar, convert to Tensor first\n",
    "        3. Return the result\n",
    "        \n",
    "        EXAMPLE:\n",
    "        Tensor([1, 2]) + Tensor([3, 4]) → Tensor([4, 6])\n",
    "        Tensor([1, 2]) + 5 → Tensor([6, 7])\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "\n",
    "    def __mul__(self, other: Union['Tensor', int, float]) -> 'Tensor':\n",
    "        \"\"\"\n",
    "        Multiplication operator: tensor * other\n",
    "        \n",
    "        TODO: Implement * operator for tensors.\n",
    "        \n",
    "        APPROACH:\n",
    "        1. If other is a Tensor, use tensor multiplication\n",
    "        2. If other is a scalar, convert to Tensor first\n",
    "        3. Return the result\n",
    "        \n",
    "        EXAMPLE:\n",
    "        Tensor([1, 2]) * Tensor([3, 4]) → Tensor([3, 8])\n",
    "        Tensor([1, 2]) * 3 → Tensor([3, 6])\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "\n",
    "    def __sub__(self, other: Union['Tensor', int, float]) -> 'Tensor':\n",
    "        \"\"\"\n",
    "        Subtraction operator: tensor - other\n",
    "        \n",
    "        TODO: Implement - operator for tensors.\n",
    "        \n",
    "        APPROACH:\n",
    "        1. Convert other to Tensor if needed\n",
    "        2. Subtract using numpy arrays\n",
    "        3. Return new Tensor with result\n",
    "        \n",
    "        EXAMPLE:\n",
    "        Tensor([5, 6]) - Tensor([1, 2]) → Tensor([4, 4])\n",
    "        Tensor([5, 6]) - 1 → Tensor([4, 5])\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "\n",
    "    def __truediv__(self, other: Union['Tensor', int, float]) -> 'Tensor':\n",
    "        \"\"\"\n",
    "        Division operator: tensor / other\n",
    "        \n",
    "        TODO: Implement / operator for tensors.\n",
    "        \n",
    "        APPROACH:\n",
    "        1. Convert other to Tensor if needed\n",
    "        2. Divide using numpy arrays\n",
    "        3. Return new Tensor with result\n",
    "        \n",
    "        EXAMPLE:\n",
    "        Tensor([6, 8]) / Tensor([2, 4]) → Tensor([3, 2])\n",
    "        Tensor([6, 8]) / 2 → Tensor([3, 4])\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()\n",
    "\n",
    "    def mean(self) -> 'Tensor':\n",
    "        \"\"\"Computes the mean of the tensor's elements.\"\"\"\n",
    "        return Tensor(np.mean(self.data))\n",
    "\n",
    "    def matmul(self, other: 'Tensor') -> 'Tensor':\n",
    "        \"\"\"\n",
    "        Perform matrix multiplication between two tensors.\n",
    "        \n",
    "        TODO: Implement matrix multiplication.\n",
    "        \n",
    "        APPROACH:\n",
    "        1. Use np.matmul() to perform matrix multiplication\n",
    "        2. Return a new Tensor with the result\n",
    "        3. Handle broadcasting automatically\n",
    "        \n",
    "        EXAMPLE:\n",
    "        Tensor([[1, 2], [3, 4]]) @ Tensor([[5, 6], [7, 8]]) → Tensor([[19, 22], [43, 50]])\n",
    "        \n",
    "        HINTS:\n",
    "        - Use np.matmul(self._data, other._data)\n",
    "        - Return Tensor(result)\n",
    "        - This is matrix multiplication, not element-wise multiplication\n",
    "        \"\"\"\n",
    "        # YOUR CODE HERE\n",
    "        raise NotImplementedError()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "871073e3",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "# Testing Your Implementation\n",
    "\n",
    "Now let's test our tensor implementation with comprehensive tests that validate all functionality."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ffb13371",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "### 🧪 Unit Test: Tensor Creation\n",
    "\n",
    "Let's test your tensor creation implementation right away! This gives you immediate feedback on whether your `__init__` method works correctly.\n",
    "\n",
    "**This is a unit test** - it tests one specific function (tensor creation) in isolation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc38719e",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "f7696dbfeee54746e4963cf1546b560a",
     "grade": true,
     "grade_id": "test_unit_tensor_creation_immediate",
     "locked": true,
     "points": 5,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# Test tensor creation immediately after implementation\n",
    "print(\"🔬 Unit Test: Tensor Creation...\")\n",
    "\n",
    "# Test basic tensor creation\n",
    "try:\n",
    "    # Test scalar\n",
    "    scalar = Tensor(5.0)\n",
    "    assert hasattr(scalar, '_data'), \"Tensor should have _data attribute\"\n",
    "    assert scalar._data.shape == (), f\"Scalar should have shape (), got {scalar._data.shape}\"\n",
    "    print(\"✅ Scalar creation works\")\n",
    "    \n",
    "    # Test vector\n",
    "    vector = Tensor([1, 2, 3])\n",
    "    assert vector._data.shape == (3,), f\"Vector should have shape (3,), got {vector._data.shape}\"\n",
    "    print(\"✅ Vector creation works\")\n",
    "    \n",
    "    # Test matrix\n",
    "    matrix = Tensor([[1, 2], [3, 4]])\n",
    "    assert matrix._data.shape == (2, 2), f\"Matrix should have shape (2, 2), got {matrix._data.shape}\"\n",
    "    print(\"✅ Matrix creation works\")\n",
    "    \n",
    "    print(\"📈 Progress: Tensor Creation ✓\")\n",
    "    \n",
    "except Exception as e:\n",
    "    print(f\"❌ Tensor creation test failed: {e}\")\n",
    "    raise\n",
    "\n",
    "print(\"🎯 Tensor creation behavior:\")\n",
    "print(\"   Converts data to NumPy arrays\")\n",
    "print(\"   Preserves shape and data type\")\n",
    "print(\"   Stores in _data attribute\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1455a40",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "### 🧪 Unit Test: Tensor Properties\n",
    "\n",
    "Now let's test that your tensor properties work correctly. This tests the @property methods you implemented.\n",
    "\n",
    "**This is a unit test** - it tests specific properties (shape, size, dtype, data) in isolation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "462632a0",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "0f37e1021365caca6d982ad9725fe8a5",
     "grade": true,
     "grade_id": "test_unit_tensor_properties_immediate",
     "locked": true,
     "points": 5,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# Test tensor properties immediately after implementation\n",
    "print(\"🔬 Unit Test: Tensor Properties...\")\n",
    "\n",
    "# Test properties with simple examples\n",
    "try:\n",
    "    # Test with a simple matrix\n",
    "    tensor = Tensor([[1, 2, 3], [4, 5, 6]])\n",
    "    \n",
    "    # Test shape property\n",
    "    assert tensor.shape == (2, 3), f\"Shape should be (2, 3), got {tensor.shape}\"\n",
    "    print(\"✅ Shape property works\")\n",
    "    \n",
    "    # Test size property\n",
    "    assert tensor.size == 6, f\"Size should be 6, got {tensor.size}\"\n",
    "    print(\"✅ Size property works\")\n",
    "    \n",
    "    # Test data property\n",
    "    assert np.array_equal(tensor.data, np.array([[1, 2, 3], [4, 5, 6]])), \"Data property should return numpy array\"\n",
    "    print(\"✅ Data property works\")\n",
    "    \n",
    "    # Test dtype property\n",
    "    assert tensor.dtype in [np.int32, np.int64], f\"Dtype should be int32 or int64, got {tensor.dtype}\"\n",
    "    print(\"✅ Dtype property works\")\n",
    "    \n",
    "    print(\"📈 Progress: Tensor Properties ✓\")\n",
    "    \n",
    "except Exception as e:\n",
    "    print(f\"❌ Tensor properties test failed: {e}\")\n",
    "    raise\n",
    "\n",
    "print(\"🎯 Tensor properties behavior:\")\n",
    "print(\"   shape: Returns tuple of dimensions\")\n",
    "print(\"   size: Returns total number of elements\")\n",
    "print(\"   data: Returns underlying NumPy array\")\n",
    "print(\"   dtype: Returns NumPy data type\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dbf8b2ef",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "### 🧪 Unit Test: Tensor Arithmetic\n",
    "\n",
    "Let's test your tensor arithmetic operations. This tests the __add__, __mul__, __sub__, __truediv__ methods.\n",
    "\n",
    "**This is a unit test** - it tests specific arithmetic operations in isolation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb6261af",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "325214249c3929f6b8f275777bc39fea",
     "grade": true,
     "grade_id": "test_unit_tensor_arithmetic_immediate",
     "locked": true,
     "points": 5,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "# Test tensor arithmetic immediately after implementation\n",
    "print(\"🔬 Unit Test: Tensor Arithmetic...\")\n",
    "\n",
    "# Test basic arithmetic with simple examples\n",
    "try:\n",
    "    # Test addition\n",
    "    a = Tensor([1, 2, 3])\n",
    "    b = Tensor([4, 5, 6])\n",
    "    result = a + b\n",
    "    expected = np.array([5, 7, 9])\n",
    "    assert np.array_equal(result.data, expected), f\"Addition failed: expected {expected}, got {result.data}\"\n",
    "    print(\"✅ Addition works\")\n",
    "    \n",
    "    # Test scalar addition\n",
    "    result_scalar = a + 10\n",
    "    expected_scalar = np.array([11, 12, 13])\n",
    "    assert np.array_equal(result_scalar.data, expected_scalar), f\"Scalar addition failed: expected {expected_scalar}, got {result_scalar.data}\"\n",
    "    print(\"✅ Scalar addition works\")\n",
    "    \n",
    "    # Test multiplication\n",
    "    result_mul = a * b\n",
    "    expected_mul = np.array([4, 10, 18])\n",
    "    assert np.array_equal(result_mul.data, expected_mul), f\"Multiplication failed: expected {expected_mul}, got {result_mul.data}\"\n",
    "    print(\"✅ Multiplication works\")\n",
    "    \n",
    "    # Test scalar multiplication\n",
    "    result_scalar_mul = a * 2\n",
    "    expected_scalar_mul = np.array([2, 4, 6])\n",
    "    assert np.array_equal(result_scalar_mul.data, expected_scalar_mul), f\"Scalar multiplication failed: expected {expected_scalar_mul}, got {result_scalar_mul.data}\"\n",
    "    print(\"✅ Scalar multiplication works\")\n",
    "    \n",
    "    print(\"📈 Progress: Tensor Arithmetic ✓\")\n",
    "    \n",
    "except Exception as e:\n",
    "    print(f\"❌ Tensor arithmetic test failed: {e}\")\n",
    "    raise\n",
    "\n",
    "print(\"🎯 Tensor arithmetic behavior:\")\n",
    "print(\"   Element-wise operations on tensors\")\n",
    "print(\"   Broadcasting with scalars\")\n",
    "print(\"   Returns new Tensor objects\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e469dcb",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 0
   },
   "source": [
    "### 🔬 Comprehensive Tests\n",
    "\n",
    "Now let's run comprehensive tests that validate all tensor functionality together. These tests ensure your implementation is production-ready.\n",
    "\n",
    "**These are comprehensive tests** - they test multiple features and edge cases to ensure robustness."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "665bec40",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "518af1a785ed405f386f7a53c7f9b918",
     "grade": true,
     "grade_id": "test_unit_tensor_creation",
     "locked": true,
     "points": 5,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "def test_unit_tensor_creation():\n",
    "    \"\"\"Comprehensive test of tensor creation with all data types and shapes.\"\"\"\n",
    "    print(\"🔬 Testing comprehensive tensor creation...\")\n",
    "    \n",
    "    # Test scalar creation\n",
    "    scalar_int = Tensor(42)\n",
    "    assert scalar_int.shape == ()\n",
    "    \n",
    "    # Test vector creation\n",
    "    vector_int = Tensor([1, 2, 3])\n",
    "    assert vector_int.shape == (3,)\n",
    "\n",
    "    # Test matrix creation\n",
    "    matrix_2x2 = Tensor([[1, 2], [3, 4]])\n",
    "    assert matrix_2x2.shape == (2, 2)\n",
    "    print(\"✅ Tensor creation tests passed!\")\n",
    "\n",
    "# Run the test\n",
    "test_unit_tensor_creation()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1aec4da",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 1
   },
   "source": [
    "### Unit Test: Tensor Properties\n",
    "\n",
    "This test validates your tensor property methods (shape, size, dtype, data), ensuring they correctly reflect the tensor's dimensional structure and data characteristics."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5bd7717",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "011eb361a067064f0c08caa69d205c61",
     "grade": true,
     "grade_id": "test_unit_tensor_properties",
     "locked": true,
     "points": 5,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "def test_unit_tensor_properties():\n",
    "    \"\"\"Comprehensive test of tensor properties (shape, size, dtype, data access).\"\"\"\n",
    "    print(\"🔬 Testing comprehensive tensor properties...\")\n",
    "\n",
    "    tensor = Tensor([[1, 2, 3], [4, 5, 6]])\n",
    "    \n",
    "    # Test shape property\n",
    "    assert tensor.shape == (2, 3)\n",
    "    \n",
    "    # Test size property\n",
    "    assert tensor.size == 6\n",
    "    \n",
    "    # Test data property\n",
    "    assert np.array_equal(tensor.data, np.array([[1, 2, 3], [4, 5, 6]]))\n",
    "    \n",
    "    # Test dtype property\n",
    "    assert tensor.dtype in [np.int32, np.int64]\n",
    "    print(\"✅ Tensor properties tests passed!\")\n",
    "\n",
    "# Run the test\n",
    "test_unit_tensor_properties()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e30c4ffc",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 1
   },
   "source": [
    "### 🧪 Unit Test: Tensor Arithmetic Operations\n",
    "\n",
    "Now let's test all your arithmetic operations working together! This comprehensive test validates that addition, subtraction, multiplication, and division all work correctly with your tensor implementation.\n",
    "\n",
    "**What This Tests:**\n",
    "- Element-wise addition, subtraction, multiplication, division\n",
    "- Proper NumPy array handling in arithmetic\n",
    "- Result correctness across different operations\n",
    "\n",
    "**Why This Matters:**\n",
    "- Arithmetic operations are the foundation of all neural network computations\n",
    "- These operations must be fast and mathematically correct\n",
    "- Your implementation should match NumPy's behavior exactly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d6b8aa3",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "a08887014ed3b6f76ba6e455251e67a9",
     "grade": true,
     "grade_id": "test_unit_tensor_arithmetic",
     "locked": true,
     "points": 5,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "def test_unit_tensor_arithmetic():\n",
    "    \"\"\"Comprehensive test of tensor arithmetic operations.\"\"\"\n",
    "    print(\"🔬 Testing comprehensive tensor arithmetic...\")\n",
    "    \n",
    "    a = Tensor([1, 2, 3])\n",
    "    b = Tensor([4, 5, 6])\n",
    "    \n",
    "    # Test addition\n",
    "    c = a + b\n",
    "    expected = np.array([5, 7, 9])\n",
    "    assert np.array_equal(c.data, expected)\n",
    "    \n",
    "    # Test multiplication\n",
    "    d = a * b\n",
    "    expected = np.array([4, 10, 18])\n",
    "    assert np.array_equal(d.data, expected)\n",
    "\n",
    "    # Test subtraction\n",
    "    e = b - a\n",
    "    expected = np.array([3, 3, 3])\n",
    "    assert np.array_equal(e.data, expected)\n",
    "\n",
    "    # Test division\n",
    "    f = b / a\n",
    "    expected = np.array([4.0, 2.5, 2.0])\n",
    "    assert np.allclose(f.data, expected)\n",
    "    print(\"✅ Tensor arithmetic tests passed!\")\n",
    "\n",
    "# Run the test\n",
    "test_unit_tensor_arithmetic()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "42467e47",
   "metadata": {
    "cell_marker": "\"\"\"",
    "lines_to_next_cell": 1
   },
   "source": [
    "### 🧪 Integration Test: Tensor-NumPy Integration\n",
    "\n",
    "This integration test validates that your tensor system works seamlessly with NumPy, the foundation of the scientific Python ecosystem.\n",
    "\n",
    "**What This Tests:**\n",
    "- Creating tensors from NumPy arrays\n",
    "- Converting tensors back to NumPy arrays  \n",
    "- Mixed operations between tensors and NumPy\n",
    "- Data type preservation and consistency\n",
    "\n",
    "**Why This Matters:**\n",
    "- Real ML systems must integrate with NumPy seamlessly\n",
    "- Data scientists expect tensors to work with existing NumPy code\n",
    "- Performance optimizations often involve NumPy operations\n",
    "- This compatibility is what makes PyTorch and TensorFlow so powerful\n",
    "\n",
    "**Real-World Connection:**\n",
    "- PyTorch tensors have `.numpy()` and `torch.from_numpy()` methods\n",
    "- TensorFlow has similar NumPy integration\n",
    "- This test ensures your tensors work in real data science workflows"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ff6663b",
   "metadata": {
    "deletable": false,
    "editable": false,
    "nbgrader": {
     "cell_type": "code",
     "checksum": "6de5b72780ace27f248de67099a97dff",
     "grade": true,
     "grade_id": "test_module_tensor_numpy_integration",
     "locked": true,
     "points": 10,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "def test_module_tensor_numpy_integration():\n",
    "    \"\"\"\n",
    "    Integration test for tensor operations with NumPy arrays.\n",
    "    \n",
    "    Tests that tensors properly integrate with NumPy operations and maintain\n",
    "    compatibility with the scientific Python ecosystem.\n",
    "    \"\"\"\n",
    "    print(\"🔬 Running Integration Test: Tensor-NumPy Integration...\")\n",
    "    \n",
    "    # Test 1: Tensor from NumPy array\n",
    "    numpy_array = np.array([[1, 2, 3], [4, 5, 6]])\n",
    "    tensor_from_numpy = Tensor(numpy_array)\n",
    "    \n",
    "    assert tensor_from_numpy.shape == (2, 3), \"Tensor should preserve NumPy array shape\"\n",
    "    assert np.array_equal(tensor_from_numpy.data, numpy_array), \"Tensor should preserve NumPy array data\"\n",
    "    \n",
    "    # Test 2: Tensor arithmetic with NumPy-compatible operations\n",
    "    a = Tensor([1.0, 2.0, 3.0])\n",
    "    b = Tensor([4.0, 5.0, 6.0])\n",
    "    \n",
    "    # Test operations that would be used in neural networks\n",
    "    dot_product_result = np.dot(a.data, b.data)  # Common in layers\n",
    "    assert np.isclose(dot_product_result, 32.0), \"Dot product should work with tensor data\"\n",
    "    \n",
    "    # Test 3: Broadcasting compatibility\n",
    "    matrix = Tensor([[1, 2], [3, 4]])\n",
    "    scalar = Tensor(10)\n",
    "    \n",
    "    result = matrix + scalar\n",
    "    expected = np.array([[11, 12], [13, 14]])\n",
    "    assert np.array_equal(result.data, expected), \"Broadcasting should work like NumPy\"\n",
    "    \n",
    "    # Test 4: Integration with scientific computing patterns\n",
    "    data = Tensor([1, 4, 9, 16, 25])\n",
    "    sqrt_result = Tensor(np.sqrt(data.data))  # Using NumPy functions on tensor data\n",
    "    expected_sqrt = np.array([1., 2., 3., 4., 5.])\n",
    "    assert np.allclose(sqrt_result.data, expected_sqrt), \"Should integrate with NumPy functions\"\n",
    "    \n",
    "    print(\"✅ Integration Test Passed: Tensor-NumPy integration works correctly.\")\n",
    "\n",
    "# Run the integration test\n",
    "test_module_tensor_numpy_integration()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b722b1d",
   "metadata": {
    "cell_marker": "\"\"\""
   },
   "source": [
    "## 🤔 ML Systems Thinking: Reflection Questions\n",
    "\n",
    "Now that you've built a working tensor system, take a moment to reflect on how this simple foundation connects to the massive ML systems powering today's AI revolution:\n",
    "\n",
    "### System Design - How does this fit into larger systems?\n",
    "1. **The Universal Language**: You just built the fundamental data structure of modern AI. How does having one unified way to represent data (as tensors) enable frameworks like PyTorch to handle everything from image recognition to language models using the same operations?\n",
    "\n",
    "2. **Memory and Scale**: Your tensor creates a new result for every operation. When OpenAI trains GPT models with billions of parameters, why might memory management become a critical system design challenge? What trade-offs do you think they make?\n",
    "\n",
    "3. **Hardware Abstraction**: Your tensor works on CPU through NumPy. How does abstracting tensor operations allow the same neural network code to run on CPUs, GPUs, and specialized AI chips like TPUs without changing the model logic?\n",
    "\n",
    "### Production ML - How is this used in real ML workflows?\n",
    "4. **Batch Processing Power**: Real ML systems process thousands of images or sentences simultaneously in batches. How does your element-wise tensor math suddenly become a superpower when applied to batches? Why is this crucial for real-time applications?\n",
    "\n",
    "5. **Data Pipeline Integration**: Your tensor wraps NumPy arrays, making it compatible with the entire scientific Python ecosystem. How does this design choice affect a data scientist's ability to move from data exploration to model deployment?\n",
    "\n",
    "6. **Production Reliability**: In a live recommendation system serving millions of users, what happens when tensor operations encounter unexpected data shapes or types? How might this influence framework design priorities?\n",
    "\n",
    "### Framework Design - Why do frameworks make certain choices?\n",
    "7. **API Philosophy**: You chose property-style access (`tensor.shape`) like PyTorch, rather than function calls. How does this seemingly small design decision affect the developer experience when building complex neural architectures?\n",
    "\n",
    "8. **Broadcasting Magic**: PyTorch tensors can add a scalar to a matrix automatically, while your current implementation requires matching shapes. Why do you think frameworks invest heavily in broadcasting logic? What problems does it solve for researchers?\n",
    "\n",
    "9. **Type System Design**: Your tensor supports different data types (int32, float32). How do these choices ripple through an entire ML pipeline, from training speed to model accuracy to deployment costs?\n",
    "\n",
    "### Performance & Scale - What happens when systems get large?\n",
    "10. **Memory Explosion**: Every operation in your tensor creates new memory. Imagine a neural network with millions of operations during training. How might this connect to why modern frameworks offer both copying and in-place operations?\n",
    "\n",
    "11. **Computational Graphs**: Your operations happen immediately. Large language models track millions of tensor operations to compute gradients. How does the shift from immediate computation to deferred execution change system architecture?\n",
    "\n",
    "12. **Hardware Optimization**: Your simple `+` operation translates to highly optimized kernel code on GPUs. How does having a clean tensor abstraction enable frameworks to automatically optimize operations for different hardware without changing user code?\n",
    "\n",
    "**💡 Systems Insight**: The tensor abstraction you just built is one of computing's most elegant solutions—it provides a simple, mathematical interface that hides incredible complexity in optimization, hardware acceleration, and distributed computing. Every major AI breakthrough, from computer vision to large language models, flows through tensor operations just like the ones you implemented."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0a96b83",
   "metadata": {
    "cell_marker": "\"\"\""
   },
   "source": [
    "# MODULE SUMMARY: Tensor Foundation\n",
    "\n",
    "Congratulations! You've successfully implemented the fundamental data structure that powers all machine learning:\n",
    "\n",
    "## What You've Built\n",
    "- **Tensor Class**: N-dimensional array wrapper with professional interfaces\n",
    "- **Core Operations**: Creation, property access, and arithmetic operations\n",
    "- **Shape Management**: Automatic shape tracking and validation\n",
    "- **Data Types**: Proper NumPy integration and type handling\n",
    "- **Foundation**: The building block for all subsequent TinyTorch modules\n",
    "\n",
    "## Key Learning Outcomes\n",
    "- **Understanding**: How tensors work as the foundation of machine learning\n",
    "- **Implementation**: Built tensor operations from scratch\n",
    "- **Professional patterns**: Clean APIs, proper error handling, comprehensive testing\n",
    "- **Real-world connection**: Understanding PyTorch/TensorFlow tensor foundations\n",
    "- **Systems thinking**: Building reliable, reusable components\n",
    "\n",
    "## Mathematical Foundations Mastered\n",
    "- **N-dimensional arrays**: Shape, size, and dimensionality concepts\n",
    "- **Element-wise operations**: Addition, subtraction, multiplication, division\n",
    "- **Broadcasting**: Understanding how operations work with different shapes\n",
    "- **Memory management**: Efficient data storage and access patterns\n",
    "\n",
    "## Professional Skills Developed\n",
    "- **API design**: Clean, intuitive interfaces for tensor operations\n",
    "- **Error handling**: Graceful handling of invalid operations and edge cases\n",
    "- **Testing methodology**: Comprehensive validation of tensor functionality\n",
    "- **Documentation**: Clear, educational documentation with examples\n",
    "\n",
    "## Ready for Advanced Applications\n",
    "Your tensor implementation now enables:\n",
    "- **Neural Networks**: Foundation for all layer implementations\n",
    "- **Automatic Differentiation**: Gradient computation through computational graphs\n",
    "- **Complex Models**: CNNs, RNNs, Transformers - all built on tensors\n",
    "- **Real Applications**: Training models on real datasets\n",
    "\n",
    "## Connection to Real ML Systems\n",
    "Your implementation mirrors production systems:\n",
    "- **PyTorch**: `torch.Tensor` provides identical functionality\n",
    "- **TensorFlow**: `tf.Tensor` implements similar concepts\n",
    "- **NumPy**: `numpy.ndarray` serves as the foundation\n",
    "- **Industry Standard**: Every major ML framework uses these exact principles\n",
    "\n",
    "## The Power of Tensors\n",
    "You've built the fundamental data structure of modern AI:\n",
    "- **Universality**: Tensors represent all data: images, text, audio, video\n",
    "- **Efficiency**: Vectorized operations enable fast computation\n",
    "- **Scalability**: Handles everything from single numbers to massive matrices\n",
    "- **Flexibility**: Foundation for any mathematical operation\n",
    "\n",
    "## What's Next\n",
    "Your tensor implementation is the foundation for:\n",
    "- **Activations**: Nonlinear functions that enable complex learning\n",
    "- **Layers**: Linear transformations and neural network building blocks\n",
    "- **Networks**: Composing layers into powerful architectures\n",
    "- **Training**: Optimizing networks to solve real problems\n",
    "\n",
    "**Next Module**: Activation functions - adding the nonlinearity that makes neural networks powerful!\n",
    "\n",
    "You've built the foundation of modern AI. Now let's add the mathematical functions that enable machines to learn complex patterns!"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "main_language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
