Upload edit\Qwen3-TTS-test\.venv\Lib\site-packages\librosa\_cache.py with huggingface_hub
Browse files
edit//Qwen3-TTS-test//.venv//Lib//site-packages//librosa//_cache.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
"""Function caching"""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
from typing import Any, Callable, TypeVar
|
| 7 |
+
from joblib import Memory
|
| 8 |
+
from decorator import FunctionMaker
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def _decorator_apply(dec, func):
|
| 12 |
+
return FunctionMaker.create(
|
| 13 |
+
func,
|
| 14 |
+
"return decfunc(%(shortsignature)s)",
|
| 15 |
+
dict(decfunc=dec(func)),
|
| 16 |
+
__wrapped__=func,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
_F = TypeVar("_F", bound=Callable[..., Any])
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class CacheManager(object):
|
| 24 |
+
"""The librosa cache manager class wraps joblib.Memory
|
| 25 |
+
with a __call__ attribute, so that it may act as a function.
|
| 26 |
+
|
| 27 |
+
Additionally, it provides a caching level filter, so that
|
| 28 |
+
different functions can be cached or not depending on the user's
|
| 29 |
+
preference for speed vs. storage usage.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
def __init__(self, *args: Any, **kwargs: Any):
|
| 33 |
+
level = kwargs.pop("level", 10)
|
| 34 |
+
|
| 35 |
+
# Initialize the memory object
|
| 36 |
+
self.memory: Memory = Memory(*args, **kwargs)
|
| 37 |
+
# The level parameter controls which data we cache
|
| 38 |
+
# smaller numbers mean less caching
|
| 39 |
+
self.level: int = level
|
| 40 |
+
|
| 41 |
+
def __call__(self, level: int) -> Callable[[_F], _F]:
|
| 42 |
+
"""
|
| 43 |
+
Cache with an explicitly defined level.
|
| 44 |
+
|
| 45 |
+
Example usage:
|
| 46 |
+
|
| 47 |
+
@cache(level=2)
|
| 48 |
+
def semi_important_function(some_arguments):
|
| 49 |
+
...
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
def wrapper(function):
|
| 53 |
+
"""Add an input/output cache to the specified function."""
|
| 54 |
+
if self.memory.location is not None and self.level >= level:
|
| 55 |
+
return _decorator_apply(self.memory.cache, function)
|
| 56 |
+
|
| 57 |
+
else:
|
| 58 |
+
return function
|
| 59 |
+
|
| 60 |
+
return wrapper
|
| 61 |
+
|
| 62 |
+
def clear(self, *args: Any, **kwargs: Any) -> None:
|
| 63 |
+
"""Clear the cache"""
|
| 64 |
+
self.memory.clear(*args, **kwargs)
|
| 65 |
+
|
| 66 |
+
def eval(self, *args: Any, **kwargs: Any) -> Any:
|
| 67 |
+
"""Evaluate a function"""
|
| 68 |
+
return self.memory.eval(*args, **kwargs)
|
| 69 |
+
|
| 70 |
+
def format(self, *args: Any, **kwargs: Any) -> Any:
|
| 71 |
+
"""Return the formatted representation of an object"""
|
| 72 |
+
return self.memory.format(*args, **kwargs)
|
| 73 |
+
|
| 74 |
+
def reduce_size(self, *args: Any, **kwargs: Any) -> None:
|
| 75 |
+
"""Reduce the size of the cache"""
|
| 76 |
+
self.memory.reduce_size(*args, **kwargs) # pragma: no cover
|
| 77 |
+
|
| 78 |
+
def warn(self, *args: Any, **kwargs: Any) -> None:
|
| 79 |
+
"""Raise a warning"""
|
| 80 |
+
self.memory.warn(*args, **kwargs) # pragma: no cover
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# Instantiate the cache from the environment
|
| 84 |
+
cache: CacheManager = CacheManager(
|
| 85 |
+
os.environ.get("LIBROSA_CACHE_DIR", None),
|
| 86 |
+
mmap_mode=os.environ.get("LIBROSA_CACHE_MMAP", None),
|
| 87 |
+
compress=os.environ.get("LIBROSA_CACHE_COMPRESS", False),
|
| 88 |
+
verbose=int(os.environ.get("LIBROSA_CACHE_VERBOSE", 0)),
|
| 89 |
+
level=int(os.environ.get("LIBROSA_CACHE_LEVEL", 10)),
|
| 90 |
+
)
|