NumCpp  1.0
A C++ implementation of the Python Numpy library
outer.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
34 
35 #include <algorithm>
36 
37 namespace nc
38 {
39  //============================================================================
40  // Method Description:
50  template<typename dtype>
51  NdArray<dtype> outer(const NdArray<dtype>& inArray1, const NdArray<dtype>& inArray2)
52  {
54 
55  const auto size = inArray1.size();
56 
57  if (size != inArray2.size())
58  {
59  THROW_INVALID_ARGUMENT_ERROR("Input arrays must be the same length");
60  }
61 
62  auto returnArray = NdArray<dtype>(size);
63  for (uint32 row = 0; row < size; ++row)
64  {
65  const auto array1Value = inArray1[row];
66 
67  std::transform(inArray2.begin(), inArray2.end(), returnArray.begin(row),
68  [array1Value](dtype value) -> dtype
69  {
70  return array1Value * value;
71  });
72  }
73 
74  return returnArray;
75  }
76 }
StaticAsserts.hpp
nc::size
uint32 size(const NdArray< dtype > &inArray) noexcept
Definition: size.hpp:46
Error.hpp
STATIC_ASSERT_ARITHMETIC_OR_COMPLEX
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:51
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
NdArray.hpp
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
nc::NdArray::size
size_type size() const noexcept
Definition: NdArrayCore.hpp:4310
nc
Definition: Coordinate.hpp:45
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction) noexcept
Definition: StlAlgorithms.hpp:703
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
nc::outer
NdArray< dtype > outer(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: outer.hpp:51