update approx, models, simulators, and processors

This commit is contained in:
Brian Delhaisse
2019-03-25 02:04:46 +01:00
parent 05a7c51640
commit f44b1fe17c
50 changed files with 2866 additions and 2346 deletions
+7 -1
View File
@@ -38,7 +38,9 @@ def convert_numpy(f):
x = f(self, x)
# reconvert to numpy array if specified, and return it
if to_numpy:
if to_numpy and isinstance(x, torch.Tensor):
if x.requires_grad:
return x.detach().numpy()
return x.numpy()
# return torch Tensor
@@ -56,14 +58,18 @@ class Processor(object):
"""
def __init__(self):
"""Initialize the processor."""
pass
def reset(self):
"""Reset the processor."""
pass
@convert_numpy
def compute(self, x):
"""Compute the output given the input :attr:`x`."""
pass
def __call__(self, x, to_numpy=False):
"""Alias: call :func:`compute` to compute the output given the input :attr:`x`."""
return self.compute(x, to_numpy=to_numpy)