-
# HG changeset patch
# User Alexandru Ghitza <aghitza@alum.mit.edu>
# Date 1247481054 -36000
# Node ID d1f2723e7fc794d3f08afe7580e985843aee4dd5
# Parent ca1f31d6f6bf7b1f8da0cb8973c838ab19921c29
trac 111: replace .copy() with .__copy__()
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/combinat/matrices/latin.py
|
a
|
b
|
|
| 131 | 131 | #***************************************************************************** |
| 132 | 132 | |
| 133 | 133 | import sets |
| 134 | | import copy |
| 135 | 134 | |
| 136 | 135 | from sage.matrix.all import matrix |
| 137 | 136 | from sage.rings.all import ZZ |
| … |
… |
|
| 318 | 317 | |
| 319 | 318 | return self.square == Q.square |
| 320 | 319 | |
| 321 | | def copy(self): |
| | 320 | def __copy__(self): |
| 322 | 321 | """ |
| 323 | 322 | To copy a latin square we must copy the underlying matrix. |
| 324 | 323 | |
| 325 | 324 | EXAMPLES:: |
| 326 | 325 | |
| 327 | 326 | sage: A = LatinSquare(matrix(ZZ, [[0, 1], [2, 3]])) |
| 328 | | sage: B = A.copy() |
| 329 | | sage: A |
| | 327 | sage: B = copy(A) |
| | 328 | sage: B |
| 330 | 329 | [0 1] |
| 331 | 330 | [2 3] |
| 332 | 331 | """ |
| 333 | | |
| 334 | 332 | C = LatinSquare(self.square.nrows(), self.square.ncols()) |
| 335 | | C.square = self.square.copy() |
| | 333 | from copy import copy |
| | 334 | C.square = copy(self.square) |
| 336 | 335 | return C |
| 337 | 336 | |
| 338 | 337 | def clear_cells(self): |
| … |
… |
|
| 908 | 907 | |
| 909 | 908 | n = self.nrows() |
| 910 | 909 | |
| 911 | | G = self.copy() |
| | 910 | from copy import copy |
| | 911 | G = copy(self) |
| 912 | 912 | |
| 913 | 913 | for r in range(n-1, -1, -1): |
| 914 | 914 | for c in range(n-1, -1, -1): |
| … |
… |
|
| 1117 | 1117 | for x in DLXCPP(dlx_rows): |
| 1118 | 1118 | nr_found += 1 |
| 1119 | 1119 | |
| 1120 | | Q = copy.deepcopy(self) |
| | 1120 | from copy import deepcopy |
| | 1121 | Q = deepcopy(self) |
| 1121 | 1122 | |
| 1122 | 1123 | for y in x: |
| 1123 | 1124 | if len(dlx_rows[y]) == 1: continue # dummy row |
| … |
… |
|
| 1987 | 1988 | r1 = r2 = c1 = c2 = x = y = z = -1 |
| 1988 | 1989 | proper = True |
| 1989 | 1990 | |
| 1990 | | L = L_start.copy() |
| | 1991 | from copy import copy |
| | 1992 | L = copy(L_start) |
| 1991 | 1993 | |
| 1992 | 1994 | L_rce = L |
| 1993 | 1995 | L_cer = LatinSquare(n, n) |
| … |
… |
|
| 2642 | 2644 | for i in SOLUTIONS.keys(): |
| 2643 | 2645 | soln = list(i) |
| 2644 | 2646 | |
| 2645 | | Q = copy.deepcopy(P) |
| | 2647 | from copy import deepcopy |
| | 2648 | Q = deepcopy(P) |
| 2646 | 2649 | |
| 2647 | 2650 | for x in soln: |
| 2648 | 2651 | (r, c, e) = cmap[tuple(dlx_rows[x])] |
| … |
… |
|
| 2688 | 2691 | assert T1.nrows() == T2.nrows() |
| 2689 | 2692 | |
| 2690 | 2693 | n = T1.nrows() |
| 2691 | | |
| 2692 | | Q1 = T1.copy() |
| 2693 | | Q2 = T2.copy() |
| | 2694 | |
| | 2695 | from copy import copy |
| | 2696 | Q1 = copy(T1) |
| | 2697 | Q2 = copy(T2) |
| 2694 | 2698 | |
| 2695 | 2699 | for r in range(n): |
| 2696 | 2700 | for c in range(n): |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/databases/database.py
|
a
|
b
|
|
| 572 | 572 | from copy import copy |
| 573 | 573 | return copy(self.__query_string__) |
| 574 | 574 | |
| 575 | | def copy(self): |
| | 575 | def __copy__(self): |
| 576 | 576 | """ |
| 577 | 577 | Returns a copy of the query. |
| 578 | 578 | |
| … |
… |
|
| 581 | 581 | sage: q = 'select graph_id,graph6,num_vertices,num_edges from graph_data where graph_id<=(?) and num_vertices=(?)' |
| 582 | 582 | sage: param = (22,5) |
| 583 | 583 | sage: Q = GenericSQLQuery(G,q,param) |
| 584 | | sage: R = Q.copy() |
| | 584 | sage: R = copy(Q) |
| 585 | 585 | sage: R.get_query_string() |
| 586 | 586 | 'select graph_id,graph6,num_vertices,num_edges from graph_data where graph_id<=(?) and num_vertices=(?)' |
| 587 | 587 | sage: R.show() |
| … |
… |
|
| 1000 | 1000 | else: |
| 1001 | 1001 | self.__query_string__ = '' |
| 1002 | 1002 | |
| 1003 | | def copy(self): |
| | 1003 | def __copy__(self): |
| 1004 | 1004 | """ |
| 1005 | 1005 | Returns a copy of itself. |
| 1006 | 1006 | |
| … |
… |
|
| 1032 | 1032 | 55 E?C_ 6 |
| 1033 | 1033 | 210 F???W 7 |
| 1034 | 1034 | 211 F??G_ 7 |
| 1035 | | sage: R = Q.copy() |
| | 1035 | sage: R = copy(Q) |
| 1036 | 1036 | sage: print R |
| 1037 | 1037 | Query for sql database: ...graphs.db |
| 1038 | 1038 | Query string: SELECT graph_data.graph_id, graph_data.graph6, graph_data.num_vertices FROM graph_data WHERE graph_data.num_edges < ? |
| … |
… |
|
| 1154 | 1154 | self.__param_tuple__ = self.__param_tuple__ + other.__param_tuple__ |
| 1155 | 1155 | |
| 1156 | 1156 | else: |
| 1157 | | if not self.__query_string__: return other.copy() |
| 1158 | | if not other.__query_string__: return self.copy() |
| | 1157 | from copy import copy |
| | 1158 | if not self.__query_string__: return copy(other) |
| | 1159 | if not other.__query_string__: return copy(self) |
| 1159 | 1160 | if join_table is None or join_dict is None: |
| 1160 | 1161 | pattern = ' JOIN ' |
| 1161 | 1162 | if re.search(pattern,self.__query_string__) or re.search(pattern,other.__query_string__): |
| … |
… |
|
| 1167 | 1168 | if s[0] != o[0]: |
| 1168 | 1169 | raise ValueError('Input queries query different tables but join parameters are NoneType') |
| 1169 | 1170 | |
| 1170 | | q = self.copy() |
| | 1171 | q = copy(self) |
| 1171 | 1172 | |
| 1172 | 1173 | # inner join clause |
| 1173 | 1174 | if join_dict is not None: |
| … |
… |
|
| 1288 | 1289 | |
| 1289 | 1290 | self.__param_tuple__ = self.__param_tuple__ + other.__param_tuple__ |
| 1290 | 1291 | else: |
| 1291 | | q = self.copy() |
| | 1292 | from copy import copy |
| | 1293 | q = copy(self) |
| 1292 | 1294 | if not self.__query_string__: return q |
| 1293 | | if not other.__query_string__: return other.copy() |
| | 1295 | if not other.__query_string__: return copy(other) |
| 1294 | 1296 | if join_table is None or join_dict is None: |
| 1295 | 1297 | pattern = ' JOIN ' |
| 1296 | 1298 | if re.search(pattern,self.__query_string__) or re.search(pattern,other.__query_string__): |
| … |
… |
|
| 1355 | 1357 | self.__query_string__ = re.sub(' WHERE ',' WHERE NOT ( ',self.__query_string__) + ' )' |
| 1356 | 1358 | else: return |
| 1357 | 1359 | else: |
| 1358 | | if not self.__query_string__: return self.copy() |
| | 1360 | if not self.__query_string__: |
| | 1361 | from copy import copy |
| | 1362 | return copy(self) |
| 1359 | 1363 | q = SQLQuery(self.__database__) |
| 1360 | 1364 | q.__query_string__ = re.sub(' WHERE ',' WHERE NOT ( ',self.__query_string__) |
| 1361 | 1365 | q.__query_string__ += ' )' |
| … |
… |
|
| 1543 | 1547 | s += '\n' |
| 1544 | 1548 | return s |
| 1545 | 1549 | |
| 1546 | | def copy(self): |
| | 1550 | def __copy__(self): |
| 1547 | 1551 | """ |
| 1548 | 1552 | Returns an instance of SQLDatabase that points to a copy database, |
| 1549 | 1553 | and allows modification. |
| … |
… |
|
| 1552 | 1556 | sage: DB = SQLDatabase() |
| 1553 | 1557 | sage: DB.create_table('lucy',{'id':{'sql':'INTEGER', 'primary_key':True, 'index':True},'a1':{'sql':'bool','primary_key':False}, 'b2':{'sql':'int', 'primary_key':False}}) |
| 1554 | 1558 | sage: DB.add_rows('lucy', [(0,1,1),(1,1,4),(2,0,7),(3,1,384),(4,1,978932)],['id','a1','b2']) |
| 1555 | | sage: d = DB.copy() |
| | 1559 | sage: d = copy(DB) |
| 1556 | 1560 | |
| 1557 | 1561 | sage: d.show('lucy') |
| 1558 | 1562 | a1 id b2 |
| … |
… |
|
| 1591 | 1595 | 1 4 978932 |
| 1592 | 1596 | |
| 1593 | 1597 | """ |
| 1594 | | from copy import copy |
| 1595 | 1598 | # copy .db file |
| 1596 | 1599 | new_loc = tmp_filename() + '.db' |
| 1597 | 1600 | os.system('cp '+ self.__dblocation__ + ' ' + new_loc) |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/groups/perm_gps/partn_ref/refinement_python.pyx
|
a
|
b
|
|
| 142 | 142 | """ |
| 143 | 143 | PS_move_min_to_front(self.c_ps, start, end) |
| 144 | 144 | |
| 145 | | def copy(self): |
| | 145 | def __copy__(self): |
| 146 | 146 | """ |
| 147 | 147 | |
| 148 | 148 | EXAMPLE:: |
| 149 | 149 | |
| 150 | 150 | sage: from sage.groups.perm_gps.partn_ref.refinement_python import PythonPartitionStack |
| 151 | 151 | sage: P = PythonPartitionStack(7) |
| 152 | | sage: Q = P.copy() |
| | 152 | sage: Q = copy(P) |
| 153 | 153 | sage: P.display() |
| 154 | 154 | (0 1 2 3 4 5 6) |
| 155 | 155 | sage: Q.display() |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/libs/ntl/ntl_ZZX.pyx
|
a
|
b
|
|
| 149 | 149 | cpp_delete_array(val) |
| 150 | 150 | return result |
| 151 | 151 | |
| 152 | | def copy(self): |
| 153 | | """ |
| 154 | | Return a copy of self. |
| 155 | | |
| 156 | | EXAMPLES: |
| 157 | | sage: x = ntl.ZZX([1,32]) |
| 158 | | sage: y = x.copy() |
| 159 | | sage: y == x |
| 160 | | True |
| 161 | | sage: y is x |
| 162 | | False |
| 163 | | """ |
| 164 | | _sig_on |
| 165 | | return self.__copy__() |
| 166 | | |
| 167 | 152 | def __copy__(self): |
| 168 | 153 | """ |
| 169 | 154 | Return a copy of self. |
| 170 | 155 | |
| 171 | 156 | EXAMPLES: |
| 172 | 157 | sage: x = ntl.ZZX([1,32]) |
| 173 | | sage: y = x.copy() |
| | 158 | sage: y = copy(x) |
| 174 | 159 | sage: y == x |
| 175 | 160 | True |
| 176 | 161 | sage: y is x |
| … |
… |
|
| 424 | 409 | if n < 0: |
| 425 | 410 | raise NotImplementedError |
| 426 | 411 | import sage.groups.generic as generic |
| 427 | | return generic.power(self, n, one_ZZX.copy()) |
| | 412 | from copy import copy |
| | 413 | return generic.power(self, n, copy(one_ZZX)) |
| 428 | 414 | |
| 429 | 415 | def __cmp__(ntl_ZZX self, ntl_ZZX other): |
| 430 | 416 | """ |
| … |
… |
|
| 822 | 808 | [] |
| 823 | 809 | """ |
| 824 | 810 | if m <= 0: |
| 825 | | return zero_ZZX.copy() |
| | 811 | from copy import copy |
| | 812 | return copy(zero_ZZX) |
| 826 | 813 | _sig_on |
| 827 | 814 | return make_ZZX(ZZX_truncate(&self.x, m)) |
| 828 | 815 | |
| … |
… |
|
| 839 | 826 | [10 20] |
| 840 | 827 | """ |
| 841 | 828 | if m <= 0: |
| 842 | | return zero_ZZX.copy() |
| | 829 | from copy import copy |
| | 830 | return copy(zero_ZZX) |
| 843 | 831 | return make_ZZX(ZZX_multiply_and_truncate(&self.x, &other.x, m)) |
| 844 | 832 | |
| 845 | 833 | def square_and_truncate(self, long m): |
| … |
… |
|
| 854 | 842 | [1 4 10 20] |
| 855 | 843 | """ |
| 856 | 844 | if m < 0: |
| 857 | | return zero_ZZX.copy() |
| | 845 | from copy import copy |
| | 846 | return copy(zero_ZZX) |
| 858 | 847 | return make_ZZX(ZZX_square_and_truncate(&self.x, m)) |
| 859 | 848 | |
| 860 | 849 | def invert_and_truncate(self, long m): |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/libs/ntl/ntl_ZZ_pEX.pyx
|
a
|
b
|
|
| 181 | 181 | sage: f = ntl.ZZ_pEX([a, b, b]) |
| 182 | 182 | sage: f |
| 183 | 183 | [[3 2] [1 2] [1 2]] |
| 184 | | sage: y = f.copy() |
| | 184 | sage: y = copy(f) |
| 185 | 185 | sage: y == f |
| 186 | 186 | True |
| 187 | 187 | sage: y is f |
| … |
… |
|
| 194 | 194 | r.x = self.x |
| 195 | 195 | return r |
| 196 | 196 | |
| 197 | | def copy(self): |
| 198 | | """ |
| 199 | | Return a copy of self. |
| 200 | | |
| 201 | | EXAMPLES: |
| 202 | | sage: c=ntl.ZZ_pEContext(ntl.ZZ_pX([1,1,1], 7)) |
| 203 | | sage: a = ntl.ZZ_pE([3,2], c) |
| 204 | | sage: b = ntl.ZZ_pE([1,2], c) |
| 205 | | sage: f = ntl.ZZ_pEX([a, b, b]) |
| 206 | | sage: f |
| 207 | | [[3 2] [1 2] [1 2]] |
| 208 | | sage: y = f.copy() |
| 209 | | sage: y == f |
| 210 | | True |
| 211 | | sage: y is f |
| 212 | | False |
| 213 | | sage: f[0] = 0; y |
| 214 | | [[3 2] [1 2] [1 2]] |
| 215 | | """ |
| 216 | | return self.__copy__() |
| 217 | | |
| 218 | 197 | def get_modulus_context(self): |
| 219 | 198 | """ |
| 220 | 199 | Returns the structure that holds the underlying NTL modulus. |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/libs/ntl/ntl_ZZ_pX.pyx
|
a
|
b
|
|
| 173 | 173 | |
| 174 | 174 | EXAMPLES: |
| 175 | 175 | sage: x = ntl.ZZ_pX([0,5,-3],11) |
| 176 | | sage: y = x.copy() |
| | 176 | sage: y = copy(x) |
| 177 | 177 | sage: x == y |
| 178 | 178 | True |
| 179 | 179 | sage: x is y |
| … |
… |
|
| 186 | 186 | r.x = self.x |
| 187 | 187 | return r |
| 188 | 188 | |
| 189 | | def copy(self): |
| 190 | | """ |
| 191 | | Return a copy of self. |
| 192 | | |
| 193 | | EXAMPLES: |
| 194 | | sage: x = ntl.ZZ_pX([0,5,-3],11) |
| 195 | | sage: y = x.copy() |
| 196 | | sage: x == y |
| 197 | | True |
| 198 | | sage: x is y |
| 199 | | False |
| 200 | | sage: x[0] = 4; y |
| 201 | | [0 5 8] |
| 202 | | """ |
| 203 | | return self.__copy__() |
| 204 | | |
| 205 | 189 | def get_modulus_context(self): |
| 206 | 190 | """ |
| 207 | 191 | Return the modulus for self. |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/libs/pari/gen.pyx
|
a
|
b
|
|
| 1048 | 1048 | """ |
| 1049 | 1049 | return gcmp_sage(left.g, (<gen>right).g) |
| 1050 | 1050 | |
| 1051 | | def copy(gen self): |
| | 1051 | def __copy__(gen self): |
| 1052 | 1052 | _sig_on |
| 1053 | 1053 | return P.new_gen(gcopy(self.g)) |
| 1054 | 1054 | |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/modular/modsym/manin_symbols.py
|
a
|
b
|
|
| 1664 | 1664 | """ |
| 1665 | 1665 | raise NotImplementedError |
| 1666 | 1666 | |
| 1667 | | def copy(self): |
| | 1667 | def __copy__(self): |
| 1668 | 1668 | """ |
| 1669 | 1669 | Return a copy of this ManinSymbol. |
| 1670 | 1670 | |
| … |
… |
|
| 1673 | 1673 | sage: from sage.modular.modsym.manin_symbols import ManinSymbol, ManinSymbolList_gamma0 |
| 1674 | 1674 | sage: m = ManinSymbolList_gamma0(5,8) |
| 1675 | 1675 | sage: s = ManinSymbol(m,(2,2,3)) |
| 1676 | | sage: s2=s.copy() |
| | 1676 | sage: s2 = copy(s) |
| 1677 | 1677 | sage: s2 |
| 1678 | 1678 | [X^2*Y^4,(2,3)] |
| 1679 | 1679 | |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/modules/free_module.py
|
a
|
b
|
|
| 116 | 116 | sage: A.0[0] = 5 |
| 117 | 117 | Traceback (most recent call last): |
| 118 | 118 | ... |
| 119 | | ValueError: vector is immutable; please change a copy instead (use self.copy()) |
| | 119 | ValueError: vector is immutable; please change a copy instead (use copy()) |
| 120 | 120 | |
| 121 | 121 | We can save and load submodules and elements:: |
| 122 | 122 | |
| … |
… |
|
| 5984 | 5984 | sage: v[0] = 0 # immutable |
| 5985 | 5985 | Traceback (most recent call last): |
| 5986 | 5986 | ... |
| 5987 | | ValueError: vector is immutable; please change a copy instead (use self.copy()) |
| | 5987 | ValueError: vector is immutable; please change a copy instead (use copy()) |
| 5988 | 5988 | sage: sage.modules.free_module.basis_seq(V, V.gens()) |
| 5989 | 5989 | [ |
| 5990 | 5990 | (1, 0), |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/modules/free_module_element.pyx
|
a
|
b
|
|
| 510 | 510 | def _hash(self): |
| 511 | 511 | return hash(tuple(list(self))) |
| 512 | 512 | |
| 513 | | def copy(self): |
| | 513 | def __copy__(self): |
| 514 | 514 | """ |
| 515 | 515 | Make a copy of this vector. |
| 516 | 516 | |
| … |
… |
|
| 518 | 518 | |
| 519 | 519 | sage: v = vector([1..5]); v |
| 520 | 520 | (1, 2, 3, 4, 5) |
| 521 | | sage: w = v.copy() |
| | 521 | sage: w = copy(v) |
| 522 | 522 | sage: v == w |
| 523 | 523 | True |
| 524 | 524 | sage: v is w |
| … |
… |
|
| 528 | 528 | |
| 529 | 529 | sage: v = vector([1..5], sparse=True); v |
| 530 | 530 | (1, 2, 3, 4, 5) |
| 531 | | sage: v.copy() |
| | 531 | sage: copy(v) |
| 532 | 532 | (1, 2, 3, 4, 5) |
| 533 | 533 | """ |
| 534 | | return self.__copy__() |
| 535 | | |
| 536 | | def __copy__(self): |
| 537 | 534 | if self.is_sparse(): |
| 538 | 535 | return self.parent()(self.dict()) |
| 539 | 536 | else: |
| … |
… |
|
| 552 | 549 | sage: v[1] = 10 |
| 553 | 550 | Traceback (most recent call last): |
| 554 | 551 | ... |
| 555 | | ValueError: vector is immutable; please change a copy instead (use self.copy()) |
| | 552 | ValueError: vector is immutable; please change a copy instead (use copy()) |
| 556 | 553 | """ |
| 557 | 554 | self._is_mutable = 0 |
| 558 | 555 | |
| … |
… |
|
| 893 | 890 | sage: v[1:2] = [3,5] |
| 894 | 891 | Traceback (most recent call last): |
| 895 | 892 | ... |
| 896 | | ValueError: vector is immutable; please change a copy instead (use self.copy()) |
| | 893 | ValueError: vector is immutable; please change a copy instead (use copy()) |
| 897 | 894 | """ |
| 898 | 895 | if not self._is_mutable: |
| 899 | | raise ValueError, "vector is immutable; please change a copy instead (use self.copy())" |
| | 896 | raise ValueError, "vector is immutable; please change a copy instead (use copy())" |
| 900 | 897 | cdef Py_ssize_t k, d, n |
| 901 | 898 | d = self.degree() |
| 902 | 899 | R = self.base_ring() |
| … |
… |
|
| 1533 | 1530 | |
| 1534 | 1531 | if self._degree == 0: |
| 1535 | 1532 | if sparse == self.is_sparse(): |
| 1536 | | return self.copy() |
| | 1533 | from copy import copy |
| | 1534 | return copy(self) |
| 1537 | 1535 | elif sparse: |
| 1538 | 1536 | return self.sparse_vector() |
| 1539 | 1537 | else: |
| … |
… |
|
| 1591 | 1589 | # We would just use apply_map, except that Cython doesn't |
| 1592 | 1590 | # allow lambda functions |
| 1593 | 1591 | if self._degree == 0: |
| 1594 | | return self.copy() |
| | 1592 | from copy import copy |
| | 1593 | return copy(self) |
| 1595 | 1594 | |
| 1596 | 1595 | if self.is_sparse(): |
| 1597 | 1596 | v = dict([(i,z.derivative(var)) for i,z in self.dict().items()]) |
| … |
… |
|
| 1843 | 1842 | Set entry i of self to value. |
| 1844 | 1843 | """ |
| 1845 | 1844 | if not self._is_mutable: |
| 1846 | | raise ValueError, "vector is immutable; please change a copy instead (use self.copy())" |
| | 1845 | raise ValueError, "vector is immutable; please change a copy instead (use copy())" |
| 1847 | 1846 | i = int(i) |
| 1848 | 1847 | #if not isinstance(i, int): |
| 1849 | 1848 | # raise TypeError, "index must an integer" |
| … |
… |
|
| 1869 | 1868 | (5, 3) |
| 1870 | 1869 | """ |
| 1871 | 1870 | if not self._is_mutable: |
| 1872 | | raise ValueError, "vector is immutable; please change a copy instead (use self.copy())" |
| | 1871 | raise ValueError, "vector is immutable; please change a copy instead (use copy())" |
| 1873 | 1872 | cdef Py_ssize_t k, n, d |
| 1874 | 1873 | d = self.degree() |
| 1875 | 1874 | R = self.base_ring() |
| … |
… |
|
| 2198 | 2197 | Like __setitem__ but with no type or bounds checking. |
| 2199 | 2198 | """ |
| 2200 | 2199 | if not self._is_mutable: |
| 2201 | | raise ValueError, "vector is immutable; please change a copy instead (use self.copy())" |
| | 2200 | raise ValueError, "vector is immutable; please change a copy instead (use copy())" |
| 2202 | 2201 | i = int(i) |
| 2203 | 2202 | if x == 0: |
| 2204 | 2203 | if self._entries.has_key(i): |
| … |
… |
|
| 2225 | 2224 | TypeError: unable to convert x (=sqrt(2)) to an integer |
| 2226 | 2225 | """ |
| 2227 | 2226 | if not self._is_mutable: |
| 2228 | | raise ValueError, "vector is immutable; please change a copy instead (use self.copy())" |
| | 2227 | raise ValueError, "vector is immutable; please change a copy instead (use copy())" |
| 2229 | 2228 | i = int(i) |
| 2230 | 2229 | #if not isinstance(i, int): |
| 2231 | 2230 | # raise TypeError, "index must an integer" |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/modules/vector_double_dense.pyx
|
a
|
b
|
|
| 133 | 133 | |
| 134 | 134 | EXAMPLE: |
| 135 | 135 | sage: a = vector(RDF, range(9)) |
| 136 | | sage: a == a.copy() |
| | 136 | sage: a == copy(a) |
| 137 | 137 | True |
| 138 | 138 | """ |
| 139 | 139 | if self._degree == 0: |
| 140 | 140 | return self |
| 141 | | return self._new(self._vector_numpy.copy()) |
| | 141 | from copy import copy |
| | 142 | return self._new(copy(self._vector_numpy)) |
| 142 | 143 | |
| 143 | 144 | def __init__(self, parent, entries, coerce = True, copy = True): |
| 144 | 145 | """ |
| … |
… |
|
| 302 | 303 | (0.0, 2.0, 4.0) |
| 303 | 304 | """ |
| 304 | 305 | if self._degree == 0: |
| 305 | | return self.copy() |
| | 306 | from copy import copy |
| | 307 | return copy(self) |
| 306 | 308 | |
| 307 | 309 | cdef Vector_double_dense _right, _left |
| 308 | 310 | _right = right |
| … |
… |
|
| 320 | 322 | True |
| 321 | 323 | """ |
| 322 | 324 | if self._degree == 0: |
| 323 | | return self.copy() |
| | 325 | from copy import copy |
| | 326 | return copy(self) |
| 324 | 327 | |
| 325 | 328 | cdef Vector_double_dense _right, _left |
| 326 | 329 | _right = right |
| … |
… |
|
| 342 | 345 | if not right.parent() == self.parent(): |
| 343 | 346 | right = self.parent().ambient_module()(right) |
| 344 | 347 | if self._degree == 0: |
| 345 | | return self.copy() |
| | 348 | from copy import copy |
| | 349 | return copy(self) |
| 346 | 350 | |
| 347 | 351 | cdef Vector_double_dense _right, _left |
| 348 | 352 | _right = right |
| … |
… |
|
| 366 | 370 | right = self.parent().ambient_module()(right) |
| 367 | 371 | |
| 368 | 372 | if self._degree == 0: |
| 369 | | return self.copy() |
| | 373 | from copy import copy |
| | 374 | return copy(self) |
| 370 | 375 | |
| 371 | 376 | cdef Vector_double_dense _right, _left |
| 372 | 377 | _right = right |
| … |
… |
|
| 384 | 389 | (0, 3.0, 6.0) |
| 385 | 390 | """ |
| 386 | 391 | if self._degree == 0: |
| 387 | | return self.copy() |
| | 392 | from copy import copy |
| | 393 | return copy(self) |
| 388 | 394 | |
| 389 | 395 | return self._new(self._python_dtype(left)*self._vector_numpy) |
| 390 | 396 | |
| … |
… |
|
| 399 | 405 | (0, 3.0, 6.0) |
| 400 | 406 | """ |
| 401 | 407 | if self._degree == 0: |
| 402 | | return self.copy() |
| | 408 | from copy import copy |
| | 409 | return copy(self) |
| 403 | 410 | |
| 404 | 411 | return self._new(self._vector_numpy*self._python_dtype(right)) |
| 405 | 412 | |
| … |
… |
|
| 505 | 512 | sage: v.numpy() |
| 506 | 513 | array([], dtype=float64) |
| 507 | 514 | """ |
| 508 | | return self._vector_numpy.copy() |
| | 515 | from copy import copy |
| | 516 | return copy(self._vector_numpy) |
| 509 | 517 | |
| 510 | 518 | cdef _replace_self_with_numpy(self,cnumpy.ndarray numpy_array): |
| 511 | 519 | """ |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/modules/vector_integer_dense.pyx
|
a
|
b
|
|
| 144 | 144 | |
| 145 | 145 | """ |
| 146 | 146 | if not self._is_mutable: |
| 147 | | raise ValueError, "vector is immutable; please change a copy instead (use self.copy())" |
| | 147 | raise ValueError, "vector is immutable; please change a copy instead (use copy())" |
| 148 | 148 | cdef Integer z |
| 149 | 149 | if i < 0 or i >= self._degree: |
| 150 | 150 | raise IndexError |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/modules/vector_rational_dense.pyx
|
a
|
b
|
|
| 145 | 145 | |
| 146 | 146 | def __setitem__(self, Py_ssize_t i, x): |
| 147 | 147 | if not self._is_mutable: |
| 148 | | raise ValueError, "vector is immutable; please change a copy instead (use self.copy())" |
| | 148 | raise ValueError, "vector is immutable; please change a copy instead (use copy())" |
| 149 | 149 | cdef Rational z |
| 150 | 150 | if i < 0 or i >= self._degree: |
| 151 | 151 | raise IndexError |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/finite_field_element.py
|
a
|
b
|
|
| 393 | 393 | self.__multiplicative_order = order |
| 394 | 394 | return order |
| 395 | 395 | |
| 396 | | def copy(self): |
| | 396 | def __copy__(self): |
| 397 | 397 | """ |
| 398 | 398 | Return a copy of this element. |
| 399 | 399 | |
| … |
… |
|
| 404 | 404 | sage: a = k(5) |
| 405 | 405 | sage: a |
| 406 | 406 | 2 |
| 407 | | sage: a.copy() |
| | 407 | sage: copy(a) |
| 408 | 408 | 2 |
| 409 | | sage: b = a.copy() |
| | 409 | sage: b = copy(a) |
| 410 | 410 | sage: a == b |
| 411 | 411 | True |
| 412 | 412 | sage: a is b |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/fraction_field_element.pyx
|
a
|
b
|
|
| 176 | 176 | except NotImplementedError, s: |
| 177 | 177 | raise ArithmeticError, "unable to reduce because gcd algorithm not implemented on input" |
| 178 | 178 | |
| 179 | | def copy(self): |
| | 179 | def __copy__(self): |
| 180 | 180 | """ |
| 181 | 181 | EXAMPLES:: |
| 182 | 182 | |
| 183 | 183 | sage: R.<x,y> = ZZ[] |
| 184 | 184 | sage: f = x/y+1; f |
| 185 | 185 | (x + y)/y |
| 186 | | sage: f.copy() |
| | 186 | sage: copy(f) |
| 187 | 187 | (x + y)/y |
| 188 | 188 | """ |
| 189 | 189 | return self.__class__(self._parent, self.__numerator, |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/laurent_series_ring_element.pyx
|
a
|
b
|
|
| 940 | 940 | """ |
| 941 | 941 | return self.__u.prec() + self.__n |
| 942 | 942 | |
| 943 | | def copy(self): |
| | 943 | def __copy__(self): |
| 944 | 944 | return LaurentSeries(self._parent, self.__u.copy(), self.__n) |
| 945 | 945 | |
| 946 | 946 | |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/padics/padic_ZZ_pX_CA_element.pyx
|
a
|
b
|
|
| 1564 | 1564 | ZZ_to_mpz(&ans.value, &tmp_z) |
| 1565 | 1565 | return ans |
| 1566 | 1566 | |
| 1567 | | def copy(self): |
| | 1567 | def __copy__(self): |
| 1568 | 1568 | """ |
| 1569 | 1569 | Returns a copy of ``self``. |
| 1570 | 1570 | |
| … |
… |
|
| 1576 | 1576 | sage: W.<w> = R.ext(f) |
| 1577 | 1577 | sage: b = W(45, 17); b |
| 1578 | 1578 | 4*w^5 + 3*w^7 + w^9 + w^10 + 2*w^11 + w^12 + w^13 + 3*w^14 + w^16 + O(w^17) |
| 1579 | | sage: c = b.copy(); c |
| | 1579 | sage: c = copy(b); c |
| 1580 | 1580 | 4*w^5 + 3*w^7 + w^9 + w^10 + 2*w^11 + w^12 + w^13 + 3*w^14 + w^16 + O(w^17) |
| 1581 | 1581 | sage: c is b |
| 1582 | 1582 | False |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/padics/padic_ZZ_pX_CR_element.pyx
|
a
|
b
|
|
| 2190 | 2190 | # for now, a simple implementation |
| 2191 | 2191 | return self * (~right) |
| 2192 | 2192 | |
| 2193 | | def copy(self): |
| | 2193 | def __copy__(self): |
| 2194 | 2194 | """ |
| 2195 | 2195 | Returns a copy of ``self``. |
| 2196 | 2196 | |
| … |
… |
|
| 2202 | 2202 | sage: W.<w> = R.ext(f) |
| 2203 | 2203 | sage: b = W(45, 17); b |
| 2204 | 2204 | 4*w^5 + 3*w^7 + w^9 + w^10 + 2*w^11 + w^12 + w^13 + 3*w^14 + w^16 + O(w^17) |
| 2205 | | sage: c = b.copy(); c |
| | 2205 | sage: c = copy(b); c |
| 2206 | 2206 | 4*w^5 + 3*w^7 + w^9 + w^10 + 2*w^11 + w^12 + w^13 + 3*w^14 + w^16 + O(w^17) |
| 2207 | 2207 | sage: c is b |
| 2208 | 2208 | False |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/padics/padic_ZZ_pX_FM_element.pyx
|
a
|
b
|
|
| 837 | 837 | ZZ_pX_MulMod_pre(ans.value, self.value, ans.value, self.prime_pow.get_top_modulus()[0]) |
| 838 | 838 | return ans |
| 839 | 839 | |
| 840 | | def copy(self): |
| | 840 | def __copy__(self): |
| 841 | 841 | """ |
| 842 | 842 | Returns a copy of ``self``. |
| 843 | 843 | |
| … |
… |
|
| 849 | 849 | sage: W.<w> = R.ext(f) |
| 850 | 850 | sage: b = W(45); b |
| 851 | 851 | 4*w^5 + 3*w^7 + w^9 + w^10 + 2*w^11 + w^12 + w^13 + 3*w^14 + w^16 + 2*w^17 + w^19 + 4*w^20 + w^21 + 3*w^22 + 3*w^23 + 4*w^24 + O(w^25) |
| 852 | | sage: c = b.copy(); c |
| | 852 | sage: c = copy(b); c |
| 853 | 853 | 4*w^5 + 3*w^7 + w^9 + w^10 + 2*w^11 + w^12 + w^13 + 3*w^14 + w^16 + 2*w^17 + w^19 + 4*w^20 + w^21 + 3*w^22 + 3*w^23 + 4*w^24 + O(w^25) |
| 854 | 854 | sage: c is b |
| 855 | 855 | False |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/padics/padic_capped_absolute_element.pyx
|
a
|
b
|
|
| 807 | 807 | mpz_mod(ans.value, ans.value, self.prime_pow.pow_mpz_t_tmp(ans.absprec)[0]) |
| 808 | 808 | return ans |
| 809 | 809 | |
| 810 | | def copy(pAdicCappedAbsoluteElement self): |
| | 810 | def __copy__(pAdicCappedAbsoluteElement self): |
| 811 | 811 | """ |
| 812 | 812 | Returns a copy of ``self``. |
| 813 | 813 | |
| 814 | 814 | EXAMPLES:: |
| 815 | 815 | |
| 816 | | sage: a = ZpCA(5,6)(17); b = a.copy() |
| | 816 | sage: a = ZpCA(5,6)(17); b = copy(a) |
| 817 | 817 | sage: a == b |
| 818 | 818 | True |
| 819 | 819 | sage: a is b |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/padics/padic_capped_relative_element.pyx
|
a
|
b
|
|
| 1450 | 1450 | ans._normalized = self._normalized |
| 1451 | 1451 | return ans |
| 1452 | 1452 | |
| 1453 | | def copy(self): |
| | 1453 | def __copy__(self): |
| 1454 | 1454 | """ |
| 1455 | 1455 | Returns a copy of self. |
| 1456 | 1456 | |
| 1457 | 1457 | EXAMPLES:: |
| 1458 | 1458 | |
| 1459 | | sage: a = Zp(5,6)(17); b = a.copy() |
| | 1459 | sage: a = Zp(5,6)(17); b = copy(a) |
| 1460 | 1460 | sage: a == b |
| 1461 | 1461 | True |
| 1462 | 1462 | sage: a is b |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/padics/padic_fixed_mod_element.pyx
|
a
|
b
|
|
| 658 | 658 | mpz_mod(ans.value, self.value, self.prime_pow.pow_mpz_t_tmp(mpz_get_ui((<Integer>absprec).value))[0]) |
| 659 | 659 | return ans |
| 660 | 660 | |
| 661 | | def copy(self): |
| | 661 | def __copy__(self): |
| 662 | 662 | """ |
| 663 | 663 | Returns a copy of self. |
| 664 | 664 | |
| 665 | 665 | EXAMPLES:: |
| 666 | 666 | |
| 667 | | sage: a = ZpFM(5,6)(17); b = a.copy() |
| | 667 | sage: a = ZpFM(5,6)(17); b = copy(a) |
| 668 | 668 | sage: a == b |
| 669 | 669 | True |
| 670 | 670 | sage: a is b |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py
|
a
|
b
|
|
| 723 | 723 | variable = self.parent().variable_name() |
| 724 | 724 | return pari(self.list()).Polrev(variable) |
| 725 | 725 | |
| 726 | | def copy(self): |
| 727 | | return Polynomial_padic_capped_relative_dense(self.parent(), (self._poly.copy(), self._valbase, copy.copy(self._relprecs), self._normalized, copy.copy(self._valaddeds), copy.copy(self._list)), construct = True) |
| | 726 | def __copy__(self): |
| | 727 | return Polynomial_padic_capped_relative_dense(self.parent(), (copy.copy(self._poly), self._valbase, copy.copy(self._relprecs), self._normalized, copy.copy(self._valaddeds), copy.copy(self._list)), construct = True) |
| 728 | 728 | |
| 729 | 729 | def degree(self): |
| 730 | 730 | """ |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/polynomial/polynomial_element.pyx
|
a
|
b
|
|
| 2502 | 2502 | f = pari(v).Polrev() |
| 2503 | 2503 | Rpari = R.pari_nf() |
| 2504 | 2504 | if (Rpari.variable() != "a"): |
| 2505 | | Rpari = Rpari.copy() |
| | 2505 | Rpari = copy.copy(Rpari) |
| 2506 | 2506 | Rpari[0] = Rpari[0]("a") |
| 2507 | 2507 | Rpari[6] = [ x("a") for x in Rpari[6] ] |
| 2508 | 2508 | G = list(Rpari.nffactor(f)) |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/polynomial/polynomial_element_generic.py
|
a
|
b
|
|
| 610 | 610 | |
| 611 | 611 | if isinstance(x, Polynomial): |
| 612 | 612 | if x.parent() == self.parent(): |
| 613 | | self.__poly = x.__poly.copy() |
| | 613 | from copy import copy |
| | 614 | self.__poly = copy(x.__poly) |
| 614 | 615 | return |
| 615 | 616 | else: |
| 616 | 617 | x = [QQ(a) for a in x.list()] |
| … |
… |
|
| 868 | 869 | Return a copy of this polynomial. |
| 869 | 870 | """ |
| 870 | 871 | f = Polynomial_rational_dense(self.parent()) |
| 871 | | f.__poly = self.__poly.copy() |
| | 872 | from copy import copy |
| | 873 | f.__poly = copy(self.__poly) |
| 872 | 874 | return f |
| 873 | 875 | |
| 874 | 876 | def degree(self, gen=None): |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/power_series_poly.pyx
|
a
|
b
|
|
| 186 | 186 | |
| 187 | 187 | def _unsafe_mutate(self, i, value): |
| 188 | 188 | """ |
| 189 | | SAGE assumes throughout that commutative ring elements are immutable. |
| | 189 | Sage assumes throughout that commutative ring elements are immutable. |
| 190 | 190 | This is relevant for caching, etc. But sometimes you need to change |
| 191 | 191 | a power series and you really know what you're doing. That's |
| 192 | 192 | when this function is for you. |
| … |
… |
|
| 311 | 311 | |
| 312 | 312 | def __iter__(self): |
| 313 | 313 | """ |
| 314 | | Return an interator over the coefficients of this power series. |
| | 314 | Return an iterator over the coefficients of this power series. |
| 315 | 315 | |
| 316 | 316 | EXAMPLES: |
| 317 | 317 | sage: R.<t> = QQ[[]] |
| … |
… |
|
| 572 | 572 | return PowerSeries_poly(self._parent, self.__f.truncate(prec), |
| 573 | 573 | min(self._prec, prec), check=False) |
| 574 | 574 | |
| 575 | | def copy(self): |
| 576 | | """ |
| 577 | | Return a copy of self. |
| 578 | | |
| 579 | | EXAMPLES: |
| 580 | | sage: R.<t> = ZZ[[]] |
| 581 | | sage: f = t + t^3 |
| 582 | | sage: f.copy() |
| 583 | | t + t^3 |
| 584 | | sage: f.copy() == f |
| 585 | | True |
| 586 | | sage: f.copy() is f |
| 587 | | False |
| 588 | | """ |
| 589 | | return PowerSeries_poly(self._parent, self.__f, self._prec, check=False) |
| 590 | | |
| 591 | 575 | def list(self): |
| 592 | 576 | """ |
| 593 | 577 | Return the list of known coefficients for self. This is just |
-
diff -r ca1f31d6f6bf -r d1f2723e7fc7 sage/rings/rational.pyx
|
a
|
b
|
|
| 555 | 555 | elif i == 0: return 0 |
| 556 | 556 | else: return 1 |
| 557 | 557 | |
| 558 | | def copy(self): |
| | 558 | def __copy__(self): |
| 559 | 559 | """ |
| 560 | 560 | Return a copy of self. |
| 561 | 561 | |
| … |
… |
|
| 564 | 564 | EXAMPLES:: |
| 565 | 565 | |
| 566 | 566 | sage: a = -17/37 |
| 567 | | sage: a.copy() is a |
| | 567 | sage: copy(a) is a |
| 568 | 568 | False |
| 569 | 569 | |
| 570 | 570 | Coercion does not make a new copy:: |