Fixed indexing mistake in cuistl/vector_operations

This commit is contained in:
Kjetil Olsen Lye 2023-04-12 15:38:10 +02:00
parent 046ef6cdc0
commit 133a8897a0
2 changed files with 12 additions and 1 deletions

View File

@ -54,7 +54,7 @@ namespace
// TODO: [perf] Is it faster to just use a mask? Probably does not matter either way // TODO: [perf] Is it faster to just use a mask? Probably does not matter either way
// This is hopefully not where we will spend most of our time. // This is hopefully not where we will spend most of our time.
if (globalIndex < numberOfElements) { if (globalIndex < numberOfElements) {
buffer[indices[globalIndex]] = a[indices[globalIndex]] * b[indices[globalIndex]]; buffer[globalIndex] = a[indices[globalIndex]] * b[indices[globalIndex]];
} }
} }

View File

@ -280,5 +280,16 @@ BOOST_AUTO_TEST_CASE(RandomVectors)
BOOST_CHECK_EQUAL(projectedA[i], a[i]); BOOST_CHECK_EQUAL(projectedA[i], a[i]);
} }
} }
aGPU = GVector(a);
auto twoNormAtIndices = aGPU.two_norm(indexSetGPU);
double correctTwoNormAtIndices = 0.0;
for (size_t i = 0; i < indexSet.size(); ++i) {
correctTwoNormAtIndices += a[indexSet[i]] * a[indexSet[i]];
}
correctTwoNormAtIndices = std::sqrt(correctTwoNormAtIndices);
BOOST_CHECK_CLOSE(correctTwoNormAtIndices, twoNormAtIndices, 1e-7);
} }
} }