NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
copySign.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <cmath>
31
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
49 template<typename dtype>
50 NdArray<dtype> copySign(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
51 {
53
54 if (inArray1.shape() != inArray2.shape())
55 {
56 THROW_INVALID_ARGUMENT_ERROR("input arrays are not consistant.");
57 }
58
59 NdArray<dtype> returnArray(inArray1.shape());
61 inArray1.cend(),
62 inArray2.cbegin(),
63 returnArray.begin(),
64 [](dtype inValue1, dtype inValue2) -> dtype
65 { return inValue2 < dtype{ 0 } ? std::abs(inValue1) * -1 : std::abs(inValue1); });
66
67 return returnArray;
68 }
69} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
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
NdArray< dtype > copySign(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition copySign.hpp:50