NumCpp  2.4.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:
52  template<typename dtype1, typename dtype2>
53  auto powerf(dtype1 inValue, dtype2 inExponent) noexcept
54  {
55  return utils::powerf(inValue, inExponent);
56  }
57 
58  //============================================================================
59  // Method Description:
69  template<typename dtype1, typename dtype2>
70  auto powerf(const NdArray<dtype1>& inArray, dtype2 inExponent)
71  {
72  NdArray<decltype(powerf(dtype1{0}, dtype2{0}))> returnArray(inArray.shape());
73  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
74  [inExponent](dtype1 inValue) noexcept -> auto
75  {
76  return nc::powerf(inValue, inExponent);
77  });
78 
79  return returnArray;
80  }
81 
82  //============================================================================
83  // Method Description:
93  template<typename dtype1, typename dtype2>
94  auto powerf(const NdArray<dtype1>& inArray, const NdArray<dtype2>& inExponents)
95  {
96  if (inArray.shape() != inExponents.shape())
97  {
98  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
99  }
100 
101  NdArray<decltype(powerf(dtype1{0}, dtype2{0}))> returnArray(inArray.shape());
102  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), inExponents.cbegin(), returnArray.begin(),
103  [](dtype1 inValue, dtype2 inExponent) noexcept -> auto
104  {
105  return nc::powerf(inValue, inExponent);
106  });
107 
108  return returnArray;
109  }
110 } // namespace nc
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4356
Error.hpp
nc::NdArray
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:71
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1487
Shape.hpp
nc
Definition: Coordinate.hpp:44
powerf.hpp
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1143
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087
nc::powerf
auto powerf(dtype1 inValue, dtype2 inExponent) noexcept
Definition: Functions/powerf.hpp:53
nc::utils::powerf
auto powerf(dtype1 inValue, const dtype2 inPower) noexcept
Definition: Utils/powerf.hpp:51