|
| 1 | + |
| 2 | +[](https://github.com/marketplace/actions/arduino_ci) |
| 3 | +[](https://github.com/RobTillaart/SparseMatrix/actions/workflows/arduino-lint.yml) |
| 4 | +[](https://github.com/RobTillaart/SparseMatrix/actions/workflows/jsoncheck.yml) |
| 5 | +[](https://github.com/RobTillaart/SparseMatrix/blob/master/LICENSE) |
| 6 | +[](https://github.com/RobTillaart/SparseMatrix/releases) |
| 7 | + |
| 8 | + |
| 9 | +# SparseMatrix |
| 10 | + |
| 11 | +Arduino library for sparse matrices. |
| 12 | + |
| 13 | + |
| 14 | +## Description |
| 15 | + |
| 16 | +SparseMatrix is an **experimental** library to implement sparse matrices on an Arduino. |
| 17 | + |
| 18 | +The maximum matrix that can be represented is 255 x 255 |
| 19 | +with a maximum of 255 non-zero elements. |
| 20 | +This would just fit in an UNO's 2K memory. |
| 21 | + |
| 22 | +The library does not hold the dimensions of the matrix (at least in 0.1.0) |
| 23 | + |
| 24 | +The purpose of the library is efficient storage in memory. |
| 25 | +It does not do math operations except sum(). |
| 26 | + |
| 27 | +Relates to https://github.com/RobTillaart/distanceTable |
| 28 | + |
| 29 | + |
| 30 | +#### Implementation |
| 31 | + |
| 32 | +The implementation is based on 3 arrays holding ``` x, y, value``` where value is float. |
| 33 | +In the future other datatypes should be possible. |
| 34 | + |
| 35 | +The elements are not kept sorted or indexed so optimizations are possible |
| 36 | +but not investigated yet. |
| 37 | + |
| 38 | + |
| 39 | +## Interface |
| 40 | + |
| 41 | +- **SparseMatrix(uint8_t size)** constructor. |
| 42 | +Parameter is the maximum number of elements in the sparse matrix. |
| 43 | +- **uint8_t size()** maximum number of elements. |
| 44 | +- **uint8_t count()** current number of elements in the matrix. |
| 45 | +- **float sum()** sum of all elements ( > 0 ) in the matrix. |
| 46 | +- **bool set(uint8_t x, uint8_t y, float value)** gives an element in the matrix a value. |
| 47 | +If the value is set to zero, it is removed from the internal store. |
| 48 | +Returns false if the internal store is full, true otherwise. |
| 49 | +- **float get(uint8_t x, uint8_t y)** returns the value in the matrix. |
| 50 | + |
| 51 | + |
| 52 | +## Future |
| 53 | + |
| 54 | +- documentation |
| 55 | +- test |
| 56 | +- template version to store other data types |
| 57 | + - 1, 2, 3 (RGB), 4 byte integer or 8 byte doubles |
| 58 | + - struct, complex number |
| 59 | + - etc |
| 60 | +- add examples |
| 61 | + - 2D histogram e.g. temperature vs humidity |
| 62 | + - N queens game. |
| 63 | +- investigate optimizations. |
| 64 | +- should **set()** return the number of free places? |
| 65 | + - no hard code and more informative than just a bool. |
| 66 | +- add link in distanceTable repo |
| 67 | +- uint16_t size for larger platforms. |
| 68 | + - max matrix still 255 x 255 but more elements <> 0. |
| 69 | + |
| 70 | + |
| 71 | +#### new functions |
| 72 | + |
| 73 | +- **float add(uint8_t x, uint8_t y, float value)** adds value to the x,y position. |
| 74 | + - add or remove an internal element if needed, |
| 75 | + - functional **set(x,y, get(x,y) + value)** |
| 76 | +- **void clear()** sets all elements to zero again. |
| 77 | + - \_count = 0; should be sufficient. |
| 78 | +- walking through the elements? |
| 79 | + - first -> next; last -> prev. |
| 80 | + |
| 81 | + |
| 82 | +#### won't |
| 83 | + |
| 84 | +- math |
| 85 | + - determinant? |
| 86 | + - M x M |
| 87 | + - diagonal? |
| 88 | +- add examples |
| 89 | + - battleship game |
| 90 | + - minesweeper game |
| 91 | + - nice exercise |
| 92 | + |
0 commit comments