@@ -1707,6 +1707,13 @@ static Tensor& std_var_out(
1707
1707
TORCH_CHECK (at::isFloatingType (self.scalar_type ()) || at::isComplexType (self.scalar_type ()),
1708
1708
" std and var only support floating point and complex dtypes" );
1709
1709
1710
+ if (!correction_opt.has_value ()) {
1711
+ TORCH_WARN_ONCE (
1712
+ fname, " : the default for the correction parameter is deprecated. " ,
1713
+ " Call with correction=1 to maintain the current default behavior." )
1714
+ }
1715
+
1716
+ const auto correction = correction_opt.value_or (1 );
1710
1717
if (at::isComplexType (self.scalar_type ())) {
1711
1718
// For complex, calculate variance of real and imaginary components
1712
1719
// separately then add to get overall variance.
@@ -1718,7 +1725,7 @@ static Tensor& std_var_out(
1718
1725
real_out,
1719
1726
real_in,
1720
1727
dim,
1721
- correction_opt ,
1728
+ correction ,
1722
1729
keepdim,
1723
1730
/* take_sqrt=*/ false );
1724
1731
@@ -1729,7 +1736,7 @@ static Tensor& std_var_out(
1729
1736
imag_out,
1730
1737
imag_in,
1731
1738
dim,
1732
- correction_opt ,
1739
+ correction ,
1733
1740
keepdim,
1734
1741
/* take_sqrt=*/ false );
1735
1742
@@ -1741,7 +1748,6 @@ static Tensor& std_var_out(
1741
1748
}
1742
1749
1743
1750
// Computation for floating point
1744
- const auto correction = correction_opt.value_or (1 );
1745
1751
ScalarType dtype = get_dtype_from_result (result, {});
1746
1752
auto iter = make_reduction (fname, result, self, dim, keepdim, dtype);
1747
1753
TORCH_CHECK (at::canCast (self.scalar_type (), result.scalar_type ()),
@@ -1781,7 +1787,13 @@ static std::tuple<Tensor&, Tensor&> std_var_mean_out(
1781
1787
TORCH_CHECK (result1.scalar_type () == c10::toRealValueType (result2.scalar_type ()),
1782
1788
fname, " expected result1 to be real and match the precision of result2. Got " ,
1783
1789
result1.scalar_type (), " and " , result2.scalar_type (), " ." );
1790
+ if (!correction_opt.has_value ()) {
1791
+ TORCH_WARN_ONCE (
1792
+ fname, " : the default for the correction parameter is deprecated. " ,
1793
+ " Call with correction=1 to maintain the current default behavior." )
1794
+ }
1784
1795
1796
+ const auto correction = correction_opt.value_or (1 );
1785
1797
if (at::isComplexType (self.scalar_type ())) {
1786
1798
// For complex, calculate for real and imaginary components separately then combine as:
1787
1799
// variance = var_real + var_imag
@@ -1796,7 +1808,7 @@ static std::tuple<Tensor&, Tensor&> std_var_mean_out(
1796
1808
real_out_mean,
1797
1809
real_in,
1798
1810
dim,
1799
- correction_opt ,
1811
+ correction ,
1800
1812
keepdim,
1801
1813
/* take_sqrt=*/ false );
1802
1814
@@ -1809,7 +1821,7 @@ static std::tuple<Tensor&, Tensor&> std_var_mean_out(
1809
1821
imag_out_mean,
1810
1822
imag_in,
1811
1823
dim,
1812
- correction_opt ,
1824
+ correction ,
1813
1825
keepdim,
1814
1826
/* take_sqrt=*/ false );
1815
1827
@@ -1822,7 +1834,6 @@ static std::tuple<Tensor&, Tensor&> std_var_mean_out(
1822
1834
}
1823
1835
1824
1836
// Computation for floating point
1825
- const auto correction = correction_opt.value_or (1 );
1826
1837
ScalarType dtype = get_dtype_from_result (result1, {});
1827
1838
auto iter =
1828
1839
make_reduction (fname, result1, result2, self, dim, keepdim, dtype);
@@ -1837,32 +1848,41 @@ static std::tuple<Tensor&, Tensor&> std_var_mean_out(
1837
1848
return std::tuple<Tensor&, Tensor&>(result1, result2);
1838
1849
}
1839
1850
1851
+ static inline c10::optional<int64_t > correction_from_unbiased (
1852
+ c10::string_view fname, bool unbiased) {
1853
+ if (unbiased) {
1854
+ TORCH_WARN_ONCE (
1855
+ fname, " : The 'unbiased' parameter and it's default value are deprecated in favor of 'correction'. "
1856
+ " Use correction=1 for Bessel's correction, equivalent to unbiased=True." );
1857
+ return 1 ;
1858
+ } else {
1859
+ TORCH_WARN_ONCE (
1860
+ fname, " : The 'unbiased; parameter is deprecated. "
1861
+ " Use correction=0 to apply no Bessel's correction, equivalent to unbiased=False." );
1862
+ return 0 ;
1863
+ }
1864
+ }
1865
+
1840
1866
std::tuple<Tensor, Tensor> var_mean (
1841
1867
const Tensor& self, at::OptionalIntArrayRef dim, bool unbiased, bool keepdim) {
1842
- return at::var_mean (
1843
- self, /* dim=*/ at::OptionalIntArrayRef (dim),
1844
- /* correction=*/ c10::make_optional<int64_t >({unbiased ? 1 : 0 }),
1845
- keepdim);
1868
+ const auto correction = correction_from_unbiased (" var_mean" , unbiased);
1869
+ return at::var_mean (self, dim, correction, keepdim);
1846
1870
}
1847
1871
1848
1872
std::tuple<Tensor, Tensor> std_mean (
1849
1873
const Tensor& self, at::OptionalIntArrayRef dim, bool unbiased, bool keepdim) {
1850
- return at::std_mean (
1851
- self, /* dim=*/ at::OptionalIntArrayRef (dim),
1852
- /* correction=*/ c10::make_optional<int64_t >({unbiased ? 1 : 0 }),
1853
- keepdim);
1874
+ const auto correction = correction_from_unbiased (" std_mean" , unbiased);
1875
+ return at::std_mean (self, dim, correction, keepdim);
1854
1876
}
1855
1877
1856
1878
std::tuple<Tensor, Tensor> std_mean (const Tensor& self, bool unbiased) {
1857
- return at::std_mean (
1858
- self, /* dim=*/ c10::nullopt,
1859
- /* correction=*/ c10::make_optional<int64_t >({unbiased ? 1 : 0 }));
1879
+ const auto correction = correction_from_unbiased (" std_mean" , unbiased);
1880
+ return at::std_mean (self, /* dim=*/ c10::nullopt, correction);
1860
1881
}
1861
1882
1862
1883
std::tuple<Tensor, Tensor> var_mean (const Tensor& self, bool unbiased) {
1863
- return at::var_mean (
1864
- self, /* dim=*/ c10::nullopt,
1865
- /* correction=*/ c10::make_optional<int64_t >({unbiased ? 1 : 0 }));
1884
+ const auto correction = correction_from_unbiased (" var_mean" , unbiased);
1885
+ return at::var_mean (self, /* dim=*/ c10::nullopt, correction);
1866
1886
}
1867
1887
1868
1888
std::tuple<Tensor&, Tensor&> var_mean_out (
@@ -1896,38 +1916,34 @@ std::tuple<Tensor, Tensor> std_mean(
1896
1916
}
1897
1917
1898
1918
Tensor var (const Tensor& self, bool unbiased) {
1899
- return at::var (
1900
- self, /* dim=*/ c10::nullopt,
1901
- /* correction=*/ c10::make_optional<int64_t >({unbiased ? 1 : 0 }));
1919
+ const auto correction = correction_from_unbiased (" var" , unbiased);
1920
+ return at::var (self, /* dim=*/ c10::nullopt, correction);
1902
1921
}
1903
1922
1904
- Tensor var (const Tensor& self, at::OptionalIntArrayRef dim, bool unbiased, bool keepdim) {
1905
- return at::var (
1906
- self, /* dim=*/ at::OptionalIntArrayRef (dim),
1907
- /* correction=*/ c10::make_optional<int64_t >({unbiased ? 1 : 0 }),
1908
- keepdim);
1923
+ Tensor var (const Tensor& self, at::OptionalIntArrayRef dim,
1924
+ bool unbiased, bool keepdim) {
1925
+ const auto correction = correction_from_unbiased (" var" , unbiased);
1926
+ return at::var (self, dim, correction, keepdim);
1909
1927
}
1910
1928
1911
1929
Tensor& var_out (const Tensor& self, at::OptionalIntArrayRef dim, bool unbiased, bool keepdim, Tensor& result) {
1912
- return at::var_out (
1913
- result, self, /* dim=*/ at::OptionalIntArrayRef (dim),
1914
- /* correction=*/ c10::make_optional<int64_t >({unbiased ? 1 : 0 }),
1915
- keepdim);
1930
+ const auto correction = correction_from_unbiased (" var" , unbiased);
1931
+ return at::var_out (result, self, dim, correction, keepdim);
1916
1932
}
1917
1933
1918
1934
Tensor std (const Tensor& self, bool unbiased) {
1919
- return at::std (
1920
- self, /* dim=*/ c10::nullopt, /* correction= */ c10::make_optional< int64_t >({unbiased ? 1 : 0 }) );
1935
+ const auto correction = correction_from_unbiased ( " std " , unbiased);
1936
+ return at::std ( self, /* dim=*/ c10::nullopt, correction);
1921
1937
}
1922
1938
1923
1939
Tensor std (const Tensor& self, at::OptionalIntArrayRef dim, bool unbiased, bool keepdim) {
1924
- return at::std (self, dim,
1925
- /* correction= */ c10::make_optional< int64_t >({unbiased ? 1 : 0 }) , keepdim);
1940
+ const auto correction = correction_from_unbiased ( " std " , unbiased);
1941
+ return at::std (self, dim, correction , keepdim);
1926
1942
}
1927
1943
1928
1944
Tensor& std_out (const Tensor& self, at::OptionalIntArrayRef opt_dim, bool unbiased, bool keepdim, Tensor& result) {
1929
- return at::std_out (result, self, opt_dim,
1930
- /* correction= */ c10::make_optional< int64_t >({unbiased ? 1 : 0 }) , keepdim);
1945
+ const auto correction = correction_from_unbiased ( " std " , unbiased);
1946
+ return at::std_out (result, self, opt_dim, correction , keepdim);
1931
1947
}
1932
1948
1933
1949
Tensor std (const Tensor& self, at::OptionalIntArrayRef dim,
0 commit comments