get_result_tensor_for_unary_op Class — pytorch Architecture
Architecture documentation for the get_result_tensor_for_unary_op class in SparseCsrTensorMath.cpp from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/native/sparse/SparseCsrTensorMath.cpp lines 292–319
template <typename F>
inline Tensor get_result_tensor_for_unary_op(F op, const Tensor& input) {
auto values = input.values();
// To handle type promotion for inputs to unary ops,
// we first get the result from the underlined op, and use the result
// to create a sparse compressed tensor, which is used as the input to the out=
// variant
auto result_values = op(values);
auto compressed_indices = AT_DISPATCH_ROW_SPARSE_COMPRESSED_LAYOUTS(input.layout(),
"get_result_tensor_for_unary_op",
[&]{ return input.crow_indices(); },
[&]{ return input.ccol_indices(); });
auto plain_indices = AT_DISPATCH_ROW_SPARSE_COMPRESSED_LAYOUTS(input.layout(),
"get_result_tensor_for_unary_op",
[&]{ return input.col_indices(); },
[&]{ return input.row_indices(); });
auto result = at::_sparse_compressed_tensor_unsafe(
compressed_indices.clone(),
plain_indices.clone(),
result_values,
input.sizes(),
input.options().dtype(result_values.scalar_type()));
return result;
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free