51 template<
typename dtype>
66 if (arraySize != inArray2.
size() || arraySize < 2 || arraySize > 3)
69 "incompatible dimensions for cross product (dimension must be 2 or 3)");
79 NdArray<dtype> returnArray = { in1[0] * in2[1] - in1[1] * in2[0] };
84 dtype i = in1[1] * in2[2] - in1[2] * in2[1];
85 dtype
j = -(in1[0] * in2[2] - in1[2] * in2[0]);
86 dtype k = in1[0] * in2[1] - in1[1] * in2[0];
101 if (arrayShape != inArray2.
shape() || arrayShape.
rows < 2 || arrayShape.
rows > 3)
104 "incompatible dimensions for cross product (dimension must be 2 or 3)");
107 Shape returnArrayShape;
108 returnArrayShape.
cols = arrayShape.
cols;
109 if (arrayShape.
rows == 2)
111 returnArrayShape.
rows = 1;
115 returnArrayShape.
rows = 3;
119 for (
uint32 col = 0; col < arrayShape.
cols; ++col)
121 const auto theCol =
static_cast<int32>(col);
126 returnArray.
put({ 0,
static_cast<int32>(returnArrayShape.
rows) }, { theCol, theCol + 1 }, vecCross);
134 if (arrayShape != inArray2.
shape() || arrayShape.
cols < 2 || arrayShape.
cols > 3)
137 "incompatible dimensions for cross product (dimension must be 2 or 3)");
140 Shape returnArrayShape;
141 returnArrayShape.
rows = arrayShape.
rows;
142 if (arrayShape.
cols == 2)
144 returnArrayShape.
cols = 1;
148 returnArrayShape.
cols = 3;
152 for (
uint32 row = 0; row < arrayShape.
rows; ++row)
154 const auto theRow =
static_cast<int32>(row);
159 returnArray.
put({ theRow, theRow + 1 }, { 0,
static_cast<int32>(returnArrayShape.
cols) }, vecCross);
#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
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4511
self_type flatten() const
Definition: NdArrayCore.hpp:2847
Slice rSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition: NdArrayCore.hpp:1022
Slice cSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition: NdArrayCore.hpp:1008
self_type & put(index_type inIndex, const value_type &inValue)
Definition: NdArrayCore.hpp:3693
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 rows
Definition: Core/Shape.hpp:44
uint32 cols
Definition: Core/Shape.hpp:45
constexpr auto j
Definition: Core/Constants.hpp:42
Definition: Cartesian.hpp:40
Axis
Enum To describe an axis.
Definition: Enums.hpp:36
std::int32_t int32
Definition: Types.hpp:36
NdArray< dtype > cross(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2, Axis inAxis=Axis::NONE)
Definition: cross.hpp:52
std::uint32_t uint32
Definition: Types.hpp:40