NumCpp  2.5.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
outer.hpp
Go to the documentation of this file.
1 #pragma once
29 
32 #include "NumCpp/NdArray.hpp"
33 
34 #include <algorithm>
35 
36 namespace nc
37 {
38  //============================================================================
39  // Method Description:
49  template<typename dtype>
50  NdArray<dtype> outer(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
51  {
53 
54  const auto size = inArray1.size();
55 
56  if (size != inArray2.size())
57  {
58  THROW_INVALID_ARGUMENT_ERROR("Input arrays must be the same length");
59  }
60 
61  auto returnArray = NdArray<dtype>(size);
62  for (uint32 row = 0; row < size; ++row)
63  {
64  const auto array1Value = inArray1[row];
65 
66  std::transform(inArray2.begin(), inArray2.end(), returnArray.begin(row),
67  [array1Value](dtype value) -> dtype
68  {
69  return array1Value * value;
70  });
71  }
72 
73  return returnArray;
74  }
75 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:50
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
size_type size() const noexcept
Definition: NdArrayCore.hpp:4497
iterator end() noexcept
Definition: NdArrayCore.hpp:1558
iterator begin() noexcept
Definition: NdArrayCore.hpp:1214
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:702
Definition: Coordinate.hpp:45
uint32 size(const NdArray< dtype > &inArray) noexcept
Definition: size.hpp:45
NdArray< dtype > outer(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: outer.hpp:50
std::uint32_t uint32
Definition: Types.hpp:40