mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-14 20:57:59 +00:00
20 lines
503 B
Python
20 lines
503 B
Python
|
|
def pluralize(count: int, singular_word: str, plural_word: str = "") -> str:
|
||
|
|
if count == 1:
|
||
|
|
return f"{count} {singular_word}"
|
||
|
|
|
||
|
|
if not plural_word:
|
||
|
|
plural_word = f"{singular_word}s"
|
||
|
|
|
||
|
|
return f"{count} {plural_word}"
|
||
|
|
|
||
|
|
|
||
|
|
def duration_to_str(seconds: float) -> str:
|
||
|
|
if seconds < 0.00001:
|
||
|
|
return "0s"
|
||
|
|
elif seconds < 60:
|
||
|
|
return f"{seconds:.1f}s"
|
||
|
|
elif seconds < 3600:
|
||
|
|
return f"{seconds / 60:.1f}m"
|
||
|
|
else:
|
||
|
|
return f"{seconds / 3600:.1f}h"
|