NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
multi_dot.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <initializer_list>
31
35#include "NumCpp/NdArray.hpp"
36
37namespace nc::linalg
38{
39 //============================================================================
40 // Method Description:
51 template<typename dtype>
52 NdArray<dtype> multi_dot(const std::initializer_list<NdArray<dtype>>& inList)
53 {
55
56 typename std::initializer_list<NdArray<dtype>>::iterator iter = inList.begin();
57
58 if (inList.size() == 0)
59 {
60 THROW_INVALID_ARGUMENT_ERROR("input empty list of arrays.");
61 }
62 else if (inList.size() == 1)
63 {
64 return iter->copy();
65 }
66
67 NdArray<dtype> returnArray = dot<dtype>(*iter, *(iter + 1));
68 iter += 2;
69 for (; iter < inList.end(); ++iter)
70 {
71 returnArray = dot(returnArray, *iter);
72 }
73
74 return returnArray;
75 }
76} // 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:135
Definition cholesky.hpp:41
NdArray< dtype > multi_dot(const std::initializer_list< NdArray< dtype > > &inList)
Definition multi_dot.hpp:52
NdArray< dtype > dot(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition dot.hpp:48