-
Notifications
You must be signed in to change notification settings - Fork 191
Kronecker Product addition to stdlib_linalg #700
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c14f6eb
Added the Kronecker product functionality to stdlib_linalg, and added…
adenchfi 04caad8
Update README.md
adenchfi dc814f6
Update test/linalg/test_linalg.fypp
adenchfi 9612c71
Apply suggestions from code review
adenchfi 0ce039b
Added spec and example program.
adenchfi b42e423
Merged some parentheses spacings and changed the numpy.kron reference…
adenchfi b3755cc
Condensed the tests into a single fypp loop, and made the expected ou…
adenchfi 25b219d
Apply suggestions from code review
adenchfi 22536ec
Apply suggestions from code review
adenchfi 3fd0def
Update example/linalg/example_kronecker_product.f90
adenchfi 94a555a
Organized the unit test list into a fypp loop as well.
adenchfi a6584f7
Update src/stdlib_linalg_kronecker.fypp
jvdp1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
program example_kronecker_product | ||
use stdlib_linalg, only: kronecker_product | ||
implicit none | ||
integer, parameter :: m1 = 1, n1 = 2, m2 = 2, n2 = 3 | ||
integer :: i, j | ||
real :: A(m1, n1), B(m2,n2) | ||
real, allocatable :: C(:,:) | ||
|
||
do j = 1, n1 | ||
do i = 1, m1 | ||
A(i,j) = i*j ! A = [1, 2] | ||
end do | ||
end do | ||
|
||
do j = 1, n2 | ||
do i = 1, m2 ! B = [ 1, 2, 3 ] | ||
B(i,j) = i*j ! [ 2, 4, 6 ] | ||
end do | ||
end do | ||
|
||
C = kronecker_product(A, B) | ||
! C = [ a(1,1) * B(:,:) | a(1,2) * B(:,:) ] | ||
! or in other words, | ||
! C = [ 1.00 2.00 3.00 2.00 4.00 6.00 ] | ||
! [ 2.00 4.00 6.00 4.00 8.00 12.00 ] | ||
end program example_kronecker_product |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#:include "common.fypp" | ||
#:set RCI_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES + INT_KINDS_TYPES | ||
submodule (stdlib_linalg) stdlib_linalg_kronecker | ||
|
||
implicit none | ||
|
||
contains | ||
|
||
#:for k1, t1 in RCI_KINDS_TYPES | ||
pure module function kronecker_product_${t1[0]}$${k1}$(A, B) result(C) | ||
${t1}$, intent(in) :: A(:,:), B(:,:) | ||
${t1}$ :: C(size(A,dim=1)*size(B,dim=1),size(A,dim=2)*size(B,dim=2)) | ||
integer :: m1, n1, maxM1, maxN1, maxM2, maxN2 | ||
|
||
maxM1 = size(A, dim=1) | ||
maxN1 = size(A, dim=2) | ||
maxM2 = size(B, dim=1) | ||
maxN2 = size(B, dim=2) | ||
|
||
|
||
do n1 = 1, maxN1 | ||
do m1 = 1, maxM1 | ||
! We use the Wikipedia convention for ordering of the matrix elements | ||
! https://en.wikipedia.org/wiki/Kronecker_product | ||
C((m1-1)*maxM2+1:m1*maxM2, (n1-1)*maxN2+1:n1*maxN2) = A(m1, n1) * B(:,:) | ||
end do | ||
end do | ||
end function kronecker_product_${t1[0]}$${k1}$ | ||
#:endfor | ||
end submodule stdlib_linalg_kronecker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.