NumCpp  1.0
A C++ implementation of the Python Numpy library
maximum.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
35 
36 #include <cmath>
37 #include <complex>
38 #include <string>
39 
40 namespace nc
41 {
42  //============================================================================
43  // Method Description:
55  template<typename dtype>
56  NdArray<dtype> maximum(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
57  {
59 
60  if (inArray1.shape() != inArray2.shape())
61  {
62  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
63  }
64 
65  const auto comparitor = [](dtype lhs, dtype rhs) noexcept -> bool
66  {
67  return lhs < rhs;
68  };
69 
70  NdArray<dtype> returnArray(inArray1.shape());
71  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
72  [comparitor](dtype inValue1, dtype inValue2) -> dtype
73  {
74  return std::max(inValue1, inValue2, comparitor);
75  });
76 
77  return returnArray;
78  }
79 }
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
Error.hpp
nc::maximum
NdArray< dtype > maximum(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: maximum.hpp:56
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:51
nc::NdArray< dtype >
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::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction) noexcept
Definition: StlAlgorithms.hpp:703
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091