我试图找出最快的矩阵乘法方法,尝试了3种不同的方法:
numpy.dot(a, b)ctypesPython中的模块与C连接.这是转换为共享库的C代码:
#include <stdio.h>
#include <stdlib.h>
void matmult(float* a, float* b, float* c, int n) {
int i = 0;
int j = 0;
int k = 0;
/*float* c = malloc(nay * sizeof(float));*/
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
int sub = 0;
for (k = 0; k < n; k++) {
sub = sub + a[i * n + …Run Code Online (Sandbox Code Playgroud)