def geomspace(start, stop, num=50, endpoint=True, dtype=None, axis=0): # pylint: disable=missing-docstring dtype = dtypes.as_dtype(dtype) if dtype else np_utils.result_type( start, stop, float(num), np_array_ops.zeros((), dtype)) computation_dtype = np.promote_types(dtype.as_numpy_dtype, np.float32) start = np_array_ops.asarray(start, dtype=computation_dtype) stop = np_array_ops.asarray(stop, dtype=computation_dtype) # follow the numpy geomspace convention for negative and complex endpoints start_sign = 1 - np_array_ops.sign(np_array_ops.real(start)) stop_sign = 1 - np_array_ops.sign(np_array_ops.real(stop)) signflip = 1 - start_sign * stop_sign // 2 res = signflip * logspace(log10(signflip * start), log10(signflip * stop), num, endpoint=endpoint, base=10.0, dtype=computation_dtype, axis=0) if axis != 0: res = np_array_ops.moveaxis(res, 0, axis) return math_ops.cast(res, dtype)
def _test(*args): expected = np.moveaxis(*args) raw_ans = np_array_ops.moveaxis(*args) self.assertAllEqual(expected, raw_ans)
def _test(*args): # pylint: disable=no-value-for-parameter expected = np.moveaxis(*args) raw_ans = np_array_ops.moveaxis(*args) self.assertAllEqual(expected, raw_ans)