|
1 | 1 | #:include "common.fypp"
|
| 2 | +#:set RCI_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES + INT_KINDS_TYPES |
2 | 3 |
|
3 | 4 | module test_linalg
|
4 | 5 | use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
|
5 | 6 | use stdlib_kinds, only: sp, dp, xdp, qp, int8, int16, int32, int64
|
6 |
| - use stdlib_linalg, only: diag, eye, trace, outer_product, cross_product |
| 7 | + use stdlib_linalg, only: diag, eye, trace, outer_product, cross_product, kronecker_product |
7 | 8 |
|
8 | 9 | implicit none
|
9 | 10 |
|
@@ -48,6 +49,9 @@ contains
|
48 | 49 | new_unittest("trace_int16", test_trace_int16), &
|
49 | 50 | new_unittest("trace_int32", test_trace_int32), &
|
50 | 51 | new_unittest("trace_int64", test_trace_int64), &
|
| 52 | + #:for k1, t1 in RCI_KINDS_TYPES |
| 53 | + new_unittest("kronecker_product_${t1[0]}$${k1}$", test_kronecker_product_${t1[0]}$${k1}$), & |
| 54 | + #:endfor |
51 | 55 | new_unittest("outer_product_rsp", test_outer_product_rsp), &
|
52 | 56 | new_unittest("outer_product_rdp", test_outer_product_rdp), &
|
53 | 57 | new_unittest("outer_product_rqp", test_outer_product_rqp), &
|
@@ -554,6 +558,43 @@ contains
|
554 | 558 | end subroutine test_trace_int64
|
555 | 559 |
|
556 | 560 |
|
| 561 | + |
| 562 | + #:for k1, t1 in RCI_KINDS_TYPES |
| 563 | + subroutine test_kronecker_product_${t1[0]}$${k1}$(error) |
| 564 | + !> Error handling |
| 565 | + type(error_type), allocatable, intent(out) :: error |
| 566 | + integer, parameter :: m1 = 1, n1 = 2, m2 = 2, n2 = 3 |
| 567 | + ${t1}$, dimension(m1*m2,n1*n2), parameter :: expected & |
| 568 | + = transpose(reshape([1,2,3, 2,4,6, 2,4,6, 4,8,12], [m2*n2, m1*n1])) |
| 569 | + ${t1}$, parameter :: tol = 1.e-6 |
| 570 | + |
| 571 | + ${t1}$ :: A(m1,n1), B(m2,n2) |
| 572 | + ${t1}$ :: C(m1*m2,n1*n2), diff(m1*m2,n1*n2) |
| 573 | + |
| 574 | + integer :: i,j |
| 575 | + |
| 576 | + do j = 1, n1 |
| 577 | + do i = 1, m1 |
| 578 | + A(i,j) = i*j ! A = [1, 2] |
| 579 | + end do |
| 580 | + end do |
| 581 | + |
| 582 | + do j = 1, n2 |
| 583 | + do i = 1, m2 |
| 584 | + B(i,j) = i*j ! B = [[1, 2, 3], [2, 4, 6]] |
| 585 | + end do |
| 586 | + end do |
| 587 | + |
| 588 | + C = kronecker_product(A,B) |
| 589 | + |
| 590 | + diff = C - expected |
| 591 | + |
| 592 | + call check(error, all(abs(diff) .le. abs(tol)), "all(abs(diff) .le. abs(tol)) failed") |
| 593 | + ! Expected: C = [1*B, 2*B] = [[1,2,3, 2,4,6], [2,4,6, 4, 8, 12]] |
| 594 | + |
| 595 | + end subroutine test_kronecker_product_${t1[0]}$${k1}$ |
| 596 | + #:endfor |
| 597 | + |
557 | 598 | subroutine test_outer_product_rsp(error)
|
558 | 599 | !> Error handling
|
559 | 600 | type(error_type), allocatable, intent(out) :: error
|
|
0 commit comments