Skip to content

Instantly share code, notes, and snippets.

@masaponto
Last active February 9, 2017 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masaponto/bab7c5ef60b64fa2d4a7dbdcd47bba3f to your computer and use it in GitHub Desktop.
Save masaponto/bab7c5ef60b64fa2d4a7dbdcd47bba3f to your computer and use it in GitHub Desktop.
cmake_minimum_required (VERSION 3.7)
project (matrix_calc_ndk)
add_executable(matrix_calc_ndk matrix_calc_ndk.cpp)
#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