quantnn/generic/__init__.py
def to_array(module, array, like=None):
    """
    Turn a list into an array.

    Args:
         module: Module representing the module which should be used as
             backend.
         array: Iterable to turn into array.

    Returns:
        Array-object corresponding to the given backend module containing the
        data in array.
    """
    _import_modules()
    if module in [np, ma]:
        if like is not None:
            return module.asarray(array, dtype=like.dtype)
        else:
            return module.asarray(array)
    elif module == torch:
        if isinstance(array, torch.Tensor):
            if like is None:
                return array
            else:
                t = array.to(device=like.device, dtype=like.dtype)
                if like.requires_grad:
                    t.requires_grad = True
                return t

        if like is not None:
            return module.tensor(
                array,
                dtype=like.dtype,
                device=like.device,
                requires_grad=like.requires_grad,
            )
        else:
            return module.tensor(array)
    elif module == jnp:
        return module.asarray(array)
    elif module == tf:
        return module.convert_to_tensor(array)
    raise UnknownModuleException(f"Module {module.__name__} not supported.")

    Turn a list into an array.

    Args:
         module: Module representing the module which should be used as
             backend.
         array: Iterable to turn into array.

    Returns:
        Array-object corresponding to the given backend module containing the
        data in array.
    
Turn a list into an array.
Turn a list into an array .
def to_array(module, array, like=None):
    _import_modules()
    if module in [np, ma]:
        if like is not None:
            return module.asarray(array, dtype=like.dtype)
        else:
            return module.asarray(array)
    elif module == torch:
        if isinstance(array, torch.Tensor):
            if like is None:
                return array
            else:
                t = array.to(device=like.device, dtype=like.dtype)
                if like.requires_grad:
                    t.requires_grad = True
                return t
        if like is not None:
            return module.tensor(
                array,
                dtype=like.dtype,
                device=like.device,
                requires_grad=like.requires_grad,
            )
        else:
            return module.tensor(array)
    elif module == jnp:
        return module.asarray(array)
    elif module == tf:
        return module.convert_to_tensor(array)
    raise UnknownModuleException(f"Module {module.__name__} not supported.")
def to_array ( module , array , like = None ) : _import_modules ( ) if module in [ np , ma ] : if like is not None : return module . asarray ( array , dtype = like . dtype ) else : return module . asarray ( array ) elif module == torch : if isinstance ( array , torch . Tensor ) : if like is None : return array else : t = array . to ( device = like . device , dtype = like . dtype ) if like . requires_grad : t . requires_grad = True return t if like is not None : return module . tensor ( array , dtype = like . dtype , device = like . device , requires_grad = like . requires_grad , ) else : return module . tensor ( array ) elif module == jnp : return module . asarray ( array ) elif module == tf : return module . convert_to_tensor ( array ) raise UnknownModuleException ( f"Module {module.__name__} not supported." )
Turn a list into an array.
Turn a list into an array .
"""
    Turn a list into an array.

    Args:
         module: Module representing the module which should be used as
             backend.
         array: Iterable to turn into array.

    Returns:
        Array-object corresponding to the given backend module containing the
        data in array.
    """
Array-object corresponding to the given backend module containing the
data in array.
Array - object corresponding to the given backend module containing the data in array .
module
Module representing the module which should be used as
backend.
Module representing the module which should be used as backend .
array
Iterable to turn into array.
Iterable to turn into array .
like