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

65 lines
1.6 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include "binary_library.h"
  10. #include "stdio.h"
  11. void demo_MatrixXd()
  12. {
  13. struct C_MatrixXd *matrix1, *matrix2, *result;
  14. printf("*** demo_MatrixXd ***\n");
  15. matrix1 = MatrixXd_new(3, 3);
  16. MatrixXd_set_zero(matrix1);
  17. MatrixXd_set_coeff(matrix1, 0, 1, 2.5);
  18. MatrixXd_set_coeff(matrix1, 1, 0, 1.4);
  19. printf("Here is matrix1:\n");
  20. MatrixXd_print(matrix1);
  21. matrix2 = MatrixXd_new(3, 3);
  22. MatrixXd_multiply(matrix1, matrix1, matrix2);
  23. printf("Here is matrix1*matrix1:\n");
  24. MatrixXd_print(matrix2);
  25. MatrixXd_delete(matrix1);
  26. MatrixXd_delete(matrix2);
  27. }
  28. // this helper function takes a plain C array and prints it in one line
  29. void print_array(double *array, int n)
  30. {
  31. struct C_Map_MatrixXd *m = Map_MatrixXd_new(array, 1, n);
  32. Map_MatrixXd_print(m);
  33. Map_MatrixXd_delete(m);
  34. }
  35. void demo_Map_MatrixXd()
  36. {
  37. struct C_Map_MatrixXd *map;
  38. double array[5];
  39. int i;
  40. printf("*** demo_Map_MatrixXd ***\n");
  41. for(i = 0; i < 5; ++i) array[i] = i;
  42. printf("Initially, the array is:\n");
  43. print_array(array, 5);
  44. map = Map_MatrixXd_new(array, 5, 1);
  45. Map_MatrixXd_add(map, map, map);
  46. Map_MatrixXd_delete(map);
  47. printf("Now the array is:\n");
  48. print_array(array, 5);
  49. }
  50. int main()
  51. {
  52. demo_MatrixXd();
  53. demo_Map_MatrixXd();
  54. }