NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
Functions/power.hpp
Go to the documentation of this file.
1
28#pragma once
29
32#include "NumCpp/Core/Types.hpp"
33#include "NumCpp/NdArray.hpp"
35
36namespace nc
37{
38 //============================================================================
39 // Method Description:
48 template<typename dtype>
49 constexpr dtype power(dtype inValue, uint8 inExponent) noexcept
50 {
51 return utils::power(inValue, inExponent);
52 }
53
54 //============================================================================
55 // Method Description:
64 template<typename dtype>
65 NdArray<dtype> power(const NdArray<dtype>& inArray, uint8 inExponent)
66 {
67 NdArray<dtype> returnArray(inArray.shape());
69 inArray.cend(),
70 returnArray.begin(),
71 [inExponent](dtype inValue) noexcept -> dtype
72 { return nc::power(inValue, inExponent); });
73
74 return returnArray;
75 }
76
77 //============================================================================
78 // Method Description:
87 template<typename dtype>
88 NdArray<dtype> power(const NdArray<dtype>& inArray, const NdArray<uint8>& inExponents)
89 {
90 if (inArray.shape() != inExponents.shape())
91 {
92 THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
93 }
94
95 NdArray<dtype> returnArray(inArray.shape());
97 inArray.cend(),
98 inExponents.cbegin(),
99 returnArray.begin(),
100 [](dtype inValue, uint8 inExponent) -> dtype
101 { return nc::power(inValue, inExponent); });
102
103 return returnArray;
104 }
105} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
const_iterator cbegin() const noexcept
Definition NdArrayCore.hpp:1361
const Shape & shape() const noexcept
Definition NdArrayCore.hpp:4587
const_iterator cend() const noexcept
Definition NdArrayCore.hpp:1669
iterator begin() noexcept
Definition NdArrayCore.hpp:1311
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:776
dtype power(dtype inValue, uint8 inPower) noexcept
Definition Utils/power.hpp:44
Definition Cartesian.hpp:39
constexpr dtype power(dtype inValue, uint8 inExponent) noexcept
Definition Functions/power.hpp:49
std::uint8_t uint8
Definition Types.hpp:42