7 Commits
Author SHA1 Message Date
Aaron Gokaslan 8e0279cb50 [BE][Ez]: Use CPP20 rvalue overload for ostringstream (#187208)
Followup to #186552 . Uses the rvalue overload of ostringstream newly introduced in CPP20 to reduce the amount of string copy allowing us to steal the internal string buffer.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/187208
Approved by: https://github.com/d4l3k, https://github.com/lakshayg, https://github.com/malfet
2026-07-10 23:33:00 +00:00
PyTorch MergeBot fd64c8a016 Revert "[BE][Ez]: Use CPP20 rvalue overload for ostringstream (#187208)"
This reverts commit 6f2953ae46.

Reverted https://github.com/pytorch/pytorch/pull/187208 on behalf of https://github.com/huydhn due to Sorry for the churn, we are attempting to migrate some internal builds to C++ 20 to unblock this change ([comment](https://github.com/pytorch/pytorch/pull/187208#issuecomment-4744424607))
2026-06-18 17:23:59 +00:00
Aaron Gokaslan 6f2953ae46 [BE][Ez]: Use CPP20 rvalue overload for ostringstream (#187208)
Followup to #186552 . Uses the rvalue overload of ostringstream newly introduced in CPP20 to reduce the amount of string copy allowing us to steal the internal string buffer.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/187208
Approved by: https://github.com/d4l3k, https://github.com/lakshayg, https://github.com/malfet
2026-06-14 16:04:34 +00:00
PyTorch MergeBot 442c060adc Revert "[BE][Ez]: Use CPP20 rvalue overload for ostringstream (#187208)"
This reverts commit 27759216f2.

Reverted https://github.com/pytorch/pytorch/pull/187208 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](https://github.com/pytorch/pytorch/pull/187208#issuecomment-4699607134))
2026-06-13 19:53:10 +00:00
Aaron Gokaslan 27759216f2 [BE][Ez]: Use CPP20 rvalue overload for ostringstream (#187208)
Followup to #186552 . Uses the rvalue overload of ostringstream newly introduced in CPP20 to reduce the amount of string copy allowing us to steal the internal string buffer.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/187208
Approved by: https://github.com/d4l3k, https://github.com/lakshayg, https://github.com/malfet
2026-06-13 17:43:46 +00:00
Aaron Gokaslan a29983011f [BE][Ez]: Micro-opt char literal ostream overloads (#186387)
A lot of streams append single characters without going through the char level overload. This requires them to calculate and reserve length on it and go through less efficient string and `<<` overloads.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/186387
Approved by: https://github.com/malfet, https://github.com/cyyever
2026-06-06 03:00:51 +00:00
chani0343andEdward Yang 24a91e9c55 Add C++ API support for controlling scientific notation in tensor printing (#173321)
This PR implements a native C++ API to toggle scientific notation in tensor printing (fixes #40613). Previously, C++ users could not disable scientific notation, unlike Python's `torch.set_printoptions(sci_mode=False)`.

**Key Changes:**
- Added `torch::set_print_sci_mode(bool)` for native C++ control
- Updates core ATen tensor formatting logic
- Works without Python dependencies
- Includes GTest coverage (`PrintSciModeTest`)

**Usage Example:**

```cpp
auto t = torch::tensor({0.00001, 100000.0});
torch::set_print_sci_mode(false); // disable scientific notation
std::cout << t << std::endl;      // Output: 0.0000, 100000.0000
```

**Testing:**

```bash
cd build
cmake --build . --target test_api -j4
./bin/test_api --gtest_filter="PrintSciModeTest*"
```

Expected Output:

```
With sci_mode=true:  1.0000e-05, 1.0000e+05
With sci_mode=false: 0.0000, 100000.0000
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/173321
Approved by: https://github.com/ezyang

Co-authored-by: Edward Yang <ezyang@meta.com>
2026-05-03 12:27:07 +00:00