Opened 13 years ago

Closed 13 years ago

#7519 closed enhancement (fixed)

Allowing the choice of word datatype for images under WordMorphism

Reported by: slabbe Owned by: slabbe
Priority: major Milestone: sage-4.3
Component: combinatorics Keywords:
Cc: vdelecroix, saliola Merged in: sage-4.3.alpha1
Authors: Sébastien Labbé Reviewers: Franco Saliola
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

By default, the image of a word under a morphism is given by a iterator which is good because it is returned in constant time but which is bad because it is not directly picklable.

sage: m = WordMorphism({0:[0,1], 1:[1,0,0,1]})
sage: print m
WordMorphism: 0->01, 1->1001
sage: W = m.domain()
sage: w = W([0,1,1,1])
sage: type(w)
<class 'sage.combinat.words.word.FiniteWord_list'>
sage: z = m(w)
sage: type(z)
<class 'sage.combinat.words.word.FiniteWord_iter_with_caching'>
sage: loads(dumps(z))
Traceback (most recent call last):
...
PicklingError: Can't pickle <type 'generator'>: attribute lookup __builtin__.generator failed

This patch allows one to suggest under which datatype to represent the word :

sage: m = WordMorphism({0:[0,1], 1:[1,0,0,1]})
sage: z = m([0,1,1,1], datatype='list')
sage: type(z)
<class 'sage.combinat.words.word.FiniteWord_list'>
sage: loads(dumps(z))
word: 01100110011001

It also leaves the current default behavior :

sage: m = WordMorphism({0:[0,1], 1:[1,0,0,1]})
sage: m([0,1,1,1])
word: 01100110011001
sage: type(_)
<class 'sage.combinat.words.word.FiniteWord_iter_with_caching'>

Attachments (1)

trac_7519_wordmorphism_datatype_choice-sl.patch (6.3 KB) - added by slabbe 13 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 13 years ago by slabbe

  • Cc vdelecroix saliola added
  • Status changed from new to needs_review

comment:2 Changed 13 years ago by saliola

This patch seems to depend on #7405.

Patches apply cleanly on top of sage-4.3.alpha0.

The doctests in sage.combinat.words pass.

I'm running the full test suite now. Will report back soon.

comment:3 Changed 13 years ago by saliola

  • Status changed from needs_review to positive_review

Tests pass. Positive review.

comment:4 Changed 13 years ago by saliola

  • Authors set to Sébastien Labbé
  • Reviewers set to Franco Saliola

comment:5 Changed 13 years ago by slabbe

Great. Thank you Franco for the quick review.

comment:6 Changed 13 years ago by mhansen

  • Merged in set to sage-4.3.alpha1
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.