Open hope205 opened 1 year ago
# Existing Tensor class in PaddlePaddle frontend
class Tensor:
def __init__(self, data):
self.data = data
# Existing methods ...
# Define your custom instance method
def custom_method(self, value):
# Your custom logic here
result = self.data * value
return Tensor(result)
# Attach the custom method to the Tensor class
Tensor.custom_method = custom_method
# Usage example:
# Create a Tensor object
tensor = Tensor(5)
# Use the custom instance method
result = tensor.custom_method(2)
print(result.data) # Output should be 10
Existing Tensor class in PaddlePaddle frontend
class Tensor: def init(self, data): self.data = data