Skip to content

Commit

Permalink
Merge pull request #20 from ewanwm/feature_trig_functions
Browse files Browse the repository at this point in the history
add trig functions in Tensor
  • Loading branch information
ewanwm authored Jul 13, 2024
2 parents b5eafcb + dbb02c1 commit 34a149b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions nuTens/tensors/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ class Tensor{

/// @}


/// @name Trigonometric
/// @{

/// @brief Get element-wise sin of a tensor
/// @param t The tensor
static Tensor sin(const Tensor &t);

/// @brief Get element-wise cosine of a tensor
/// @param t The tensor
static Tensor cos(const Tensor &t);

/// @}

/// @brief Overwrite the << operator to print this tensor out to the command line
friend std::ostream &operator<< (std::ostream &stream, const Tensor &tensor) {
Expand Down
16 changes: 14 additions & 2 deletions nuTens/tensors/torch-tensor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

#include <nuTens/tensors/tensor.hpp>
#include <torch/torch.h>


// map between the data types used in nuTens and those used by pytorch
Expand Down Expand Up @@ -312,7 +311,7 @@ Tensor Tensor::operator- () const {

Tensor Tensor::cumsum(int dim) const {
Tensor ret;
ret._tensor = _tensor.cumsum(dim);
ret._tensor = torch::cumsum(_tensor, dim);
return ret;
}

Expand All @@ -332,6 +331,19 @@ Tensor Tensor::grad() const {
return ret;
}


Tensor Tensor::sin(const Tensor &t) {
Tensor ret;
ret._tensor = torch::sin(t._tensor);
return ret;
}

Tensor Tensor::cos(const Tensor &t) {
Tensor ret;
ret._tensor = torch::cos(t._tensor);
return ret;
}

std::string Tensor::toString() const {
std::ostringstream stream;
stream << _tensor;
Expand Down

0 comments on commit 34a149b

Please sign in to comment.