bitcast_convert_type

bitcast_convert_type#

class brainunit.lax.bitcast_convert_type(operand, new_dtype, **kwargs)#

Elementwise bitcast.

Wraps XLA’s BitcastConvertType operator, which performs a bit cast from one type to another.

The output shape depends on the size of the input and output dtypes:

if new_dtype.itemsize == operand.dtype.itemsize:
    output_shape = operand.shape
if new_dtype.itemsize < operand.dtype.itemsize:
    output_shape = (*operand.shape, operand.dtype.itemsize // new_dtype.itemsize)
if new_dtype.itemsize > operand.dtype.itemsize:
    assert operand.shape[-1] * operand.dtype.itemsize == new_dtype.itemsize
    output_shape = operand.shape[:-1]
Parameters:
  • operand (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – An array or scalar value to be cast.

  • new_dtype (str | type[Any] | dtype | SupportsDType) – The new type. Should be a NumPy dtype.

Returns:

out – An array of shape output_shape (see above) and type new_dtype, constructed from the same bits as operand.

Return type:

saiunit.Quantity | Array