NumCpp  2.1.0
A C++ implementation of the Python Numpy library
Functions/powerf.hpp
Go to the documentation of this file.
1 #pragma once
30 
33 #include "NumCpp/Core/Shape.hpp"
34 #include "NumCpp/Core/Types.hpp"
35 #include "NumCpp/NdArray.hpp"
36 #include "NumCpp/Utils/powerf.hpp"
37 
38 #include <string>
39 
40 namespace nc
41 {
42  //============================================================================
43  // Method Description:
53  template<typename dtype1, typename dtype2>
54  auto powerf(dtype1 inValue, dtype2 inExponent) noexcept
55  {
56  return utils::powerf(inValue, inExponent);
57  }
58 
59  //============================================================================
60  // Method Description:
70  template<typename dtype1, typename dtype2>
71  auto powerf(const NdArray<dtype1>& inArray, dtype2 inExponent)
72  {
73  NdArray<decltype(powerf(dtype1{0}, dtype2{0}))> returnArray(inArray.shape());
74  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), returnArray.begin(),
75  [inExponent](dtype1 inValue) noexcept -> auto
76  {
77  return nc::powerf(inValue, inExponent);
78  });
79 
80  return returnArray;
81  }
82 
83  //============================================================================
84  // Method Description:
94  template<typename dtype1, typename dtype2>
95  auto powerf(const NdArray<dtype1>& inArray, const NdArray<dtype2>& inExponents)
96  {
97  if (inArray.shape() != inExponents.shape())
98  {
99  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
100  }
101 
102  NdArray<decltype(powerf(dtype1{0}, dtype2{0}))> returnArray(inArray.shape());
103  stl_algorithms::transform(inArray.cbegin(), inArray.cend(), inExponents.cbegin(), returnArray.begin(),
104  [](dtype1 inValue, dtype2 inExponent) noexcept -> auto
105  {
106  return nc::powerf(inValue, inExponent);
107  });
108 
109  return returnArray;
110  }
111 } // namespace nc
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
Error.hpp
nc::NdArray
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:75
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:703
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
Shape.hpp
nc
Definition: Coordinate.hpp:45
powerf.hpp
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
nc::powerf
auto powerf(dtype1 inValue, dtype2 inExponent) noexcept
Definition: Functions/powerf.hpp:54
nc::utils::powerf
auto powerf(dtype1 inValue, const dtype2 inPower) noexcept
Definition: Utils/powerf.hpp:52