NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Functions/powerf.hpp
Go to the documentation of this file.
1 #pragma once
29 
32 #include "NumCpp/Core/Shape.hpp"
33 #include "NumCpp/Core/Types.hpp"
34 #include "NumCpp/NdArray.hpp"
35 #include "NumCpp/Utils/powerf.hpp"
36 
37 #include <string>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
51  template<typename dtype1, typename dtype2>
52  auto powerf(dtype1 inValue, dtype2 inExponent) noexcept
53  {
54  return utils::powerf(inValue, inExponent);
55  }
56 
57  //============================================================================
58  // Method Description:
67  template<typename dtype1, typename dtype2>
68  auto powerf(const NdArray<dtype1>& inArray, dtype2 inExponent)
69  {
70  NdArray<decltype(powerf(dtype1{0}, dtype2{0}))> returnArray(inArray.shape());
71  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
72  [inExponent](dtype1 inValue) noexcept -> auto
73  {
74  return nc::powerf(inValue, inExponent);
75  });
76 
77  return returnArray;
78  }
79 
80  //============================================================================
81  // Method Description:
90  template<typename dtype1, typename dtype2>
91  auto powerf(const NdArray<dtype1>& inArray, const NdArray<dtype2>& inExponents)
92  {
93  if (inArray.shape() != inExponents.shape())
94  {
95  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
96  }
97 
98  NdArray<decltype(powerf(dtype1{0}, dtype2{0}))> returnArray(inArray.shape());
99  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), inExponents.cbegin(), returnArray.begin(),
100  [](dtype1 inValue, dtype2 inExponent) noexcept -> auto
101  {
102  return nc::powerf(inValue, inExponent);
103  });
104 
105  return returnArray;
106  }
107 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1216
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4283
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1524
iterator begin() noexcept
Definition: NdArrayCore.hpp:1166
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
auto powerf(dtype1 inValue, const dtype2 inPower) noexcept
Definition: Utils/powerf.hpp:49
Definition: Coordinate.hpp:45
auto powerf(dtype1 inValue, dtype2 inExponent) noexcept
Definition: Functions/powerf.hpp:52