chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Basic
|
||||
from .basic import (
|
||||
NestedList as NestedList,
|
||||
NestedNumericSequence as NestedNumericSequence,
|
||||
NestedSequence as NestedSequence,
|
||||
NestedStructure as NestedStructure,
|
||||
Numeric as Numeric,
|
||||
NumericSequence as NumericSequence,
|
||||
ParamAttrLike as ParamAttrLike,
|
||||
TensorIndex as TensorIndex,
|
||||
TensorLike as TensorLike,
|
||||
TensorOrTensors as TensorOrTensors,
|
||||
unreached as unreached,
|
||||
)
|
||||
|
||||
# Device
|
||||
from .device_like import (
|
||||
PlaceLike as PlaceLike,
|
||||
)
|
||||
|
||||
# DType
|
||||
from .dtype_like import DTypeLike as DTypeLike
|
||||
|
||||
# DataLayout
|
||||
from .layout import (
|
||||
DataLayout0D as DataLayout0D,
|
||||
DataLayout1D as DataLayout1D,
|
||||
DataLayout1DVariant as DataLayout1DVariant,
|
||||
DataLayout2D as DataLayout2D,
|
||||
DataLayout3D as DataLayout3D,
|
||||
DataLayoutImage as DataLayoutImage,
|
||||
DataLayoutND as DataLayoutND,
|
||||
)
|
||||
|
||||
# Shape
|
||||
from .shape import (
|
||||
ShapeLike as ShapeLike,
|
||||
Size1 as Size1,
|
||||
Size2 as Size2,
|
||||
Size3 as Size3,
|
||||
Size4 as Size4,
|
||||
Size5 as Size5,
|
||||
Size6 as Size6,
|
||||
SizeN as SizeN,
|
||||
)
|
||||
@@ -0,0 +1,66 @@
|
||||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
from types import EllipsisType
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
TypeAlias,
|
||||
TypeVar,
|
||||
Union,
|
||||
)
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
from typing_extensions import Never
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from paddle import ParamAttr, Tensor
|
||||
from paddle.nn.initializer import Initializer
|
||||
from paddle.regularizer import WeightDecayRegularizer
|
||||
|
||||
|
||||
Numeric: TypeAlias = Union[int, float, bool, complex, np.number, "Tensor"]
|
||||
TensorLike: TypeAlias = Union[npt.NDArray[Any], "Tensor", Numeric]
|
||||
_TensorIndexItem: TypeAlias = Union[
|
||||
None, bool, int, slice, "Tensor", EllipsisType
|
||||
]
|
||||
TensorIndex: TypeAlias = (
|
||||
_TensorIndexItem | tuple[_TensorIndexItem, ...] | list[_TensorIndexItem]
|
||||
)
|
||||
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
NestedSequence = _T | Sequence["NestedSequence[_T]"]
|
||||
NestedList = _T | list["NestedList[_T]"]
|
||||
NestedStructure = (
|
||||
_T | dict[str, "NestedStructure[_T]"] | Sequence["NestedStructure[_T]"]
|
||||
)
|
||||
NumericSequence = Sequence[Numeric]
|
||||
NestedNumericSequence: TypeAlias = NestedSequence[Numeric]
|
||||
TensorOrTensors: TypeAlias = Union["Tensor", Sequence["Tensor"]]
|
||||
|
||||
ParamAttrLike: TypeAlias = Union[
|
||||
"ParamAttr", "Initializer", "WeightDecayRegularizer", str, bool
|
||||
]
|
||||
|
||||
|
||||
def unreached() -> Never:
|
||||
"""Mark a code path as unreachable.
|
||||
Refer to https://typing.readthedocs.io/en/latest/source/unreachable.html#marking-code-as-unreachable
|
||||
"""
|
||||
raise RuntimeError("Unreachable code path")
|
||||
@@ -0,0 +1,24 @@
|
||||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, TypeAlias, Union
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from paddle.base.core import Place
|
||||
|
||||
PlaceLike: TypeAlias = Union[
|
||||
"Place",
|
||||
str, # some string like "cpu", "gpu:0", etc.
|
||||
]
|
||||
@@ -0,0 +1,56 @@
|
||||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Literal, TypeAlias, Union
|
||||
|
||||
import numpy as np
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from paddle import dtype
|
||||
|
||||
_DTypeLiteral: TypeAlias = Literal[
|
||||
"uint8",
|
||||
"int8",
|
||||
"int16",
|
||||
"int32",
|
||||
"int64",
|
||||
"float32",
|
||||
"float64",
|
||||
"float16",
|
||||
"bfloat16",
|
||||
"complex64",
|
||||
"complex128",
|
||||
"bool",
|
||||
]
|
||||
|
||||
_DTypeNumpy: TypeAlias = (
|
||||
type[
|
||||
np.uint8
|
||||
| np.int8
|
||||
| np.int16
|
||||
| np.int32
|
||||
| np.int64
|
||||
| np.float16
|
||||
| np.float32
|
||||
| np.float64
|
||||
| np.complex64
|
||||
| np.complex128
|
||||
| np.bool_
|
||||
]
|
||||
| np.dtype
|
||||
)
|
||||
|
||||
|
||||
DTypeLike: TypeAlias = Union["dtype", _DTypeNumpy, _DTypeLiteral]
|
||||
@@ -0,0 +1,29 @@
|
||||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Literal, TypeAlias
|
||||
|
||||
# Note: Do not conform to predefined naming style in pylint.
|
||||
DataLayout0D: TypeAlias = Literal["NC"]
|
||||
DataLayout1D: TypeAlias = Literal["NCL", "NLC"]
|
||||
DataLayout2D: TypeAlias = Literal["NCHW", "NHWC"]
|
||||
DataLayout3D: TypeAlias = Literal["NCDHW", "NDHWC"]
|
||||
|
||||
DataLayoutND: TypeAlias = (
|
||||
DataLayout0D | DataLayout1D | DataLayout2D | DataLayout3D
|
||||
)
|
||||
|
||||
DataLayout1DVariant: TypeAlias = Literal["NCW", "NWC"]
|
||||
DataLayoutImage: TypeAlias = Literal["HWC", "CHW"]
|
||||
@@ -0,0 +1,5 @@
|
||||
# Stub files for pybind11 C++ APIs
|
||||
|
||||
The files in this directory (`python/paddle/_typing/libs`) are auto generated from pybind11 C++ APIs.
|
||||
|
||||
Please do NOT edit these files, or the changes may be lost.
|
||||
@@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
from typing import TYPE_CHECKING, TypeAlias, Union
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .. import Tensor
|
||||
|
||||
_DynamicShapeLike: TypeAlias = Union[
|
||||
Sequence[Union[int, "Tensor", None]],
|
||||
"Tensor",
|
||||
]
|
||||
|
||||
|
||||
_StaticShapeLike: TypeAlias = Union[
|
||||
Sequence[int],
|
||||
"Tensor",
|
||||
]
|
||||
|
||||
ShapeLike: TypeAlias = _DynamicShapeLike | _StaticShapeLike
|
||||
|
||||
# for size parameters, eg, kernel_size, stride ...
|
||||
Size1: TypeAlias = int | tuple[int] | list[int]
|
||||
Size2: TypeAlias = int | tuple[int, int] | list[int]
|
||||
Size3: TypeAlias = int | tuple[int, int, int] | list[int]
|
||||
Size4: TypeAlias = int | tuple[int, int, int, int] | list[int]
|
||||
Size5: TypeAlias = int | tuple[int, int, int, int, int] | list[int]
|
||||
Size6: TypeAlias = int | tuple[int, int, int, int, int, int] | list[int]
|
||||
SizeN: TypeAlias = int | tuple[int, ...] | list[int]
|
||||
Reference in New Issue
Block a user