ivy-llc / ivy

Convert Machine Learning Code Between Frameworks
https://ivy.dev
Other
14.01k stars 5.76k forks source link

norm #23708

Open hope205 opened 1 year ago

maliksaad1 commented 1 year ago

Existing Tensor class in PaddlePaddle frontend

class Tensor: def init(self, data): self.data = data


    # Existing methods ...

# Your new instance method
def my_instance_method(self):
    # Do something with self.data
    result = self.data + 10
    return Tensor(result)

# Add the new method to the class
Tensor.my_instance_method = my_instance_method
maliksaad1 commented 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