gemm!(tA,tB,alpha,A,B,beta,C)
根据tA(转置A)和tB将C更新为alpha * A * B + beta * C或其他三个变体.返回更新的C.
Update C as alpha * A * B + beta*C or the other three variants according to tA (transpose A) and tB. Returns the updated C.
注意:此处,alpha
和beta
必须是float
类型的标量. A
,B
和C
都是矩阵.确保矩阵尺寸匹配由您决定.
Note: here, alpha
and beta
must be float
type scalars. A
, B
and C
are all matrices. It's up to you to make sure the matrix dimensions match.
因此,tA
和tB
参数是指在乘法之前是要对A
还是对B
应用移调运算.请注意,这将花费您一些计算时间和分配资源-转置不是免费的. (因此,如果您要多次使用乘法,并且每次都使用相同的转置规范,则最好从一开始就将矩阵存储为转置版本).选择N
表示不进行转置,选择T
表示进行转置.您必须选择一个.
Thus, the tA
and tB
parameters refer to whether you want to apply the transpose operation to A
or to B
before multiplying. Note that this will cost you some computation time and allocations - the transpose isn't free. (thus, if you were going to apply the multiplication many times, each time with the same transpose specification, you'd be better off storing your matrix as the transposed version from the beginning). Select N
for no transpose, T
for transpose. You must select one or the other.
gemm!()
和gemv!()
之间的区别在于,对于gemm!()
,您已经需要分配矩阵C
. !
是原位修改"信号.考虑以下不同用途的图示:
The difference between gemm!()
and gemv!()
is that for gemm!()
you already need to have allocated the matrix C
. The !
is a "modify in place" signal. Consider the following illustration of their different uses:
A = rand(5,5)
B = rand(5,5)
C = Array(Float64, 5, 5)
BLAS.gemm!('N', 'T', 1.0, A, B, 0.0, C)
D = BLAS.gemm('N', 'T', 1.0, A, B)
julia> C == D
true
从本质上讲,每一个都执行计算C = A * B'. (从技术上讲,gemm!()
执行C =(0.0)* C +(1.0)* A * B'.)
Each of these, in essence, perform the calculation C = A * B'. (Technically, gemm!()
performs C = (0.0)*C + (1.0)*A * B'.)
因此,gemm!()
修改的语法在某些方面有点不寻常(除非您已经使用过像C这样的语言,在这种情况下它看起来非常直观).像使用Julia这样的面向对象的高级语言来调用函数来赋值时,您没有像通常那样具有显式的=
符号.
Thus, the syntax for the modify in place gemm!()
is a bit unusual in some respects (unless you've already worked with a language like C in which case it seems very intuitive). You don't have the explicit =
sign like you frequently do when calling functions in assigning values in a high level object oriented language like Julia.
如上图所示,即使实现该结果的语法和过程稍有不同,在这种情况下,gemm!()
和gemm()
的结果也是相同的.但是,实际上,取决于您的用例,两者之间的性能差异可能很大.特别是,如果您要执行多次乘法运算,每次都替换/更新C
的值,那么gemm!()
可能会更快一些,因为您不需要继续分配新的每次都有内存,这确实要花费时间,无论是在最初的内存分配中,还是后来的垃圾回收中.
As the illustration above shows, the outcome of gemm!()
and gemm()
in this case is identical, even though the syntax and procedure to achieve that outcome is a bit different. Practically speaking, however, performance differences between the two can be significant, depending on your use case. In particular, if you are going to be performing that multiplication operation many times, replacing/updating the value of C
each time, then gemm!()
can be a decent bit quicker because you don't need to keep re-allocating new memory each time, which does have time costs, both in the initial memory allocation and then in the garbage collection later on.
这篇关于朱莉娅:BLAS.gemm!()参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!