# Path: tf_slim/metrics/metric_ops.py
# def _next_array_size(required_size, growth_factor=1.5):
#   """Calculate the next size for reallocating a dynamic array.
# 
#   Args:
#     required_size: number or tf.Tensor specifying required array capacity.
#     growth_factor: optional number or tf.Tensor specifying the growth factor
#       between subsequent allocations.
# 
#   Returns:
#     tf.Tensor with dtype=int32 giving the next array size.
#   """
#   exponent = math_ops.ceil(
#       math_ops.log(math_ops.cast(required_size, dtypes.float32)) /
#       math_ops.log(math_ops.cast(growth_factor, dtypes.float32)))
#   return math_ops.cast(math_ops.ceil(growth_factor**exponent), dtypes.int32)


import math
import numpy as np
import tensorflow.compat.v1 as tf
import tf_slim.metrics as metrics_lib
from six.moves import xrange  # pylint: disable=redefined-builtin
from tf_slim.metrics.metric_ops import _next_array_size
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes as dtypes_lib
from tensorflow.python.framework import errors_impl
from tensorflow.python.framework import ops
from tensorflow.python.framework import sparse_tensor
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import data_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops import variable_scope
from tensorflow.python.ops import variables
      self.assertAlmostEqual(1 / 2 * (9 / (9 + 3 + 5) + 7 / (7 + 5 + 3)),
                             miou.eval())


class StreamingConcatTest(tf.test.TestCase):

  def setUp(self):
    super(StreamingConcatTest, self).setUp()
    variable_scope.enable_resource_variables()

  def testVars(self):
    metrics.streaming_concat(values=array_ops.ones((10,)))
    _assert_metric_variables(self, (
        'streaming_concat/array:0',
        'streaming_concat/size:0',
    ))

  def testMetricsCollection(self):
    my_collection_name = '__metrics__'
    value, _ = metrics.streaming_concat(
        values=array_ops.ones((10,)), metrics_collections=[my_collection_name])
    self.assertListEqual(ops.get_collection(my_collection_name), [value])

  def testUpdatesCollection(self):
    my_collection_name = '__updates__'
    _, update_op = metrics.streaming_concat(
        values=array_ops.ones((10,)), updates_collections=[my_collection_name])
    self.assertListEqual(ops.get_collection(my_collection_name), [update_op])

  def testNextArraySize(self):

# Path: tf_slim/metrics/metric_ops.py
# def _next_array_size(required_size, growth_factor=1.5):
#   """Calculate the next size for reallocating a dynamic array.
# 
#   Args:
#     required_size: number or tf.Tensor specifying required array capacity.
#     growth_factor: optional number or tf.Tensor specifying the growth factor
#       between subsequent allocations.
# 
#   Returns:
#     tf.Tensor with dtype=int32 giving the next array size.
#   """
#   exponent = math_ops.ceil(
#       math_ops.log(math_ops.cast(required_size, dtypes.float32)) /
#       math_ops.log(math_ops.cast(growth_factor, dtypes.float32)))
#   return math_ops.cast(math_ops.ceil(growth_factor**exponent), dtypes.int32)


# Path: tf_slim/metrics/metric_ops_test.py
import math
import numpy as np
import tensorflow.compat.v1 as tf
import tf_slim.metrics as metrics_lib
from six.moves import xrange  # pylint: disable=redefined-builtin
from tf_slim.metrics.metric_ops import _next_array_size
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes as dtypes_lib
from tensorflow.python.framework import errors_impl
from tensorflow.python.framework import ops
from tensorflow.python.framework import sparse_tensor
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import data_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops import variable_scope
from tensorflow.python.ops import variables

      self.assertAlmostEqual(1 / 2 * (9 / (9 + 3 + 5) + 7 / (7 + 5 + 3)),
                             miou.eval())


class StreamingConcatTest(tf.test.TestCase):

  def setUp(self):
    super(StreamingConcatTest, self).setUp()
    variable_scope.enable_resource_variables()

  def testVars(self):
    metrics.streaming_concat(values=array_ops.ones((10,)))
    _assert_metric_variables(self, (
        'streaming_concat/array:0',
        'streaming_concat/size:0',
    ))

  def testMetricsCollection(self):
    my_collection_name = '__metrics__'
    value, _ = metrics.streaming_concat(
        values=array_ops.ones((10,)), metrics_collections=[my_collection_name])
    self.assertListEqual(ops.get_collection(my_collection_name), [value])

  def testUpdatesCollection(self):
    my_collection_name = '__updates__'
    _, update_op = metrics.streaming_concat(
        values=array_ops.ones((10,)), updates_collections=[my_collection_name])
    self.assertListEqual(ops.get_collection(my_collection_name), [update_op])

  def testNextArraySize(self):

    next_array_size = _next_array_size  # pylint: disable=protected-access