Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame^] | 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 | |
| 10 | #include "binary_library.h" |
| 11 | #include "stdio.h" |
| 12 | |
| 13 | void demo_MatrixXd() |
| 14 | { |
| 15 | struct C_MatrixXd *matrix1, *matrix2, *result; |
| 16 | printf("*** demo_MatrixXd ***\n"); |
| 17 | |
| 18 | matrix1 = MatrixXd_new(3, 3); |
| 19 | MatrixXd_set_zero(matrix1); |
| 20 | MatrixXd_set_coeff(matrix1, 0, 1, 2.5); |
| 21 | MatrixXd_set_coeff(matrix1, 1, 0, 1.4); |
| 22 | printf("Here is matrix1:\n"); |
| 23 | MatrixXd_print(matrix1); |
| 24 | |
| 25 | matrix2 = MatrixXd_new(3, 3); |
| 26 | MatrixXd_multiply(matrix1, matrix1, matrix2); |
| 27 | printf("Here is matrix1*matrix1:\n"); |
| 28 | MatrixXd_print(matrix2); |
| 29 | |
| 30 | MatrixXd_delete(matrix1); |
| 31 | MatrixXd_delete(matrix2); |
| 32 | } |
| 33 | |
| 34 | // this helper function takes a plain C array and prints it in one line |
| 35 | void print_array(double *array, int n) |
| 36 | { |
| 37 | struct C_Map_MatrixXd *m = Map_MatrixXd_new(array, 1, n); |
| 38 | Map_MatrixXd_print(m); |
| 39 | Map_MatrixXd_delete(m); |
| 40 | } |
| 41 | |
| 42 | void demo_Map_MatrixXd() |
| 43 | { |
| 44 | struct C_Map_MatrixXd *map; |
| 45 | double array[5]; |
| 46 | int i; |
| 47 | printf("*** demo_Map_MatrixXd ***\n"); |
| 48 | |
| 49 | for(i = 0; i < 5; ++i) array[i] = i; |
| 50 | printf("Initially, the array is:\n"); |
| 51 | print_array(array, 5); |
| 52 | |
| 53 | map = Map_MatrixXd_new(array, 5, 1); |
| 54 | Map_MatrixXd_add(map, map, map); |
| 55 | Map_MatrixXd_delete(map); |
| 56 | |
| 57 | printf("Now the array is:\n"); |
| 58 | print_array(array, 5); |
| 59 | } |
| 60 | |
| 61 | int main() |
| 62 | { |
| 63 | demo_MatrixXd(); |
| 64 | demo_Map_MatrixXd(); |
| 65 | } |