NumCpp  2.1.0
A C++ implementation of the Python Numpy library
sign.hpp
Go to the documentation of this file.
1 #pragma once
30 
34 #include "NumCpp/NdArray.hpp"
35 
36 #include <complex>
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
54  template<typename dtype>
55  int8 sign(dtype inValue) noexcept
56  {
58 
59  if (inValue < dtype{ 0 })
60  {
61  return -1;
62  }
63 
64  if (inValue > dtype{ 0 })
65  {
66  return 1;
67  }
68 
69  return 0;
70  }
71 
72  //============================================================================
73  // Method Description:
86  template<typename dtype>
88  {
89  NdArray<int8> returnArray(inArray.shape());
90  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
91  [](dtype inValue) noexcept -> int8
92  {
93  return sign(inValue);
94  });
95 
96  return returnArray;
97  }
98 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
StdComplexOperators.hpp
nc::sign
int8 sign(dtype inValue) noexcept
Definition: sign.hpp:55
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:51
nc::NdArray
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:75
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:703
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
nc::int8
std::int8_t int8
Definition: Types.hpp:39