|
1 | | -""" |
2 | | - *(a, b) |
3 | | -
|
4 | | -A more performant version of `a * b` where a, b are matrices |
5 | | -""" |
6 | | -function Base.:(*)(a::Array{DoubleFloat{T},2}, b::Array{DoubleFloat{T},2}) where {T<:IEEEFloat} |
7 | | - arows, acols = size(a) |
8 | | - brows, bcols = size(b) |
9 | | - if acols != brows |
10 | | - throw(DimensionMismatch(string("size(a,1) != size(b,2): ",size(a,1), " != ", size(b,2)))) |
11 | | - end |
12 | | - |
13 | | - result_rows, result_cols = arows, bcols |
14 | | - result = reshape(Array{DoubleFloat{T}, 1}(undef, result_rows*result_cols), (result_rows, result_cols)) |
15 | | - |
16 | | - for bcol = 1:bcols |
17 | | - for arow=1:arows |
18 | | - asum = zero(DoubleFloat{T}) |
19 | | - for acol=1:acols |
20 | | - @inbounds asum = fma(a[arow,acol], b[acol,bcol], asum) |
21 | | - end |
22 | | - @inbounds result[arow,bcol] = asum |
23 | | - end |
24 | | - end |
25 | | - |
26 | | - return result |
27 | | -end |
28 | | - |
29 | | - |
30 | | -function Base.:(*)(a::Array{DoubleFloat{T},2}, b::Array{T,2}) where {T<:IEEEFloat} |
31 | | - arows, acols = size(a) |
32 | | - brows, bcols = size(b) |
33 | | - if acols != brows |
34 | | - throw(DimensionMismatch(string("size(a,1) != size(b,2): ",size(a,1), " != ", size(b,2)))) |
35 | | - end |
36 | | - |
37 | | - result_rows, result_cols = arows, bcols |
38 | | - result = reshape(Array{DoubleFloat{T}, 1}(undef, result_rows*result_cols), (result_rows, result_cols)) |
39 | | - |
40 | | - for bcol = 1:bcols |
41 | | - for arow=1:arows |
42 | | - asum = zero(DoubleFloat{T}) |
43 | | - for acol=1:acols |
44 | | - @inbounds asum = fma(a[arow,acol], b[acol,bcol], asum) |
45 | | - end |
46 | | - @inbounds result[arow,bcol] = asum |
47 | | - end |
48 | | - end |
49 | | - |
50 | | - return result |
51 | | -end |
52 | | - |
53 | | - |
54 | | -function Base.:(*)(a::Array{T,2}, b::Array{DoubleFloat{T},2}) where {T<:IEEEFloat} |
55 | | - arows, acols = size(a) |
56 | | - brows, bcols = size(b) |
57 | | - if acols != brows |
58 | | - throw(DimensionMismatch(string("size(a,1) != size(b,2): ",size(a,1), " != ", size(b,2)))) |
59 | | - end |
60 | | - |
61 | | - result_rows, result_cols = arows, bcols |
62 | | - result = reshape(Array{DoubleFloat{T}, 1}(undef, result_rows*result_cols), (result_rows, result_cols)) |
63 | | - |
64 | | - for bcol = 1:bcols |
65 | | - for arow=1:arows |
66 | | - asum = zero(DoubleFloat{T}) |
67 | | - for acol=1:acols |
68 | | - @inbounds asum = fma(a[arow,acol], b[acol,bcol], asum) |
69 | | - end |
70 | | - @inbounds result[arow,bcol] = asum |
71 | | - end |
72 | | - end |
73 | | - |
74 | | - return result |
75 | | -end |
76 | | - |
77 | 1 | """ |
78 | 2 | mul!(c, a, b) |
79 | 3 | A more performant version of `c = a * b` where a, b, c are matrices |
|
0 commit comments