pytorch/test
Mike Ruberry 3b7e1cd2cc Makes floor_divide a method, adds sparse floor division (#34552)
Summary:
(Updated per review feedback)

`torch.floor_divide` is currently a function that can operate on two tensors or a tensor and a scalar (scalar x scalar floor division is handled natively by Python and the JIT has a builtin function for it). This PR updates it to:

- have an out variant: `floor_divide(x, y, out=z)`
- be a method on a tensor: `x.floor_divide(y)`
- have an in-place variant: `x.floor_divide_(y)`
- work with sparse tensors

Tests are added to test_sparse.py and test_torch.py for these new behaviors.

In addition, this PR:

- cleans up the existing sparse division and true_division code and improves their error message
- adds testing of sparse true_division to test_sparse.py
- extends existing floor_divide testing in test_torch to run on CUDA, too, not just the CPU

Unfortunately, making floor_divide a method requires breaking backwards compatibility, and floor_divide has been added to the BC whitelist since this is international. The BC issue is that the first parameter name to torch.floor_divide is changing from input to self. If you previously called torch.floor_divide with keyword arguments, e.g. torch.floor_divide(input=x, other=y), you will need to update to torch.floor_divide(self=x, other=y), or the more common torch.floor_divide(x, y).

The intent of this PR is to allow floor_divide to be substituted for division (torch.div, /) wherever division was previously used. In 1.6 we expect torch.div to perform true_division, and floor_divide is how users can continue to perform integer division with tensors.

There are two potential follow-up issues suggested by this PR:

- the test framework might benefit from additional tensor construction classes, like one to create dividends and divisors for multiple dtypes
- the test framework might benefit from a universal function test class. while methods have reasonable coverage as part of test_torch.py's TestTensorOp tests, function coverage is spotty. Universal functions are similar enough it should be possible to generate tests for them.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/34552

Differential Revision: D20509850

Pulled By: mruberry

fbshipit-source-id: 2cd3c828aad67191c77f2ed8470411e246f604f8
2020-03-18 15:00:53 -07:00
..
backward_compatibility Makes floor_divide a method, adds sparse floor division (#34552) 2020-03-18 15:00:53 -07:00
bottleneck_test
cpp [C++ API Parity] LBFGS optimizer step() update and added closure to the Optimizer step() function (#34564) 2020-03-17 22:27:24 -07:00
cpp_api_parity [C++ API] RNN / GRU / LSTM layer refactoring (#34322) 2020-03-15 17:48:29 -07:00
cpp_extensions
custom_operator [jit] kill script namespace (#34515) 2020-03-11 23:32:48 -07:00
distributed Revert D20346700: [pytorch][PR] Eager autocasting, out-of-place ops only 2020-03-18 11:42:51 -07:00
error_messages
expect
jit [JIT] Add support for tolist for GPU-resident Tensors (#34554) 2020-03-11 15:14:12 -07:00
mobile [jit] kill script namespace (#34515) 2020-03-11 23:32:48 -07:00
onnx [ONNX] Fix for expand -1 dim value (#34069) 2020-03-16 15:30:20 -07:00
optim
scripts
type_hint_tests Support for Tensor Shape Type Hint (#34595) 2020-03-13 15:16:24 -07:00
HowToWriteTestsUsingFileCheck.md
run_test.py [TensorExpr] Add a fuser pass based on tensor expressions. (#34226) 2020-03-16 11:49:24 -07:00
simulate_nccl_errors.py
te_utils.py [TensorExpr] Pull changes from bertmaher/pytorch_fusion. (#34842) 2020-03-17 11:02:48 -07:00
test_autograd.py Fix version check for grad_fn for views (#34145) 2020-03-12 09:47:56 -07:00
test_complex.py
test_cpp_api_parity.py [jit] kill script namespace (#34515) 2020-03-11 23:32:48 -07:00
test_cpp_extensions_aot.py
test_cpp_extensions_jit.py
test_cuda.py Revert D20346700: [pytorch][PR] Eager autocasting, out-of-place ops only 2020-03-18 11:42:51 -07:00
test_cuda_primary_ctx.py
test_dataloader.py
test_determination.py [pytorch_ci] Python target determinator (#33577) 2020-03-03 18:01:12 -08:00
test_distributions.py Continuous bernoulli distribution (take 2) (#34619) 2020-03-12 11:53:18 -07:00
test_docs_coverage.py [doc] Add grad context manager doc to toplevel torch module. (#33877) 2020-03-02 06:32:36 -08:00
test_expecttest.py
test_fake_quant.py
test_function_schema.py
test_indexing.py Fix index_put when tensor length > int_max (#33753) 2020-03-01 21:51:23 -08:00
test_jit.py [quant][graphmode] Add quantization support for aten::dropout (#34347) 2020-03-18 14:35:27 -07:00
test_jit_disabled.py
test_jit_fuser.py Check fuser results when profiling (#33944) 2020-02-28 17:01:34 -08:00
test_jit_fuser_legacy.py
test_jit_legacy.py
test_jit_py3.py [jit] Resolve type annotation names to types (#29623) 2020-02-28 18:35:10 -08:00
test_jit_simple.py
test_jit_string.py
test_logging.py
test_mkldnn.py Fix MKLDNN conv2d 5d weight handling (#34115) 2020-03-04 11:26:38 -08:00
test_multiprocessing.py Better handing of Autograd+Fork errors. (#33885) 2020-02-27 16:07:29 -08:00
test_multiprocessing_spawn.py
test_namedtensor.py Adds true_divide function, analogous to Python 's, JAX's, NumPy's (true) division (#34236) 2020-03-09 21:06:33 -07:00
test_namedtuple_return_api.py
test_nn.py Fix problem in NHWC max_pool2d; use accumulate type in NHWC max_pool2d (#34934) 2020-03-18 08:32:10 -07:00
test_numba_integration.py
test_optim.py Turn on exact_dtype by default on test_optim.py (#34825) 2020-03-17 14:41:13 -07:00
test_overrides.py Add types argument to __torch_function__ (#34303) 2020-03-17 13:32:00 -07:00
test_qat.py
test_quantization.py [quant][graphmode] Add Finalize function that inlines graph and produce quantized ops (#33927) 2020-03-12 14:52:58 -07:00
test_quantized.py Revert D20480546: adds quantized implementation of hard sigmoid 2020-03-17 19:58:08 -07:00
test_quantized_models.py
test_quantized_nn_mods.py Add the quantized batch_norm3d and also batch_norm3d fused with relu operators (#34702) 2020-03-13 20:30:28 -07:00
test_quantized_tensor.py
test_serialization.py Avoid problematic pickle usages on Python 3.8.0 and 3.8.1 (#33824) 2020-02-26 21:15:38 -08:00
test_sparse.py Makes floor_divide a method, adds sparse floor division (#34552) 2020-03-18 15:00:53 -07:00
test_tensorboard.py
test_tensorexpr.py [TensorExpr] Pull changes from bertmaher/pytorch_fusion. (#34842) 2020-03-17 11:02:48 -07:00
test_throughput_benchmark.py
test_torch.py Makes floor_divide a method, adds sparse floor division (#34552) 2020-03-18 15:00:53 -07:00
test_type_hints.py Support for Tensor Shape Type Hint (#34595) 2020-03-13 15:16:24 -07:00
test_type_info.py
test_type_promotion.py Makes floor_divide a method, adds sparse floor division (#34552) 2020-03-18 15:00:53 -07:00
test_utils.py Add retry decorator and use it for Hub tests. (#34829) 2020-03-16 20:19:45 -07:00
test_xnnpack_integration.py Pass to remove prepacking ops. (#34319) 2020-03-14 12:53:31 -07:00