Skip to content
Open

test #90

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/nncf/tensor/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,26 @@ def get_tensor_backend(backend: BackendType) -> TensorBackend:
raise nncf.ValidationError(msg)

return BACKEND_TO_TENSOR_BACKEND[backend]


def wrap_tensor(data: Tensor) -> Tensor:
"""
Wrap input data into a Tensor object.

Parameters
----------
data : Tensor
Comment on lines +317 to +323

Copilot AI Feb 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint specifies data: Tensor but the documentation states it can be "either a Tensor instance or data that can be used to construct a Tensor". The type hint should be data: Union[Tensor, TTensor] or data: Any to match the intended behavior described in the docstring.

Suggested change
def wrap_tensor(data: Tensor) -> Tensor:
"""
Wrap input data into a Tensor object.
Parameters
----------
data : Tensor
def wrap_tensor(data: Union[Tensor, TTensor]) -> Tensor:
"""
Wrap input data into a Tensor object.
Parameters
----------
data : Union[Tensor, TTensor]

Copilot uses AI. Check for mistakes.
Input data to be wrapped. Can be either a Tensor instance or data that
can be used to construct a Tensor.

Returns
-------
Tensor
If input is already a Tensor, returns it unchanged. Otherwise, returns
a new Tensor instance created from the input data.
Comment on lines +321 to +331

Copilot AI Feb 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation style uses NumPy format (Parameters/Returns sections with dashes), while the rest of the file uses reStructuredText format with :param and :return tags (see lines 243-252, 276-281, 288-293, 299-302). The documentation should be consistent with the existing convention in this file.

Suggested change
Parameters
----------
data : Tensor
Input data to be wrapped. Can be either a Tensor instance or data that
can be used to construct a Tensor.
Returns
-------
Tensor
If input is already a Tensor, returns it unchanged. Otherwise, returns
a new Tensor instance created from the input data.
:param data: Input data to be wrapped. Can be either a Tensor instance or
data that can be used to construct a Tensor.
:return: If input is already a Tensor, returns it unchanged. Otherwise,
returns a new Tensor instance created from the input data.

Copilot uses AI. Check for mistakes.
"""
import copy

Copilot AI Feb 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement should be placed at the top of the file with other imports, not inside the function. The codebase follows the convention of placing all imports at module level (lines 11-23).

Copilot uses AI. Check for mistakes.

if isinstance(data, Tensor):
return data
return Tensor(copy.deepcopy(data))
Comment on lines +317 to +337

Copilot AI Feb 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function appears to be redundant. The Tensor class constructor (line 34) already handles both Tensor instances and raw data, extracting the .data attribute when a Tensor is passed. Simply calling Tensor(data) would achieve the same result without needing a separate wrapper function. If this function is intended to perform a deep copy, that intent should be documented and the implementation should be reconsidered given the issues with deepcopy on tensor backends.

Copilot uses AI. Check for mistakes.
Comment on lines +333 to +337

Copilot AI Feb 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of copy.deepcopy is unnecessary and potentially problematic. The Tensor.__init__ method (line 34) already handles both Tensor instances and raw data correctly by extracting .data from Tensor objects. Additionally, deepcopy can be expensive for large tensors and may not work correctly with all tensor backends (e.g., CUDA tensors). Consider simply using return Tensor(data) for non-Tensor inputs.

Suggested change
import copy
if isinstance(data, Tensor):
return data
return Tensor(copy.deepcopy(data))
if isinstance(data, Tensor):
return data
return Tensor(data)

Copilot uses AI. Check for mistakes.