{
  "id": "fn-gpu-multiply",
  "dataComponent": "gpu",
  "heading": {
    "title": "multiply",
    "badges": ["GPU", "Matrix", "PARTIAL"]
  },
  "synopsis": "Performs a standard 2D matrix multiplication (A×B) on the GPU, returning a new 2D tensor. Supports partial usage and shape mismatch checks.",
  "codeBlocks": [
    "extend(\"gpu\")\\n\\n# 1) Basic matrix multiply => 2×2 by 2×2\\nA = gpu:to_tensor([[1,2],[3,4]])\\nB = gpu:to_tensor([[5,6],[7,8]])\\nC = gpu:multiply(A, B)\\nslog(gpu:to_array(C))\\n# => Float2DArray([[19.0, 22.0],[43.0, 50.0]])\\n\\n# 2) Partial usage => known A, missing B\\nmulA = gpu:multiply(A)\\nres = mulA(B)\\nslog(gpu:to_array(res))\\n# => [[19.0, 22.0],[43.0, 50.0]]\\n\\n# 3) Shape mismatch => error\\n# Attempt 2×3 multiplied by 2×2 => dimension mismatch => triggers fallback CPU or error\\n# test:expect_error(() => {\\n#   gpu:multiply( gpu:to_tensor([[1,2,3],[4,5,6]]), gpu:to_tensor([[7,8],[9,10]]) )\\n# },\\n# \"Dimension mismatch\"\\n# )\\n\\n# 4) CPU fallback => if no real GPU pipeline is found, or if bridging is incomplete,\\n#    the code logs \"fallback CPU\" but still calculates the result with a CPU approach.\\n"
  ],
  "notes": [
    "gpu:multiply(A,B) multiplies two 2D tensors A (m×k) and B (k×n). The result is (m×n).",
    "If shapes mismatch, bridging raises an error. If GPU is unavailable or not implemented for multiply, it may fallback to CPU with a console message.",
    "Partial usage: you can call gpu:multiply(A) => returns a function expecting B, or placeholders (gpu:multiply(_, B)) => expects A next."
  ]
}
