-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
44 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vt::astype | ||
======================= | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
.. doxygenfunction:: vt::astype |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ Core | |
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
astype | ||
broadcast | ||
broadcast_to | ||
cutensor | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include "lib/core/tensor.hpp" | ||
|
||
namespace vt { | ||
|
||
/// Forward declaration of the Tensor class. | ||
template <typename T, size_t N> | ||
class Tensor; | ||
|
||
/** | ||
* @brief Convert the tensor to a new data type. | ||
* | ||
* @tparam T: Data type of the tensor. | ||
* @tparam U: The data type to cast. | ||
* @tparam N: Number of dimensions of the tensor. | ||
* @param tensor: The tensor object. | ||
* @return Tensor<U, N>: The new tensor object. | ||
*/ | ||
template <typename T, typename U, size_t N> | ||
Tensor<U, N> astype(Tensor<T, N> tensor) { | ||
if constexpr (std::is_same_v<T, U>) { | ||
return tensor; | ||
} else { | ||
auto result = Tensor<U, N>(tensor.shape()); | ||
thrust::transform(tensor.begin(), tensor.end(), result.begin(), [] __device__(const T& x) { return static_cast<U>(x); }); | ||
return result; | ||
} | ||
} | ||
|
||
} // namespace vt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters