mirror of
https://github.com/opencv/opencv.git
synced 2026-12-03 05:33:03 -06:00
core: support 1D Mat inputs in gemm (#30704)
* core: support 1D Mat inputs in gemm A 1D Mat is a single row, but its step[0] is the element size, not the row size, so gemm passed a too-small row step to the HAL kernels and failed with "_step >= minstep". Give 1D A, B and C an ordinary 2D one-row header before calling the kernels. Fixes #30703 * core: support preallocated 1D output in gemm When the caller passes a 1D Mat of the right size as the output, _matD.create() keeps it as is, so D still had step[0] == elemSize() and the kernel failed with "_step >= minstep". Give a 1D D a 2D one-row header too. The result is still written into the caller's buffer. * core: use TEST_P for the 1D gemm test
This commit is contained in:
@@ -350,6 +350,11 @@ void gemm(InputArray matA, InputArray matB, double alpha,
|
||||
#endif
|
||||
|
||||
Mat A = matA.getMat(), B = matB.getMat(), C = beta != 0.0 ? matC.getMat() : Mat();
|
||||
// A 1D Mat is one row, but its step[0] is the size of one element, not of the whole row.
|
||||
// Give it an ordinary 2D one-row header so the row step passed to the kernels is right.
|
||||
if (A.dims == 1) A = A.reshape(0, 1);
|
||||
if (B.dims == 1) B = B.reshape(0, 1);
|
||||
if (C.dims == 1) C = C.reshape(0, 1);
|
||||
Size a_size = A.size(), d_size;
|
||||
int len = 0, type = A.type();
|
||||
|
||||
@@ -388,6 +393,8 @@ void gemm(InputArray matA, InputArray matB, double alpha,
|
||||
|
||||
_matD.create( d_size.height, d_size.width, type );
|
||||
Mat D = _matD.getMat();
|
||||
// A preallocated 1D output keeps its 1D header after create(), so normalize it like A, B and C.
|
||||
if (D.dims == 1) D = D.reshape(0, 1);
|
||||
if( (flags & GEMM_3_T) != 0 && C.data == D.data )
|
||||
{
|
||||
transpose( C, C );
|
||||
|
||||
Reference in New Issue
Block a user