NumCpp  1.0
A C++ implementation of the Python Numpy library
copySign.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
35 
36 #include <cmath>
37 #include <string>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
52  template<typename dtype>
53  NdArray<dtype> copySign(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
54  {
56 
57  if (inArray1.shape() != inArray2.shape())
58  {
59  THROW_INVALID_ARGUMENT_ERROR("input arrays are not consistant.");
60  }
61 
62  NdArray<dtype> returnArray(inArray1.shape());
63  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
64  [](dtype inValue1, dtype inValue2) -> dtype
65  {
66  return inValue2 < dtype{ 0 } ? std::abs(inValue1) * -1 : std::abs(inValue1);
67  });
68 
69  return returnArray;
70  }
71 }
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::NdArray< dtype >
nc::copySign
NdArray< dtype > copySign(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: copySign.hpp:53
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
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::abs
auto abs(dtype inValue) noexcept
Definition: abs.hpp:52