# HG changeset patch
# User Xavier Caruso <xavier.caruso@normalesup.org>
# Date 1341738209 -7200
# Node ID b510f107752e0babcad7e1e2845cd1148d30dc49
# Parent 6fdfbac91d70604e701510fd469df37f860bbedb
Trac #13184: Unique parent assumption for homset
diff --git a/sage/categories/homset.py b/sage/categories/homset.py
a
|
b
|
from sage.categories.category import Cat |
68 | 68 | import morphism |
69 | 69 | from sage.structure.parent import Parent, Set_generic |
70 | 70 | from sage.misc.lazy_attribute import lazy_attribute |
71 | | from sage.misc.cachefunc import cached_function |
72 | 71 | import types |
73 | 72 | |
74 | 73 | ################################### |
… |
… |
def Hom(X, Y, category=None): |
157 | 156 | |
158 | 157 | TESTS: |
159 | 158 | |
| 159 | Homset are unique parents:: |
| 160 | |
| 161 | sage: k = GF(5) |
| 162 | sage: H1 = Hom(k,k) |
| 163 | sage: H2 = Hom(k,k) |
| 164 | sage: H1 is H2 |
| 165 | True |
| 166 | |
160 | 167 | Some doc tests in :mod:`sage.rings` (need to) break the unique parent |
161 | 168 | assumption. But if domain or codomain are not unique parents, then the hom |
162 | | set won't fit. That's to say, the hom set found in the cache will have a |
| 169 | set will not fit. That is to say, the hom set found in the cache will have a |
163 | 170 | (co)domain that is equal to, but not identic with, the given (co)domain. |
164 | 171 | |
165 | 172 | By :trac:`9138`, we abandon the uniqueness of hom sets, if the domain or |
… |
… |
def Hom(X, Y, category=None): |
227 | 234 | |
228 | 235 | try: |
229 | 236 | # Apparently X._Hom_ is supposed to be cached |
230 | | return X._Hom_(Y, category) |
| 237 | # but it is not in some cases (e.g. X is a finite field) |
| 238 | # To be investigated |
| 239 | H = X._Hom_(Y,category) |
| 240 | _cache[key] = H |
| 241 | return H |
231 | 242 | except (AttributeError, TypeError): |
232 | 243 | pass |
233 | 244 | |
diff --git a/sage/modules/vector_space_homspace.py b/sage/modules/vector_space_homspace.py
a
|
b
|
TESTS:: |
193 | 193 | import inspect |
194 | 194 | import sage.matrix.all as matrix |
195 | 195 | import sage.modules.free_module_homspace |
196 | | import vector_space_morphism |
197 | 196 | |
198 | 197 | # This module initially overrides just the minimum functionality necessary |
199 | 198 | # from sage.modules.free_module_homspace.FreeModuleHomSpace. |
… |
… |
class VectorSpaceHomspace(sage.modules.f |
333 | 332 | |
334 | 333 | sage: U = QQ^3 |
335 | 334 | sage: V = QQ^4 |
336 | | sage: W = QQ^3 |
| 335 | sage: W = FreeModule(QQ,3,sparse=True) |
337 | 336 | sage: X = QQ^4 |
338 | 337 | sage: H = Hom(U, V) |
339 | 338 | sage: K = Hom(W, X) |
| 339 | sage: H is K |
| 340 | False |
340 | 341 | |
341 | 342 | sage: A = matrix(QQ, 3, 4, [0]*12) |
342 | 343 | sage: f = H(A) |
343 | 344 | sage: B = matrix(QQ, 3, 4, range(12)) |
344 | 345 | sage: g = K(B) |
345 | | sage: f.parent() is g.parent() |
346 | | False |
| 346 | sage: f.parent() is H and g.parent() is K |
| 347 | True |
347 | 348 | |
348 | 349 | sage: h = H(g) |
349 | 350 | sage: f.parent() is h.parent() |
… |
… |
class VectorSpaceHomspace(sage.modules.f |
362 | 363 | Previously the above code resulted in a TypeError because the |
363 | 364 | dimensions of the matrix were incorrect. |
364 | 365 | """ |
365 | | import vector_space_morphism |
| 366 | from vector_space_morphism import is_VectorSpaceMorphism, VectorSpaceMorphism |
366 | 367 | D = self.domain() |
367 | 368 | C = self.codomain() |
368 | 369 | if matrix.is_Matrix(A): |
369 | 370 | pass |
370 | | elif vector_space_morphism.is_VectorSpaceMorphism(A): |
| 371 | elif is_VectorSpaceMorphism(A): |
371 | 372 | A = A.matrix() |
372 | 373 | elif inspect.isfunction(A): |
373 | 374 | try: |
… |
… |
class VectorSpaceHomspace(sage.modules.f |
393 | 394 | else: |
394 | 395 | msg = 'vector space homspace can only coerce matrices, vector space morphisms, functions or lists, not {0}' |
395 | 396 | raise TypeError(msg.format(A)) |
396 | | return vector_space_morphism.VectorSpaceMorphism(self, A) |
| 397 | return VectorSpaceMorphism(self, A) |
397 | 398 | |
398 | 399 | def _repr_(self): |
399 | 400 | r""" |
… |
… |
class VectorSpaceHomspace(sage.modules.f |
409 | 410 | 'dimension', '3', 'over', 'Rational', 'Field'] |
410 | 411 | """ |
411 | 412 | msg = 'Set of Morphisms (Linear Transformations) from {0} to {1}' |
412 | | return msg.format(self.domain(), self.codomain()) |
413 | | No newline at end of file |
| 413 | return msg.format(self.domain(), self.codomain()) |