NumCpp  2.11.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::linalg
39 {
40  //============================================================================
41  // Method Description:
52  template<typename dtype>
53  NdArray<dtype> multi_dot(const std::initializer_list<NdArray<dtype>>& inList)
54  {
56 
57  typename std::initializer_list<NdArray<dtype>>::iterator iter = inList.begin();
58 
59  if (inList.size() == 0)
60  {
61  THROW_INVALID_ARGUMENT_ERROR("input empty list of arrays.");
62  }
63  else if (inList.size() == 1)
64  {
65  return iter->copy();
66  }
67 
68  NdArray<dtype> returnArray = dot<dtype>(*iter, *(iter + 1));
69  iter += 2;
70  for (; iter < inList.end(); ++iter)
71  {
72  returnArray = dot(returnArray, *iter);
73  }
74 
75  return returnArray;
76  }
77 } // namespace nc::linalg
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC_OR_COMPLEX(dtype)
Definition: StaticAsserts.hpp:56
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:138
Definition: cholesky.hpp:41
NdArray< dtype > multi_dot(const std::initializer_list< NdArray< dtype >> &inList)
Definition: multi_dot.hpp:53
NdArray< dtype > dot(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition: dot.hpp:47