forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinting.cpp
More file actions
28 lines (25 loc) · 843 Bytes
/
printing.cpp
File metadata and controls
28 lines (25 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <gtest/gtest.h>
#include <torch/torch.h>
#include <iostream>
#include <sstream>
TEST(PrintSciModeTest, ToggleScientificNotation) {
auto t = torch::tensor({0.00001, 100000.0});
// Test with scientific notation enabled
torch::set_printoption_sci_mode(true);
std::ostringstream oss1;
oss1 << t;
auto out1 = oss1.str();
std::cout << "With sci_mode=true: '" << out1 << "'" << std::endl;
EXPECT_TRUE(
out1.find("e-") != std::string::npos ||
out1.find("e+") != std::string::npos);
// Test with scientific notation disabled
torch::set_printoption_sci_mode(false);
std::ostringstream oss2;
oss2 << t;
auto out2 = oss2.str();
std::cout << "With sci_mode=false: '" << out2 << "'" << std::endl;
EXPECT_TRUE(
out2.find("e-") == std::string::npos &&
out2.find("e+") == std::string::npos);
}