CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-cupy-rocm-4-3

CuPy: NumPy & SciPy for GPU - A NumPy/SciPy-compatible array library for GPU-accelerated computing with Python, specifically built for AMD ROCm 4.3 platform

Pending
Overview
Eval results
Files

data-types.mddocs/

Data Type Functions

Data type utilities for type checking, conversion, and promotion. These functions help manage data types and ensure compatibility between operations on GPU arrays.

Capabilities

Type Checking and Casting

Functions to check type compatibility and determine safe casting between data types.

def can_cast(from_, to, casting='safe'):
    """
    Returns True if cast between data types can occur according to casting rule.
    
    Parameters:
    - from_: dtype or cupy.ndarray, source data type or array
    - to: dtype, target data type
    - casting: {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, casting rule
    
    Returns:
    bool: True if cast is possible under specified rule
    """

def result_type(*arrays_and_dtypes):
    """
    Returns the type that results from applying NumPy type promotion rules.
    
    Parameters:
    - arrays_and_dtypes: sequence of arrays and dtypes
    
    Returns:
    numpy.dtype: resulting data type after promotion
    """

def common_type(*arrays):
    """
    Return a scalar type which is common to the input arrays.
    
    Parameters:
    - arrays: sequence of cupy.ndarray
    
    Returns:
    type: common scalar type for floating point arrays
    """

def min_scalar_type(a):
    """
    For scalar a, returns the data type with the smallest size and smallest 
    scalar kind which can hold its value.
    
    Parameters:
    - a: scalar, input scalar value
    
    Returns:
    numpy.dtype: smallest suitable data type
    """

def promote_types(type1, type2):
    """
    Returns the data type with the smallest size and smallest scalar kind 
    to which both type1 and type2 may be safely cast.
    
    Parameters:
    - type1: numpy.dtype, first data type
    - type2: numpy.dtype, second data type  
    
    Returns:
    numpy.dtype: promoted data type
    """

Data Type Information

Functions to obtain information about data types including precision and ranges.

def finfo(dtype):
    """
    Machine limits for floating point types.
    
    Parameters:
    - dtype: float, dtype, or instance, floating point data type
    
    Returns:
    numpy.finfo: object with floating point type information
    """

def iinfo(int_type):
    """
    Machine limits for integer types.
    
    Parameters:
    - int_type: integer type, dtype, or instance
    
    Returns:
    numpy.iinfo: object with integer type information
    """

def issubdtype(arg1, arg2):
    """
    Returns True if first argument is a typecode lower/equal in type hierarchy.
    
    Parameters:
    - arg1: numpy.dtype, data type to check
    - arg2: numpy.dtype, data type to compare against
    
    Returns:
    bool: True if arg1 is subtype of arg2
    """

def dtype(obj, align=False, copy=None):
    """
    Create a data type object.
    
    Parameters:
    - obj: object to convert to dtype
    - align: bool, add padding to match hardware alignment
    - copy: bool, make a copy of dtype object
    
    Returns:
    numpy.dtype: data type object
    """

Legacy Type Functions

Legacy functions for backwards compatibility with older NumPy versions.

def mintypecode(typechars, typeset='GDFgdf', default='d'):
    """
    Return the character for the minimum-size type which can represent 
    the data types in typechars.
    
    Parameters:
    - typechars: list of strings, type characters
    - typeset: str, set of type characters to choose from  
    - default: str, default type character
    
    Returns:
    str: type character for minimum type
    """

def typename(char):
    """
    Return a description for the given data type code.
    
    Parameters:
    - char: str, data type character code
    
    Returns:
    str: description of data type
    """

Data Type Constants

Available data types and type categories inherited from NumPy.

# Numeric type hierarchy
class generic: ...
class number(generic): ...
class integer(number): ...
class signedinteger(integer): ...
class unsignedinteger(integer): ...
class inexact(number): ...
class floating(inexact): ...
class complexfloating(inexact): ...

# Boolean type
class bool_(generic): ...

# Integer types
class int8(signedinteger): ...
class int16(signedinteger): ...
class int32(signedinteger): ...
class int64(signedinteger): ...

class uint8(unsignedinteger): ...
class uint16(unsignedinteger): ...
class uint32(unsignedinteger): ...
class uint64(unsignedinteger): ...

# Floating point types  
class float16(floating): ...
class float32(floating): ...
class float64(floating): ...

# Complex types
class complex64(complexfloating): ...
class complex128(complexfloating): ...

# Platform-dependent types
int_ = int64    # Platform integer
intp = int64    # Pointer-sized integer
float_ = float64  # Platform float
complex_ = complex128  # Platform complex

Usage Examples

import cupy as cp
import numpy as np

# Type checking and casting
arr_int = cp.array([1, 2, 3], dtype=cp.int32)
arr_float = cp.array([1.0, 2.0, 3.0], dtype=cp.float64)

# Check if casting is safe
can_cast_safe = cp.can_cast(arr_int.dtype, cp.float64, 'safe')  # True
can_cast_unsafe = cp.can_cast(arr_float.dtype, cp.int32, 'safe')  # False

# Find common result type
result_dtype = cp.result_type(arr_int, arr_float)  # float64

# Type promotion
promoted = cp.promote_types(cp.int32, cp.float32)  # float64

# Get type information
float_info = cp.finfo(cp.float32)
print(f"Float32 precision: {float_info.precision}")
print(f"Float32 range: {float_info.min} to {float_info.max}")

int_info = cp.iinfo(cp.int16)
print(f"Int16 range: {int_info.min} to {int_info.max}")

# Check type hierarchy
is_sub = cp.issubdtype(cp.int32, cp.integer)  # True
is_sub2 = cp.issubdtype(cp.float32, cp.integer)  # False

# Find minimum type for scalar
scalar_val = 100
min_type = cp.min_scalar_type(scalar_val)  # int8 (if 100 fits)

# Create dtype objects
dt1 = cp.dtype('f4')  # float32
dt2 = cp.dtype(cp.int64)  # int64
dt3 = cp.dtype([('x', cp.float32), ('y', cp.float32)])  # structured type

# Common type for arrays
common = cp.common_type(arr_int, arr_float)  # <class 'numpy.float64'>

# Legacy functions (mainly for compatibility)
type_char = cp.mintypecode(['i', 'f'], 'GDFgdf')  # 'd' for float64
type_desc = cp.typename('d')  # Description of float64

Install with Tessl CLI

npx tessl i tessl/pypi-cupy-rocm-4-3

docs

array-creation.md

cuda-integration.md

custom-kernels.md

data-types.md

extended-functionality.md

fft.md

index.md

io-functions.md

linear-algebra.md

logic-functions.md

mathematical-functions.md

polynomial.md

random.md

statistics.md

utilities.md

tile.json