or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/cupy-cuda101@9.6.x
tile.json

tessl/pypi-cupy-cuda101

tessl install tessl/pypi-cupy-cuda101@9.6.0

CuPy: NumPy & SciPy for GPU (CUDA 10.1 version)

Agent Success

Agent success rate when using this tile

87%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.19x

Baseline

Agent success rate without this tile

73%

task.mdevals/scenario-8/

Array Shape Normalizer

Problem Statement

Implement a system that prepares arrays of different shapes for batch operations by ensuring they are all compatible for element-wise operations. The system should handle arrays with different dimensionalities and broadcast them to a common shape.

Requirements

Core Functionality

  1. Implement a function broadcast_arrays_to_common_shape(arrays) that:

    • Takes a list of arrays with different shapes
    • Returns all arrays broadcast to their common shape
    • Should handle arrays with 1-3 dimensions
    • All returned arrays should have the same shape
  2. Implement a function expand_to_shape(array, target_shape) that:

    • Takes a single array and a target shape
    • Expands the array to match the target shape following broadcasting rules
    • Returns the expanded array with the specified shape

Constraints

  • Arrays can have shapes like (3,), (3, 1), (1, 5), (3, 5), etc.
  • The solution should follow standard broadcasting semantics
  • Do not use explicit loops to replicate data; use proper array broadcasting mechanisms

Dependencies { .dependencies }

cupy { .dependency }

GPU-accelerated array library with NumPy-compatible API for numerical computing.

Test Cases

Test Case 1: Basic broadcasting { .test }

File: test_shape_normalizer.py

Description: Test basic broadcasting with two arrays

Input:

import cupy as cp
from shape_normalizer import broadcast_arrays_to_common_shape

arrays = [
    cp.array([1, 2, 3]),
    cp.array([[4], [5], [6]])
]
result = broadcast_arrays_to_common_shape(arrays)

Expected Output: All arrays in result should have shape (3, 3). The first array is broadcast from (3,) to (3, 3), and the second array is broadcast from (3, 1) to (3, 3).

Test Case 2: Expanding to target shape { .test }

File: test_shape_normalizer.py

Description: Test expanding a single array to a target shape

Input:

import cupy as cp
from shape_normalizer import expand_to_shape

arr = cp.array([1, 2, 3])
result = expand_to_shape(arr, (4, 3))

Expected Output: Result shape should be (4, 3) with the original array values repeated along the first axis.

Implementation Notes

  • Focus on using efficient array operations
  • Ensure the solution works with GPU arrays
  • Handle edge cases where arrays cannot be broadcast together
  • The implementation should be concise and leverage library capabilities

Deliverables

  1. shape_normalizer.py - Main implementation file
  2. test_shape_normalizer.py - Test file with the test cases above