-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added comments to methods implementation #41
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 12099465068Details
💛 - Coveralls |
src/foapy/alphabet.py
Outdated
data = np.asanyarray(X) | ||
if data.ndim > 1: # Checking for d1 array | ||
raise Not1DArrayException( | ||
{"message": f"Incorrect array form. Expected d1 array, exists {data.ndim}"} | ||
) | ||
|
||
# Sort data positions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ChainsManipulator Indices that would sort an array
?
https://numpy.org/doc/stable/reference/generated/numpy.argsort.html
src/foapy/alphabet.py
Outdated
perm = data.argsort(kind="mergesort") | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"First element is always new"
src/foapy/alphabet.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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[perm[unique_mask]] = True | ||
|
||
# Return elements that are first appears of unique values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Return array of first occurrences of elements in the data array"
src/foapy/order.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have moved this one line higher and added that this is "data" array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have moved this one line higher and added that this is "data" array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is that on top in sorted data on bottom original order data
src/foapy/intervals.py
Outdated
mask_shape = ar.shape | ||
mask = np.empty(mask_shape[0] + 1, dtype=bool) | ||
mask[:1] = True | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Create masks of first and last occurrences of elements by excluding first and last elements from unique_mask accordingly"
src/foapy/order.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" 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
data = np.asanyarray(X) | ||
if data.ndim > 1: # Checking for d1 array | ||
raise Not1DArrayException( | ||
{"message": f"Incorrect array form. Expected d1 array, exists {data.ndim}"} | ||
) | ||
|
||
# Sort data positions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
data = np.asanyarray(X) | ||
if data.ndim > 1: # Checking for d1 array | ||
raise Not1DArrayException( | ||
{"message": f"Incorrect array form. Expected d1 array, exists {data.ndim}"} | ||
) | ||
|
||
# Sort data positions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Sort data positions | |
# Indices that would sort data array |
src/foapy/alphabet.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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[perm[unique_mask]] = True | ||
|
||
# Return elements that are first appears of unique values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 = ar[::-1] | ||
|
||
# Sort data positions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Sort data positions | |
# Get original indices of sorted data array |
src/foapy/intervals.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 = 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# For binding to the end, we need to reverse the result | |
# For binding to the end, we need to reverse the result back |
What
alphabet
methodintervals
methodorder
method