You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

matrix_def.h 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef MATRIX_DEF
  2. #define MATRIX_DEF
  3. #pragma once
  4. #include<iostream>
  5. #include<sys/malloc.h>
  6. #include<stdio.h>
  7. #include<string>
  8. using namespace std;
  9. /*
  10. ███████╗██████╗ ██████╗ ███████╗ ███████╗███╗ ██╗ ██████╗ ██╗███╗ ██╗███████╗
  11. ██╔════╝██╔══██╗██╔════╝ ██╔════╝ ██╔════╝████╗ ██║██╔════╝ ██║████╗ ██║██╔════╝
  12. █████╗ ██║ ██║██║ ███╗█████╗ █████╗ ██╔██╗ ██║██║ ███╗██║██╔██╗ ██║█████╗
  13. ██╔══╝ ██║ ██║██║ ██║██╔══╝ ██╔══╝ ██║╚██╗██║██║ ██║██║██║╚██╗██║██╔══╝
  14. ███████╗██████╔╝╚██████╔╝███████╗ ███████╗██║ ╚████║╚██████╔╝██║██║ ╚████║███████╗
  15. ╚══════╝╚═════╝ ╚═════╝ ╚══════╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝╚══════╝
  16. Author:Edge
  17. Web:likedge.top
  18. Date:20200925
  19. */
  20. //CreateMatrix Create a Matrix for ones;
  21. //ex:
  22. //2*3
  23. //0 0 0
  24. //0 0 0
  25. //change the value in matrix
  26. typedef struct
  27. {
  28. int row,col;
  29. float **matrix;
  30. }Matrix;
  31. typedef struct
  32. {
  33. int row,col;
  34. string **str_matrix;
  35. }str_Matrix;
  36. str_Matrix CreateStr_Ma(int ro, int co)
  37. {
  38. str_Matrix str_arr;
  39. int row,col;
  40. string **designma;
  41. designma = (string**)malloc(ro*sizeof(string*));
  42. for(int i = 0;i<ro;i++)
  43. {
  44. designma[i] = (string*)malloc(co*sizeof(string));
  45. }
  46. for(int i = 0;i <ro;i++)
  47. {
  48. for(int j =0;j<co;j++)
  49. {
  50. //cout<<"designma"<<designma[i][j]<<endl;
  51. designma[i][j] = "edge";
  52. }
  53. }
  54. str_arr.row = ro;
  55. str_arr.col = co;
  56. str_arr.str_matrix = designma;
  57. return str_arr;
  58. }
  59. Matrix CreateMatrix(int ro,int co)
  60. {
  61. Matrix m;
  62. int row,col;
  63. float **inputMatrix;
  64. inputMatrix=(float**)malloc(ro*sizeof(float*));
  65. for(int i = 0;i<ro;i++)
  66. {
  67. inputMatrix[i]=(float*)malloc(co*sizeof(float));
  68. }
  69. for(int i=0; i<ro; i++)
  70. {
  71. for(int j=0; j<co; j++)
  72. {
  73. inputMatrix[i][j] = 0;
  74. }
  75. }
  76. m.col = co;
  77. m.row = ro;
  78. m.matrix = inputMatrix;
  79. return m;
  80. }
  81. Matrix ones(int ro,int co)
  82. {
  83. Matrix m;
  84. int row,col;
  85. float **inputMatrix;
  86. inputMatrix=(float**)malloc(ro*sizeof(float*));
  87. for(int i = 0;i<ro;i++)
  88. {
  89. inputMatrix[i]=(float*)malloc(co*sizeof(float));
  90. }
  91. for(int i=0; i<ro; i++)
  92. {
  93. for(int j=0; j<co; j++)
  94. {
  95. inputMatrix[i][j] = 1;
  96. }
  97. }
  98. m.col = co;
  99. m.row = ro;
  100. m.matrix = inputMatrix;
  101. return m;
  102. }
  103. void cout_strmat(str_Matrix mid1)
  104. {
  105. for(int index_x = 0;index_x<mid1.row;index_x++)
  106. {
  107. for(int index_y=0;index_y<mid1.col;index_y++)
  108. {
  109. cout<<mid1.str_matrix[index_x][index_y]<<",";
  110. }
  111. cout<<endl;
  112. }
  113. }
  114. int change_va(Matrix Matrix ,int index_x,int index_y,float value)
  115. {
  116. Matrix.matrix[index_x][index_y] = value;
  117. return 0;
  118. }
  119. #endif

Edge : 一个开源的科学计算引擎