It's not totally clear what you're asking. A dot product takes two vectors as arguments, but you keep talking about "the dot product for each [vector]."
What I think you're asking for is a way to compute the dot product of each row [or column] with itself, which is the l2 norm squared of each row [or product]. The result would be a vector whose i
th entry is given by:
result_i = sum_{j=0}^{j<n} A_ij * A_ij
If that's really what you're trying to compute, then calling vDSP_svesq
on each row is a perfectly reasonably solution.
For computing the norm squared of the columns, however, I would suggest a different solution. If you try to do it using vDSP_svesq
, as you noted, you will need to have a non-unit stride, which will pretty much ruin your performance. Instead, you can do the following:
void normsSquaredOfColumns(float *result, const float * restrict matrix,
int rows, int cols) {
// initialize result with squares of the first row.
vDSP_vsq(matrix, 1, result, 1, cols);
// loop over rows, adding square of each to the result.
for (int row=1; row<rows; ++row)
vDSP_vma(&matrix[i*cols], 1, &matrix[i*cols], 1, result, 1, result, 1, cols);
}