53 template<
typename dtype>
62 const auto inShape = inArray.
shape();
70 for (
uint32 col = 0; col < inShape.cols; ++col)
72 returnArray(0, col) =
static_cast<double>(inArray(1, col)) -
static_cast<double>(inArray(0, col));
73 returnArray(-1, col) =
74 static_cast<double>(inArray(-1, col)) -
static_cast<double>(inArray(-2, col));
78 for (
uint32 col = 0; col < inShape.cols; ++col)
80 for (
uint32 row = 1; row < inShape.rows - 1; ++row)
82 returnArray(row, col) =
83 (
static_cast<double>(inArray(row + 1, col)) -
static_cast<double>(inArray(row - 1, col))) /
92 const auto inShape = inArray.
shape();
100 for (
uint32 row = 0; row < inShape.rows; ++row)
102 returnArray(row, 0) =
static_cast<double>(inArray(row, 1)) -
static_cast<double>(inArray(row, 0));
103 returnArray(row, -1) =
104 static_cast<double>(inArray(row, -1)) -
static_cast<double>(inArray(row, -2));
108 for (
uint32 row = 0; row < inShape.rows; ++row)
110 for (
uint32 col = 1; col < inShape.cols - 1; ++col)
112 returnArray(row, col) =
113 (
static_cast<double>(inArray(row, col + 1)) -
static_cast<double>(inArray(row, col - 1))) /
123 if (inArray.
size() < 2)
129 returnArray[0] =
static_cast<double>(inArray[1]) -
static_cast<double>(inArray[0]);
130 returnArray[-1] =
static_cast<double>(inArray[-1]) -
static_cast<double>(inArray[-2]);
135 returnArray.begin() + 1,
136 [](dtype value1, dtype value2) ->
double
137 { return (static_cast<double>(value1) - static_cast<double>(value2)) / 2.; });
155 template<
typename dtype>
164 const auto inShape = inArray.shape();
165 if (inShape.rows < 2)
172 for (
uint32 col = 0; col < inShape.cols; ++col)
175 returnArray(-1, col) =
180 for (
uint32 col = 0; col < inShape.cols; ++col)
182 for (
uint32 row = 1; row < inShape.rows - 1; ++row)
194 const auto inShape = inArray.shape();
195 if (inShape.cols < 2)
202 for (
uint32 row = 0; row < inShape.rows; ++row)
205 returnArray(row, -1) =
210 for (
uint32 row = 0; row < inShape.rows; ++row)
212 for (
uint32 col = 1; col < inShape.cols - 1; ++col)
225 if (inArray.size() < 2)
235 inArray.cbegin() + 2,
238 returnArray.begin() + 1,
239 [](
const std::complex<dtype>& value1,
const std::complex<dtype>& value2) -> std::complex<double>
240 { return (complex_cast<double>(value1) - complex_cast<double>(value2)) / 2.; });
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
size_type size() const noexcept
Definition NdArrayCore.hpp:4600
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
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:776
Definition Cartesian.hpp:39
Axis
Enum To describe an axis.
Definition Enums.hpp:36
@ ROW
Definition Enums.hpp:38
@ COL
Definition Enums.hpp:39
std::complex< Out > complex_cast(const std::complex< In > &value) noexcept
Definition StdComplexOperators.hpp:111
NdArray< double > gradient(const NdArray< dtype > &inArray, Axis inAxis=Axis::ROW)
Definition gradient.hpp:54
std::uint32_t uint32
Definition Types.hpp:40