'Updates the masks for sparse training.
Parameters
index : int
The index for weight.
weight : NDArray
The weight matrix.
Returns
boolean
If the masks were changed'

def update_masks(self, index, weight):

    if (index not in self._index_update_count):
        num_update = self.begin_num_update
    else:
        num_update = self._index_update_count[index]
    num_update += 1
    num_update = max(num_update, self.num_update)
    epoch = (int(((num_update - 1) / self.batches_per_epoch)) + 1)
    if (index == 0):
        self.masks_updated = True
    if (self.epoch != epoch):
        self.epoch = epoch
        if (epoch == 1):
            self.masks_updated = False
            if (self.weight_sparsity is not None):
                logging.info((log + 'bias-sparsity={},    weight-sparsity={}'.format(self.bias_sparsity[0], self.weight_sparsity[0])))
            else:
                logging.info((log + 'bias-threshold={},    weight-threshold={}'.format(self.bias_threshold[0], self.weight_threshold[0])))
        if ((self.pruning_switch_epoch[0] + 1) == epoch):
            self.masks_updated = False
            self.pruning_switch_epoch.pop(0)
            if (self.weight_sparsity is not None):
                self.weight_sparsity.pop(0)
                self.bias_sparsity.pop(0)
                logging.info((log + 'bias-sparsity={},    weight-sparsity={}'.format(self.bias_sparsity[0], self.weight_sparsity[0])))
            else:
                self.weight_threshold.pop(0)
                self.bias_threshold.pop(0)
                logging.info((log + 'bias-threshold={},    weight-threshold={}'.format(self.bias_threshold[0], self.weight_threshold[0])))
    if (not self.masks_updated):
        if (epoch == 1):
            self.masks.append(None)
        if (self.weight_sparsity is not None):
            if (len(weight.shape) == 1):
                sparsity = self.bias_sparsity[0]
            else:
                sparsity = self.weight_sparsity[0]
            number_unpruned = int((((100.0 - sparsity) * weight.size) / 100.0))
            self.masks[index] = topk(NDabs(weight), axis=None, ret_typ='mask', k=number_unpruned)
        else:
            if (len(weight.shape) == 1):
                threshold = self.bias_threshold[0]
            else:
                threshold = self.weight_threshold[0]
            self.masks[index] = (NDabs(weight) >= threshold)
    return (not self.masks_updated)
