NumCpp  2.1.0
A C++ implementation of the Python Numpy library
logical_xor.hpp
Go to the documentation of this file.
1 #pragma once
30 
34 #include "NumCpp/NdArray.hpp"
35 
36 #include <string>
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
52  template<typename dtype>
53  NdArray<bool> logical_xor(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
54  {
56 
57  if (inArray1.shape() != inArray2.shape())
58  {
59  THROW_INVALID_ARGUMENT_ERROR("input array shapes are not consistant.");
60  }
61 
62  NdArray<bool> returnArray(inArray1.shape());
63  stl_algorithms::transform(inArray1.cbegin(), inArray1.cend(), inArray2.cbegin(), returnArray.begin(),
64  [](dtype inValue1, dtype inValue2) -> bool
65  {
66  return (inValue1 != dtype{ 0 }) != (inValue2 != dtype{ 0 });
67  });
68 
69  return returnArray;
70  }
71 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
Error.hpp
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:51
nc::NdArray< bool >
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::logical_xor
NdArray< bool > logical_xor(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: logical_xor.hpp:53
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
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091