NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
multi_dot.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <initializer_list>
31 #include <string>
32 
35 #include "NumCpp/Functions/dot.hpp"
36 #include "NumCpp/NdArray.hpp"
37 
38 namespace nc
39 {
40  namespace linalg
41  {
42  //============================================================================
43  // Method Description:
54  template<typename dtype>
55  NdArray<dtype> multi_dot(const std::initializer_list<NdArray<dtype>>& inList)
56  {
58 
59  typename std::initializer_list<NdArray<dtype>>::iterator iter = inList.begin();
60 
61  if (inList.size() == 0)
62  {
63  THROW_INVALID_ARGUMENT_ERROR("input empty list of arrays.");
64  }
65  else if (inList.size() == 1)
66  {
67  return iter->copy();
68  }
69 
70  NdArray<dtype> returnArray = dot<dtype>(*iter, *(iter + 1));
71  iter += 2;
72  for (; iter < inList.end(); ++iter)
73  {
74  returnArray = dot(returnArray, *iter);
75  }
76 
77  return returnArray;
78  }
79  } // namespace linalg
80 } // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:49
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
NdArray< dtype > multi_dot(const std::initializer_list< NdArray< dtype >> &inList)
Definition: multi_dot.hpp:55
Definition: Coordinate.hpp:45
NdArray< dtype > dot(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: dot.hpp:47