def _get_numerical_grads_and_val(self, f_str, tensors, next_error=None):
        '''`
        get autodiff grads from numpy string expression
        tensors: numpy tensor vals
        '''
        # buffer for gradients
        gradients = []
        for tensor in tensors:
            gradients.append(np.zeros(tensor.shape))
        # function values
        f_val = TestAutodiff._numpy_call(f_str, tensors)
        # init next error
        if next_error is None:
            next_error = np.ones_like(f_val)
        # numerical gradients
        for tensor, gradient in zip(tensors, gradients):
            gradient_flat = np.copy(gradient.reshape((-1, )))
            ind = 0
            for x in np.nditer(tensor, op_flags=['readwrite']):
                # backup
                x_backup = np.copy(x)
                # increment
                x[...] = x + self.delta
                f_inc = np.sum(TestAutodiff._numpy_call(f_str, tensors) * next_error)
                x[...] = x_backup
                # decrement
                x[...] = x - self.delta
                f_dec = np.sum(TestAutodiff._numpy_call(f_str, tensors) * next_error)
                x[...] = x_backup
                # gradient
                gradient_flat[ind] = (f_inc - f_dec) / (2.0 * self.delta)
                ind += 1
            # write to gradient
            gradient[:] = gradient_flat.reshape(gradient.shape)

        return [gradients, f_val]
dataset/ETHPy150Open NervanaSystems/neon/neon/backends/tests/test_autodiff_extra.py/TestAutodiff._get_numerical_grads_and_val/original