Skip to content

Commit e05e5ed

Browse files
conqerAtapplecaisq
authored andcommitted
Use vector constructor to initialize Array3D. (tensorflow#8144)
* Use vector constructor to initialize Array3D. Current constructor of Array3D calls resize to initialize the inner vector of Array3D and follows up with a Fill call. This can be replaced with a simple call to vector constructor. Vector constructor might also be more efficient. * Change Array4D ctor implementation. Using vector ctor.
1 parent 53e3c4f commit e05e5ed

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

tensorflow/compiler/xla/array3d.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@ class Array3D {
3939
public:
4040
// Creates an array of dimensions n1 x n2 x n3, uninitialized values.
4141
Array3D(const int64 n1, const int64 n2, const int64 n3)
42-
: n1_(n1), n2_(n2), n3_(n3) {
43-
values_.resize(n1 * n2 * n3);
44-
}
42+
: n1_(n1), n2_(n2), n3_(n3), values_(n1 * n2 * n3) {}
4543

4644
// Creates an array of dimensions n1 x n2 x n3, initialized to value.
4745
Array3D(const int64 n1, const int64 n2, const int64 n3, const T value)
48-
: Array3D(n1, n2, n3) {
49-
Fill(value);
50-
}
46+
: n1_(n1), n2_(n2), n3_(n3), values_(n1 * n2 * n3, value) {}
5147

5248
// Creates an array from the given nested initializer list. The outer
5349
// initializer list is the first dimension, and so on.

tensorflow/compiler/xla/array4d.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,19 @@ class Array4D {
5656
public:
5757
// Creates a 4D array, unitialized values.
5858
Array4D(int64 planes, int64 depth, int64 height, int64 width)
59-
: planes_(planes), depth_(depth), height_(height), width_(width) {
60-
values_.resize(planes * depth * height * width);
61-
}
59+
: planes_(planes),
60+
depth_(depth),
61+
height_(height),
62+
width_(width),
63+
values_(planes * depth * height * width) {}
6264

6365
// Creates a 4D array, initalized to value.
6466
Array4D(int64 planes, int64 depth, int64 height, int64 width, T value)
65-
: Array4D(planes, depth, height, width) {
66-
Fill(value);
67-
}
67+
: planes_(planes),
68+
depth_(depth),
69+
height_(height),
70+
width_(width),
71+
values_(planes * depth * height * width, value) {}
6872

6973
// Creates a 4D array, filled with values.
7074
//

0 commit comments

Comments
 (0)