def _phi(r, order): eps = _ivy.array([1e-6], 'float32') if order % 2 == 0: r = _ivy.maximum(r, eps) return 0.5 * (r**(0.5 * order)) * _ivy.log(r) else: r = _ivy.maximum(r, eps) return r**(0.5 * order)
def test_log(x, dtype_str, tensor_fn, dev_str, call): # smoke test x = tensor_fn(x, dtype_str, dev_str) ret = ivy.log(x) # type test assert ivy.is_array(ret) # cardinality test assert ret.shape == x.shape # value test assert np.allclose(call(ivy.log, x), ivy.numpy.log(ivy.to_numpy(x))) # compilation test helpers.assert_compilable(ivy.log)
def __init__(self, depth_prior=None, feat_prior=None, num_feature_channels=3, smooth_kernel_size=25, threshold_var_factor=0.99, depth_limits=(1e-3, 10.), depth_var_limits=(1e-3, 1e4), feat_var_limits=(1e-3, 1e4), omni_image_dims=(180, 360), smooth_mean=True, depth_buffer=True, stateful=False, device='cpu'): # ToDo: make variance fully optional. If not specified, # then do not compute and scatter during function call for better efficiency. # features self._feat_dim = num_feature_channels # hole priors if depth_prior is None: depth_prior = ivy.ones((1, ), dev_str=device) * 1e-2 if feat_prior is None: feat_prior = ivy.ones( (num_feature_channels, ), dev_str=device) * 0.5 self._sphere_depth_prior_val = depth_prior self._sphere_feat_prior_val = feat_prior self._sphere_depth_prior = None self._sphere_feat_prior = None # value clipping self._min_depth = ivy.array(depth_limits[0], dev_str=device) self._max_depth = ivy.array(depth_limits[1], dev_str=device) # variance clipping ang_pix_var_limits = (1e-3, float(omni_image_dims[0])) self._min_ang_pix_var = ivy.array(ang_pix_var_limits[0], dev_str=device) self._min_depth_var = ivy.array(depth_var_limits[0], dev_str=device) self._min_feat_var = ivy.array(feat_var_limits[0], dev_str=device) self._ang_pix_prior_var_val = ivy.array(ang_pix_var_limits[1], dev_str=device) self._depth_prior_var_val = ivy.array(depth_var_limits[1], dev_str=device) self._feat_prior_var_val = ivy.array(feat_var_limits[1], dev_str=device) self._threshold_var_factor = ivy.array(threshold_var_factor, dev_str=device) self._ang_pix_var_threshold = ivy.array(ang_pix_var_limits[1] * self._threshold_var_factor, dev_str=device) self._depth_var_threshold = ivy.array(depth_var_limits[1] * self._threshold_var_factor, dev_str=device) self._feat_var_threshold = ivy.array(feat_var_limits[1] * self._threshold_var_factor, dev_str=device) # normalization self._depth_range = self._max_depth - self._min_depth self._min_log_depth_var = ivy.log(self._min_depth_var) self._min_log_feat_var = ivy.log(self._min_feat_var) max_log_depth_var = ivy.log(self._depth_prior_var_val) max_log_feat_var = ivy.log(self._feat_prior_var_val) self._log_depth_var_range = max_log_depth_var - self._min_log_depth_var self._log_feat_var_range = max_log_feat_var - self._min_log_feat_var # sphere image self._sphere_img_dims = list(omni_image_dims) self._pixels_per_degree = self._sphere_img_dims[0] / 180 # image smoothing self._smooth_kernel_size = smooth_kernel_size self._smooth_mean = smooth_mean # rendering config self._with_depth_buffer = depth_buffer # memory self._stateful = stateful self._memory = None # variables ivy.Module.__init__(self, device)
def _normalize_var(self, var): normed_depth_var = (ivy.log(var[..., 0:1]) - self._min_log_depth_var) / \ (self._log_depth_var_range + MIN_DENOMINATOR) normed_feat_var = (ivy.log(var[..., 4:]) - self._min_log_feat_var) / \ (self._log_feat_var_range + MIN_DENOMINATOR) return ivy.concatenate((normed_depth_var, normed_feat_var), -1)