<commit_before># Copyright (c) 2017 Sony Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import copy


def plot_series_command(args):
    import nnabla.monitor as M
    plot_any_command(args, M.plot_series)


def plot_timer_command(args):
    import nnabla.monitor as M
    format_unit = dict(
        s='seconds',
        m='minutes',
        h='hours',
        d='days',
        )

    if not args.ylabel:
        if args.elapsed:
            args.ylabel = 'Total elapsed time [{}]'.format(
                format_unit[args.time_unit])
        else:
            args.ylabel = 'Elapsed time [{}/iter]'.format(
                format_unit[args.time_unit])
    plot_any_command(args, M.plot_time_elapsed, dict(
        elapsed=args.elapsed, unit=args.time_unit))


def plot_any_command(args, plot_func, plot_func_kwargs=None):
    if plot_func_kwargs is None:
        plot_func_kwargs = {}
    if args.outfile:
        import matplotlib
        matplotlib.use('Agg')

    import matplotlib.pyplot as plt
    plt.figure()
    for i, inp in enumerate(args.inputs):
        label = args.label[i] if len(args.label) > i else inp
        plot_func(inp, plot_kwargs=dict(label=label), **plot_func_kwargs)
    plt.legend(loc='best')
    if args.title:
        plt.title(args.title)
    if args.xlabel:
        plt.xlabel(args.xlabel)
    if args.ylabel:
        plt.ylabel(args.ylabel)
    if args.xlim_min is not None:
        plt.xlim(left=args.xlim_min)
    if args.xlim_max is not None:
        plt.xlim(right=args.xlim_max)
    if args.ylim_min is not None:
        plt.ylim(bottom=args.ylim_min)<commit_msg>[python][cli] fix return value in cli plot<commit_after># Copyright (c) 2017 Sony Corporation. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import copy


def plot_series_command(args):
    import nnabla.monitor as M
    plot_any_command(args, M.plot_series)
    return True


def plot_timer_command(args):
    import nnabla.monitor as M
    format_unit = dict(
        s='seconds',
        m='minutes',
        h='hours',
        d='days',
        )

    if not args.ylabel:
        if args.elapsed:
            args.ylabel = 'Total elapsed time [{}]'.format(
                format_unit[args.time_unit])
        else:
            args.ylabel = 'Elapsed time [{}/iter]'.format(
                format_unit[args.time_unit])
    plot_any_command(args, M.plot_time_elapsed, dict(
        elapsed=args.elapsed, unit=args.time_unit))
    return True


def plot_any_command(args, plot_func, plot_func_kwargs=None):
    if plot_func_kwargs is None:
        plot_func_kwargs = {}
    if args.outfile:
        import matplotlib
        matplotlib.use('Agg')

    import matplotlib.pyplot as plt
    plt.figure()
    for i, inp in enumerate(args.inputs):
        label = args.label[i] if len(args.label) > i else inp
        plot_func(inp, plot_kwargs=dict(label=label), **plot_func_kwargs)
    plt.legend(loc='best')
    if args.title:
        plt.title(args.title)
    if args.xlabel:
        plt.xlabel(args.xlabel)
    if args.ylabel:
        plt.ylabel(args.ylabel)
    if args.xlim_min is not None:
        plt.xlim(left=args.xlim_min)
    if args.xlim_max is not None:
        plt.xlim(right=args.xlim_max)
    if args.ylim_min is not None:
        plt.ylim(bottom=args.ylim_min)
{'fraction_non_alphanumeric': 0.0977634309430482, 'fraction_numerical': 0.0036891860733225734, 'mean_word_length': 2.8086040386303774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4114908', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1349, 'n_words': 395}