NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
sign.hpp
Go to the documentation of this file.
1
28#pragma once
29
32#include "NumCpp/NdArray.hpp"
33
34namespace nc
35{
36 //============================================================================
37 // Method Description:
48 template<typename dtype>
49 int8 sign(dtype inValue) noexcept
50 {
52
53 if (inValue < dtype{ 0 })
54 {
55 return -1;
56 }
57
58 if (inValue > dtype{ 0 })
59 {
60 return 1;
61 }
62
63 return 0;
64 }
65
66 //============================================================================
67 // Method Description:
78 template<typename dtype>
80 {
81 NdArray<int8> returnArray(inArray.shape());
83 inArray.cend(),
84 returnArray.begin(),
85 [](dtype inValue) noexcept -> int8 { return sign(inValue); });
86
87 return returnArray;
88 }
89} // namespace nc
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition StaticAsserts.hpp:56
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
const_iterator cbegin() const noexcept
Definition NdArrayCore.hpp:1361
const Shape & shape() const noexcept
Definition NdArrayCore.hpp:4587
const_iterator cend() const noexcept
Definition NdArrayCore.hpp:1669
iterator begin() noexcept
Definition NdArrayCore.hpp:1311
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:776
Definition Cartesian.hpp:39
std::int8_t int8
Definition Types.hpp:38
int8 sign(dtype inValue) noexcept
Definition sign.hpp:49