Skip to content

Latest commit

 

History

History
145 lines (85 loc) · 3.59 KB

data_type_functions.md

File metadata and controls

145 lines (85 loc) · 3.59 KB

Data type functions

Array API specification for data type functions.

A conforming implementation of the array API standard must provide and support the following data type functions.

Objects in API

(function-broadcast_arrays)=

broadcast_arrays(*arrays)

Broadcasts one or more arrays against one another.

Parameters

  • arrays: Sequence[ <array> ]

    • arrays to broadcast.

Returns

  • out: List[ <array> ]

    • a list of broadcasted arrays. Each array must have the same shape. Each array must have the same dtype as its corresponding input array.

(function-broadcast_to)=

broadcast_to(x, /, shape)

Broadcasts an array to a specified shape.

Parameters

  • x: <array>

    • array to broadcast.
  • shape: Tuple[int, ...]

    • array shape. Must be compatible with x (see {ref}broadcasting).

Returns

  • out: <array>

    • an array having a specified shape. Must have the same data type as x.

Raises

  • if the array is incompatible with the specified shape (see {ref}broadcasting).

(function-can_cast)=

can_cast(from_, to, /)

Determines if one data type can be cast to another data type according {ref}type-promotion rules.

Parameters

  • from_: Union[ <dtype>, <array>]

    • input data type or array from which to cast.
  • to: <dtype>

    • desired data type.

Returns

  • out: bool

    • True if the cast can occur according to {ref}type-promotion rules; otherwise, False.

(function-finfo)=

finfo(type, /)

Machine limits for floating-point data types.

Parameters

  • type: Union[ <dtype>, <array> ]

    • the kind of floating-point data-type about which to get information.

Returns

  • out: <finfo object>

    • an object having the following attributes:

      • bits: int
        • number of bits occupied by the floating-point data type.
      • eps: float
        • difference between 1.0 and the next smallest representable floating-point number larger than 1.0 according to the IEEE-754 standard.
      • max: float
        • largest representable number.
      • min: float
        • smallest representable number.
      • smallest_normal: float
        • smallest positive floating-point number with full precision.

(function-iinfo)=

iinfo(type, /)

Machine limits for integer data types.

Parameters

  • type: Union[ <dtype>, <array> ]

    • the kind of integer data-type about which to get information.

Returns

  • out: <iinfo object>

    • a class with that encapsules the following attributes:

      • bits: int
        • number of bits occupied by the type
      • max: int
        • largest representable number.
      • min: int
        • smallest representable number.

(function-result_type)=

result_type(*arrays_and_dtypes)

Returns the dtype that results from applying the type promotion rules (see {ref}type-promotion) to the arguments.

If provided mixed dtypes (e.g., integer and floating-point), the returned dtype will be implementation-specific.

Parameters

  • arrays_and_dtypes: Sequence[ Union[ <array>, <dtype> ] ]

    • input arrays and dtypes.

Returns

  • out: <dtype>

    • the dtype resulting from an operation involving the input arrays and dtypes.