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