sumabs!

sumabs!(r, A)

Sum absolute values of elements of `A` over the singleton dimensions of `r`, and write results to `r`.

Examples

1. Calculate sum of absolute values along singleton dimensions:

``````julia> A = [1, -2, 3, -4, 5];
julia> r = zeros(5);
julia> sumabs!(r, A)
5-element Array{Float64,1}:
1.0
2.0
3.0
4.0
5.0``````

This example calculates the sum of absolute values of each element in `A` along the singleton dimensions (in this case, along the first dimension) and stores the results in the array `r`.

2. Calculate sum of absolute values along multiple singleton dimensions:

``````julia> A = [1 -2; 3 -4; 5 -6];
julia> r = zeros(2);
julia> sumabs!(r, A)
2-element Array{Float64,1}:
9.0
12.0``````

Here, the `sumabs!` function calculates the sum of absolute values along the columns of `A` (singleton dimension 1) and stores the results in the array `r`.

3. Modify existing array with sum of absolute values:
``````julia> A = [1, -2, 3, -4, 5];
julia> sumabs!(A, A)
5-element Array{Int64,1}:
1
2
3
4
5``````

In this example, the `sumabs!` function modifies the existing array `A` by replacing its elements with the sum of their absolute values.

Common mistake example:

``````julia> A = [1 -2 3; 4 -5 6];
julia> r = zeros(2);
julia> sumabs!(r, A)
ERROR: DimensionMismatch("dimensions must match")``````

This error occurs when the dimensions of `r` and `A` do not match. Ensure that the dimensions of `r` are compatible with the singleton dimensions of `A` to avoid this mistake.