Python wrapper for Nvidia CUDA parallel computation API with object cleanup, automatic error checking, and convenient abstractions.
Implement a GPU-accelerated calculator for computing properties of 2D vector fields. The calculator should perform element-wise arithmetic operations on vector components stored as GPU arrays.
Compute the magnitude of 2D vectors using the formula: magnitude = sqrt(x^2 + y^2).
Add two vector fields component-wise.
Scale a vector field by a constant factor.
Normalize vectors in the field to unit length (magnitude = 1.0) by dividing each component by its magnitude. Handle zero-magnitude vectors by leaving them unchanged.
@generates
import numpy as np
from typing import Tuple
def calculate_magnitude(x_components: np.ndarray, y_components: np.ndarray) -> np.ndarray:
"""
Calculate the magnitude of 2D vectors using GPU acceleration.
Args:
x_components: Array of x-components
y_components: Array of y-components
Returns:
Array of vector magnitudes
"""
pass
def add_vector_fields(
x1: np.ndarray, y1: np.ndarray,
x2: np.ndarray, y2: np.ndarray
) -> Tuple[np.ndarray, np.ndarray]:
"""
Add two vector fields component-wise using GPU acceleration.
Args:
x1, y1: First vector field components
x2, y2: Second vector field components
Returns:
Tuple of (x_result, y_result) arrays
"""
pass
def scale_vector_field(
x: np.ndarray, y: np.ndarray, scale: float
) -> Tuple[np.ndarray, np.ndarray]:
"""
Scale a vector field by a constant factor using GPU acceleration.
Args:
x, y: Vector field components
scale: Scaling factor
Returns:
Tuple of (x_scaled, y_scaled) arrays
"""
pass
def normalize_vector_field(
x: np.ndarray, y: np.ndarray
) -> Tuple[np.ndarray, np.ndarray]:
"""
Normalize vectors in the field to unit length using GPU acceleration.
Zero-magnitude vectors remain unchanged.
Args:
x, y: Vector field components
Returns:
Tuple of (x_normalized, y_normalized) arrays
"""
passProvides GPU-accelerated array operations for computing vector field properties.
@satisfied-by
tessl i tessl/pypi-pycuda@2025.1.0docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10