Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outer product #432

Merged
merged 16 commits into from
Jun 30, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions doc/specs/stdlib_linalg.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,41 @@ program demo_trace
print *, trace(A) ! 1 + 5 + 9
end program demo_trace
```

## `outer_product` - Computes the outer product of two vectors

### Status

Experimental

### Description

Create a diagonal array or extract the diagonal elements of an array
awvwgk marked this conversation as resolved.
Show resolved Hide resolved

### Syntax

`d = [[stdlib_linalg(module):outer_product(interface)]](u, v)`

### Arguments

`u`: Shall be a rank-1 array

`v`: Shall be a rank-1 array

### Return value

Returns a rank-2 array equal to `u v^T` (assuming `u, v` are column vectors). The dimensions of the returned array are `[size(u), size(v)]`
awvwgk marked this conversation as resolved.
Show resolved Hide resolved

### Example

```fortran
program demo_outer_product
use stdlib_linalg, only: outer_product
implicit none
real, allocatable :: A(:,:), u(:), v(:)
u = [1.,2.,3.]
awvwgk marked this conversation as resolved.
Show resolved Hide resolved
v = [3., 4.]
A=outer_product(u,v)
awvwgk marked this conversation as resolved.
Show resolved Hide resolved
!A = transpose(reshape([3., 4., 6., 8., 9., 12.], [3,2]))
awvwgk marked this conversation as resolved.
Show resolved Hide resolved
end program demo_outer_product
```