README.md 3.94 KB
Newer Older
1
2
3
4
5
6
7
8
9
# armawrap


A wrapper around [Armadillo](http://arma.sourceforge.net/) which provides a
[Newmat](http://www.robertnz.net/nm_intro.htm) style API.

The current version of `armawrap` is written against:

- newmat10D
10
- Armadillo 10.5.1
11
12
13
14
15
16
17
18
19
20
21
22
23
24


Please cite:

 > Conrad Sanderson.
 > Armadillo: An Open Source C++ Linear Algebra Library for
 > Fast Prototyping and Computationally Intensive Experiments.
 > Technical Report, NICTA, 2010.


## Usage


Like Armadillo, `armawrap` is a header library, so no compilation is
Paul McCarthy's avatar
Paul McCarthy committed
25
required.
26

Paul McCarthy's avatar
Paul McCarthy committed
27
28
1. Copy `armadillo`, `armadillo_bits`, and `armawrap` into your
   `$PREFIX/include/` path.
29
2. `#include "armawrap/newmat.h"` in your code.
Paul McCarthy's avatar
Paul McCarthy committed
30
3. Code against the Newmat API.
Paul McCarthy's avatar
Paul McCarthy committed
31
4. Compile with `-I$PREFIX/include`.
32
33


Paul McCarthy's avatar
Paul McCarthy committed
34
## Running the tests
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175


[![Code coverage](https://git.fmrib.ox.ac.uk/fsl/armawrap/badges/master/coverage.svg)](https://git.fmrib.ox.ac.uk/fsl/armawrap/pipelines)


To run the tests, simply call the `run_tests.sh` script. This script assumes
that you have a C++ development environment configured to compile Armadillo
code:

    path/to/armawrap/tests/run_tests.sh


The `run_tests.sh` script will return an exit code of zero if all tests
passed, or non-zero if any tests failed.


## Differences between `armawrap` and `newmat`


The following behavioural differences between `armawrap` and `newmat` are
known to exist.


### Matrix assignment


With `armawrap`, it is possible to perform lossy assignments between
matrices of different types:

```c++
Matrix m(3, 3);
m << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9;
DiagonalMatrix d;
d = m;
cout << d << endl;
```

This will result in the diagonal elements being filled:

```
1 0 0
0 5 0
0 0 9
```

Under `newmat` this will cause a runtime exception to be raised, because
`newmat` only allows assignments which do not lose information.


### Insertion of vectors into diagonal/triangular/symmetric matrices


In `armawrap`, it is possible to insert a vector into a diagonal (or
triangular, or symmetric) matrix, with predictable results:

```c++
DiagonalMatrix d;
RowVector r(5);
r << 5 << 4 << 3 << 2 << 1;
d << r;
cout << d << endl;
```

This will result in a matrix with the values of `r` along the diagonal:
```
5
  4
    3
      2
        1
```

This is not possible in `newmat` in the above code, `d` will be set to a
`(1, 1)` matrix containing `5`.

Column vectors produce slightly different behaviour:

```c++
DiagonalMatrix d;
ColumnVector c(5);
c << 5 << 4 << 3 << 2 << 1;
d << r;
```

In this code, `d` will be set to a `(5, 5)` matrix containing `5` as its
first element, and zeros everywhere else.


### Calling `.Storage` on a sub-view


In `armawrap`, you can call `.Storage` on a subview, e.g.:


```c++
SymmetricMatrix m(5);
cout << m.Row(4).Storage() << endl;
```


This will output `4` (as symmetric matrices are internally represented as
lower-triangular matrices).


This is not possible in `newmat`.


 > The `.Storage` method is not implemented on sub-views of the band
 > matrix types.


## `armawrap` development


The `armawrap` source code is located at:

  https://git.fmrib.ox.ac.uk/fsl/armawrap


All changes to the source must occur via merge requests to the master
branch. New releases are denoted by a tag off the master branch, with the tag
name equal to the new version number.


`armawrap` follows [Semantic Versioning](https://www.semver.org>)
conventions. The current version of `armawrap` can be found in
`armawrap.hpp`.


When you wish to make a new release, ensure that the following criteria have
been met before tagging the new release:


 - Version number updated in `armawrap.hpp`
 - Change log updated


## License


`armawrap` is released under the Apache License, Version 2.0. `armawrap`
176
177
includes a copy of the Armadillo source, which is also released under the
Apache License, Version 2.0.
178
179
180
181
182


The `armawrap/tests` directory includes a copy of the `newmat` 10D source
code, which is released under a liberal open source license - see the
[newmat](http://robertnz.net/nm10.htm#use) web site for details.