From 9f4f0ad16192735e4c7f4ff38b891ba8f35e7bb3 Mon Sep 17 00:00:00 2001 From: Tammy Kolda Date: Fri, 4 Apr 2025 16:18:58 -0700 Subject: [PATCH] Minor updates to documentation of `pyttb.tensor.copy`. Mainly making it very clear that it's a deep copy. --- pyttb/tensor.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pyttb/tensor.py b/pyttb/tensor.py index 152d30e1..2450463e 100644 --- a/pyttb/tensor.py +++ b/pyttb/tensor.py @@ -227,18 +227,21 @@ def copy(self) -> tensor: Returns ------- - Copy of original tensor. + Deep copy of original tensor. Examples -------- - >>> T1 = ttb.tensor(np.ones((3, 2))) - >>> T2 = T1 - >>> T3 = T2.copy() - >>> T1[0, 0] = 3 - >>> T1[0, 0] == T2[0, 0] - True - >>> T1[0, 0] == T3[0, 0] - False + Observing the difference between a shallow copy and a deep copy. When the + original tensor changes, so does the shallow copy, but the deep copy does not:: + + >>> T = ttb.tensor(np.ones((3, 2))) + >>> T_shallow = T + >>> T_deep = T.copy() + >>> T[0, 0] = 3 + >>> T[0, 0] == T_shallow[0, 0] + True + >>> T[0, 0] == T_deep[0, 0] + False """ return ttb.tensor(self.data, self.shape, copy=True)