# sumabs2!

sumabs2!(r, A)

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

## Examples

1. Calculate sum of squared absolute values for a vector:

``````julia> r = zeros(3);
julia> A = [1, -2, 3];
julia> sumabs2!(r, A)
3-element Array{Float64,1}:
14.0
0.0
0.0``````

This example calculates the sum of squared absolute values of the elements in vector `A` and stores the results in vector `r`.

2. Calculate sum of squared absolute values for a matrix along rows:

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

It calculates the sum of squared absolute values of the elements in matrix `A` along each row and stores the results in vector `r`.

3. Calculate sum of squared absolute values for a tensor along specified dimensions:
``````julia> r = zeros(2);
julia> A = [1 2 3; -4 -5 -6; 7 8 9];
julia> sumabs2!(r, A, dims=(1, 2))
2-element Array{Float64,1}:
285.0
0.0``````

It calculates the sum of squared absolute values of the elements in tensor `A` along dimensions 1 and 2 and stores the results in vector `r`.

Common mistake example:

``````julia> r = [10, 20, 30];
julia> A = [1, -2, 3];
julia> sumabs2!(r, A)
ERROR: MethodError: no method matching sumabs2!(::Array{Int64,1}, ::Array{Int64,1})``````

In this example, the input arrays `r` and `A` have different element types (`Int64` and `Float64`). Ensure that the types of the arrays match to avoid such errors.