forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
【Hackathon 6th Fundable Projects 1 1-1】Add
_typing
module to paddle (…
…PaddlePaddle#63604) --------- Co-authored-by: SigureMo <[email protected]>
- Loading branch information
Showing
16 changed files
with
384 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,7 @@ | |
# high-level api | ||
from . import ( # noqa: F401 | ||
_pir_ops, | ||
_typing as _typing, | ||
callbacks, | ||
fft, | ||
hub, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 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 ( | ||
IntSequence as IntSequence, | ||
NestedNumbericSequence as NestedNumbericSequence, | ||
NestedSequence as NestedSequence, | ||
Numberic as Numberic, | ||
NumbericSequence as NumbericSequence, | ||
TensorOrTensors as TensorOrTensors, | ||
) | ||
|
||
# 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 ( | ||
DynamicShapeLike as DynamicShapeLike, | ||
ShapeLike as ShapeLike, | ||
Size1 as Size1, | ||
Size2 as Size2, | ||
Size3 as Size3, | ||
Size4 as Size4, | ||
Size5 as Size5, | ||
Size6 as Size6, | ||
SizeN as SizeN, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# 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, Sequence, TypeVar, Union | ||
|
||
import numpy as np | ||
from typing_extensions import TypeAlias | ||
|
||
if TYPE_CHECKING: | ||
from paddle import Tensor | ||
|
||
Numberic: TypeAlias = Union[int, float, complex, np.number, "Tensor"] | ||
|
||
_T = TypeVar("_T", bound=Numberic) | ||
_SeqLevel1: TypeAlias = Sequence[_T] | ||
_SeqLevel2: TypeAlias = Sequence[Sequence[_T]] | ||
_SeqLevel3: TypeAlias = Sequence[Sequence[Sequence[_T]]] | ||
_SeqLevel4: TypeAlias = Sequence[Sequence[Sequence[Sequence[_T]]]] | ||
_SeqLevel5: TypeAlias = Sequence[Sequence[Sequence[Sequence[Sequence[_T]]]]] | ||
_SeqLevel6: TypeAlias = Sequence[ | ||
Sequence[Sequence[Sequence[Sequence[Sequence[_T]]]]] | ||
] | ||
|
||
IntSequence: TypeAlias = _SeqLevel1[int] | ||
|
||
NumbericSequence: TypeAlias = _SeqLevel1[Numberic] | ||
|
||
NestedSequence: TypeAlias = Union[ | ||
_T, | ||
_SeqLevel1[_T], | ||
_SeqLevel2[_T], | ||
_SeqLevel3[_T], | ||
_SeqLevel4[_T], | ||
_SeqLevel5[_T], | ||
_SeqLevel6[_T], | ||
] | ||
|
||
NestedNumbericSequence: TypeAlias = NestedSequence[Numberic] | ||
|
||
TensorOrTensors: TypeAlias = Union["Tensor", Sequence["Tensor"]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 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, Union | ||
|
||
from typing_extensions import TypeAlias | ||
|
||
if TYPE_CHECKING: | ||
from paddle import ( | ||
CPUPlace, | ||
CUDAPinnedPlace, | ||
CUDAPlace, | ||
CustomPlace, | ||
IPUPlace, | ||
XPUPlace, | ||
) | ||
|
||
PlaceLike: TypeAlias = Union[ | ||
"CPUPlace", | ||
"CUDAPlace", | ||
"CUDAPinnedPlace", | ||
"IPUPlace", | ||
"CustomPlace", | ||
"XPUPlace", | ||
str, # some string like "cpu", "gpu:0", etc. | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Literal, Type, Union | ||
|
||
import numpy as np | ||
from typing_extensions import TypeAlias | ||
|
||
if TYPE_CHECKING: | ||
from paddle import dtype | ||
|
||
_DTypeLiteral: TypeAlias = Literal[ | ||
"uint8", | ||
"int8", | ||
"int16", | ||
"int32", | ||
"int64", | ||
"float32", | ||
"float64", | ||
"float16", | ||
"bfloat16", | ||
"complex64", | ||
"complex128", | ||
"bool", | ||
] | ||
|
||
_DTypeNumpy: TypeAlias = Union[ | ||
Type[ | ||
Union[ | ||
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 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, Union | ||
|
||
from typing_extensions import TypeAlias | ||
|
||
# Note: Do not confrom to predefined naming style in pylint. | ||
DataLayout0D: TypeAlias = Literal["NC"] | ||
DataLayout1D: TypeAlias = Literal["NCL", "NLC"] | ||
DataLayout2D: TypeAlias = Literal["NCHW", "NHCW"] | ||
DataLayout3D: TypeAlias = Literal["NCDHW", "NDHWC"] | ||
|
||
DataLayoutND: TypeAlias = Union[ | ||
DataLayout0D, | ||
DataLayout1D, | ||
DataLayout2D, | ||
DataLayout3D, | ||
] | ||
|
||
DataLayout1DVariant: TypeAlias = Literal["NCW", "NWC"] | ||
DataLayoutImage: TypeAlias = Literal["HWC", "CHW"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# 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 List, Tuple, Union | ||
|
||
from typing_extensions import TypeAlias | ||
|
||
from .. import Tensor | ||
|
||
DynamicShapeLike: TypeAlias = Union[ | ||
Tuple[Union[int, Tensor, None], ...], | ||
List[Union[int, Tensor, None]], | ||
Tensor, | ||
] | ||
|
||
|
||
ShapeLike: TypeAlias = Union[ | ||
Tuple[int, ...], | ||
List[int], | ||
Tensor, | ||
] | ||
|
||
|
||
# for size parameters, eg, kernel_size, stride ... | ||
Size1: TypeAlias = Union[int, Tuple[int], List[int]] | ||
Size2: TypeAlias = Union[int, Tuple[int, int], List[int]] | ||
Size3: TypeAlias = Union[int, Tuple[int, int, int], List[int]] | ||
Size4: TypeAlias = Union[int, Tuple[int, int, int, int], List[int]] | ||
Size5: TypeAlias = Union[int, Tuple[int, int, int, int, int], List[int]] | ||
Size6: TypeAlias = Union[int, Tuple[int, int, int, int, int, int], List[int]] | ||
SizeN: TypeAlias = Union[int, Tuple[int, ...], List[int]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 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. | ||
|
||
class CPUPlace: ... | ||
|
||
class CUDAPlace: | ||
def __init__(self, id: int, /) -> None: ... | ||
|
||
class CUDAPinnedPlace: ... | ||
|
||
class NPUPlace: | ||
def __init__(self, id: int, /) -> None: ... | ||
|
||
class IPUPlace: ... | ||
|
||
class CustomPlace: | ||
def __init__(self, name: str, id: int, /) -> None: ... | ||
|
||
class MLUPlace: | ||
def __init__(self, id: int, /) -> None: ... | ||
|
||
class XPUPlace: | ||
def __init__(self, id: int, /) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 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. | ||
|
||
class dtype: ... | ||
|
||
uint8: dtype | ||
int8: dtype | ||
int16: dtype | ||
int32: dtype | ||
int64: dtype | ||
|
||
float32: dtype | ||
float64: dtype | ||
float16: dtype | ||
bfloat16: dtype | ||
|
||
complex64: dtype | ||
complex128: dtype | ||
|
||
bool: dtype |
Empty file.
Oops, something went wrong.