auto declared VecVecMul in matrix.cpp was added.

This commit is contained in:
davoudn 2024-04-23 14:13:02 +03:30
parent 1fc5123d88
commit 9478b3a802
2 changed files with 31 additions and 3 deletions

View File

@ -1,9 +1,36 @@
#include <iostream>
#include <array>
#include <vector>
#include <concepts>
// abbreviated function template with constrained auto
constexpr size_t rows{4};
constexpr size_t columns{4};
auto Dot(auto& V, auto& B) {
auto tmp {V[0]*B[0]};
for (int i{1}; i < B.size(); i++)
tmp+= B[i] * V[i];
return tmp;
}
void MatVecMul_auto(const auto& A, const auto & V, auto& B){
if (A[0].size() == V.size() && A.size() == B.size() ){
for (int i{0}; i < A.size(); i++)
for (int j{0}; j < A[0].size(); j++)
B[i]+= A[i][j] * V[j];
}
else{
std::cout << "sizes are not compatible!";
}
}
void MatVecMul(const std::array<std::array<int, columns>, rows>& A, const std::array<int,columns>& V, std::array<int,rows>& B);
template <typename T, long unsigned int N>
@ -17,10 +44,10 @@ void printArrayTemplate(const T& a);
int main() {
std::array A{std::array{1, 2, 3}, std::array{4, 5, 6},std::array{4, 5, 0}};
std::array V{1, 2, 3,5};
std::array V{1, 2, 3 };
std::array <int,3> B{};
MatVecMul_template(A, B, V);
Dot(B,V);
return 0;
}
@ -54,4 +81,5 @@ void MatVecMul_templatefull(const T& A, const U& V, U& B){
else{
std::cout << "sizes are not compatible!";
}
}
}