Last active
February 9, 2017 03:15
-
-
Save masaponto/bab7c5ef60b64fa2d4a7dbdcd47bba3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required (VERSION 3.7) | |
project (matrix_calc_ndk) | |
add_executable(matrix_calc_ndk matrix_calc_ndk.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "numpy.hpp" | |
#include <string> | |
std::vector<float> dot(const int m, | |
const int n, | |
const std::vector<float> a, | |
const std::vector<float> b) | |
{ | |
std::vector<float> c(m, 0); | |
for (int i = 0; i < m; i++) { | |
for (int j = 0; j < n; j++) { | |
std::cout << (n*i) + j << " : " << a[(n*i) + j] << " * " << b[j] << std::endl; | |
c[i] += a[(n*i) + j] * b[j]; | |
} | |
} | |
return c; | |
} | |
template <typename T> | |
void print_vector(std::vector<T> vector) | |
{ | |
std::cout << "size" << vector.size() << std::endl; | |
std::cout << "[ "; | |
for (T x : vector) { | |
std::cout << x << ", "; | |
} | |
std::cout << "]\n" << std::endl; | |
} | |
void load_matrix(void) | |
{ | |
const std::string vector_path = "float_vector.npy"; | |
const std::string matrix_path = "float_array.npy"; | |
std::vector<int> vector_size, matrix_size; // Vetor for matrix size | |
std::vector<float> vector, matrix; | |
aoba::LoadArrayFromNumpy(vector_path, vector_size, vector); | |
aoba::LoadArrayFromNumpy(matrix_path, matrix_size, matrix); | |
print_vector(matrix); | |
print_vector(vector); | |
std::vector<float> result = dot(matrix_size[0], matrix_size[1], matrix, vector); | |
print_vector(result); | |
} | |
int main(void) { | |
load_matrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment