def update(self, labels, preds, masks=None):<EOL>
labels, preds = check_label_shapes(labels, preds, True)<EOL>masks = [None] * len(labels) if masks is None else masks<EOL>for label, pred_label, mask in zip(labels, preds, masks):<EOL><INDENT>if pred_label.shape != label.shape:<EOL><INDENT>pred_label = ndarray.topk(pred_label.astype('<STR_LIT>', copy=False),<EOL>k=<NUM_LIT:1>, ret_typ='<STR_LIT>', axis=self.axis)<EOL><DEDENT>pred_label = pred_label.astype('<STR_LIT>', copy=False).reshape((-<NUM_LIT:1>,))<EOL>label = label.astype('<STR_LIT>', copy=False).reshape((-<NUM_LIT:1>,))<EOL>check_label_shapes(label, pred_label)<EOL>if mask is not None:<EOL><INDENT>mask = mask.astype('<STR_LIT>', copy=False).reshape((-<NUM_LIT:1>,))<EOL>check_label_shapes(label, mask)<EOL>num_correct = ((pred_label == label) * mask).sum().asscalar()<EOL>num_inst = mask.sum().asscalar()<EOL><DEDENT>else:<EOL><INDENT>num_correct = (pred_label == label).sum().asscalar()<EOL>num_inst = len(label)<EOL><DEDENT>self.sum_metric += num_correct<EOL>self.global_sum_metric += num_correct<EOL>self.num_inst += num_inst<EOL>self.global_num_inst += num_inst<EOL><DEDENT>
Updates the internal evaluation result.

        Parameters
        ----------
        labels : list of `NDArray`
            The labels of the data with class indices as values, one per sample.
        preds : list of `NDArray`
            Prediction values for samples. Each prediction value can either be the class index,
            or a vector of likelihoods for all classes.
        masks : list of `NDArray` or None, optional
            Masks for samples, with the same shape as `labels`. value of its element must
            be either 1 or 0. If None, all samples are considered valid.