MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / zero_first_timestep

Function zero_first_timestep

src/layers/decoder.cc:13–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11 namespace layers {
12
13 void zero_first_timestep(StorageView& x, dim_t step) {
14 if (step == 0) {
15 x.zero();
16 } else if (step < 0) {
17 // TODO: a more direct way to set the first timestep to 0.
18 const auto dtype = x.dtype();
19 const auto device = x.device();
20 StorageView first_step(dtype, device);
21 StorageView other_steps(dtype, device);
22 ops::Split(1, {1, x.dim(1) - 1})(x, first_step, other_steps);
23 first_step.zero();
24 ops::Concat(1)({&first_step, &other_steps}, x);
25 }
26 }
27
28
29 Decoder::Decoder(Device device)

Callers 1

decodeMethod · 0.85

Calls 5

SplitClass · 0.85
ConcatClass · 0.85
dimMethod · 0.80
dtypeMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected