移植seetaface到樹莓派
阿新 • • 發佈:2019-02-13
include "math_functions.h"
#include <cstdint>
float simd_dot(const float* x, const float* y, const long& len) {
float inner_prod = 0.0f;
long i=0;
// add the remaining values
for (; i < len; ++i) {
inner_prod += x[i] * y[i];
}
return inner_prod;
}
void matrix_procuct(const float* A, const float* B, float* C, const int n,
const int m, const int k, bool ta, bool tb) {
#ifdef _BLAS
arma::fmat mA = ta ? arma::fmat(A, k, n).t() : arma::fmat(A, n, k);
arma::fmat mB = tb ? arma::fmat(B, m, k).t() : arma::fmat(B, k, m);
arma::fmat mC(C, n, m, false);
mC = mA * mB;
#else
CHECK_TRUE(ta && !tb);
const float* x = B;
for (int i = 0, idx = 0; i < m; ++i) {
const float* y = A;
for (int j = 0; j < n; ++j, ++idx) {
C[idx] = simd_dot(x, y, k);
y += k;
}
x += k;
}
#endif
}
#include <cstdint>
float simd_dot(const float* x, const float* y, const long& len) {
float inner_prod = 0.0f;
long i=0;
// add the remaining values
for (; i < len; ++i) {
inner_prod += x[i] * y[i];
}
return inner_prod;
}
void matrix_procuct(const float* A, const float* B, float* C, const int n,
const int m, const int k, bool ta, bool tb) {
#ifdef _BLAS
arma::fmat mA = ta ? arma::fmat(A, k, n).t() : arma::fmat(A, n, k);
arma::fmat mB = tb ? arma::fmat(B, m, k).t() : arma::fmat(B, k, m);
arma::fmat mC(C, n, m, false);
mC = mA * mB;
#else
CHECK_TRUE(ta && !tb);
const float* x = B;
for (int i = 0, idx = 0; i < m; ++i) {
const float* y = A;
for (int j = 0; j < n; ++j, ++idx) {
C[idx] = simd_dot(x, y, k);
y += k;
}
x += k;
}
#endif
}