Contains various utility functions
from fastcore.test import test_eq

General

noop[source]

noop(x=None, *args, **kwargs)

Do nothing

apply[source]

apply(func, x, *args, **kwargs)

Apply func recursively to x, passing on args

retain_type[source]

retain_type(new, old=None, typ=None, copy_meta=False)

Cast new to type of old or typ if it's a superclass

retain_meta[source]

retain_meta(x, res, copy_meta=False)

Call res.set_meta(x), if it exists

Torch

to_device[source]

to_device(b, device='cpu')

Recursively put b on device.

tensor[source]

tensor(x, *rest, **kwargs)

Like torch.as_tensor, but handle lists too, and can pass multiple vector elements directly.

test_eq(_array2tensor(np.array([3,2,1])), tensor([3,2,1]))