NumCpp  2.7.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 
32 #include "NumCpp/Functions/dot.hpp"
33 #include "NumCpp/NdArray.hpp"
34 
35 #include <initializer_list>
36 #include <string>
37 
38 namespace nc
39 {
40  namespace linalg
41  {
42  //============================================================================
43  // Method Description:
53  template<typename dtype>
54  NdArray<dtype> multi_dot(const std::initializer_list<NdArray<dtype> >& inList)
55  {
57 
58  typename std::initializer_list<NdArray<dtype> >::iterator iter = inList.begin();
59 
60  if (inList.size() == 0)
61  {
62  THROW_INVALID_ARGUMENT_ERROR("input empty list of arrays.");
63  }
64  else if (inList.size() == 1)
65  {
66  return iter->copy();
67  }
68 
69  NdArray<dtype> returnArray = dot<dtype>(*iter, *(iter + 1));
70  iter += 2;
71  for (; iter < inList.end(); ++iter)
72  {
73  returnArray = dot(returnArray, *iter);
74  }
75 
76  return returnArray;
77  }
78  } // namespace linalg
79 } // 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
NdArray< dtype > multi_dot(const std::initializer_list< NdArray< dtype > > &inList)
Definition: multi_dot.hpp:54
Definition: Coordinate.hpp:45
NdArray< dtype > dot(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: dot.hpp:47