implemented matrix multiplication for subnatrices
This commit is contained in:
+10
-2
@@ -28,8 +28,16 @@
|
|||||||
** - This function can never fail.
|
** - This function can never fail.
|
||||||
*/
|
*/
|
||||||
void lina_dot(double *A, double *B, double *C, int m, int n, int l)
|
void lina_dot(double *A, double *B, double *C, int m, int n, int l)
|
||||||
|
{
|
||||||
|
lina_dot2(A, B, C, 0, 0, 0, m, n, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lina_dot2(double *A, double *B, double *C,
|
||||||
|
int As, int Bs, int Cs,
|
||||||
|
int m, int n, int l)
|
||||||
{
|
{
|
||||||
assert(m > 0 && n > 0 && l > 0);
|
assert(m > 0 && n > 0 && l > 0);
|
||||||
|
assert(As >= 0 && Bs >= 0 && Cs >= 0);
|
||||||
assert(A != NULL && B != NULL && C != NULL);
|
assert(A != NULL && B != NULL && C != NULL);
|
||||||
assert(A != C && B != C);
|
assert(A != C && B != C);
|
||||||
|
|
||||||
@@ -46,9 +54,9 @@ void lina_dot(double *A, double *B, double *C, int m, int n, int l)
|
|||||||
|
|
||||||
for(int j=0; j < n; j++)
|
for(int j=0; j < n; j++)
|
||||||
|
|
||||||
pos += A[i*n + j] * B[j*l + k];
|
pos += A[(i + As)*n + j] * B[(j + Bs) *l + k];
|
||||||
|
|
||||||
C[i*l + k] = pos;
|
C[(i + Cs)*l + k] = pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ void lina_transpose(double *A, double *B, int m, int n);
|
|||||||
void lina_conv(double *A, double *B, double *C,
|
void lina_conv(double *A, double *B, double *C,
|
||||||
int Aw, int Ah, int Bw, int Bh);
|
int Aw, int Ah, int Bw, int Bh);
|
||||||
|
|
||||||
|
void lina_dot2(double *A, double *B, double *C,
|
||||||
|
int As, int Bs, int Cs,
|
||||||
|
int m, int n, int l);
|
||||||
|
|
||||||
/* ---- Utilities ---- */
|
/* ---- Utilities ---- */
|
||||||
double *lina_loadMatrixFromStream(FILE *fp, int *width, int *height, char **error);
|
double *lina_loadMatrixFromStream(FILE *fp, int *width, int *height, char **error);
|
||||||
int lina_saveMatrixToStream(FILE *fp, double *A, int width, int height, char **error);
|
int lina_saveMatrixToStream(FILE *fp, double *A, int width, int height, char **error);
|
||||||
Reference in New Issue
Block a user