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
@@ -25,10 +25,8 @@ static void test_1d()
|
||||
vec1(4) = 23; vec2(4) = 4;
|
||||
vec1(5) = 42; vec2(5) = 5;
|
||||
|
||||
int col_major[6];
|
||||
int row_major[6];
|
||||
memset(col_major, 0, 6*sizeof(int));
|
||||
memset(row_major, 0, 6*sizeof(int));
|
||||
int col_major[6] = {0};
|
||||
int row_major[6] = {0};
|
||||
TensorMap<Tensor<int, 1> > vec3(col_major, 6);
|
||||
TensorMap<Tensor<int, 1, RowMajor> > vec4(row_major, 6);
|
||||
|
||||
@@ -88,10 +86,8 @@ static void test_2d()
|
||||
mat2(1,1) = 4;
|
||||
mat2(1,2) = 5;
|
||||
|
||||
int col_major[6];
|
||||
int row_major[6];
|
||||
memset(col_major, 0, 6*sizeof(int));
|
||||
memset(row_major, 0, 6*sizeof(int));
|
||||
int col_major[6] = {0};
|
||||
int row_major[6] = {0};
|
||||
TensorMap<Tensor<int, 2> > mat3(row_major, 2, 3);
|
||||
TensorMap<Tensor<int, 2, RowMajor> > mat4(col_major, 2, 3);
|
||||
|
||||
@@ -148,10 +144,8 @@ static void test_3d()
|
||||
}
|
||||
}
|
||||
|
||||
int col_major[2*3*7];
|
||||
int row_major[2*3*7];
|
||||
memset(col_major, 0, 2*3*7*sizeof(int));
|
||||
memset(row_major, 0, 2*3*7*sizeof(int));
|
||||
int col_major[2*3*7] = {0};
|
||||
int row_major[2*3*7] = {0};
|
||||
TensorMap<Tensor<int, 3> > mat3(col_major, 2, 3, 7);
|
||||
TensorMap<Tensor<int, 3, RowMajor> > mat4(row_major, 2, 3, 7);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user