Skip to content
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f06f556
add interface and procedures
wassup05 Mar 13, 2025
fed4d73
add implementation for 3,4,5 matrices
wassup05 Mar 13, 2025
27911ae
add very basic example
wassup05 Mar 13, 2025
a7f645c
fix typo
wassup05 Mar 13, 2025
cc77dee
a bit efficient
wassup05 Mar 14, 2025
3958018
refactor algorithm
wassup05 Mar 14, 2025
35a5a28
add new interface
wassup05 Mar 14, 2025
ebf92d7
add helper functions
wassup05 Mar 14, 2025
5f5c5a9
add implementation, refactor select to if clauses
wassup05 Mar 15, 2025
06ce735
slightly better examples
wassup05 Mar 15, 2025
e709f83
replace all matmul's by gemm
wassup05 Mar 20, 2025
cf5f030
add error handling in a better way
wassup05 Apr 4, 2025
b6d07e6
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
5e3b588
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
7d2130a
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
61851fc
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
ee7da8d
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
195c57e
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
e71b9bb
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
00c4461
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
5c2bbc5
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
79113da
Update src/stdlib_intrinsics_matmul.fypp
perazz Apr 22, 2025
72dc641
added specs
wassup05 May 20, 2025
cee5bba
added tests
wassup05 May 20, 2025
a052599
modified example and slight changes
wassup05 May 20, 2025
24c5787
Merge branch 'fortran-lang:master' into matmul
wassup05 May 23, 2025
0174145
Merge branch 'master' of github.com:wassup05/stdlib into matmul
wassup05 Jul 5, 2025
2d0d9ca
reduce size, increase tolerance
wassup05 Jul 5, 2025
ca3e470
Merge remote-tracking branch 'origin/matmul' into matmul
wassup05 Jul 5, 2025
7e296bb
add comments to the example
wassup05 Sep 24, 2025
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
Prev Previous commit
Next Next commit
added tests
  • Loading branch information
wassup05 committed May 20, 2025
commit cee5bba407d0358230afcbb7ac3553bd7859105b
45 changes: 43 additions & 2 deletions test/intrinsics/test_intrinsics.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module test_intrinsics
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
use stdlib_kinds, only: sp, dp, xdp, qp, int8, int16, int32, int64
use stdlib_intrinsics
use stdlib_linalg_state, only: linalg_state_type, LINALG_VALUE_ERROR, operator(==)
use stdlib_math, only: swap
implicit none

Expand All @@ -19,7 +20,8 @@ subroutine collect_suite(testsuite)

testsuite = [ &
new_unittest('sum', test_sum), &
new_unittest('dot_product', test_dot_product) &
new_unittest('dot_product', test_dot_product), &
new_unittest('matmul', test_matmul) &
]
end subroutine

Expand Down Expand Up @@ -249,6 +251,45 @@ subroutine test_dot_product(error)
#:endfor

end subroutine

subroutine test_matmul(error)
type(error_type), allocatable, intent(out) :: error
type(linalg_state_type) :: linerr
real :: a(2, 3), b(3, 4), c(3, 2), d(2, 2)

d = stdlib_matmul(a, b, c, err=linerr)
call check(error, linerr == LINALG_VALUE_ERROR, "incompatible matrices are considered compatible")
if (allocated(error)) return

#:for k, t, s in R_KINDS_TYPES
block
${t}$ :: x(10,20), y(20,30), z(30,10), r(10,10), r1(10,10)
call random_number(x)
call random_number(y)
call random_number(z)

r = stdlib_matmul(x, y, z) ! the optimal ordering would be (x(yz))
r1 = matmul(matmul(x, y), z) ! the opposite order to induce a difference

call check(error, all(abs(r-r1) <= epsilon(0._${k}$) * 300), "real, ${k}$, 3 args: error too large")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm probably late for this party but isn't epsilon(0.0_wp) like the smallest number that can be represented in the working precision wp? If it is indeed the case, then I wouldn't be surprised to see the tests fail.

I guess, a better indicator would be to consider the matrix 2-norm (i.e. the largest singular value of $A - \tilde{A}$ where $A$ is the matrix you'd compute with a chain of matmul and $\tilde{A}$ the one from your implementation).

Copy link
Contributor

@jalvesz jalvesz Jun 14, 2025

Choose a reason for hiding this comment

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

but isn't epsilon(0.0_wp) like the smallest number that can be represented in the working precision wp

That would be tiny(0.0) which is indeed a very tiny number. epsilon() represents the smallest significant difference between two consecutive real numbers in the given precision.

if (allocated(error)) return
end block

block
${t}$ :: x(10,20), y(20,30), z(30,10), w(10, 20), r(10,20), r1(10,20)
call random_number(x)
call random_number(y)
call random_number(z)
call random_number(w)

r = stdlib_matmul(x, y, z, w) ! the optimal order would be ((x(yz))w)
r1 = matmul(matmul(x, y), matmul(z, w))

call check(error, all(abs(r-r1) <= epsilon(0._${k}$) * 1500), "real, ${k}$, 4 args: error too large")
if (allocated(error)) return
end block
#:endfor
end subroutine test_matmul

end module test_intrinsics

Expand Down Expand Up @@ -276,4 +317,4 @@ program tester
write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!"
error stop
end if
end program
end program