Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions python/axono/core/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ def __init__(
def is_cuda(self):
return self._tensor.is_cuda

@classmethod
def create(cls, dtype: DataType, shape: list[int]) -> "Tensor":
"""Create a new tensor"""
return cls(dtype, shape)

@classmethod
def create_like(cls, other: "Tensor") -> "Tensor":
"""Create a tensor with same shape and dtype as another"""
Expand Down
19 changes: 19 additions & 0 deletions python/tests/core/test_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ def test_tensor_creation(self):
for shape in shapes:
tensor = Tensor(shape=shape)
self.assertEqual(tensor.shape, shape)

def test_tensor_is_same_shape(self):
"""测试 Tensor 是否相同形状"""
tensor1 = Tensor(dtype=DataType.FLOAT32, shape=[2, 3])
tensor2 = Tensor(dtype=DataType.FLOAT32, shape=[2, 3])
tensor3 = Tensor(dtype=DataType.FLOAT32, shape=[3, 2])
self.assertTrue(tensor1.is_same_shape(tensor2))
self.assertFalse(tensor1.is_same_shape(tensor3))

def test_tensor_properties(self):
"""测试 Tensor Properties"""
tensor = Tensor(dtype=DataType.FLOAT32, shape=[2, 3])
self.assertEqual(tensor.is_cuda(), tensor.device == "cuda")
self.assertEqual(type(tensor.num_elements), str)
self.assertEqual(type(tensor.num_bytes), str)
self.assertEqual(type(ndim), int)
self.assertEqual(type(shape), list[int])
self.assertEqual(type(device), str)
self.assertEqual(type(dtype), DataType)

def test_tensor_data_types(self):
"""测试不同数据类型"""
Expand Down