NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
diff.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <string>
31
34#include "NumCpp/Core/Shape.hpp"
35#include "NumCpp/Core/Types.hpp"
36#include "NumCpp/NdArray.hpp"
37
38namespace nc
39{
40 //============================================================================
41 // Method Description:
51 template<typename dtype>
53 {
55
56 const Shape inShape = inArray.shape();
57
58 switch (inAxis)
59 {
60 case Axis::NONE:
61 {
62 if (inArray.size() < 2)
63 {
64 return NdArray<dtype>(0);
65 }
66
67 NdArray<dtype> returnArray(1, inArray.size() - 1);
69 inArray.cend() - 1,
70 inArray.cbegin() + 1,
71 returnArray.begin(),
73 { return inValue2 - inValue1; });
74
75 return returnArray;
76 }
77 case Axis::COL:
78 {
79 if (inShape.cols < 2)
80 {
81 return NdArray<dtype>(0);
82 }
83
85 for (uint32 row = 0; row < inShape.rows; ++row)
86 {
88 inArray.cend(row) - 1,
89 inArray.cbegin(row) + 1,
90 returnArray.begin(row),
92 { return inValue2 - inValue1; });
93 }
94
95 return returnArray;
96 }
97 case Axis::ROW:
98 {
99 return diff(inArray.transpose(), Axis::COL).transpose();
100 }
101 default:
102 {
103 THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
104 return {}; // get rid of compiler warning
105 }
106 }
107 }
108} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition StaticAsserts.hpp:56
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:775
Definition Cartesian.hpp:40
Axis
Enum To describe an axis.
Definition Enums.hpp:36
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
NdArray< dtype > diff(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition diff.hpp:52
std::uint32_t uint32
Definition Types.hpp:40