{"id":28128,"date":"2022-12-28T20:20:47","date_gmt":"2022-12-28T14:50:47","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/"},"modified":"2022-12-28T20:20:47","modified_gmt":"2022-12-28T14:50:47","slug":"solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/","title":{"rendered":"[Solved] How to multiply two matrices having fractions as inputs in c [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-39584946\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"39584946\" data-parentid=\"39578134\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>I wanted to use my own implementation of the Strassen optimization for matrix multiplication. It is highly optimized and hence has almost no pedagogical use but then I remembered that Wikipedia has actual C code in the Strassen-matrix-multiplication entry.<\/p>\n<p>The implementation there is not the best:<\/p>\n<ul>\n<li>it has no fallback to the naive algorithm if the size falls below a certain limit<\/li>\n<li>only matrix sizes are allowed that are a power of two<\/li>\n<li>it accumulates a lot of error if used with finite floating point data types<\/li>\n<li>it uses a lot of memory, more than necessary<\/li>\n<li>it needs some work to make it parallelizable<\/li>\n<\/ul>\n<p>But it works, so &#8230;<\/p>\n<pre><code>#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;string.h&gt;\n\n#define MM_OK 1\n#define MM_ERR 0\n\nvoid mat_print(double **M, int dim);\ndouble **mat_init(int dim);\nvoid mat_clear(double **M, int dim);\ndouble **mat_rand(int dim, int seed);\nint mat_mul_naive(double **A, double **B, double **C, int dim);\nint mat_add(double **A, double **B, double **C, int dim);\nint mat_sub(double **A, double **B, double **C, int dim);\nint mat_mul_strassen(double **A, double **B, double **C, int dim);\n\n\/\/ ALL CHECKS OMMITTED!\n\n\/\/ Octave\/Matlab format, for getting a second opinion\nvoid mat_print(double **M, int dim)\n{\n  int i, j;\n  printf(\"[\");\n  for (i = 0; i &lt; dim; i++) {\n    for (j = 0; j &lt; dim; j++) {\n      printf(\"%.10g\", M[i][j]);\n      if (j &lt; dim - 1) {\n        putc(',', stdout);\n      }\n    }\n    if (i &lt; dim - 1) {\n      putc(';', stdout);\n    }\n  }\n  printf(\"]\\n\");\n}\n\ndouble **mat_init(int dim)\n{\n  int i, j;\n  double **M;\n  M = malloc(dim * sizeof(double *));\n  if (M == NULL) {\n    return NULL;\n  }\n  for (i = 0; i &lt; dim; i++) {\n    M[i] = malloc(dim * sizeof(double));\n    if (M[i] == NULL) {\n      mat_clear(M, i);\n      return NULL;\n    }\n    for (j = 0; j &lt; dim; j++) {\n      M[i][j] = 0;\n    }\n  }\n  return M;\n}\n\nvoid mat_clear(double **M, int dim)\n{\n  int i;\n  for (i = 0; i &lt; dim; i++) {\n    free(M[i]);\n  }\n  free(M);\n}\n\ndouble **mat_rand(int dim, int seed)\n{\n  int i, j;\n  double **M;\n  M = mat_init(dim);\n  if (M == NULL) {\n    return NULL;\n  }\n  srand(seed);\n  for (i = 0; i &lt; dim; i++) {\n    for (j = 0; j &lt; dim; j++) {\n      M[i][j] = (double) rand() \/ (double) rand();\n    }\n  }\n  return M;\n}\n\nint mat_mul_naive(double **A, double **B, double **C, int dim)\n{\n  int i, j, k;\n  if (C == NULL) {\n    return MM_ERR;\n  }\n  for (i = 0; i &lt; dim; i++) {\n    for (k = 0; k &lt; dim; k++) {   \/\/&lt;- exchanged for better\n      for (j = 0; j &lt; dim; j++) { \/\/&lt;- memory access\n        C[i][j] += (A[i][k] * B[k][j]);\n      }\n    }\n  }\n  return MM_OK;\n}\n\n\n\/\/ helper for mat_mul_strassen, only square matrices of same size\nint mat_add(double **A, double **B, double **C, int dim)\n{\n  int i, j;\n  if (C == NULL) {\n    fprintf(stderr, \"C == NULL in mat_add\\n\");\n    return MM_ERR;\n  }\n  for (i = 0; i &lt; dim; i++) {\n    for (j = 0; j &lt; dim; j++) {\n      C[i][j] = A[i][j] + B[i][j];\n    }\n  }\n  return MM_OK;\n}\n\n\/\/ helper for mat_mul_strassen, only square matrices of same size\nint mat_sub(double **A, double **B, double **C, int dim)\n{\n  int i, j;\n  if (C == NULL) {\n    fprintf(stderr, \"C == NULL in mat_sub\\n\");\n    return MM_ERR;\n  }\n  for (i = 0; i &lt; dim; i++) {\n    for (j = 0; j &lt; dim; j++) {\n      C[i][j] = A[i][j] - B[i][j];\n    }\n  }\n  return MM_OK;\n}\n\n\/\/ This implementation is from Wikipedia\n\/\/ https:\/\/en.wikipedia.org\/w\/index.php?title=Strassen_algorithm&amp;oldid=498910018#Source_code_of_the_Strassen_algorithm_in_C_language\n\/\/ And it is a really slow one.\nint mat_mul_strassen(double **A, double **B, double **C, int dim)\n{\n  if (dim == 1) {\n    C[0][0] = A[0][0] * B[0][0];\n    return MM_OK;\n  }\n#ifdef MAKE_IT_ACTUALLY_WORK_FAST\n  \/\/ 256 on my machine, YMMV\n  else if (dim &lt;= 256) {\n    return mat_mul_naive(A, B, C, dim);\n  }\n#endif\n  else {\n    int new_dim = dim \/ 2;\n    double **a11, **a12, **a21, **a22;\n    double **b11, **b12, **b21, **b22;\n    double **c11, **c12, **c21, **c22;\n    double **p1, **p2, **p3, **p4, **p5, **p6, **p7;\n    double **aResult;\n    double **bResult;\n    int i, j;\n    a11 = mat_init(new_dim);\n    a12 = mat_init(new_dim);\n    a21 = mat_init(new_dim);\n    a22 = mat_init(new_dim);\n\n    b11 = mat_init(new_dim);\n    b12 = mat_init(new_dim);\n    b21 = mat_init(new_dim);\n    b22 = mat_init(new_dim);\n\n    c11 = mat_init(new_dim);\n    c12 = mat_init(new_dim);\n    c21 = mat_init(new_dim);\n    c22 = mat_init(new_dim);\n\n    p1 = mat_init(new_dim);\n    p2 = mat_init(new_dim);\n    p3 = mat_init(new_dim);\n    p4 = mat_init(new_dim);\n    p5 = mat_init(new_dim);\n    p6 = mat_init(new_dim);\n    p7 = mat_init(new_dim);\n\n    aResult = mat_init(new_dim);\n    bResult = mat_init(new_dim);\n    \/\/ the divide part of divide&amp;conquer\n    for (i = 0; i &lt; new_dim; i++) {\n      for (j = 0; j &lt; new_dim; j++) {\n        a11[i][j] = A[i][j];\n        a12[i][j] = A[i][j + new_dim];\n        a21[i][j] = A[i + new_dim][j];\n        a22[i][j] = A[i + new_dim][j + new_dim];\n\n        b11[i][j] = B[i][j];\n        b12[i][j] = B[i][j + new_dim];\n        b21[i][j] = B[i + new_dim][j];\n        b22[i][j] = B[i + new_dim][j + new_dim];\n      }\n    }\n\n    \/\/ Calculating p1 to p7:\n\n    mat_add(a11, a22, aResult, new_dim);        \/\/ a11 + a22\n    mat_add(b11, b22, bResult, new_dim);        \/\/ b11 + b22\n    mat_mul_strassen(aResult, bResult, p1, new_dim);    \/\/ p1 = (a11+a22) * (b11+b22)\n\n    mat_add(a21, a22, aResult, new_dim);        \/\/ a21 + a22\n    mat_mul_strassen(aResult, b11, p2, new_dim);        \/\/ p2 = (a21+a22) * (b11)\n\n    mat_sub(b12, b22, bResult, new_dim);        \/\/ b12 - b22\n    mat_mul_strassen(a11, bResult, p3, new_dim);        \/\/ p3 = (a11) * (b12 - b22)\n\n    mat_sub(b21, b11, bResult, new_dim);        \/\/ b21 - b11\n    mat_mul_strassen(a22, bResult, p4, new_dim);        \/\/ p4 = (a22) * (b21 - b11)\n\n    mat_add(a11, a12, aResult, new_dim);        \/\/ a11 + a12\n    mat_mul_strassen(aResult, b22, p5, new_dim);        \/\/ p5 = (a11+a12) * (b22)  \n\n    mat_sub(a21, a11, aResult, new_dim);        \/\/ a21 - a11\n    mat_add(b11, b12, bResult, new_dim);        \/\/ b11 + b12\n    mat_mul_strassen(aResult, bResult, p6, new_dim);    \/\/ p6 = (a21-a11) * (b11+b12)\n\n    mat_sub(a12, a22, aResult, new_dim);        \/\/ a12 - a22\n    mat_add(b21, b22, bResult, new_dim);        \/\/ b21 + b22\n    mat_mul_strassen(aResult, bResult, p7, new_dim);    \/\/ p7 = (a12-a22) * (b21+b22)\n\n    \/\/ calculating c21, c21, c11 e c22:\n\n    mat_add(p3, p5, c12, new_dim);      \/\/ c12 = p3 + p5\n    mat_add(p2, p4, c21, new_dim);      \/\/ c21 = p2 + p4\n\n    mat_add(p1, p4, aResult, new_dim);  \/\/ p1 + p4\n    mat_add(aResult, p7, bResult, new_dim);     \/\/ p1 + p4 + p7\n    mat_sub(bResult, p5, c11, new_dim); \/\/ c11 = p1 + p4 - p5 + p7\n\n    mat_add(p1, p3, aResult, new_dim);  \/\/ p1 + p3\n    mat_add(aResult, p6, bResult, new_dim);     \/\/ p1 + p3 + p6\n    mat_sub(bResult, p2, c22, new_dim); \/\/ c22 = p1 + p3 - p2 + p6\n\n    \/\/ Grouping the results obtained in a single matrix:\n    for (i = 0; i &lt; new_dim; i++) {\n      for (j = 0; j &lt; new_dim; j++) {\n        C[i][j] = c11[i][j];\n        C[i][j + new_dim] = c12[i][j];\n        C[i + new_dim][j] = c21[i][j];\n        C[i + new_dim][j + new_dim] = c22[i][j];\n      }\n    }\n    mat_clear(a11, new_dim);\n    mat_clear(a12, new_dim);\n    mat_clear(a21, new_dim);\n    mat_clear(a22, new_dim);\n\n    mat_clear(b11, new_dim);\n    mat_clear(b12, new_dim);\n    mat_clear(b21, new_dim);\n    mat_clear(b22, new_dim);\n\n    mat_clear(c11, new_dim);\n    mat_clear(c12, new_dim);\n    mat_clear(c21, new_dim);\n    mat_clear(c22, new_dim);\n\n    mat_clear(p1, new_dim);\n    mat_clear(p2, new_dim);\n    mat_clear(p3, new_dim);\n    mat_clear(p4, new_dim);\n    mat_clear(p5, new_dim);\n    mat_clear(p6, new_dim);\n    mat_clear(p7, new_dim);\n    mat_clear(aResult, new_dim);\n    mat_clear(bResult, new_dim);\n\n  }\n  return MM_OK;\n}\n\nstatic int ispow2(unsigned int x)\n{\n  while (((x &amp; 1) == 0) &amp;&amp; x &gt; 1) {\n    x &gt;&gt;= 1;\n  }\n  if (x == 1) {\n    return 1;\n  }\n  return 0;\n}\n\n#include &lt;time.h&gt;\nint main(int argc, char **argv)\n{\n  \/\/int res;\n  int dim1;\n  double **A, **B, **C, **D;\n  clock_t start, stop;\n\n  \/\/ only square matrices of same size\n  if (argc != 2) {\n    fprintf(stderr, \"Usage: %s dimension\\n\", argv[0]);\n    exit(EXIT_FAILURE);\n  }\n\n  dim1 = atoi(argv[1]);\n  if (!ispow2(dim1)) {\n    fprintf(stderr,\n            \"Dimension of matrix must be a power of two and %d is not\\n\", dim1);\n    exit(EXIT_FAILURE);\n  }\n\n  A = mat_rand(dim1, 123);\n  B = mat_rand(dim1, 456);\n\n  \/\/mat_print(A, dim1);\n  \/\/mat_print(B, dim1);\n\n  C = mat_init(dim1);\n  start = clock();\n  mat_mul_naive(A, B, C, dim1);\n  stop = clock();\n  printf(\"Naive    %.10f seconds\\n\", (double) (stop - start) \/ CLOCKS_PER_SEC);\n  \/\/mat_print(C, dim1);\n\n  D = mat_init(dim1);\n  start = clock();\n  mat_mul_strassen(A, B, D, dim1);\n  stop = clock();\n  printf(\"Strassen %.10f seconds\\n\", (double) (stop - start) \/ CLOCKS_PER_SEC);\n  \/\/mat_print(D, dim1);\n\n  mat_sub(C, D, C, dim1);\n  \/\/ results will differ more and more the larger the matrix is\n  \/\/mat_print(C, dim1);\n\n  mat_clear(A, dim1);\n  mat_clear(B, dim1);\n  mat_clear(C, dim1);\n  mat_clear(D, dim1);\n  exit(EXIT_SUCCESS);\n}\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved How to multiply two matrices having fractions as inputs in c [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] I wanted to use my own implementation of the Strassen optimization for matrix multiplication. It is highly optimized and hence has almost no pedagogical use but then I remembered that Wikipedia has actual C code in the Strassen-matrix-multiplication entry. The implementation there is not the best: it has no fallback to the naive algorithm &#8230; <a title=\"[Solved] How to multiply two matrices having fractions as inputs in c [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/\" aria-label=\"More on [Solved] How to multiply two matrices having fractions as inputs in c [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[361,324,1331,2905],"class_list":["post-28128","post","type-post","status-publish","format-standard","hentry","category-solved","tag-arrays","tag-c","tag-matrix","tag-matrix-multiplication"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] How to multiply two matrices having fractions as inputs in c [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] How to multiply two matrices having fractions as inputs in c [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] I wanted to use my own implementation of the Strassen optimization for matrix multiplication. It is highly optimized and hence has almost no pedagogical use but then I remembered that Wikipedia has actual C code in the Strassen-matrix-multiplication entry. The implementation there is not the best: it has no fallback to the naive algorithm ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-28T14:50:47+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] How to multiply two matrices having fractions as inputs in c [closed]\",\"datePublished\":\"2022-12-28T14:50:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\\\/\"},\"wordCount\":136,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"arrays\",\"c++\",\"matrix\",\"matrix-multiplication\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\\\/\",\"name\":\"[Solved] How to multiply two matrices having fractions as inputs in c [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-12-28T14:50:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] How to multiply two matrices having fractions as inputs in c [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] How to multiply two matrices having fractions as inputs in c [closed] - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] How to multiply two matrices having fractions as inputs in c [closed] - JassWeb","og_description":"[ad_1] I wanted to use my own implementation of the Strassen optimization for matrix multiplication. It is highly optimized and hence has almost no pedagogical use but then I remembered that Wikipedia has actual C code in the Strassen-matrix-multiplication entry. The implementation there is not the best: it has no fallback to the naive algorithm ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/","og_site_name":"JassWeb","article_published_time":"2022-12-28T14:50:47+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] How to multiply two matrices having fractions as inputs in c [closed]","datePublished":"2022-12-28T14:50:47+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/"},"wordCount":136,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["arrays","c++","matrix","matrix-multiplication"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/","name":"[Solved] How to multiply two matrices having fractions as inputs in c [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-12-28T14:50:47+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-how-to-multiply-two-matrices-having-fractions-as-inputs-in-c-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] How to multiply two matrices having fractions as inputs in c [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/28128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=28128"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/28128\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=28128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=28128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=28128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}