





"""simple docstring"""






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



class 					__UpperCAmelCase							(						_UpperCamelCase  ):
				def __init__(		self    :			List[Any]    )	->	Optional[int]:



							'''simple docstring'''



							self.test()
				def       UpperCAmelCase      (		self    :			int    )	->	str:



							'''simple docstring'''



							a__  :	str		 =			0
							a__  :	Union[str, Any]		 =			False
							while not completed:
										if counter == 1:
													self.reset()
										a__  :	Union[str, Any]		 =			self.advance()
										if not self.does_advance(a_    ):
													raise Exception(
													    "Custom Constraint is not defined correctly. self.does_advance(self.advance()) must be true."    )

										a__ ,	a__ ,	a__  :	Union[str, Any]		 =			self.update(a_    )
										counter += 1

										if counter > 1_00_00:
													raise Exception("update() does not fulfill the constraint."    )

							if self.remaining() != 0:
										raise Exception("Custom Constraint is not defined correctly."    )
				@abstractmethod
				def       UpperCAmelCase      (		self    :			Optional[int]    )	->	Dict:



							'''simple docstring'''



							raise NotImplementedError(
							    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."    )
				@abstractmethod
				def       UpperCAmelCase      (		self    :			List[str]	, a_    :			int    )	->	List[str]:



							'''simple docstring'''



							raise NotImplementedError(
							    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."    )
				@abstractmethod
				def       UpperCAmelCase      (		self    :			List[str]	, a_    :			int    )	->	Optional[Any]:



							'''simple docstring'''



							raise NotImplementedError(
							    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."    )
				@abstractmethod
				def       UpperCAmelCase      (		self    :			int    )	->	List[Any]:



							'''simple docstring'''



							raise NotImplementedError(
							    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."    )
				@abstractmethod
				def       UpperCAmelCase      (		self    :			Optional[Any]    )	->	List[Any]:



							'''simple docstring'''



							raise NotImplementedError(
							    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."    )






				@abstractmethod
				def       UpperCAmelCase      (		self    :			Optional[Any]	, a_    :			int=False    )	->	Union[str, Any]:



							'''simple docstring'''



							raise NotImplementedError(
							    F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."    )



class 					__UpperCAmelCase							(						_UpperCamelCase  ):
				def __init__(		self    :			List[Any]	, a_    :			List[int]    )	->	Any:



							'''simple docstring'''



							super(a_	, self    ).__init__()

							if not isinstance(a_	, a_    ) or len(a_    ) == 0:
										raise ValueError(F"`token_ids` has to be a non-empty list, but is {token_ids}."    )
							if any((not isinstance(a_	, a_    ) or token_id < 0) for token_id in token_ids    ):
										raise ValueError(F"Each list in `token_ids` has to be a list of positive integers, but is {token_ids}."    )

							a__  :	str		 =			token_ids

							a__  :	Optional[Any]		 =			len(self.token_ids    )
							a__  :	Tuple		 =			-1  # the index of the currently fulfilled step
							a__  :	Any		 =			False
				def       UpperCAmelCase      (		self    :			Optional[Any]    )	->	int:



							'''simple docstring'''



							if self.completed:
										return None
							return self.token_ids[self.fulfilled_idx + 1]
				def       UpperCAmelCase      (		self    :			int	, a_    :			int    )	->	int:



							'''simple docstring'''



							if not isinstance(a_	, a_    ):
										raise ValueError(F"`token_id` has to be an `int`, but is {token_id} of type {type(a_    )}"    )

							if self.completed:
										return False

							return token_id == self.token_ids[self.fulfilled_idx + 1]
				def       UpperCAmelCase      (		self    :			Any	, a_    :			int    )	->	Dict:



							'''simple docstring'''



							if not isinstance(a_	, a_    ):
										raise ValueError(F"`token_id` has to be an `int`, but is {token_id} of type {type(a_    )}"    )

							a__  :	Tuple		 =			False
							a__  :	Union[str, Any]		 =			False
							a__  :	str		 =			False

							if self.does_advance(a_    ):
										self.fulfilled_idx += 1
										a__  :	List[Any]		 =			True
										if self.fulfilled_idx == (self.seqlen - 1):
													a__  :	int		 =			True
										a__  :	str		 =			completed
							else:
										# failed to make progress.
										a__  :	List[str]		 =			True
										self.reset()
							return stepped, completed, reset
				def       UpperCAmelCase      (		self    :			Optional[int]    )	->	List[str]:



							'''simple docstring'''



							a__  :	Optional[int]		 =			False
							a__  :	List[Any]		 =			0
				def       UpperCAmelCase      (		self    :			int    )	->	List[str]:



							'''simple docstring'''



							return self.seqlen - (self.fulfilled_idx + 1)






				def       UpperCAmelCase      (		self    :			List[str]	, a_    :			Optional[int]=False    )	->	List[str]:



							'''simple docstring'''



							a__  :	Tuple		 =			PhrasalConstraint(self.token_ids    )

							if stateful:
										a__  :	List[Any]		 =			self.seqlen
										a__  :	Union[str, Any]		 =			self.fulfilled_idx
										a__  :	Any		 =			self.completed

							return new_constraint



class 					__UpperCAmelCase							:
				def __init__(		self    :			Dict	, a_    :			List[List[int]]	, a_    :			List[str]=True    )	->	Tuple:



							'''simple docstring'''



							a__  :	Optional[Any]		 =			max([len(a_    ) for one in nested_token_ids]    )

							a__  :	Optional[Any]		 =			{}
							for token_ids in nested_token_ids:
										a__  :	Tuple		 =			root
										for tidx, token_id in enumerate(a_    ):
													if token_id not in level:
																a__  :	str		 =			{}

													a__  :	List[Any]		 =			level[token_id]

							if no_subsets and self.has_subsets(a_	, a_    ):
										raise ValueError(
										    "Each list in `nested_token_ids` can't be a complete subset of another list, but is"
										    F" {nested_token_ids}."    )

							a__  :	str		 =			root
				def       UpperCAmelCase      (		self    :			Optional[Any]	, a_    :			str    )	->	Any:



							'''simple docstring'''



							a__  :	List[str]		 =			self.trie

							for current_token in current_seq:
										a__  :	Optional[int]		 =			start[current_token]

							a__  :	str		 =			list(start.keys()    )

							return next_tokens
				def       UpperCAmelCase      (		self    :			Dict	, a_    :			Any    )	->	Optional[Any]:



							'''simple docstring'''



							a__  :	Tuple		 =			self.next_tokens(a_    )

							return len(a_    ) == 0
				def       UpperCAmelCase      (		self    :			Union[str, Any]	, a_    :			Any    )	->	str:



							'''simple docstring'''



							a__  :	int		 =			list(root.values()    )
							if len(a_    ) == 0:
										return 1
							else:
										return sum([self.count_leaves(a_    ) for nn in next_nodes]    )






				def       UpperCAmelCase      (		self    :			Tuple	, a_    :			str	, a_    :			Union[str, Any]    )	->	int:



							'''simple docstring'''



							a__  :	Optional[int]		 =			self.count_leaves(a_    )
							return len(a_    ) != leaf_count



class 					__UpperCAmelCase							(						_UpperCamelCase  ):
				def __init__(		self    :			List[str]	, a_    :			List[List[int]]    )	->	Dict:



							'''simple docstring'''



							super(a_	, self    ).__init__()

							if not isinstance(a_	, a_    ) or len(a_    ) == 0:
										raise ValueError(F"`nested_token_ids` has to be a non-empty list, but is {nested_token_ids}."    )
							if any(not isinstance(a_	, a_    ) for token_ids in nested_token_ids    ):
										raise ValueError(F"`nested_token_ids` has to be a list of lists, but is {nested_token_ids}."    )
							if any(
							    any((not isinstance(a_	, a_    ) or token_id < 0) for token_id in token_ids    )
							    for token_ids in nested_token_ids    ):
										raise ValueError(
										    F"Each list in `nested_token_ids` has to be a list of positive integers, but is {nested_token_ids}."    )

							a__  :	List[str]		 =			DisjunctiveTrie(a_    )
							a__  :	Optional[Any]		 =			nested_token_ids

							a__  :	List[str]		 =			self.trie.max_height
							a__  :	Optional[int]		 =			[]
							a__  :	Any		 =			False
				def       UpperCAmelCase      (		self    :			Union[str, Any]    )	->	Optional[int]:



							'''simple docstring'''



							a__  :	List[Any]		 =			self.trie.next_tokens(self.current_seq    )

							if len(a_    ) == 0:
										return None
							else:
										return token_list
				def       UpperCAmelCase      (		self    :			Dict	, a_    :			int    )	->	Union[str, Any]:



							'''simple docstring'''



							if not isinstance(a_	, a_    ):
										raise ValueError(F"`token_id` is supposed to be type `int`, but is {token_id} of type {type(a_    )}"    )

							a__  :	int		 =			self.trie.next_tokens(self.current_seq    )

							return token_id in next_tokens
				def       UpperCAmelCase      (		self    :			List[str]	, a_    :			int    )	->	int:



							'''simple docstring'''



							if not isinstance(a_	, a_    ):
										raise ValueError(F"`token_id` is supposed to be type `int`, but is {token_id} of type {type(a_    )}"    )

							a__  :	List[Any]		 =			False
							a__  :	Tuple		 =			False
							a__  :	str		 =			False

							if self.does_advance(a_    ):
										self.current_seq.append(a_    )
										a__  :	Union[str, Any]		 =			True
							else:
										a__  :	List[Any]		 =			True
										self.reset()

							a__  :	Union[str, Any]		 =			self.trie.reached_leaf(self.current_seq    )
							a__  :	Any		 =			completed

							return stepped, completed, reset
				def       UpperCAmelCase      (		self    :			List[str]    )	->	Optional[int]:



							'''simple docstring'''



							a__  :	List[str]		 =			False
							a__  :	Any		 =			[]
				def       UpperCAmelCase      (		self    :			int    )	->	Optional[int]:



							'''simple docstring'''



							if self.completed:
										# since this can be completed without reaching max height
										return 0
							else:
										return self.seqlen - len(self.current_seq    )






				def       UpperCAmelCase      (		self    :			List[str]	, a_    :			str=False    )	->	Union[str, Any]:



							'''simple docstring'''



							a__  :	int		 =			DisjunctiveConstraint(self.token_ids    )

							if stateful:
										a__  :	Dict		 =			self.seqlen
										a__  :	Tuple		 =			self.current_seq
										a__  :	int		 =			self.completed

							return new_constraint



class 					__UpperCAmelCase							:
				def __init__(		self    :			Tuple	, a_    :			List[Constraint]    )	->	Dict:



							'''simple docstring'''



							a__  :	List[str]		 =			constraints

							# max # of steps required to fulfill a given constraint
							a__  :	Optional[Any]		 =			max([c.seqlen for c in constraints]    )
							a__  :	Union[str, Any]		 =			len(a_    )
							a__  :	Dict		 =			False

							self.init_state()
				def       UpperCAmelCase      (		self    :			List[Any]    )	->	Optional[int]:



							'''simple docstring'''



							a__  :	Optional[Any]		 =			[]
							a__  :	List[Any]		 =			None
							a__  :	Union[str, Any]		 =			[constraint.copy(stateful=a_    ) for constraint in self.constraints]
				def       UpperCAmelCase      (		self    :			List[Any]    )	->	Union[str, Any]:



							'''simple docstring'''



							a__  :	Any		 =			0
							if self.inprogress_constraint:
										# extra points for having a constraint mid-fulfilled
										add += self.max_seqlen - self.inprogress_constraint.remaining()

							return (len(self.complete_constraints    ) * self.max_seqlen) + add
				def       UpperCAmelCase      (		self    :			str    )	->	Tuple:



							'''simple docstring'''



							a__  :	int		 =			[]
							if self.inprogress_constraint is None:
										for constraint in self.pending_constraints:  # "pending" == "unfulfilled yet"
													a__  :	Optional[Any]		 =			constraint.advance()
													if isinstance(a_	, a_    ):
																token_list.append(a_    )
													elif isinstance(a_	, a_    ):
																token_list.extend(a_    )
							else:
										a__  :	List[str]		 =			self.inprogress_constraint.advance()
										if isinstance(a_	, a_    ):
													token_list.append(a_    )
										elif isinstance(a_	, a_    ):
													token_list.extend(a_    )

							if len(a_    ) == 0:
										return None
							else:
										return token_list
				def       UpperCAmelCase      (		self    :			List[Any]	, a_    :			Optional[List[int]]    )	->	int:



							'''simple docstring'''



							self.init_state()

							if token_ids is not None:
										for token in token_ids:
													# completes or steps **one** constraint
													a__ ,	a__  :	Dict		 =			self.add(a_    )

													# the entire list of constraints are fulfilled
													if self.completed:
																break
				def       UpperCAmelCase      (		self    :			Optional[int]	, a_    :			int    )	->	Any:



							'''simple docstring'''



							if not isinstance(a_	, a_    ):
										raise ValueError(F"`token_id` should be an `int`, but is `{token_id}`."    )

							a__ ,	a__  :	Dict		 =			False, False

							if self.completed:
										a__  :	List[Any]		 =			True
										a__  :	Union[str, Any]		 =			False
										return complete, stepped

							if self.inprogress_constraint is not None:
										# In the middle of fulfilling a constraint. If the `token_id` *does* makes an incremental progress to current
										# job, simply update the state

										a__ ,	a__ ,	a__  :	Tuple		 =			self.inprogress_constraint.update(a_    )
										if reset:
													# 1. If the next token breaks the progress, then we must restart.
													#     e.g. constraint = "I love pies" and sequence so far is "I love" but `token_id` == "books".

													#     But that doesn't mean we self.init_state(), since we only reset the state for this particular
													#     constraint, not the full list of constraints.

													self.pending_constraints.append(self.inprogress_constraint.copy(stateful=a_    )    )
													a__  :	Any		 =			None

										if complete:
													# 2. If the next token completes the constraint, move it to completed list, set
													#     inprogress to None. If there are no pending constraints either, then this full list of constraints
													#     is complete.

													self.complete_constraints.append(self.inprogress_constraint    )
													a__  :	str		 =			None

													if len(self.pending_constraints    ) == 0:
																# we're done!
																a__  :	List[Any]		 =			True

							else:
										# Not in the middle of fulfilling a constraint. So does this `token_id` helps us step towards any of our list
										# of constraints?

										for cidx, pending_constraint in enumerate(self.pending_constraints    ):
													if pending_constraint.does_advance(a_    ):
																a__ ,	a__ ,	a__  :	Tuple		 =			pending_constraint.update(a_    )

																if not stepped:
																			raise Exception(
																			    "`constraint.update(token_id)` is not yielding incremental progress, "
																			    "even though `constraint.does_advance(token_id)` is true."    )

																if complete:
																			self.complete_constraints.append(a_    )
																			a__  :	List[Any]		 =			None

																if not complete and stepped:
																			a__  :	List[str]		 =			pending_constraint

																if complete or stepped:
																			# If we made any progress at all, then it's at least not a "pending constraint".

																			a__  :	List[Any]		 =			(
																			    self.pending_constraints[:cidx] + self.pending_constraints[cidx + 1 :]
																			)

																			if len(self.pending_constraints    ) == 0 and self.inprogress_constraint is None:
																						# If there's no longer any pending after this and no inprogress either, then we must be
																						# complete.

																						a__  :	Optional[Any]		 =			True

																			break  # prevent accidentally stepping through multiple constraints with just one token.

							return complete, stepped






				def       UpperCAmelCase      (		self    :			Optional[int]	, a_    :			Optional[Any]=True    )	->	int:



							'''simple docstring'''



							a__  :	Any		 =			ConstraintListState(self.constraints    )  # we actually never though self.constraints objects
							# throughout this process. So it's at initialization state.

							if stateful:
										a__  :	Dict		 =			[
										    constraint.copy(stateful=a_    ) for constraint in self.complete_constraints
										]
										if self.inprogress_constraint is not None:
													a__  :	Optional[Any]		 =			self.inprogress_constraint.copy(stateful=a_    )
										a__  :	Optional[Any]		 =			[constraint.copy() for constraint in self.pending_constraints]

							return new_state






"""simple docstring"""






from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__UpperCAmelCase						=			{
    '''configuration_informer''': [
        '''INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''InformerConfig''',
    ],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__UpperCAmelCase						=			[
		    '''INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''InformerForPrediction''',
		    '''InformerModel''',
		    '''InformerPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_informer import INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, InformerConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_informer import (
				    INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
				    InformerForPrediction,
				    InformerModel,
				    InformerPreTrainedModel,
				)

else:
		import sys

		__UpperCAmelCase						=			_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)