Cast

Description

Info

Parent class: Module

Derived classes: -

This module performs the function of changing the tensor data type.

Initializing

def __init__(self, intype, outtype, name=None):

Parameters

Parameter Allowed types Description Default
intype dtype Input data type -
outtype dtype Output data type None
name str Layer name None

Explanations

-

Examples

Necessary imports.

>>> import numpy as np
>>> from PuzzleLib.Backend import gpuarray
>>> from PuzzleLib.Modules import Cast

Info

gpuarray is required to properly place the tensor in the GPU.

>>> batchsize, size, maps = 2, 3, 2
>>> data1 = gpuarray.to_gpu(np.arange(batchsize * size * maps).reshape((batchsize, size, maps)).astype(np.float32))
>>> data2 = gpuarray.to_gpu(np.arange(batchsize * size * maps).reshape((batchsize, size, maps)).astype(np.float16))

```python
>>> data1.dtype
dtype('float32')
>>> data2.dtype
dtype('float16')
>>> cast = Cast(data1.dtype, data2.dtype)
>>> data1 = cast(data1).dtype
>>> data1.dtype
dtype('float16')