code: def test_flatten(self, sparse):
      if sparse and not backend.SUPPORTS_SPARSE_TENSORS:
          pytest.skip("Backend does not support sparse tensors.")
  
      inputs = np.random.random((10, 3, 5, 5)).astype("float32")
      # Make the ndarray relatively sparse
      inputs = np.multiply(inputs, inputs >= 0.8)
      expected_output_channels_last = ops.convert_to_tensor(
          np.reshape(inputs, (-1, 5 * 5 * 3))
      )
      expected_output_channels_first = ops.convert_to_tensor(
          np.reshape(
              np.transpose(inputs, (0, 2, 3, 1)), (-1, 5 * 5 * 3)
          )
      )
      if sparse:
          import tensorflow as tf
  
          inputs = tf.sparse.from_dense(inputs)
          expected_output_channels_last = tf.sparse.from_dense(
              expected_output_channels_last
          )
          expected_output_channels_first = tf.sparse.from_dense(
              expected_output_channels_first
          )
  
      # Test default data_format and channels_last
      self.run_layer_test(
          layers.Flatten,
          init_kwargs={},
          input_data=inputs,
          input_sparse=True,
          expected_output=expected_output_channels_last
          if backend.config.image_data_format() == "channels_last"
          else expected_output_channels_first,
          expected_output_sparse=sparse,
          run_training_check=not sparse,
      )
      self.run_layer_test(
          layers.Flatten,
          init_kwargs={"data_format": "channels_last"},
          input_data=inputs,
          input_sparse=True,
          expected_output=expected_output_channels_last,
          expected_output_sparse=sparse,
          run_training_check=not sparse,
      )
  
      # Test channels_first
      self.run_layer_test(
          layers.Flatten,
          init_kwargs={"data_format": "channels_first"},
          input_data=inputs,
          input_sparse=True,
          expected_output=expected_output_channels_first,
          expected_output_sparse=sparse,
          run_training_check=not sparse,
      )
  
file_path: keras/keras/layers/reshaping/flatten_test.py
imports: import numpy
  import pytest
  from absl.testing import parameterized
  from keras import backend
  from keras import layers
  from keras import ops
  from keras import testing
label_desc: Use image node_id 1 for calling the FlattenTest obj's underlying member method code with example usage: obj.test_flatten(sparse) without return types