/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
torch
/
include
/
ATen
/
core
/
/usr/local/lib64/python3.6/site-packages/torch/include/ATen/core
mkdir
upload
Name
Size
Mode
Actions
boxing/
-
0755
rm
dispatch/
-
0755
rm
op_registration/
-
0755
rm
alias_info.h
2986
0644
edit
dl
rm
Array.h
768
0644
edit
dl
rm
ATenGeneral.h
45
0644
edit
dl
rm
ATenOpList.h
246
0644
edit
dl
rm
aten_interned_strings.h
25389
0644
edit
dl
rm
Backtrace.h
59
0644
edit
dl
rm
blob.h
5422
0644
edit
dl
rm
builtin_function.h
3649
0644
edit
dl
rm
DeprecatedTypeProperties.h
3773
0644
edit
dl
rm
DeprecatedTypePropertiesRegistry.h
795
0644
edit
dl
rm
Dict.h
13195
0644
edit
dl
rm
Dict_inl.h
7996
0644
edit
dl
rm
Dimname.h
1188
0644
edit
dl
rm
DimVector.h
247
0644
edit
dl
rm
DistributionsHelper.h
12594
0644
edit
dl
rm
Formatting.h
959
0644
edit
dl
rm
function.h
2145
0644
edit
dl
rm
functional.h
1460
0644
edit
dl
rm
function_schema.h
13577
0644
edit
dl
rm
function_schema_inl.h
9319
0644
edit
dl
rm
Generator.h
4935
0644
edit
dl
rm
grad_mode.h
210
0644
edit
dl
rm
interned_strings.h
25332
0644
edit
dl
rm
interned_strings_class.h
770
0644
edit
dl
rm
ivalue.h
38823
0644
edit
dl
rm
ivalue_inl.h
59963
0644
edit
dl
rm
ivalue_to.h
756
0644
edit
dl
rm
jit_type.h
75971
0644
edit
dl
rm
jit_type_base.h
6508
0644
edit
dl
rm
LegacyTypeDispatch.h
4626
0644
edit
dl
rm
List.h
15667
0644
edit
dl
rm
List_inl.h
11012
0644
edit
dl
rm
Macros.h
44
0644
edit
dl
rm
MT19937RNGEngine.h
6410
0644
edit
dl
rm
NamedTensor.h
5050
0644
edit
dl
rm
operator_name.h
3018
0644
edit
dl
rm
PhiloxRNGEngine.h
6496
0644
edit
dl
rm
PythonModeTLS.h
403
0644
edit
dl
rm
qualified_name.h
4358
0644
edit
dl
rm
QuantizerBase.h
2443
0644
edit
dl
rm
Range.h
418
0644
edit
dl
rm
Reduction.h
461
0644
edit
dl
rm
rref_interface.h
1144
0644
edit
dl
rm
Scalar.h
29
0644
edit
dl
rm
ScalarType.h
33
0644
edit
dl
rm
stack.h
6034
0644
edit
dl
rm
Tensor.h
1756
0644
edit
dl
rm
TensorAccessor.h
10296
0644
edit
dl
rm
TensorBase.h
32767
0644
edit
dl
rm
TensorBody.h
247555
0644
edit
dl
rm
TransformationHelper.h
6911
0644
edit
dl
rm
typeid.h
29
0644
edit
dl
rm
UndefinedTensorImpl.h
42
0644
edit
dl
rm
UnsafeFromTH.h
708
0644
edit
dl
rm
VariableHooksInterface.h
3312
0644
edit
dl
rm
Variadic.h
2257
0644
edit
dl
rm
Vitals.h
2305
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/torch/include/ATen/core/TransformationHelper.h
(6911B)
#include <c10/macros/Macros.h> #include <c10/util/Half.h> #include <c10/util/BFloat16.h> #include <c10/util/MathConstants.h> #include <ATen/NumericUtils.h> #include <limits> #include <cstdint> #include <cassert> namespace at { // Using DistAccumType in accumulate types for distributions. // Note: Ideally we'd be using ATen/AccumulateType.h but looks // like the there is some inconsistency in how accumulate types // are mapped currently, e.g. for the cpu side, float is mapped // to double. template <typename T> struct DistAccumType { }; #if defined(__CUDACC__) || defined(__HIPCC__) template <> struct DistAccumType<half> { using type = float; }; #endif template <> struct DistAccumType<BFloat16> { using type = float; }; template <> struct DistAccumType<Half> { using type = float; }; template <> struct DistAccumType<float> { using type = float; }; template <> struct DistAccumType<double> { using type = double; }; template <typename T> using dist_acctype = typename DistAccumType<T>::type; namespace transformation { /** * A transformation function for `torch.Tensor.random_()`, when both `from` and `to` are specified. * `range` is `to - from` * `base` is `from` */ template <typename T, typename V> C10_HOST_DEVICE inline T uniform_int_from_to(V val, uint64_t range, int64_t base) { return static_cast<T>(static_cast<int64_t>((val % range) + base)); } /** * A transformation function for `torch.Tensor.random_()`, when `from=min_value(int64_t)` and to=None */ template <typename T, typename V> C10_HOST_DEVICE inline T uniform_int_full_range(V val) { return static_cast<T>(static_cast<int64_t>(val)); } /** * A transformation function for `torch.Tensor.random_()`, when used without specifying `from` and `to`. * In order to prevent compiler warnings reported in GitHub issue 46391, T can't be float or double * in this overloaded version */ template <typename T, typename V> C10_HOST_DEVICE inline typename std::enable_if<!(std::is_floating_point<T>::value), T>::type uniform_int(V val) { if (std::is_same<T, bool>::value) { return static_cast<bool>(val & 1); } else if (std::is_same<T, int64_t>::value) { return static_cast<T>(val % (static_cast<uint64_t>(std::numeric_limits<T>::max()) + 1)); } else if (std::is_same<T, at::Half>::value || std::is_same<T, at::BFloat16>::value) { return static_cast<T>(val % static_cast<uint64_t>((1ULL << std::numeric_limits<T>::digits) + 1)); } else if (std::is_integral<T>::value) { return static_cast<T>(val % (static_cast<uint64_t>(std::numeric_limits<T>::max()) + 1)); } else { assert(false); return 0; } } /** * An overloaded transformation function for `torch.Tensor.random_()`, when used without specifying `from` and `to`, * added to fix compiler warnings reported in GitHub issue 46391. T is either float or double in this version. */ template<typename T, typename V> C10_HOST_DEVICE inline typename std::enable_if<std::is_floating_point<T>::value, T>::type uniform_int(V val) { return static_cast<T>(val % static_cast<uint64_t>((1ULL << std::numeric_limits<T>::digits) + 1)); } template <typename T, typename V> C10_HOST_DEVICE inline dist_acctype<T> uniform_real(V val, T from, T to) { constexpr auto MASK = static_cast<V>((static_cast<uint64_t>(1) << std::numeric_limits<T>::digits) - 1); constexpr auto DIVISOR = static_cast<dist_acctype<T>>(1) / (static_cast<uint64_t>(1) << std::numeric_limits<T>::digits); dist_acctype<T> x = (val & MASK) * DIVISOR; return (x * (to - from) + from); } /** * Transforms normally distributed `val` with mean 0.0 and standard deviation 1.0 to * normally distributed with `mean` and standard deviation `std`. */ template <typename T> C10_HOST_DEVICE inline T normal(T val, T mean, T std) { return val * std + mean; } /** * Transforms uniformly distributed `val` between 0.0 and 1.0 to * Cauchy distribution with location parameter `median` and scale parameter `sigma`. */ template <typename T> C10_HOST_DEVICE inline T cauchy(T val, T median, T sigma) { // https://en.wikipedia.org/wiki/Cauchy_distribution#Cumulative_distribution_function // __tanf overflows and returns `inf/-inf` when (val > 1 - eps) or (val < 0 + eps), // thus we clip those values. constexpr T eps = std::numeric_limits<T>::epsilon(); constexpr T one_minus_eps = 1 - eps; constexpr T zero_plus_eps = 0 + eps; val = (val > one_minus_eps ? one_minus_eps : val); val = (val < zero_plus_eps ? zero_plus_eps : val); return median + sigma * at::tan(c10::pi<T> * (val - static_cast<T>(0.5))); } template <> C10_HOST_DEVICE inline double cauchy(double val, double median, double sigma) { // https://en.wikipedia.org/wiki/Cauchy_distribution#Cumulative_distribution_function return median + sigma * at::tan(c10::pi<double> * (val - static_cast<double>(0.5))); } /** * Transforms uniformly distributed `val` between 0.0 and 1.0 to * exponentialy distributed with `lambda` parameter of the distribution. */ template <typename T> C10_HOST_DEVICE __ubsan_ignore_float_divide_by_zero__ inline T exponential(T val, T lambda) { // https://en.wikipedia.org/wiki/Exponential_distribution#Generating_exponential_variates // Different implementations for CUDA and CPU to preserve original logic // TODO: must be investigated and unified!!! // https://github.com/pytorch/pytorch/issues/38662 #if defined(__CUDACC__) || defined(__HIPCC__) // BEFORE TOUCHING THIS CODE READ: https://github.com/pytorch/pytorch/issues/16706 // curand_uniform has (0,1] bounds. log(1) is 0 and exponential excludes 0. // we need log to be not 0, and not underflow when converted to half // fast __logf approximation can underflow, so set log to -epsilon/2 for 1 or close to 1 args auto log = val >= static_cast<T>(1.) - std::numeric_limits<T>::epsilon() / 2 ? -std::numeric_limits<T>::epsilon() / 2 : at::log(val); return static_cast<T>(-1.0) / lambda * log; #else return static_cast<T>(-1.0) / lambda * at::log(static_cast<T>(1.0) - val); #endif } /** * Transforms uniformly distributed `val` between 0.0 and 1.0 to * geometricaly distributed with success probability `p`. */ template <typename T> C10_HOST_DEVICE inline T geometric(T val, T p) { // https://en.wikipedia.org/wiki/Geometric_distribution#Related_distributions return static_cast<T>(::ceil(at::log(val) / at::log(static_cast<T>(1.0) - p))); } /** * Transforms normally distributed `val` to log-normally distributed. */ template <typename T> C10_HOST_DEVICE inline T log_normal(T val) { // https://en.wikipedia.org/wiki/Log-normal_distribution#Mode,_median,_quantiles return at::exp(val); } /** * Transforms uniformly distributed `val` between 0.0 and 1.0 to * bernoulli distributed with success probability `p`. */ template <typename T> C10_HOST_DEVICE inline T bernoulli(T val, T p) { return val < p; } }} // namespace at::transformation
Save
cmd:
run