|
196 | 196 |
|
197 | 197 | class FreeModuleFactory(UniqueFactory):
|
198 | 198 | r"""
|
199 |
| - Create the free module over the given commutative ring of the given |
| 199 | + Factory class for the finite-dimensional free modules with standard basis |
| 200 | + """ |
| 201 | + def create_key(self, base_ring, rank, sparse=False, inner_product_matrix=None): |
| 202 | + """ |
| 203 | + TESTS:: |
| 204 | +
|
| 205 | + sage: loads(dumps(ZZ^6)) is ZZ^6 |
| 206 | + True |
| 207 | + sage: loads(dumps(RDF^3)) is RDF^3 |
| 208 | + True |
| 209 | +
|
| 210 | + TODO: replace the above by ``TestSuite(...).run()``, once |
| 211 | + :meth:`_test_pickling` will test unique representation and not |
| 212 | + only equality. |
| 213 | + """ |
| 214 | + rank = int(sage.rings.integer.Integer(rank)) |
| 215 | + |
| 216 | + if not (inner_product_matrix is None): |
| 217 | + inner_product_matrix = sage.matrix.matrix_space.MatrixSpace(base_ring, rank)(inner_product_matrix) |
| 218 | + inner_product_matrix.set_immutable() |
| 219 | + |
| 220 | + return (base_ring, rank, sparse, inner_product_matrix) |
| 221 | + |
| 222 | + def create_object(self, version, key): |
| 223 | + |
| 224 | + base_ring, rank, sparse, inner_product_matrix = key |
| 225 | + |
| 226 | + if inner_product_matrix is not None: |
| 227 | + from .free_quadratic_module import FreeQuadraticModule |
| 228 | + return FreeQuadraticModule(base_ring, rank, inner_product_matrix=inner_product_matrix, sparse=sparse) |
| 229 | + |
| 230 | + if not isinstance(sparse,bool): |
| 231 | + raise TypeError("Argument sparse (= %s) must be True or False" % sparse) |
| 232 | + |
| 233 | + if not (hasattr(base_ring,'is_commutative') and base_ring.is_commutative()): |
| 234 | + warn("""You are constructing a free module |
| 235 | +over a noncommutative ring. Sage does not have a concept |
| 236 | +of left/right and both sided modules, so be careful. |
| 237 | +It's also not guaranteed that all multiplications are |
| 238 | +done from the right side.""") |
| 239 | + |
| 240 | + # raise TypeError, "The base_ring must be a commutative ring." |
| 241 | + |
| 242 | + try: |
| 243 | + if not sparse and isinstance(base_ring,sage.rings.real_double.RealDoubleField_class): |
| 244 | + return RealDoubleVectorSpace_class(rank) |
| 245 | + |
| 246 | + elif not sparse and isinstance(base_ring,sage.rings.complex_double.ComplexDoubleField_class): |
| 247 | + return ComplexDoubleVectorSpace_class(rank) |
| 248 | + |
| 249 | + elif base_ring.is_field(): |
| 250 | + return FreeModule_ambient_field(base_ring, rank, sparse=sparse) |
| 251 | + |
| 252 | + elif base_ring in PrincipalIdealDomains(): |
| 253 | + return FreeModule_ambient_pid(base_ring, rank, sparse=sparse) |
| 254 | + |
| 255 | + elif isinstance(base_ring, sage.rings.number_field.order.Order) \ |
| 256 | + and base_ring.is_maximal() and base_ring.class_number() == 1: |
| 257 | + return FreeModule_ambient_pid(base_ring, rank, sparse=sparse) |
| 258 | + |
| 259 | + elif isinstance(base_ring, ring.IntegralDomain) or base_ring.is_integral_domain(): |
| 260 | + return FreeModule_ambient_domain(base_ring, rank, sparse=sparse) |
| 261 | + |
| 262 | + else: |
| 263 | + return FreeModule_ambient(base_ring, rank, sparse=sparse) |
| 264 | + except NotImplementedError: |
| 265 | + return FreeModule_ambient(base_ring, rank, sparse=sparse) |
| 266 | + |
| 267 | +FreeModuleFactory_with_standard_basis = FreeModuleFactory("FreeModule") |
| 268 | + |
| 269 | +def FreeModule(base_ring, rank_or_basis_keys=None, sparse=False, inner_product_matrix=None, *, |
| 270 | + with_basis='standard', rank=None, basis_keys=None, **args): |
| 271 | + """ |
| 272 | + Create a free module over the given commutative ``base_ring`` of the given |
200 | 273 | rank.
|
201 | 274 |
|
202 | 275 | INPUT:
|
@@ -322,78 +395,6 @@ class FreeModuleFactory(UniqueFactory):
|
322 | 395 | Refactor modules such that it only counts what category the base
|
323 | 396 | ring belongs to, but not what is its Python class.
|
324 | 397 |
|
325 |
| - """ |
326 |
| - def create_key(self, base_ring, rank, sparse=False, inner_product_matrix=None): |
327 |
| - """ |
328 |
| - TESTS:: |
329 |
| -
|
330 |
| - sage: loads(dumps(ZZ^6)) is ZZ^6 |
331 |
| - True |
332 |
| - sage: loads(dumps(RDF^3)) is RDF^3 |
333 |
| - True |
334 |
| -
|
335 |
| - TODO: replace the above by ``TestSuite(...).run()``, once |
336 |
| - :meth:`_test_pickling` will test unique representation and not |
337 |
| - only equality. |
338 |
| - """ |
339 |
| - rank = int(sage.rings.integer.Integer(rank)) |
340 |
| - |
341 |
| - if not (inner_product_matrix is None): |
342 |
| - inner_product_matrix = sage.matrix.matrix_space.MatrixSpace(base_ring, rank)(inner_product_matrix) |
343 |
| - inner_product_matrix.set_immutable() |
344 |
| - |
345 |
| - return (base_ring, rank, sparse, inner_product_matrix) |
346 |
| - |
347 |
| - def create_object(self, version, key): |
348 |
| - |
349 |
| - base_ring, rank, sparse, inner_product_matrix = key |
350 |
| - |
351 |
| - if inner_product_matrix is not None: |
352 |
| - from .free_quadratic_module import FreeQuadraticModule |
353 |
| - return FreeQuadraticModule(base_ring, rank, inner_product_matrix=inner_product_matrix, sparse=sparse) |
354 |
| - |
355 |
| - if not isinstance(sparse,bool): |
356 |
| - raise TypeError("Argument sparse (= %s) must be True or False" % sparse) |
357 |
| - |
358 |
| - if not (hasattr(base_ring,'is_commutative') and base_ring.is_commutative()): |
359 |
| - warn("""You are constructing a free module |
360 |
| -over a noncommutative ring. Sage does not have a concept |
361 |
| -of left/right and both sided modules, so be careful. |
362 |
| -It's also not guaranteed that all multiplications are |
363 |
| -done from the right side.""") |
364 |
| - |
365 |
| - # raise TypeError, "The base_ring must be a commutative ring." |
366 |
| - |
367 |
| - try: |
368 |
| - if not sparse and isinstance(base_ring,sage.rings.real_double.RealDoubleField_class): |
369 |
| - return RealDoubleVectorSpace_class(rank) |
370 |
| - |
371 |
| - elif not sparse and isinstance(base_ring,sage.rings.complex_double.ComplexDoubleField_class): |
372 |
| - return ComplexDoubleVectorSpace_class(rank) |
373 |
| - |
374 |
| - elif base_ring.is_field(): |
375 |
| - return FreeModule_ambient_field(base_ring, rank, sparse=sparse) |
376 |
| - |
377 |
| - elif base_ring in PrincipalIdealDomains(): |
378 |
| - return FreeModule_ambient_pid(base_ring, rank, sparse=sparse) |
379 |
| - |
380 |
| - elif isinstance(base_ring, sage.rings.number_field.order.Order) \ |
381 |
| - and base_ring.is_maximal() and base_ring.class_number() == 1: |
382 |
| - return FreeModule_ambient_pid(base_ring, rank, sparse=sparse) |
383 |
| - |
384 |
| - elif isinstance(base_ring, ring.IntegralDomain) or base_ring.is_integral_domain(): |
385 |
| - return FreeModule_ambient_domain(base_ring, rank, sparse=sparse) |
386 |
| - |
387 |
| - else: |
388 |
| - return FreeModule_ambient(base_ring, rank, sparse=sparse) |
389 |
| - except NotImplementedError: |
390 |
| - return FreeModule_ambient(base_ring, rank, sparse=sparse) |
391 |
| - |
392 |
| -FreeModuleFactory_with_standard_basis = FreeModuleFactory("FreeModule") |
393 |
| - |
394 |
| -def FreeModule(base_ring, rank_or_basis_keys=None, sparse=False, inner_product_matrix=None, *, |
395 |
| - with_basis='standard', rank=None, basis_keys=None, **args): |
396 |
| - """ |
397 | 398 |
|
398 | 399 | EXAMPLES::
|
399 | 400 |
|
|
0 commit comments