forward computation.
341199
def hybrid_forward(self, F, data, gamma, beta):
        """"""
        # TODO(haibin): LayerNorm does not support fp16 safe reduction. Issue is tracked at:
        # https://github.com/apache/incubator-mxnet/issues/14073
        if self._dtype:
            data = data.astype('float32')
            gamma = gamma.astype('float32')
            beta = beta.astype('float32')
        norm_data = F.LayerNorm(data, gamma=gamma, beta=beta, axis=self._axis, eps=self._epsilon)
        if self._dtype:
            norm_data = norm_data.astype(self._dtype)
        return norm_data
1258519
public static int cudnnPoolingBackward(
        cudnnHandle handle, 
        cudnnPoolingDescriptor poolingDesc, 
        Pointer alpha, 
        cudnnTensorDescriptor yDesc, 
        Pointer y, 
        cudnnTensorDescriptor dyDesc, 
        Pointer dy, 
        cudnnTensorDescriptor xDesc, 
        Pointer x, 
        Pointer beta, 
        cudnnTensorDescriptor dxDesc, 
        Pointer dx)
    {
        return checkResult(cudnnPoolingBackwardNative(handle, poolingDesc, alpha, yDesc, y, dyDesc, dy, xDesc, x, beta, dxDesc, dx));
    }
675434
def forward_backward(self, parameters):
        
        # If the features are sparse, we can use an optimization.
        # I'm not using scipy.sparse here because we want to avoid a scipy dependency and also scipy.sparse doesn't seem
        # to handle arrays of shape higher than 2.
        if isinstance(self.sparse_x, str) and self.sparse_x == 'uninitialized':
            if (self.x == 0).sum() * 1.0 / self.x.size > 0.6:
                self.sparse_x = self._construct_sparse_features(self.x)
            else:
                self.sparse_x = 'not sparse'

        I, J, K = self.x.shape
        if not isinstance(self.sparse_x, str):
            C = self.sparse_x[0].shape[2]
            S, _ = parameters.shape
            x_dot_parameters = np.zeros((I, J, S))
            sparse_multiply(x_dot_parameters, self.sparse_x[0], self.sparse_x[1], parameters.T, I, J, K, C, S)
        else:
            x_dot_parameters = np.dot(self.x, parameters.T)  # Pre-compute the dot product
        alpha = self._forward(x_dot_parameters)
        beta = self._backward(x_dot_parameters)
        classes_to_ints = {k: i for i, k in enumerate(set(self.states_to_classes.values()))}
        states_to_classes = np.array([classes_to_ints[self.states_to_classes[state]]
                                      for state in range(max(self.states_to_classes.keys()) + 1)], dtype='int64')
        if not isinstance(self.sparse_x, str):
            ll, deriv = gradient_sparse(alpha, beta, parameters, states_to_classes,
                                        self.sparse_x[0], self.sparse_x[1], classes_to_ints[self.y],
                                        I, J, self.sparse_x[0].shape[2])
        else:
            ll, deriv = gradient(alpha, beta, parameters, states_to_classes,
                                 self.x, classes_to_ints[self.y], I, J, K)
        return ll, deriv
270772
def _forward_mode(self, *args):
        """"""
        # Evaluate inner function self.f
        X: np.ndarray
        dX: np.ndarray
        X, dX = self.f._forward_mode(*args)
        # The function value
        val = self.func(X)
        # The derivative
        diff = self.deriv(X) * dX
        return (val, diff)
249172
def include_after(predicate, num, iterative):
    
    (it0, it1) = itertools.tee(iterative)
    ps = _forward_shifted_predicate(predicate, num, it1)
    return (e for (e, p) in zip(it0, ps) if p)
1224138
def forward(self, X):
        
        return self.W(X).sum(dim=1) + self.b
246256
def forward(self, is_train=False):
        """"""
        for texec in self.train_execs:
            texec.forward(is_train=is_train)
655822
def forward_word(self, e): # (M-f)
        """
        self.l_buffer.forward_word(self.argument_reset)
        self.finalize()
523063
public static void Forward(double[] data) {

        double[] result = new double[data.length];
        double sum;
        double scale = Math.sqrt(2.0 / data.length);
        for (int f = 0; f < data.length; f++) {
            sum = 0;
            for (int t = 0; t < data.length; t++) {
                double cos = Math.cos(((2.0 * t + 1.0) * f * Math.PI) / (2.0 * data.length));
                sum += data[t] * cos * alpha(f);
            }
            result[f] = scale * sum;
        }
        for (int i = 0; i < data.length; i++) {
            data[i] = result[i];
        }
    }
862777
def forwards(self, orm):
        ""
        for a in orm.Article.objects.all():
            if a.updated:
                a.last_updated = a.updated
                a.save(force_update=True)
310537
def forward_backward(self, x):
        """"""
        with mx.autograd.record():
            (ls, next_sentence_label, classified, masked_id, decoded, \
             masked_weight, ls1, ls2, valid_length) = forward(x, self._model, self._mlm_loss,
                                                              self._nsp_loss, self._vocab_size,
                                                              args.dtype)
            ls = ls / self._rescale_factor
        if args.dtype == 'float16':
            self._trainer.backward(ls)
        else:
            ls.backward()
        return ls, next_sentence_label, classified, masked_id, decoded, \
               masked_weight, ls1, ls2, valid_length
772875
def hybrid_forward(self, F, x):
        """"""
        # `transpose` doesn't support 8D, need other implementation
        f1, f2, f3 = self._factors
                                                              # (N, C*f1*f2*f3, D, H, W)
        x = F.reshape(x, (0, -4, -1, f1 * f2 * f3, 0, 0, 0))  # (N, C, f1*f2*f3, D, H, W)
        x = F.swapaxes(x, 2, 3)                               # (N, C, D, f1*f2*f3, H, W)
        x = F.reshape(x, (0, 0, 0, -4, f1, f2*f3, 0, 0))      # (N, C, D, f1, f2*f3, H, W)
        x = F.reshape(x, (0, 0, -3, 0, 0, 0))                 # (N, C, D*f1, f2*f3, H, W)
        x = F.swapaxes(x, 3, 4)                               # (N, C, D*f1, H, f2*f3, W)
        x = F.reshape(x, (0, 0, 0, 0, -4, f2, f3, 0))         # (N, C, D*f1, H, f2, f3, W)
        x = F.reshape(x, (0, 0, 0, -3, 0, 0))                 # (N, C, D*f1, H*f2, f3, W)
        x = F.swapaxes(x, 4, 5)                               # (N, C, D*f1, H*f2, W, f3)
        x = F.reshape(x, (0, 0, 0, 0, -3))                    # (N, C, D*f1, H*f2, W*f3)
        return x
1189229
private void forward(TrellisNode[][] trellis, double[] scaling) {
        int n = trellis.length; // length of sequence

        TrellisNode[] t0 = trellis[0];
        for (int i = 0; i < numClasses; i++) {
            TrellisNode t0i = t0[i];
            TreePotentialFunction pi = potentials[i];
            if (numFeatures <= 0) {
                for (int k = t0i.age; k < pi.trees.size(); k++) {
                    t0i.scores[0] += pi.eta * pi.trees.get(k).predict(t0i.samples[0]);
                }
            } else {
                for (int k = t0i.age; k < pi.trees.size(); k++) {
                    t0i.scores[0] += pi.eta * pi.trees.get(k).predict(t0i.sparseSamples[0]);
                }                
            }

            t0i.expScores[0] = Math.exp(t0i.scores[0]);
            t0i.alpha = t0i.expScores[0];
            t0i.age = pi.trees.size();
        }

        // Normalize alpha values since they increase quickly
        scaling[0] = 0.0;
        for (int i = 0; i < numClasses; i++) {
            scaling[0] += t0[i].alpha;
        }
        for (int i = 0; i < numClasses; i++) {
            t0[i].alpha /= scaling[0];
        }

        for (int t = 1; t < n; t++) {
            TrellisNode[] tt = trellis[t];
            TrellisNode[] tt1 = trellis[t-1];
            for (int i = 0; i < numClasses; i++) {
                TrellisNode tti = tt[i];
                TreePotentialFunction pi = potentials[i];
                tti.alpha = 0.0;
                for (int j = 0; j < numClasses; j++) {
                    if (numFeatures <= 0) {
                        for (int k = tti.age; k < pi.trees.size(); k++) {
                            tti.scores[j] += pi.eta * pi.trees.get(k).predict(tti.samples[j]);
                        }
                    } else {
                        for (int k = tti.age; k < pi.trees.size(); k++) {
                            tti.scores[j] += pi.eta * pi.trees.get(k).predict(tti.sparseSamples[j]);
                        }
                    }

                    tti.expScores[j] = Math.exp(tti.scores[j]);
                    tti.alpha += tti.expScores[j] * tt1[j].alpha;
                }
                tti.age = pi.trees.size();
            }

            // Normalize alpha values since they increase quickly
            scaling[t] = 0.0;
            for (int i = 0; i < numClasses; i++) {
                scaling[t] += tt[i].alpha;
            }
            for (int i = 0; i < numClasses; i++) {
                tt[i].alpha /= scaling[t];
            }
        }
    }
210017
private synchronized void precomputeLogs(int len) {
    if(len <= ilogs.length) {
      return; // Probably done by another thread.
    }
    double[] logs = Arrays.copyOf(ilogs, len);
    for(int i = ilogs.length; i < len; i++) {
      logs[i] = FastMath.log1p(i);
    }
    this.ilogs = logs;
  }
1015354
def forward_backward(self, x):
        """"""
        (src_seq, tgt_seq, src_valid_length, tgt_valid_length), batch_size = x
        with mx.autograd.record():
            out, _ = self._model(src_seq, tgt_seq[:, :-1],
                                 src_valid_length, tgt_valid_length - 1)
            smoothed_label = self._label_smoothing(tgt_seq[:, 1:])
            ls = self._loss(out, smoothed_label, tgt_valid_length - 1).sum()
            ls = (ls * (tgt_seq.shape[1] - 1)) / batch_size / self._rescale_loss
        ls.backward()
        return ls
390074
def _forward_mode(self, *args):
        """"""
        # Return the bound value and a derivative of zero regardless of the argumetns passed
        val: float = self.a
        diff: float = 0.0
        return (val, diff)
555940
def hybrid_forward(self, F, x, sampled_values, label, w_all, b_all):
        """"""
        sampled_candidates, expected_count_sampled, expected_count_true = sampled_values
        # (num_sampled, in_unit)
        w_sampled = w_all.slice(begin=(0, 0), end=(self._num_sampled, None))
        w_true = w_all.slice(begin=(self._num_sampled, 0), end=(None, None))
        b_sampled = b_all.slice(begin=(0,), end=(self._num_sampled,))
        b_true = b_all.slice(begin=(self._num_sampled,), end=(None,))
        # true pred
        # (batch_size, 1)
        x = x.reshape((-1, self._in_unit))
        pred_true = (w_true * x).sum(axis=1) + b_true
        # samples pred
        # (batch_size, num_sampled)
        b_sampled = F.reshape(b_sampled, (-1,))
        pred_sampled = F.FullyConnected(x, weight=w_sampled, bias=b_sampled,
                                        num_hidden=self._num_sampled)

        # remove accidental hits
        if self._remove_accidental_hits:
            label_vec = F.reshape(label, (-1, 1))
            sample_vec = F.reshape(sampled_candidates, (1, -1))
            mask = F.broadcast_equal(label_vec, sample_vec) * -1e37
            pred_sampled = pred_sampled + mask

        # subtract log(q)
        expected_count_sampled = F.reshape(expected_count_sampled,
                                           shape=(1, self._num_sampled))
        expected_count_true = expected_count_true.reshape((-1,))
        pred_true = pred_true - F.log(expected_count_true)
        pred_true = pred_true.reshape((-1, 1))
        pred_sampled = F.broadcast_sub(pred_sampled, F.log(expected_count_sampled))

        # pred and new_labels
        # (batch_size, 1+num_sampled)
        pred = F.concat(pred_true, pred_sampled, dim=1)
        if self._sparse_label:
            new_label = F.zeros_like(label)
        else:
            label_vec = F.reshape(label, (-1, 1))
            new_label_true = F.ones_like(label_vec)
            new_label_sampled = F.zeros_like(pred_sampled)
            new_label = F.Concat(new_label_true, new_label_sampled, dim=1)
        return pred, new_label