CamlFloat Tutorial
The basic arithmetic operators in camlFloat are +$,
-$ and *$. The trailing dollar sign serves the
same purpose as the period in the equivalent floating point operators.
Some simple manipulations might look like
# let x = eye 4 4 in
x +$ x ;;
2 0 0 0
0 2 0 0
0 0 2 0
0 0 0 2
- : Nla.DBlop.matrix =
or
# ones 3 3 *$ ones 3 3 *$ ones 3 3;;
9 9 9
9 9 9
9 9 9
- : Nla.DBlop.matrix =
Instead of calculating matrix transposes explicitly, we can use efficient algorithms
to calculate a product involving a transpose. To do this we use the operators *~$
and *$~ . It is worth taking a moment to get used to this notation, as it establishes
the convention used for the other operators.
The * must come first, as it is the leading symbol which establishes precedence. Then
we view the $ as a divider, with the tilde going on the side where the transposition is happening.
Thus a *$~ b multiplies a by the transpose of b, whereas
a *~$ b multiplies the transpose of a by b. We demonstrate
below by taking the inner and outer product of two vectors.
# let a = ones 3 1
and b = consts 4.0 3 1 in
a *~$ b ;;
12
- : Nla.DBlop.matrix =
and
# let a = ones 3 1
and b = consts 4.0 3 1 in
a *$~ b ;;
4 4 4
4 4 4
4 4 4
- : Nla.DBlop.matrix =
::: back :::