Skip to content

Improving word construction #7520

@seblabbe

Description

@seblabbe

Improve the creation of a word from a word when the parent changes :

BEFORE:

sage: w = Word('abab')
sage: P = WordPaths('abcd')
sage: P(w)
word: abab
sage: type(w)
<class 'sage.combinat.words.word.FiniteWord_str'>
sage: type(P(w))
<class 'sage.combinat.words.word.FiniteWord_str'>

AFTER:

sage: w = Word('abab')
sage: P = WordPaths('abcd')
sage: P(w)
Path: abab
sage: type(w)
<class 'sage.combinat.words.word.FiniteWord_str'>
sage: type(P(w))
<class 'sage.combinat.words.paths.FiniteWordPath_square_grid_str'>

The following construction gets also faster with the patch applied :

BEFORE:

sage: w = Word([0,1]*10000)
sage: %timeit z = Words([2,0,1])(w)
1000 loops, best of 3: 586 µs per loop

AFTER:

sage: w = Word([0,1]*10000)
sage: %timeit z = Words([2,0,1])(w)
1000 loops, best of 3: 343 µs per loop

CC: @saliola

Component: combinatorics

Author: Sébastien Labbé

Reviewer: Franco Saliola

Merged: sage-4.3.4.alpha0

Issue created by migration from https://trac.sagemath.org/ticket/7520

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions