NumCpp  2.9.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Functions/power.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <string>
31 
34 #include "NumCpp/Core/Shape.hpp"
35 #include "NumCpp/Core/Types.hpp"
36 #include "NumCpp/NdArray.hpp"
37 #include "NumCpp/Utils/power.hpp"
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
51  template<typename dtype>
52  constexpr dtype power(dtype inValue, uint8 inExponent) noexcept
53  {
54  return utils::power(inValue, inExponent);
55  }
56 
57  //============================================================================
58  // Method Description:
67  template<typename dtype>
68  NdArray<dtype> power(const NdArray<dtype>& inArray, uint8 inExponent)
69  {
70  NdArray<dtype> returnArray(inArray.shape());
72  inArray.cend(),
73  returnArray.begin(),
74  [inExponent](dtype inValue) noexcept -> dtype
75  { return nc::power(inValue, inExponent); });
76 
77  return returnArray;
78  }
79 
80  //============================================================================
81  // Method Description:
90  template<typename dtype>
91  NdArray<dtype> power(const NdArray<dtype>& inArray, const NdArray<uint8>& inExponents)
92  {
93  if (inArray.shape() != inExponents.shape())
94  {
95  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
96  }
97 
98  NdArray<dtype> returnArray(inArray.shape());
100  inArray.cend(),
101  inExponents.cbegin(),
102  returnArray.begin(),
103  [](dtype inValue, uint8 inExponent) -> dtype
104  { return nc::power(inValue, inExponent); });
105 
106  return returnArray;
107  }
108 } // 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:1221
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4092
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1529
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:784
dtype power(dtype inValue, uint8 inPower) noexcept
Definition: Utils/power.hpp:48
Definition: Coordinate.hpp:45
constexpr dtype power(dtype inValue, uint8 inExponent) noexcept
Definition: Functions/power.hpp:52
std::uint8_t uint8
Definition: Types.hpp:42