Skip to content

Outer product #432

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

Merged
merged 16 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
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
Next Next commit
Created function submodule and interface.
  • Loading branch information
ghbrown committed Jun 9, 2021
commit 2d7f4775d826fd08ebd4d8e99888ec745cc25aad
18 changes: 18 additions & 0 deletions src/stdlib_linalg.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module stdlib_linalg
public :: diag
public :: eye
public :: trace
public :: outer_product

interface diag
!! version: experimental
Expand Down Expand Up @@ -52,6 +53,7 @@ module stdlib_linalg
#:endfor
end interface


! Matrix trace
interface trace
!! version: experimental
Expand All @@ -63,6 +65,22 @@ module stdlib_linalg
#:endfor
end interface


! Outer product (of two vectors)
interface outer_product
!! version: experimental
!!
!! Computes outer product of two vectors, returning a matrix
!! ([Specification](../page/specs/stdlib_linalg.html#description_3))
#:for k1, t1 in RCI_KINDS_TYPES
module function outer_product_${t1[0]}$${k1}$(u,v) result(res)
${t1}$, intent(in) :: u(:), v(:)
${t1}$ :: res(size(u),size(v))
integer :: col
Copy link
Member

@ivan-pi ivan-pi Jun 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best to leave col only in the submodule part with the implementation. The top level module only needs to contain the public interface.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, I just copy and pasted indiscriminately from the submodule.

end function outer_product_${t1[0]}$${k1}$
#:endfor
end interface outer_product

contains

function eye(n) result(res)
Expand Down
20 changes: 20 additions & 0 deletions src/stdlib_linalg_outer_product.fypp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#:include "common.fypp"
#:set RCI_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES + INT_KINDS_TYPES
submodule (stdlib_linalg) stdlib_linalg_outer_product

implicit none

contains

#:for k1, t1 in RCI_KINDS_TYPES
module function outer_product_${t1[0]}$${k1}$(u,v) result(res)
${t1}$, intent(in) :: u(:), v(:)
${t1}$ :: res(size(u),size(v))
integer :: col
do col=1,size(v)
res(:,col) = v(col) * u
end do
end function outer_product_${t1[0]}$${k1}$
#:endfor

end submodule