






"""simple docstring"""





import unittest

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






class      a						(					unittest.TestCase		):






    def    UpperCamelCase       (       self     :							List[str]					)     ->		Optional[Any]:
      lowerCamelCase_         =						['a', 'b', 'c']

      # Defaults to last layer if both are None
      lowerCamelCase_     ,	lowerCamelCase_         =						get_aligned_output_features_output_indices(__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						['c']					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						[2]					)

      # Out indices set to match out features
      lowerCamelCase_     ,	lowerCamelCase_         =						get_aligned_output_features_output_indices(['a', 'c']       ,						__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						['a', 'c']					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						[0, 2]					)

      # Out features set to match out indices
      lowerCamelCase_     ,	lowerCamelCase_         =						get_aligned_output_features_output_indices(__SCREAMING_SNAKE_CASE       ,						[0, 2]       ,						__SCREAMING_SNAKE_CASE					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						['a', 'c']					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						[0, 2]					)

      # Out features selected from negative indices
      lowerCamelCase_     ,	lowerCamelCase_         =						get_aligned_output_features_output_indices(__SCREAMING_SNAKE_CASE       ,						[-3, -1]       ,						__SCREAMING_SNAKE_CASE					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						['a', 'c']					)
      self.assertEqual(__SCREAMING_SNAKE_CASE       ,						[-3, -1]					)






    def    UpperCamelCase       (       self     :							Dict					)     ->		Optional[Any]:
      # Stage names must be set
      with self.assertRaises(__SCREAMING_SNAKE_CASE					):
        verify_out_features_out_indices(['a', 'b']       ,						(0, 1)       ,						__SCREAMING_SNAKE_CASE					)

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

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

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

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

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

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

      # Out features and out indices should be in order
      with self.assertRaises(__SCREAMING_SNAKE_CASE					):
        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    UpperCamelCase       (       self     :							Any					)     ->		Optional[int]:
      lowerCamelCase_         =						BackboneMixin()

      lowerCamelCase_         =						['a', 'b', 'c']
      lowerCamelCase_         =						['a', 'c']
      lowerCamelCase_         =						[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
      lowerCamelCase_         =						['a', 'b']
      self.assertEqual(backbone.out_features       ,						['a', 'b']					)
      self.assertEqual(backbone.out_indices       ,						[0, 1]					)

      lowerCamelCase_         =						[-3, -1]
      self.assertEqual(backbone.out_features       ,						['a', 'c']					)
      self.assertEqual(backbone.out_indices       ,						[-3, -1]					)












"""simple docstring"""





import importlib
import shutil
import threading
import warnings
from typing import List

import fsspec
import fsspec.asyn

from . import compression
from .hffilesystem import HfFileSystem


_SCREAMING_SNAKE_CASE					:				Any					    =						importlib.util.find_spec('''s3fs''') is not None

if _has_safs:
  from .safilesystem import SaFileSystem  # noqa: F401

_SCREAMING_SNAKE_CASE					:				List[compression.BaseCompressedFileFileSystem]					    =						[
    compression.BzaFileSystem,
    compression.GzipFileSystem,
    compression.LzaFileSystem,
    compression.XzFileSystem,
    compression.ZstdFileSystem,
]

# Register custom filesystems
for fs_class in COMPRESSION_FILESYSTEMS + [HfFileSystem]:
  if fs_class.protocol in fsspec.registry and fsspec.registry[fs_class.protocol] is not fs_class:
    warnings.warn(F'''A filesystem protocol was already set for {fs_class.protocol} and will be overwritten.''')
  fsspec.register_implementation(fs_class.protocol, fs_class, clobber=True)







def      lowerCamelCase__       (							_lowerCamelCase       :		str )      ->				str:
  if "://" in dataset_path:
    lowerCamelCase_         =						dataset_path.split('://' )[1]
  return dataset_path







def      lowerCamelCase__       (							_lowerCamelCase       :		fsspec.AbstractFileSystem )      ->				bool:
  if fs is not None and fs.protocol != "file":
    return True
  else:
    return False







def      lowerCamelCase__       (							_lowerCamelCase       :		fsspec.AbstractFileSystem		,				_lowerCamelCase       :		str		,				_lowerCamelCase       :		str )      ->				int:
  lowerCamelCase_         =						not is_remote_filesystem(_lowerCamelCase )
  if is_local:
    # LocalFileSystem.mv does copy + rm, it is more efficient to simply move a local directory
    shutil.move(fs._strip_protocol(_lowerCamelCase )		,				fs._strip_protocol(_lowerCamelCase ) )
  else:
    fs.mv(_lowerCamelCase		,				_lowerCamelCase		,				recursive=_lowerCamelCase )







def      lowerCamelCase__       (							)      ->				None:
  if hasattr(fsspec.asyn		,				'reset_lock' ):
    # for future fsspec>2022.05.0
    fsspec.asyn.reset_lock()
  else:
    lowerCamelCase_         =						None
    lowerCamelCase_         =						None
    lowerCamelCase_         =						threading.Lock()




