def run(self, args):
    with fileinput.input(args.input_data) as in_:
        (header, data) = self.load_data(in_, delimiter=args.delimiter, has_header=args.header)
    if (args.input_labels is not None):
        with fileinput.input(args.input_labels) as in_:
            labels = self.load_labels(in_)
            pairs = None
    elif (args.input_pairs is not None):
        with fileinput.input(args.input_pairs) as in_:
            pairs = self.load_pairs(in_)
            labels = None
    metric = learn_metric(data, labels=labels, pairs=pairs, u=args.u_param, l=args.l_param, slack=args.slack, max_iter=args.max_iteration_number, is_sparse=args.sparse)
    if (args.output_metric is not None):
        if (args.output_metric == '-'):
            self.export_metric(sys.stdout, metric, header)
        else:
            with open(args.output_metric, 'w') as o_:
                self.export_metric(o_, metric, header)
    if (args.output_weights is not None):
        weights = numpy.diag(metric)
        if (args.output_weights == '-'):
            self.export_weights(sys.stdout, weights, header)
        else:
            with open(args.output_weights, 'w') as o_:
                self.export_weights(o_, weights, header)
    if (args.output_data is not None):
        converted_data = convert_data(metric, data)
        if (args.output_data == '-'):
            self.export_data(sys.stdout, converted_data, header)
        else:
            with open(args.output_data, 'w') as o_:
                self.export_data(o_, converted_data, header)
    return 0
def run(self, args):
    with fileinput.input(args.input_data) as in_:
        (header, data) = self.load_data(in_, delimiter=args.delimiter, has_header=args.header)
    if (args.input_labels is not None):
        with fileinput.input(args.input_labels) as in_:
            labels = self.load_labels(in_)
            pairs = None
    elif (args.input_pairs is not None):
        with fileinput.input(args.input_pairs) as in_:
            pairs = self.load_pairs(in_)
            labels = None
    metric = learn_metric(data, labels=labels, pairs=pairs, u=args.u_param, l=args.l_param, slack=args.slack, max_iter=args.max_iteration_number, is_sparse=args.sparse)
    if (args.output_metric is not None):
        if (args.output_metric == '-'):
            self.export_metric(sys.stdout, metric, header)
        else:
            with open(args.output_metric, 'w') as o_:
                self.export_metric(o_, metric, header)
    if (args.output_weights is not None):
        weights = numpy.diag(metric)
        if (args.output_weights == '-'):
            self.export_weights(sys.stdout, weights, header)
        else:
            with open(args.output_weights, 'w') as o_:
                self.export_weights(o_, weights, header)
    if (args.output_data is not None):
        converted_data = convert_data(metric, data)
        if (args.output_data == '-'):
            self.export_data(sys.stdout, converted_data, header)
        else:
            with open(args.output_data, 'w') as o_:
                self.export_data(o_, converted_data, header)
    return 0