NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
multi_dot.hpp
Go to the documentation of this file.
1 
28 #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:
55  template<typename dtype>
56  NdArray<dtype> multi_dot(const std::initializer_list<NdArray<dtype> >& inList)
57  {
59 
60  typename std::initializer_list<NdArray<dtype> >::iterator iter = inList.begin();
61 
62  if (inList.size() == 0)
63  {
64  THROW_INVALID_ARGUMENT_ERROR("input empty list of arrays.");
65  }
66  else if (inList.size() == 1)
67  {
68  return iter->copy();
69  }
70 
71  NdArray<dtype> returnArray = dot<dtype>(*iter, *(iter + 1));
72  iter += 2;
73  for (; iter < inList.end(); ++iter)
74  {
75  returnArray = dot(returnArray, *iter);
76  }
77 
78  return returnArray;
79  }
80  } // namespace linalg
81 } // 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:56
Definition: Coordinate.hpp:45
NdArray< dtype > dot(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: dot.hpp:47