mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Replace memset with fill to work for non-trivial scalars.
For custom scalars, zero is not necessarily represented by a zeroed-out memory block (e.g. gnu MPFR). We therefore cannot rely on `memset` if we want to fill a matrix or tensor with zeroes. Instead, we should rely on `fill`, which for trivial types does end up getting converted to a `memset` under-the-hood (at least with gcc/clang). Requires adding a `fill(begin, end, v)` to `TensorDevice`. Replaced all potentially bad instances of memset with fill. Fixes #2245.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
e9c9a3130b
commit
1e6c6c1576
@@ -762,7 +762,7 @@ struct TensorContractionEvaluatorBase : internal::no_assignment_operator
|
||||
const Index resIncr(1);
|
||||
|
||||
// zero out the result buffer (which must be of size at least rows * sizeof(Scalar)
|
||||
m_device.memset(buffer, 0, rows * sizeof(Scalar));
|
||||
m_device.fill(buffer, buffer + rows, Scalar(0));
|
||||
|
||||
internal::general_matrix_vector_product<Index,LhsScalar,LhsMapper,ColMajor,false,RhsScalar,RhsMapper,false>::run(
|
||||
rows, cols, lhs, rhs,
|
||||
@@ -869,7 +869,7 @@ struct TensorContractionEvaluatorBase : internal::no_assignment_operator
|
||||
// If a contraction kernel does not support beta, explicitly initialize
|
||||
// output buffer with zeroes.
|
||||
if (!TensorContractionKernel::HasBeta) {
|
||||
this->m_device.memset(buffer, 0, m * n * sizeof(Scalar));
|
||||
this->m_device.fill(buffer, buffer + m * n, Scalar(0));
|
||||
}
|
||||
|
||||
for(Index i2=0; i2<m; i2+=mc)
|
||||
|
||||
Reference in New Issue
Block a user