Conversation
Pull Request Test Coverage Report for Build 12099465068Details
💛 - Coveralls |
src/foapy/alphabet.py
Outdated
| {"message": f"Incorrect array form. Expected d1 array, exists {data.ndim}"} | ||
| ) | ||
|
|
||
| # Sort data positions |
There was a problem hiding this comment.
Maybe it would be clearer to write "Sort element indices" or "Get original indices of sorted data array"?
There was a problem hiding this comment.
@ChainsManipulator Indices that would sort an array?
https://numpy.org/doc/stable/reference/generated/numpy.argsort.html
src/foapy/alphabet.py
Outdated
|
|
||
| mask_shape = data.shape | ||
| unique_mask = np.empty(mask_shape, dtype=bool) | ||
| # Create tmp mask array to store True on positions where appears new value |
There was a problem hiding this comment.
"Create mask array to store True on positions where new value appears for the first time in the sorted array to distinguish where subarray of one element ends and another begins"
src/foapy/alphabet.py
Outdated
| # unique_mask = [True, False, True, False, True, True] | ||
| # a a c c d e | ||
| unique_mask = np.empty(data.shape, dtype=bool) | ||
| # First element is new |
There was a problem hiding this comment.
"First element is always new"
src/foapy/alphabet.py
Outdated
| # Set true on positions where value differs from previous | ||
| unique_mask[1:] = data[perm[1:]] != data[perm[:-1]] | ||
|
|
||
| # Create tmp array that will store reverse sorted mask array |
There was a problem hiding this comment.
"Create mask array to store True on positions of the data array where new value appears for the first time"
src/foapy/alphabet.py
Outdated
| result_mask[:1] = True | ||
| result_mask[perm[unique_mask]] = True | ||
|
|
||
| # Return elements that are first appears of unique values |
There was a problem hiding this comment.
"Return array of first occurrences of elements in the data array"
src/foapy/order.py
Outdated
| # Set true on positions where value differs from previous | ||
| unique_mask[1:] = data[perm[1:]] != data[perm[:-1]] | ||
|
|
||
| # Create tmp array that will store reverse sorted mask array |
There was a problem hiding this comment.
"Create mask array to store True on positions of the data array where new value appears for the first time"
| # perm = [ 0, 5, 1, 2, 4, 3] | ||
| # perm[unique_mask] = [ 0, 1, 4, 3] | ||
| # result_mask = [True, True, False, True, True, False] | ||
| # a c c e d a |
There was a problem hiding this comment.
I would have moved this one line higher and added that this is "data" array
There was a problem hiding this comment.
The difference is that on top in sorted data on bottom original order data
| # perm = [ 0, 5, 1, 2, 4, 3] | ||
| # perm[unique_mask] = [ 0, 1, 4, 3] | ||
| # result_mask = [True, True, False, True, True, False] | ||
| # a c c e d a |
There was a problem hiding this comment.
I would have moved this one line higher and added that this is "data" array
There was a problem hiding this comment.
The difference is that on top in sorted data on bottom original order data
src/foapy/intervals.py
Outdated
| mask[1:-1] = ar[perm[1:]] != ar[perm[:-1]] | ||
| mask[-1:] = True # or mask[-1] = True | ||
|
|
||
| # Save masks first and last appears of elements |
There was a problem hiding this comment.
"Create masks of first and last occurrences of elements by excluding first and last elements from unique_mask accordingly"
src/foapy/order.py
Outdated
| # a c c e d a | ||
| inverse_perm[perm] = np.arange(data.shape[0]) | ||
|
|
||
| # Create result array that count unique values starting from 0. |
There was a problem hiding this comment.
" Fill tmp result array with cumulative sums of number of unique values (starting from 0) to represent each element as a number in resulting order."
src/foapy/alphabet.py
Outdated
| {"message": f"Incorrect array form. Expected d1 array, exists {data.ndim}"} | ||
| ) | ||
|
|
||
| # Sort data positions |
There was a problem hiding this comment.
@ChainsManipulator Indices that would sort an array?
https://numpy.org/doc/stable/reference/generated/numpy.argsort.html
Co-authored-by: Igor Rodionov <goruha@gmail.com>
src/foapy/alphabet.py
Outdated
| {"message": f"Incorrect array form. Expected d1 array, exists {data.ndim}"} | ||
| ) | ||
|
|
||
| # Sort data positions |
There was a problem hiding this comment.
| # Sort data positions | |
| # Indices that would sort data array |
src/foapy/alphabet.py
Outdated
| # Set true on positions where value differs from previous | ||
| unique_mask[1:] = data[perm[1:]] != data[perm[:-1]] | ||
|
|
||
| # Create tmp array that will store reverse sorted mask array |
There was a problem hiding this comment.
| # Create tmp array that will store reverse sorted mask array | |
| # Create mask array to store True on positions of the data array where new value appears for the first time |
src/foapy/alphabet.py
Outdated
| result_mask[:1] = True | ||
| result_mask[perm[unique_mask]] = True | ||
|
|
||
| # Return elements that are first appears of unique values |
There was a problem hiding this comment.
| # Return elements that are first appears of unique values | |
| # Return array of first occurrences of elements in the data array |
src/foapy/intervals.py
Outdated
| # ar = ['a', 'd', 'e', 'c', 'c', 'a'] | ||
| ar = ar[::-1] | ||
|
|
||
| # Sort data positions |
There was a problem hiding this comment.
| # Sort data positions | |
| # Get original indices of sorted data array |
src/foapy/intervals.py
Outdated
| # perm = [0, 5, 1, 2, 4, 3] | ||
| perm = ar.argsort(kind="mergesort") | ||
|
|
||
| # Create tmp mask array to store True on positions where appears new value. |
There was a problem hiding this comment.
| # Create tmp mask array to store True on positions where appears new value. | |
| # Create mask array to store True on positions where new value appears for the first time in the sorted array to distinguish where subarray of one element ends and another begins |
| # result = [1, 2, 1, 4, 5, 5] | ||
| result = intervals[inverse_perm] | ||
| elif mod == mode.cycle: | ||
| # For cycle mode we permute intervals array to the original order |
There was a problem hiding this comment.
| # For cycle mode we permute intervals array to the original order | |
| # For cycle mode we permute intervals array to the original arrangement |
| # result = [1, 2, 1, 4, 5, 5] | ||
|
|
||
| # Create 2-dimensional array size of (2, len(ar)) | ||
| # Zero row is for intervals the first appearance of the element and intervals |
There was a problem hiding this comment.
| # Zero row is for intervals the first appearance of the element and intervals | |
| # Zero row is for the intervals of the first appearance of the element and intervals |
| # Create 2-dimensional array size of (2, len(ar)) | ||
| # Zero row is for intervals the first appearance of the element and intervals | ||
| # for intermediate appearances | ||
| # First row will store intervals for the last appearance of the element |
There was a problem hiding this comment.
| # First row will store intervals for the last appearance of the element | |
| # First row will store only intervals for the last appearance of the elements |
| # ] | ||
| result[last_mask, 1] = len(ar) - perm[last_mask] | ||
|
|
||
| # Permute intervals array to the original order |
There was a problem hiding this comment.
| # Permute intervals array to the original order | |
| # Permute intervals array to the original arrangement |
| result = result[result != 0] | ||
|
|
||
| if bind == binding.end: | ||
| # For binding to the end, we need to reverse the result |
There was a problem hiding this comment.
| # For binding to the end, we need to reverse the result | |
| # For binding to the end, we need to reverse the result back |
What
alphabetmethodintervalsmethodordermethod