NumCpp  2.1.0
A C++ implementation of the Python Numpy library
ldexp.hpp
Go to the documentation of this file.
1 #pragma once
30 
34 #include "NumCpp/Core/Types.hpp"
35 #include "NumCpp/NdArray.hpp"
36 
37 #include <cmath>
38 #include <string>
39 
40 namespace nc
41 {
42  //============================================================================
43  // Method Description:
54  template<typename dtype>
55  dtype ldexp(dtype inValue1, uint8 inValue2) noexcept
56  {
58 
59  return static_cast<dtype>(std::ldexp(static_cast<double>(inValue1), inValue2));
60  }
61 
62  //============================================================================
63  // Method Description:
74  template<typename dtype>
75  NdArray<dtype> ldexp(const NdArray<dtype>& inArray1, const NdArray<uint8>& inArray2)
76  {
77  if (inArray1.shape() != inArray2.shape())
78  {
79  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
80  }
81 
82  NdArray<dtype> returnArray(inArray1.shape());
83  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
84  [](dtype inValue1, uint8 inValue2) noexcept -> dtype
85  {
86  return ldexp(inValue1, inValue2);
87  });
88 
89  return returnArray;
90  }
91 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::uint8
std::uint8_t uint8
Definition: Types.hpp:43
nc::NdArray< dtype >
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
nc
Definition: Coordinate.hpp:45
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::ldexp
dtype ldexp(dtype inValue1, uint8 inValue2) noexcept
Definition: ldexp.hpp:55
nc::ldexp
NdArray< dtype > ldexp(const NdArray< dtype > &inArray1, const NdArray< uint8 > &inArray2)
Definition: ldexp.hpp:75