Skip to content

Instantly share code, notes, and snippets.

@fenske
Last active December 4, 2019 20:45
Show Gist options
  • Select an option

  • Save fenske/605d82f8339814278a72475fd4dd1438 to your computer and use it in GitHub Desktop.

Select an option

Save fenske/605d82f8339814278a72475fd4dd1438 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
#define N 3
tuple<int, int> findMaxIdx(float b[][N]);
int main() {
float b[N][N] = {
{-0.0004, 2.5, 6.21},
{ 19, -45.1, 0},
{ -2.75, 5.7, 12.9},
};
tuple<int, int> maxIdx = findMaxIdx(b);
float dotProduct = 0;
for (int k = 0; k < N; k++) {
int maxI = get<0>(maxIdx);
int maxJ = get<1>(maxIdx);
dotProduct += b[maxI][k] * b[k][maxJ];
}
cout << "Dot product: " << dotProduct << endl;
return 0;
}
tuple<int, int> findMaxIdx(float b[][N]) {
int maxI = 0;
int maxJ = 0;
float max = b[0][0];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (b[i][j] > max) {
max = b[i][j];
maxI = i;
maxJ = j;
}
}
}
return make_tuple(maxI, maxJ);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment