NumCpp  1.0
A C++ implementation of the Python Numpy library
sign.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #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  else if (inValue > dtype{ 0 })
64  {
65  return 1;
66  }
67  else
68  {
69  return 0;
70  }
71  }
72 
73  //============================================================================
74  // Method Description:
87  template<typename dtype>
89  {
90  NdArray<int8> returnArray(inArray.shape());
91  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
92  [](dtype inValue) noexcept -> int8
93  {
94  return sign(inValue);
95  });
96 
97  return returnArray;
98  }
99 }
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
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
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction) noexcept
Definition: StlAlgorithms.hpp:703
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