#include
#include
// Torch Scalar
std::cout << "-------------- Torch Scalar --------------\n";
const auto TorchScalar = torch::Scalar(56.0f);
std::cout << "TorchScalar value: " << TorchScalar << std::endl;
std::cout << "TorchScalar is floating point: " << std::boolalpha << TorchScalar.isFloatingPoint() << std::endl;
The provided code initializes a scalar value in LibTorch, which is a single numeric value used in computations. The value of the scalar is 56.0f, represented as a floating-point number, and it is stored in a constant variable named TorchScalar
.
const auto TorchScalar = torch::Scalar(56.0f);
To display the value of TorchScalar
, the code uses the std::cout
stream to output the string “TorchScalar value: ” followed by the value of TorchScalar
. A newline character is added to the output using std::endl
.
std::cout << "TorchScalar value: " << TorchScalar << std::endl;
In addition, the code checks whether the scalar value is a floating-point number using the isFloatingPoint()
method of TorchScalar
. The result of this check is printed to the console using std::cout
, which outputs the string “TorchScalar is floating point: ” followed by the boolean value indicating whether TorchScalar
is a floating-point number. Again, a newline character is added to the output using std::endl
.
std::cout << "TorchScalar is floating point: " << std::boolalpha << TorchScalar.isFloatingPoint() << std::endl;
This code can be useful in a variety of machine learning applications where single numeric values need to be manipulated and analyzed.
I hope you find this post useful.
Good luck!.