knittingpattern icon indicating copy to clipboard operation
knittingpattern copied to clipboard

measure and change unique

Open niccokunzmann opened this issue 8 years ago • 9 comments

Do a performance measurement of both implementations:

  • knittingpattern.utils.unique
  • uniq

depending on what is faster in CPython3.5, use it as standard implementation.

niccokunzmann avatar Aug 21 '16 07:08 niccokunzmann

Can we use python set...? https://docs.python.org/3/library/stdtypes.html#set

jainaman224 avatar Feb 25 '17 21:02 jainaman224

sure.

niccokunzmann avatar Feb 25 '17 21:02 niccokunzmann

In #73 is a discussion relating to this.

niccokunzmann avatar Feb 26 '17 11:02 niccokunzmann

@jainaman224 You can use sets. I do not care so much how it is implemented this issue is about making it faster.

niccokunzmann avatar Feb 26 '17 11:02 niccokunzmann

@pytest.mark.parametrize("input,expected_result", [
        ([], []), ([[1, 1, 1, 1, 1]], [1]),
        ([[1, 2, 3], [4, 3, 2, 1]], [1, 2, 3, 4]),
        ([[None, 4], [4, 6, None]], [None, 4, 6]),
        ([[[], [1]], [[1], [0], []]], [[], [1], [0]])])

I can't use set or map because we are using different nesting for result and including None as unique element.

It should be according to me:

@pytest.mark.parametrize("input,expected_result", [
        ([], []), ([[1, 1, 1, 1, 1]], [1]),
        ([[1, 2, 3], [4, 3, 2, 1]], [1, 2, 3, 4]),
        ([[None, 4], [4, 6, None]], [4, 6]),
        ([[[], [1]], [[1], [0], []]], Error)])

@niccokunzmann What do you think...?

jainaman224 avatar Feb 26 '17 13:02 jainaman224

([[[], [1]], [[1], [0], []]], Error)])

The last case is in case people specify a color as a list. However, this may not be of interest for now. If you think, we should remove the test or test an error, that is fine. I do not know if it is useful.

([[None, 4], [4, 6, None]], [None, 4, 6]),

The question is: is no color also a color? My answer is yes: some patterns may not specify a color, so None is also a color. What do you think? We could argue that "for all instructions in a row: the color of the instruction must be present in the row.instruction_colors"

niccokunzmann avatar Feb 26 '17 13:02 niccokunzmann

I also agree upon this. No color is also a color. So, we can assign a special integer for it. As None is not accepted by set as element. Is it ok...?

jainaman224 avatar Feb 26 '17 13:02 jainaman224

>>> s  = set()
>>> s.add(None)
>>> 

None is accepted.

niccokunzmann avatar Feb 26 '17 13:02 niccokunzmann

Okay, There was error due to sorting. Sorry for misunderstanding.

jainaman224 avatar Feb 26 '17 13:02 jainaman224