-
Notifications
You must be signed in to change notification settings - Fork 0
Added comments to methods implementation #41
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
524445d
a640eb6
283f478
14db979
e7b52bd
0926453
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -43,20 +43,51 @@ def alphabet(X) -> np.ndarray: | |||||
| >>> result | ||||||
| Exception | ||||||
| """ | ||||||
| # ex.: | ||||||
| # data = ['a', 'c', 'c', 'e', 'd', 'a'] | ||||||
| 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 | ||||||
|
||||||
| # Sort data positions | |
| # Indices that would sort data array |
Outdated
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"
ChainsManipulator marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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"
ChainsManipulator marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
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"
Outdated
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 |
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.
| # a a c c d e | |
| # sorted data array a a c c d e |
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
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.
| # a c c e d a | |
| # original data array a c c e d a |
Outdated
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"
Outdated
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 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -61,52 +61,250 @@ def intervals(X, bind, mod): | |||||
| raise ValueError( | ||||||
| {"message": "Invalid mode value. Use mode.lossy,normal,cycle or redundant."} | ||||||
| ) | ||||||
|
|
||||||
| # ex.: | ||||||
| # ar = ['a', 'c', 'c', 'e', 'd', 'a'] | ||||||
| ar = np.asanyarray(X) | ||||||
|
|
||||||
| if ar.shape == (0,): | ||||||
| return [] | ||||||
|
|
||||||
| if bind == binding.end: | ||||||
| # For binding to the end, we need to reverse the array | ||||||
| # ar = ['a', 'd', 'e', 'c', 'c', 'a'] | ||||||
| ar = ar[::-1] | ||||||
|
|
||||||
| # Sort data positions | ||||||
|
||||||
| # Sort data positions | |
| # Get original indices of sorted data array |
Outdated
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"
Outdated
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 |
Outdated
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.
"to use it as both first occurrence marker and last occurrence marker depending on the shift of the data array"
Outdated
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.
| # because we want to use the array for all binding modes. | |
| # to use it as both first occurrence marker and last occurrence marker depending on the shift of the data array |
Outdated
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.
Duplicate with line 82
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.
| # a a c c d e | |
| # sorted data array a a c c d e |
Outdated
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.
It is just "mask" in code
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 appears a a c c d e | |
| # First occurrence a a c c d e |
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.
| # Last appears a a c c d e | |
| # Last occurrence a a c c d e |
Outdated
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"
Outdated
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.
| # Save masks first and last appears of elements | |
| # Create masks of first and last occurrences of elements by excluding first and last elements from unique_mask accordingly |
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.
| # Intervals of first elements appears would be wrong on that stage. | |
| # Intervals of the first occurrence of all elements would be wrong on that stage. |
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 |
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 clarity it is better to use "arrangement" here.
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 normal mode we permute intervals array to the original order | |
| # For normal mode we permute intervals array to the original arrangement |
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 |
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 |
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 |
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 |
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 |
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