



import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)

class       _SCREAMING_SNAKE_CASE	(unittest.TestCase ):





     def 	__snake_case    (       self :							int				)->Union[str, Any]:
      __SCREAMING_SNAKE_CASE       :    Dict       =	["a", "b", "c"]

      # Defaults to last layer if both are None
      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Optional[int]       =	get_aligned_output_features_output_indices(UpperCamelCase     ,  UpperCamelCase     ,  UpperCamelCase				)
      self.assertEqual(UpperCamelCase     ,  ["c"]				)
      self.assertEqual(UpperCamelCase     ,  [2]				)

      # Out indices set to match out features
      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	get_aligned_output_features_output_indices(["a", "c"]     ,  UpperCamelCase     ,  UpperCamelCase				)
      self.assertEqual(UpperCamelCase     ,  ["a", "c"]				)
      self.assertEqual(UpperCamelCase     ,  [0, 2]				)

      # Out features set to match out indices
      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	get_aligned_output_features_output_indices(UpperCamelCase     ,  [0, 2]     ,  UpperCamelCase				)
      self.assertEqual(UpperCamelCase     ,  ["a", "c"]				)
      self.assertEqual(UpperCamelCase     ,  [0, 2]				)

      # Out features selected from negative indices
      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    int       =	get_aligned_output_features_output_indices(UpperCamelCase     ,  [-3, -1]     ,  UpperCamelCase				)
      self.assertEqual(UpperCamelCase     ,  ["a", "c"]				)
      self.assertEqual(UpperCamelCase     ,  [-3, -1]				)





     def 	__snake_case    (       self :							List[str]				)->int:
      # Stage names must be set
      with self.assertRaises(UpperCamelCase				):
       verify_out_features_out_indices(["a", "b"]     ,  (0, 1)     ,  UpperCamelCase				)

      # Out features must be a list
      with self.assertRaises(UpperCamelCase				):
       verify_out_features_out_indices(("a", "b")     ,  (0, 1)     ,  ["a", "b"]				)

      # Out features must be a subset of stage names
      with self.assertRaises(UpperCamelCase				):
       verify_out_features_out_indices(["a", "b"]     ,  (0, 1)     ,  ["a"]				)

      # Out indices must be a list or tuple
      with self.assertRaises(UpperCamelCase				):
       verify_out_features_out_indices(UpperCamelCase     ,  0     ,  ["a", "b"]				)

      # Out indices must be a subset of stage names
      with self.assertRaises(UpperCamelCase				):
       verify_out_features_out_indices(UpperCamelCase     ,  (0, 1)     ,  ["a"]				)

      # Out features and out indices must be the same length
      with self.assertRaises(UpperCamelCase				):
       verify_out_features_out_indices(["a", "b"]     ,  (0,)     ,  ["a", "b", "c"]				)

      # Out features should match out indices
      with self.assertRaises(UpperCamelCase				):
       verify_out_features_out_indices(["a", "b"]     ,  (0, 2)     ,  ["a", "b", "c"]				)

      # Out features and out indices should be in order
      with self.assertRaises(UpperCamelCase				):
       verify_out_features_out_indices(["b", "a"]     ,  (0, 1)     ,  ["a", "b"]				)

      # Check passes with valid inputs
      verify_out_features_out_indices(["a", "b", "d"]     ,  (0, 1, -1)     ,  ["a", "b", "c", "d"]				)






     def 	__snake_case    (       self :							Optional[int]				)->Any:
      __SCREAMING_SNAKE_CASE       :    str       =	BackboneMixin()

      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	["a", "b", "c"]
      __SCREAMING_SNAKE_CASE       :    List[str]       =	["a", "c"]
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	[0, 2]

      # Check that the output features and indices are set correctly
      self.assertEqual(backbone.out_features     ,  ["a", "c"]				)
      self.assertEqual(backbone.out_indices     ,  [0, 2]				)

      # Check out features and indices are updated correctly
      __SCREAMING_SNAKE_CASE       :    int       =	["a", "b"]
      self.assertEqual(backbone.out_features     ,  ["a", "b"]				)
      self.assertEqual(backbone.out_indices     ,  [0, 1]				)

      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	[-3, -1]
      self.assertEqual(backbone.out_features     ,  ["a", "c"]				)
      self.assertEqual(backbone.out_indices     ,  [-3, -1]				)











from abc import ABC, abstractmethod
from typing import Optional, Union

from .. import Dataset, DatasetDict, Features, IterableDataset, IterableDatasetDict, NamedSplit
from ..utils.typing import NestedDataStructureLike, PathLike

class       _SCREAMING_SNAKE_CASE	(UpperCamelCase ):





     def __init__(       self :							List[str]     ,  UpperCamelCase :							Optional[NestedDataStructureLike[PathLike]] = None     ,  UpperCamelCase :							Optional[NamedSplit] = None     ,  UpperCamelCase :							Optional[Features] = None     ,  UpperCamelCase :							str = None     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							Optional[int] = None     ,  **UpperCamelCase :							Dict     ,  )->int:
      __SCREAMING_SNAKE_CASE       :    List[str]       =	path_or_paths
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	split if split or isinstance(UpperCamelCase     ,  UpperCamelCase				) else "train"
      __SCREAMING_SNAKE_CASE       :    Dict       =	features
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	cache_dir
      __SCREAMING_SNAKE_CASE       :    Tuple       =	keep_in_memory
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	streaming
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	num_proc
      __SCREAMING_SNAKE_CASE       :    int       =	kwargs






     @abstractmethod
     def 	__snake_case    (       self :							Optional[int]				)->Union[Dataset, DatasetDict, IterableDataset, IterableDatasetDict]:
      pass






class       _SCREAMING_SNAKE_CASE	(UpperCamelCase ):





     def __init__(       self :							Optional[Any]     ,  UpperCamelCase :							Optional[Features] = None     ,  UpperCamelCase :							str = None     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							bool = False     ,  UpperCamelCase :							Optional[int] = None     ,  **UpperCamelCase :							Dict     ,  )->Optional[int]:
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	features
      __SCREAMING_SNAKE_CASE       :    str       =	cache_dir
      __SCREAMING_SNAKE_CASE       :    Any       =	keep_in_memory
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	streaming
      __SCREAMING_SNAKE_CASE       :    int       =	num_proc
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	kwargs






     @abstractmethod
     def 	__snake_case    (       self :							str				)->Union[Dataset, IterableDataset]:
      pass






