# Copyright 2019 The TensorFlow Authors. 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.
# ==============================================================================
"""Unit tests for `tensorboard.backend.event_processing.data_provider`."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

import six
from six.moves import xrange  # pylint: disable=redefined-builtin
import numpy as np

from tensorboard import context
from tensorboard.backend.event_processing import data_provider
from tensorboard.backend.event_processing import (
    plugin_event_multiplexer as event_multiplexer,
)
from tensorboard.compat.proto import summary_pb2
from tensorboard.data import provider as base_provider
from tensorboard.plugins.graph import metadata as graph_metadata
from tensorboard.plugins.histogram import metadata as histogram_metadata
from tensorboard.plugins.histogram import summary_v2 as histogram_summary
from tensorboard.plugins.scalar import metadata as scalar_metadata
from tensorboard.plugins.scalar import summary_v2 as scalar_summary
from tensorboard.plugins.image import metadata as image_metadata
from tensorboard.plugins.image import summary_v2 as image_summary
from tensorboard.util import tensor_util
import tensorflow.compat.v1 as tf1
import tensorflow.compat.v2 as tf


tf1.enable_eager_execution()


class MultiplexerDataProviderTest(tf.test.TestCase):
    def setUp(self):
        super(MultiplexerDataProviderTest, self).setUp()
        self.logdir = self.get_temp_dir()
        self.ctx = context.RequestContext()

        logdir = os.path.join(self.logdir, "polynomials")
        with tf.summary.create_file_writer(logdir).as_default():
            for i in xrange(10):
                scalar_summary.scalar(
                    "square", i ** 2, step=2 * i, description="boxen"
                )
                scalar_summary.scalar("cube", i ** 3, step=3 * i)

        logdir = os.path.join(self.logdir, "waves")
        with tf.summary.create_file_writer(logdir).as_default():
            for i in xrange(10):
                scalar_summary.scalar("sine", tf.sin(float(i)), step=i)
                scalar_summary.scalar(
                    "square", tf.sign(tf.sin(float(i))), step=i
                )
                # Summary with rank-0 data but not owned by the scalars plugin.
                metadata = summary_pb2.SummaryMetadata()
                metadata.plugin_data.plugin_name = "marigraphs"
                metadata.data_class = summary_pb2.DATA_CLASS_SCALAR
                tf.summary.write(
                    "high_tide", tensor=i, step=i, metadata=metadata
                )
                # Summary with rank-1 data of scalar data class (bad!).
                metadata = summary_pb2.SummaryMetadata()
                metadata.plugin_data.plugin_name = "greetings"
                metadata.data_class = summary_pb2.DATA_CLASS_SCALAR
                tf.summary.write(
                    "bad", tensor=[i, i], step=i, metadata=metadata
                )

        logdir = os.path.join(self.logdir, "lebesgue")
        with tf.summary.create_file_writer(logdir).as_default():
            data = [
                ("very smooth", (0.0, 0.25, 0.5, 0.75, 1.0), "uniform"),
                ("very smoothn't", (0.0, 0.01, 0.99, 1.0), "bimodal"),
            ]
            for (description, distribution, name) in data:
                tensor = tf.constant([distribution], dtype=tf.float64)
                for i in xrange(1, 11):
                    histogram_summary.histogram(
                        name, tensor * i, step=i, description=description
                    )

        logdir = os.path.join(self.logdir, "mondrian")
        with tf.summary.create_file_writer(logdir).as_default():
            data = [
                ("red", (221, 28, 38), "top-right"),
                ("blue", (1, 91, 158), "bottom-left"),
                ("yellow", (239, 220, 111), "bottom-right"),
            ]
            for (name, color, description) in data:
                image_1x1 = tf.constant([[[color]]], dtype=tf.uint8)
                for i in xrange(1, 11):
                    # Use a non-monotonic sequence of sample sizes to
                    # test `max_length` calculation.
                    k = 6 - abs(6 - i)  # 1, .., 6, .., 2
                    # a `k`-sample image summary of `i`-by-`i` images
                    image = tf.tile(image_1x1, [k, i, i, 1])
                    image_summary.image(
                        name,
                        image,
                        step=i,
                        description=description,
                        max_outputs=99,
                    )

    def create_multiplexer(self):
        multiplexer = event_multiplexer.EventMultiplexer()
        multiplexer.AddRunsFromDirectory(self.logdir)
        multiplexer.Reload()
        return multiplexer

    def create_provider(self):
        multiplexer = self.create_multiplexer()
        return data_provider.MultiplexerDataProvider(multiplexer, self.logdir)

    def test_data_location(self):
        provider = self.create_provider()
        result = provider.data_location(self.ctx, experiment_id="unused")
        self.assertEqual(result, self.logdir)

    def test_list_plugins_with_no_graph(self):
        provider = self.create_provider()
        result = provider.list_plugins(self.ctx, experiment_id="unused")
        self.assertItemsEqual(
            result,
            [
                "greetings",
                "marigraphs",
                histogram_metadata.PLUGIN_NAME,
                image_metadata.PLUGIN_NAME,
                scalar_metadata.PLUGIN_NAME,
            ],
        )

    def test_list_plugins_with_graph(self):
        with tf.compat.v1.Graph().as_default() as graph:
            writer = tf.compat.v1.summary.FileWriter(self.logdir)
            writer.add_graph(graph)
            writer.flush()

        provider = self.create_provider()
        result = provider.list_plugins(self.ctx, experiment_id="unused")
        self.assertItemsEqual(
            result,
            [
                "greetings",
                "marigraphs",
                graph_metadata.PLUGIN_NAME,
                histogram_metadata.PLUGIN_NAME,
                image_metadata.PLUGIN_NAME,
                scalar_metadata.PLUGIN_NAME,
            ],
        )

    def test_list_runs(self):
        # We can't control the timestamps of events written to disk (without
        # manually reading the tfrecords, modifying the data, and writing
        # them back out), so we provide a fake multiplexer instead.
        start_times = {
            "second_2": 2.0,
            "first": 1.5,
            "no_time": None,
            "second_1": 2.0,
        }

        class FakeMultiplexer(object):
            def Runs(multiplexer):
                result = ["second_2", "first", "no_time", "second_1"]
                self.assertItemsEqual(result, start_times)
                return result

            def FirstEventTimestamp(multiplexer, run):
                self.assertIn(run, start_times)
                result = start_times[run]
                if result is None:
                    raise ValueError("No event timestep could be found")
                else:
                    return result

        multiplexer = FakeMultiplexer()
        provider = data_provider.MultiplexerDataProvider(
            multiplexer, "fake_logdir"
        )
        result = provider.list_runs(self.ctx, experiment_id="unused")
        self.assertItemsEqual(
            result,
            [
                base_provider.Run(
                    run_id=run, run_name=run, start_time=start_time
                )
                for (run, start_time) in six.iteritems(start_times)
            ],
        )

    def test_list_scalars_all(self):
        provider = self.create_provider()
        result = provider.list_scalars(
            self.ctx,
            experiment_id="unused",
            plugin_name=scalar_metadata.PLUGIN_NAME,
            run_tag_filter=None,
        )
        self.assertItemsEqual(result.keys(), ["polynomials", "waves"])
        self.assertItemsEqual(result["polynomials"].keys(), ["square", "cube"])
        self.assertItemsEqual(result["waves"].keys(), ["square", "sine"])
        sample = result["polynomials"]["square"]
        self.assertIsInstance(sample, base_provider.ScalarTimeSeries)
        self.assertEqual(sample.max_step, 18)
        # nothing to test for wall time, as it can't be mocked out
        self.assertEqual(sample.plugin_content, b"")
        self.assertEqual(
            sample.display_name, ""
        )  # not written by V2 summary ops
        self.assertEqual(sample.description, "boxen")

    def test_list_scalars_filters(self):
        provider = self.create_provider()

        result = provider.list_scalars(
            self.ctx,
            experiment_id="unused",
            plugin_name=scalar_metadata.PLUGIN_NAME,
            run_tag_filter=base_provider.RunTagFilter(["waves"], ["square"]),
        )
        self.assertItemsEqual(result.keys(), ["waves"])
        self.assertItemsEqual(result["waves"].keys(), ["square"])

        result = provider.list_scalars(
            self.ctx,
            experiment_id="unused",
            plugin_name=scalar_metadata.PLUGIN_NAME,
            run_tag_filter=base_provider.RunTagFilter(
                tags=["square", "quartic"]
            ),
        )
        self.assertItemsEqual(result.keys(), ["polynomials", "waves"])
        self.assertItemsEqual(result["polynomials"].keys(), ["square"])
        self.assertItemsEqual(result["waves"].keys(), ["square"])

        result = provider.list_scalars(
            self.ctx,
            experiment_id="unused",
            plugin_name=scalar_metadata.PLUGIN_NAME,
            run_tag_filter=base_provider.RunTagFilter(runs=["waves", "hugs"]),
        )
        self.assertItemsEqual(result.keys(), ["waves"])
        self.assertItemsEqual(result["waves"].keys(), ["sine", "square"])

        result = provider.list_scalars(
            self.ctx,
            experiment_id="unused",
            plugin_name=scalar_metadata.PLUGIN_NAME,
            run_tag_filter=base_provider.RunTagFilter(["un"], ["likely"]),
        )
        self.assertEqual(result, {})

    def test_read_scalars(self):
        multiplexer = self.create_multiplexer()
        provider = data_provider.MultiplexerDataProvider(
            multiplexer, self.logdir
        )

        run_tag_filter = base_provider.RunTagFilter(
            runs=["waves", "polynomials", "unicorns"],
            tags=["sine", "square", "cube", "iridescence"],
        )
        result = provider.read_scalars(
            self.ctx,
            experiment_id="unused",
            plugin_name=scalar_metadata.PLUGIN_NAME,
            run_tag_filter=run_tag_filter,
            downsample=100,
        )

        self.assertItemsEqual(result.keys(), ["polynomials", "waves"])
        self.assertItemsEqual(result["polynomials"].keys(), ["square", "cube"])
        self.assertItemsEqual(result["waves"].keys(), ["square", "sine"])
        for run in result:
            for tag in result[run]:
                tensor_events = multiplexer.Tensors(run, tag)
                self.assertLen(result[run][tag], len(tensor_events))
                for (datum, event) in zip(result[run][tag], tensor_events):
                    self.assertEqual(datum.step, event.step)
                    self.assertEqual(datum.wall_time, event.wall_time)
                    self.assertEqual(
                        datum.value,
                        tensor_util.make_ndarray(event.tensor_proto).item(),
                    )

    def test_read_scalars_downsamples(self):
        # TODO(@wchargin): Verify that this always includes the most
        # recent datum, as specified by the interface.
        multiplexer = self.create_multiplexer()
        provider = data_provider.MultiplexerDataProvider(
            multiplexer, self.logdir
        )
        result = provider.read_scalars(
            self.ctx,
            experiment_id="unused",
            plugin_name=scalar_metadata.PLUGIN_NAME,
            downsample=3,
        )
        self.assertLen(result["waves"]["sine"], 3)

    def test_read_scalars_but_not_rank_0(self):
        provider = self.create_provider()
        run_tag_filter = base_provider.RunTagFilter(["waves"], ["bad"])
        # No explicit checks yet.
        with six.assertRaisesRegex(
            self,
            ValueError,
            "can only convert an array of size 1 to a Python scalar",
        ):
            provider.read_scalars(
                self.ctx,
                experiment_id="unused",
                plugin_name="greetings",
                run_tag_filter=run_tag_filter,
                downsample=100,
            )

    def test_list_tensors_all(self):
        provider = self.create_provider()
        result = provider.list_tensors(
            self.ctx,
            experiment_id="unused",
            plugin_name=histogram_metadata.PLUGIN_NAME,
            run_tag_filter=None,
        )
        self.assertItemsEqual(result.keys(), ["lebesgue"])
        self.assertItemsEqual(result["lebesgue"].keys(), ["uniform", "bimodal"])
        sample = result["lebesgue"]["uniform"]
        self.assertIsInstance(sample, base_provider.TensorTimeSeries)
        self.assertEqual(sample.max_step, 10)
        # nothing to test for wall time, as it can't be mocked out
        self.assertEqual(sample.plugin_content, b"")
        self.assertEqual(
            sample.display_name, ""
        )  # not written by V2 summary ops
        self.assertEqual(sample.description, "very smooth")

    def test_list_tensors_filters(self):
        provider = self.create_provider()

        # Quick check only, as scalars and tensors use the same underlying
        # filtering implementation.
        result = provider.list_tensors(
            self.ctx,
            experiment_id="unused",
            plugin_name=histogram_metadata.PLUGIN_NAME,
            run_tag_filter=base_provider.RunTagFilter(
                ["lebesgue"], ["uniform"]
            ),
        )
        self.assertItemsEqual(result.keys(), ["lebesgue"])
        self.assertItemsEqual(result["lebesgue"].keys(), ["uniform"])

    def test_read_tensors(self):
        multiplexer = self.create_multiplexer()
        provider = data_provider.MultiplexerDataProvider(
            multiplexer, self.logdir
        )

        run_tag_filter = base_provider.RunTagFilter(
            runs=["lebesgue"],
            tags=["uniform", "bimodal"],
        )
        result = provider.read_tensors(
            self.ctx,
            experiment_id="unused",
            plugin_name=histogram_metadata.PLUGIN_NAME,
            run_tag_filter=run_tag_filter,
            downsample=100,
        )

        self.assertItemsEqual(result.keys(), ["lebesgue"])
        self.assertItemsEqual(result["lebesgue"].keys(), ["uniform", "bimodal"])
        for run in result:
            for tag in result[run]:
                tensor_events = multiplexer.Tensors(run, tag)
                self.assertLen(result[run][tag], len(tensor_events))
                for (datum, event) in zip(result[run][tag], tensor_events):
                    self.assertEqual(datum.step, event.step)
                    self.assertEqual(datum.wall_time, event.wall_time)
                    np.testing.assert_equal(
                        datum.numpy,
                        tensor_util.make_ndarray(event.tensor_proto),
                    )

    def test_read_tensors_downsamples(self):
        multiplexer = self.create_multiplexer()
        provider = data_provider.MultiplexerDataProvider(
            multiplexer, self.logdir
        )
        result = provider.read_tensors(
            self.ctx,
            experiment_id="unused",
            plugin_name=histogram_metadata.PLUGIN_NAME,
            downsample=3,
        )
        self.assertLen(result["lebesgue"]["uniform"], 3)

    def test_list_blob_sequences(self):
        provider = self.create_provider()

        with self.subTest("finds all time series for a plugin"):
            result = provider.list_blob_sequences(
                self.ctx,
                experiment_id="unused",
                plugin_name=image_metadata.PLUGIN_NAME,
            )
            self.assertItemsEqual(result.keys(), ["mondrian"])
            self.assertItemsEqual(
                result["mondrian"].keys(), ["red", "blue", "yellow"]
            )
            sample = result["mondrian"]["blue"]
            self.assertIsInstance(sample, base_provider.BlobSequenceTimeSeries)
            self.assertEqual(sample.max_step, 10)
            # nothing to test for wall time, as it can't be mocked out
            self.assertEqual(sample.plugin_content, b"")
            self.assertEqual(sample.max_length, 6 + 2)
            self.assertEqual(sample.description, "bottom-left")
            self.assertEqual(sample.display_name, "")

        with self.subTest("filters by run/tag"):
            result = provider.list_blob_sequences(
                self.ctx,
                experiment_id="unused",
                plugin_name=image_metadata.PLUGIN_NAME,
                run_tag_filter=base_provider.RunTagFilter(
                    runs=["mondrian", "picasso"], tags=["yellow", "green't"]
                ),
            )
            self.assertItemsEqual(result.keys(), ["mondrian"])
            self.assertItemsEqual(result["mondrian"].keys(), ["yellow"])
            self.assertIsInstance(
                result["mondrian"]["yellow"],
                base_provider.BlobSequenceTimeSeries,
            )

    def test_read_blob_sequences_and_read_blob(self):
        provider = self.create_provider()

        with self.subTest("reads all time series for a plugin"):
            result = provider.read_blob_sequences(
                self.ctx,
                experiment_id="unused",
                plugin_name=image_metadata.PLUGIN_NAME,
                downsample=4,
            )
            self.assertItemsEqual(result.keys(), ["mondrian"])
            self.assertItemsEqual(
                result["mondrian"].keys(), ["red", "blue", "yellow"]
            )
            sample = result["mondrian"]["blue"]
            self.assertLen(sample, 4)  # downsampled from 10
            last = sample[-1]
            self.assertIsInstance(last, base_provider.BlobSequenceDatum)
            self.assertEqual(last.step, 10)
            self.assertLen(last.values, 2 + 2)
            blobs = [
                provider.read_blob(self.ctx, blob_key=v.blob_key)
                for v in last.values
            ]
            self.assertEqual(blobs[0], b"10")
            self.assertEqual(blobs[1], b"10")
            self.assertStartsWith(blobs[2], b"\x89PNG")
            self.assertStartsWith(blobs[3], b"\x89PNG")

            blue1 = blobs[2]
            blue2 = blobs[3]
            red1 = provider.read_blob(
                self.ctx,
                blob_key=result["mondrian"]["red"][-1].values[2].blob_key,
            )
            self.assertEqual(blue1, blue2)
            self.assertNotEqual(blue1, red1)

        with self.subTest("filters by run/tag"):
            result = provider.read_blob_sequences(
                self.ctx,
                experiment_id="unused",
                plugin_name=image_metadata.PLUGIN_NAME,
                run_tag_filter=base_provider.RunTagFilter(
                    runs=["mondrian", "picasso"], tags=["yellow", "green't"]
                ),
                downsample=1,
            )
            self.assertItemsEqual(result.keys(), ["mondrian"])
            self.assertItemsEqual(result["mondrian"].keys(), ["yellow"])
            self.assertIsInstance(
                result["mondrian"]["yellow"][0],
                base_provider.BlobSequenceDatum,
            )


class DownsampleTest(tf.test.TestCase):
    """Tests for the `_downsample` private helper function."""

    def test_deterministic(self):
        xs = "abcdefg"
        expected = data_provider._downsample(xs, k=4)
        for _ in range(100):
            actual = data_provider._downsample(xs, k=4)
            self.assertEqual(actual, expected)

    def test_underlong_ok(self):
        xs = list("abcdefg")
        actual = data_provider._downsample(xs, k=10)
        expected = list("abcdefg")
        self.assertIsNot(actual, xs)
        self.assertEqual(actual, expected)

    def test_inorder(self):
        xs = list(range(10000))
        actual = data_provider._downsample(xs, k=100)
        self.assertEqual(actual, sorted(actual))

    def test_zero(self):
        xs = "abcdefg"
        actual = data_provider._downsample(xs, k=0)
        self.assertEqual(actual, [])


if __name__ == "__main__":
    tf.test.main()

[((1874, 1902), 'tensorflow.compat.v1.enable_eager_execution', 'tf1.enable_eager_execution', ([], {}), '()\n', (1900, 1902), True, 'import tensorflow.compat.v1 as tf1\n'), ((21426, 21440), 'tensorflow.compat.v2.test.main', 'tf.test.main', ([], {}), '()\n', (21438, 21440), True, 'import tensorflow.compat.v2 as tf\n'), ((2097, 2121), 'tensorboard.context.RequestContext', 'context.RequestContext', ([], {}), '()\n', (2119, 2121), False, 'from tensorboard import context\n'), ((2140, 2180), 'os.path.join', 'os.path.join', (['self.logdir', '"""polynomials"""'], {}), "(self.logdir, 'polynomials')\n", (2152, 2180), False, 'import os\n'), ((2490, 2524), 'os.path.join', 'os.path.join', (['self.logdir', '"""waves"""'], {}), "(self.logdir, 'waves')\n", (2502, 2524), False, 'import os\n'), ((3604, 3641), 'os.path.join', 'os.path.join', (['self.logdir', '"""lebesgue"""'], {}), "(self.logdir, 'lebesgue')\n", (3616, 3641), False, 'import os\n'), ((4219, 4256), 'os.path.join', 'os.path.join', (['self.logdir', '"""mondrian"""'], {}), "(self.logdir, 'mondrian')\n", (4231, 4256), False, 'import os\n'), ((5301, 5337), 'tensorboard.backend.event_processing.plugin_event_multiplexer.EventMultiplexer', 'event_multiplexer.EventMultiplexer', ([], {}), '()\n', (5335, 5337), True, 'from tensorboard.backend.event_processing import plugin_event_multiplexer as event_multiplexer\n'), ((5543, 5606), 'tensorboard.backend.event_processing.data_provider.MultiplexerDataProvider', 'data_provider.MultiplexerDataProvider', (['multiplexer', 'self.logdir'], {}), '(multiplexer, self.logdir)\n', (5580, 5606), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((7931, 7996), 'tensorboard.backend.event_processing.data_provider.MultiplexerDataProvider', 'data_provider.MultiplexerDataProvider', (['multiplexer', '"""fake_logdir"""'], {}), "(multiplexer, 'fake_logdir')\n", (7968, 7996), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((10987, 11050), 'tensorboard.backend.event_processing.data_provider.MultiplexerDataProvider', 'data_provider.MultiplexerDataProvider', (['multiplexer', 'self.logdir'], {}), '(multiplexer, self.logdir)\n', (11024, 11050), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((11099, 11221), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', ([], {'runs': "['waves', 'polynomials', 'unicorns']", 'tags': "['sine', 'square', 'cube', 'iridescence']"}), "(runs=['waves', 'polynomials', 'unicorns'], tags=\n    ['sine', 'square', 'cube', 'iridescence'])\n", (11125, 11221), True, 'from tensorboard.data import provider as base_provider\n'), ((12523, 12586), 'tensorboard.backend.event_processing.data_provider.MultiplexerDataProvider', 'data_provider.MultiplexerDataProvider', (['multiplexer', 'self.logdir'], {}), '(multiplexer, self.logdir)\n', (12560, 12586), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((12963, 13009), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', (["['waves']", "['bad']"], {}), "(['waves'], ['bad'])\n", (12989, 13009), True, 'from tensorboard.data import provider as base_provider\n'), ((15005, 15068), 'tensorboard.backend.event_processing.data_provider.MultiplexerDataProvider', 'data_provider.MultiplexerDataProvider', (['multiplexer', 'self.logdir'], {}), '(multiplexer, self.logdir)\n', (15042, 15068), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((15117, 15191), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', ([], {'runs': "['lebesgue']", 'tags': "['uniform', 'bimodal']"}), "(runs=['lebesgue'], tags=['uniform', 'bimodal'])\n", (15143, 15191), True, 'from tensorboard.data import provider as base_provider\n'), ((16292, 16355), 'tensorboard.backend.event_processing.data_provider.MultiplexerDataProvider', 'data_provider.MultiplexerDataProvider', (['multiplexer', 'self.logdir'], {}), '(multiplexer, self.logdir)\n', (16329, 16355), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((20693, 20727), 'tensorboard.backend.event_processing.data_provider._downsample', 'data_provider._downsample', (['xs'], {'k': '(4)'}), '(xs, k=4)\n', (20718, 20727), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((20940, 20975), 'tensorboard.backend.event_processing.data_provider._downsample', 'data_provider._downsample', (['xs'], {'k': '(10)'}), '(xs, k=10)\n', (20965, 20975), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((21169, 21205), 'tensorboard.backend.event_processing.data_provider._downsample', 'data_provider._downsample', (['xs'], {'k': '(100)'}), '(xs, k=100)\n', (21194, 21205), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((21321, 21355), 'tensorboard.backend.event_processing.data_provider._downsample', 'data_provider._downsample', (['xs'], {'k': '(0)'}), '(xs, k=0)\n', (21346, 21355), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((2267, 2277), 'six.moves.xrange', 'xrange', (['(10)'], {}), '(10)\n', (2273, 2277), False, 'from six.moves import xrange\n'), ((2611, 2621), 'six.moves.xrange', 'xrange', (['(10)'], {}), '(10)\n', (2617, 2621), False, 'from six.moves import xrange\n'), ((6376, 6420), 'tensorflow.compat.v2.compat.v1.summary.FileWriter', 'tf.compat.v1.summary.FileWriter', (['self.logdir'], {}), '(self.logdir)\n', (6407, 6420), True, 'import tensorflow.compat.v2 as tf\n'), ((13057, 13158), 'six.assertRaisesRegex', 'six.assertRaisesRegex', (['self', 'ValueError', '"""can only convert an array of size 1 to a Python scalar"""'], {}), "(self, ValueError,\n    'can only convert an array of size 1 to a Python scalar')\n", (13078, 13158), False, 'import six\n'), ((20778, 20812), 'tensorboard.backend.event_processing.data_provider._downsample', 'data_provider._downsample', (['xs'], {'k': '(4)'}), '(xs, k=4)\n', (20803, 20812), False, 'from tensorboard.backend.event_processing import data_provider\n'), ((2295, 2367), 'tensorboard.plugins.scalar.summary_v2.scalar', 'scalar_summary.scalar', (['"""square"""', '(i ** 2)'], {'step': '(2 * i)', 'description': '"""boxen"""'}), "('square', i ** 2, step=2 * i, description='boxen')\n", (2316, 2367), True, 'from tensorboard.plugins.scalar import summary_v2 as scalar_summary\n'), ((2422, 2471), 'tensorboard.plugins.scalar.summary_v2.scalar', 'scalar_summary.scalar', (['"""cube"""', '(i ** 3)'], {'step': '(3 * i)'}), "('cube', i ** 3, step=3 * i)\n", (2443, 2471), True, 'from tensorboard.plugins.scalar import summary_v2 as scalar_summary\n'), ((2923, 2952), 'tensorboard.compat.proto.summary_pb2.SummaryMetadata', 'summary_pb2.SummaryMetadata', ([], {}), '()\n', (2950, 2952), False, 'from tensorboard.compat.proto import summary_pb2\n'), ((3101, 3167), 'tensorflow.compat.v2.summary.write', 'tf.summary.write', (['"""high_tide"""'], {'tensor': 'i', 'step': 'i', 'metadata': 'metadata'}), "('high_tide', tensor=i, step=i, metadata=metadata)\n", (3117, 3167), True, 'import tensorflow.compat.v2 as tf\n'), ((3305, 3334), 'tensorboard.compat.proto.summary_pb2.SummaryMetadata', 'summary_pb2.SummaryMetadata', ([], {}), '()\n', (3332, 3334), False, 'from tensorboard.compat.proto import summary_pb2\n'), ((3482, 3547), 'tensorflow.compat.v2.summary.write', 'tf.summary.write', (['"""bad"""'], {'tensor': '[i, i]', 'step': 'i', 'metadata': 'metadata'}), "('bad', tensor=[i, i], step=i, metadata=metadata)\n", (3498, 3547), True, 'import tensorflow.compat.v2 as tf\n'), ((3970, 4015), 'tensorflow.compat.v2.constant', 'tf.constant', (['[distribution]'], {'dtype': 'tf.float64'}), '([distribution], dtype=tf.float64)\n', (3981, 4015), True, 'import tensorflow.compat.v2 as tf\n'), ((4041, 4054), 'six.moves.xrange', 'xrange', (['(1)', '(11)'], {}), '(1, 11)\n', (4047, 4054), False, 'from six.moves import xrange\n'), ((4606, 4646), 'tensorflow.compat.v2.constant', 'tf.constant', (['[[[color]]]'], {'dtype': 'tf.uint8'}), '([[[color]]], dtype=tf.uint8)\n', (4617, 4646), True, 'import tensorflow.compat.v2 as tf\n'), ((4672, 4685), 'six.moves.xrange', 'xrange', (['(1)', '(11)'], {}), '(1, 11)\n', (4678, 4685), False, 'from six.moves import xrange\n'), ((8170, 8236), 'tensorboard.data.provider.Run', 'base_provider.Run', ([], {'run_id': 'run', 'run_name': 'run', 'start_time': 'start_time'}), '(run_id=run, run_name=run, start_time=start_time)\n', (8187, 8236), True, 'from tensorboard.data import provider as base_provider\n'), ((9574, 9623), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', (["['waves']", "['square']"], {}), "(['waves'], ['square'])\n", (9600, 9623), True, 'from tensorboard.data import provider as base_provider\n'), ((9936, 9990), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', ([], {'tags': "['square', 'quartic']"}), "(tags=['square', 'quartic'])\n", (9962, 9990), True, 'from tensorboard.data import provider as base_provider\n'), ((10420, 10470), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', ([], {'runs': "['waves', 'hugs']"}), "(runs=['waves', 'hugs'])\n", (10446, 10470), True, 'from tensorboard.data import provider as base_provider\n'), ((10791, 10837), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', (["['un']", "['likely']"], {}), "(['un'], ['likely'])\n", (10817, 10837), True, 'from tensorboard.data import provider as base_provider\n'), ((14680, 14733), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', (["['lebesgue']", "['uniform']"], {}), "(['lebesgue'], ['uniform'])\n", (14706, 14733), True, 'from tensorboard.data import provider as base_provider\n'), ((2194, 2231), 'tensorflow.compat.v2.summary.create_file_writer', 'tf.summary.create_file_writer', (['logdir'], {}), '(logdir)\n', (2223, 2231), True, 'import tensorflow.compat.v2 as tf\n'), ((2538, 2575), 'tensorflow.compat.v2.summary.create_file_writer', 'tf.summary.create_file_writer', (['logdir'], {}), '(logdir)\n', (2567, 2575), True, 'import tensorflow.compat.v2 as tf\n'), ((3655, 3692), 'tensorflow.compat.v2.summary.create_file_writer', 'tf.summary.create_file_writer', (['logdir'], {}), '(logdir)\n', (3684, 3692), True, 'import tensorflow.compat.v2 as tf\n'), ((4076, 4154), 'tensorboard.plugins.histogram.summary_v2.histogram', 'histogram_summary.histogram', (['name', '(tensor * i)'], {'step': 'i', 'description': 'description'}), '(name, tensor * i, step=i, description=description)\n', (4103, 4154), True, 'from tensorboard.plugins.histogram import summary_v2 as histogram_summary\n'), ((4270, 4307), 'tensorflow.compat.v2.summary.create_file_writer', 'tf.summary.create_file_writer', (['logdir'], {}), '(logdir)\n', (4299, 4307), True, 'import tensorflow.compat.v2 as tf\n'), ((4966, 4998), 'tensorflow.compat.v2.tile', 'tf.tile', (['image_1x1', '[k, i, i, 1]'], {}), '(image_1x1, [k, i, i, 1])\n', (4973, 4998), True, 'import tensorflow.compat.v2 as tf\n'), ((5019, 5104), 'tensorboard.plugins.image.summary_v2.image', 'image_summary.image', (['name', 'image'], {'step': 'i', 'description': 'description', 'max_outputs': '(99)'}), '(name, image, step=i, description=description,\n    max_outputs=99)\n', (5038, 5104), True, 'from tensorboard.plugins.image import summary_v2 as image_summary\n'), ((6311, 6331), 'tensorflow.compat.v2.compat.v1.Graph', 'tf.compat.v1.Graph', ([], {}), '()\n', (6329, 6331), True, 'import tensorflow.compat.v2 as tf\n'), ((8316, 8342), 'six.iteritems', 'six.iteritems', (['start_times'], {}), '(start_times)\n', (8329, 8342), False, 'import six\n'), ((17875, 17963), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', ([], {'runs': "['mondrian', 'picasso']", 'tags': '[\'yellow\', "green\'t"]'}), '(runs=[\'mondrian\', \'picasso\'], tags=[\'yellow\',\n    "green\'t"])\n', (17901, 17963), True, 'from tensorboard.data import provider as base_provider\n'), ((20060, 20148), 'tensorboard.data.provider.RunTagFilter', 'base_provider.RunTagFilter', ([], {'runs': "['mondrian', 'picasso']", 'tags': '[\'yellow\', "green\'t"]'}), '(runs=[\'mondrian\', \'picasso\'], tags=[\'yellow\',\n    "green\'t"])\n', (20086, 20148), True, 'from tensorboard.data import provider as base_provider\n'), ((16111, 16155), 'tensorboard.util.tensor_util.make_ndarray', 'tensor_util.make_ndarray', (['event.tensor_proto'], {}), '(event.tensor_proto)\n', (16135, 16155), False, 'from tensorboard.util import tensor_util\n'), ((12211, 12255), 'tensorboard.util.tensor_util.make_ndarray', 'tensor_util.make_ndarray', (['event.tensor_proto'], {}), '(event.tensor_proto)\n', (12235, 12255), False, 'from tensorboard.util import tensor_util\n')]