Giter Club home page Giter Club logo

pygorithm's Introduction

Pygorithm

Packagist

Downloads

Documentation Status

Python 3.6

Say Thanks!

Contributors

A Python module to learn all the major algorithms on the go!
Purely for educational purposes

image

Features

  • Super easy to use
  • A very easy to understand Documentation
  • Get the code right in your editor
  • Get time complexities on the go

Installation

  • Just fire the following command in your terminal:
pip3 install pygorithm
  • It's that easy. If you are using Python 2.7 use pip instead. Depending on your
    permissions, you might need to use pip install --user pygorithm to install.
  • Or you can download the source code from here, and then just install the package using
python setup.py install

Quick Start Guide

  • To sort your list
  • To get the code for function used
  • To get the time complexity of an algorithm
  • To see all the available functions in a module, you can just type help() with the module name as argument. For example,

Tests

* Just type in the following command to run the tests :

python3 -m unittest
  • This will run all the tests defined in the files of the tests/ directory

Donation

If you have found my softwares to be of any use to you, do consider helping me pay my internet bills. This would encourage me to create many such softwares :)

pygorithm's People

Contributors

aesee avatar agrdivyam avatar amicks avatar antmarakis avatar anubhav9199 avatar ashutoshcp avatar bhageena avatar dhadad avatar dmytrostriletskyi avatar dstark85 avatar kgashok avatar kingdion avatar mohamedkiouaz avatar omkarpathak avatar pratiknarola avatar quocdat32461997 avatar rathod-sahaab avatar s-sanyal avatar sharadbhat avatar skeen avatar souo avatar sudo-kid avatar tjstretchalot avatar tsehori avatar vhag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pygorithm's Issues

Abstract interface for classes

Hi!

As I see, all classes in data_structures module inherit from object, but have very similar interfaces.

What do you think about some refactoring to provide base abstract class to inherit from? It will be easier for new developers, because they will know for sure what methods should their classes implement. Additionally, similar refactoring can be done in other modules as well.

Could implement this as a PR, if you're ok with that.

Speaking about the disadvantages of such refactoring, a source code returned by get_code method may not be as clear as it is now, but on the other hand it will let users to focus only on the main parts of an implementation.

Which Version of Python?

Hello!

A couple of years ago I wrote an implementation for Tries. I am rewriting/updating it to post it here.

One question I have is whether I should make the code compatible with both Python 2 and 3. In the documentation you mention both, so I assume I need to make it backwards compatible?

Error in pygorithm.geometry

>>> from pygorithm.geometry import rect_broad_phase Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'pygorithm.geometry'

This is the error that I am getting constantly. The code was merged from PR #50. Searching SO for error yielded that any circular dependency would cause such an error. But, there is no such dependency what so ever. @aesee can you see to it what's the problem?

Help needed in Documentation

Some code has broken the documentation. The sphinx autodoc helps to automatically load the classes and its member functions in the documentation. But for some reason, this is not working.
`
.. automodule:: pygorithm.data_structures.stack

 Stack
 ------

 .. autoclass:: Stack
    :members:

`

This is the code for automatically documenting classes.
This is how latest docs appear: Latest

This is how stable docs appear: Stable

Better way to do images?

I am hoping for comment on my latest commit to the dev branch (f044a65) specifically regarding this folder: https://github.com/OmkarPathak/pygorithm/tree/dev/imgs/test_geometry/test_extrapolated_intersection/out

It contains a lot of images that help me visualize what the tests are doing. They look like:

ah04_test_line_line_intr_later

They are referenced as explained here: https://github.com/OmkarPathak/pygorithm/blob/dev/tests/test_geometry.py#L1455
Do you think that it's fine that there are a lot of these files? I can't think of any good alternatives.

The `quadtree` code is empty at 1.0.4

After

pip install https://github.com/OmkarPathak/pygorithm/releases/download/v1.0.4/pygorithm-1.0.4-py2.py3-none-any.whl

I can not import QuadTreeEntity from anywhere,

So I checked the code at pygorithm\data_structures\quadtree.py in site-packages

Here is what I got

"""
Author: Timothy Moore
Created On: 31th August 2017

Defines a two-dimensional quadtree of arbitrary
depth and bucket size.
"""
import inspect

from pygorithm.geometry import (vector2, polygon2, rect2)

class QuadTree(object):
    """
    A quadtree is a sorting tool for two-dimensional space, most
    commonly used to reduce the number of required collision 
    calculations in a two-dimensional scene. In this context, 
    the scene is stepped without collision detection, then a 
    quadtree is constructed from all of the boundaries
    """
    @staticmethod
    def get_code():
        """
        Get the code for the QuadTree class
        
        :returns: code for QuadTree
        :rtype: string
        """
        return inspect.getsource(QuadTree)

Is there anything I missed?

btw, the source_code.zip is ok.

Inconsistent Code

@AllstonMickey PR #20 is giving some error. Please check all the errors before committing the code

Jupyter Notebooks?

Do you have any plans to add jupyter notebooks for the algorithms? I could help with that if it's something you'd be interested in.

Proposal/Ideas of things to add

Proposals / Ideas

'bad title'

I'd like to propose some things that should be added to this! I'm by no means advanced enough to understand some things here (stacks, heaps, A-star), but I definitely thing we should expand to even more examples as well as other things!

Please read this and let me know if any seem like good/bad ideas!!

Data Structures


  • Hash Maps / Hash Tables
  • Binary Heap
  • Matrix

Math


  • Factorial
  • PI
  • Summation
  • Sequences?
  • Common formulas: Quadratic, slope, distance, ect.
  • Binary Conversion: bin to hex, bin to ascii, ascii to hex, ect
  • Union
  • Partition

Geometry


  • Collision detecion
  • Euclidean Distance
  • Triangluation
  • Maxmimum Area

Others


  • Physics?
  • Iteration

These are just some idea's I;ve have had, feel free to let me know if this is anything interesting!

importing strings package

I tried import the package string like this:
from pygorithm import strings (like the documentation says).
But a only figured that when I typed:
from pygorithm import string (like the pypi repository)

BinaryTree class does not have adding-node functions

In tree.py, the BinaryTree class does not have functions which add nodes or delete nodes. There are only getting data functions only.
If there is no special purposes for leaving the BinaryTree class without adding-node class, I will add adding-node functions the class.
screenshot 66

Suggestion: Alternative names

Hi,

I imagine a lot of algorithms have alternative names, which are also utilized frequently: say binsort vs bucketsort. Only having one name listed could be a source of confusion for students, who are only familiar with a synonymous term.

I therefore suggest adding a new method to the interface, aka: alternative_names(), which would return a (possibly empty) list of common synonyms.

Geometry

I'm working on separating-axis-theorem geometry on my fork at the moment. It's going to probably take a few days before it's ready to merge, but my first-pass at the minimum documentation is ready if you want to monitor progress to avoid duplicating work or have any thoughts/concerns.

In order for me to test the documentation I setup my fork through readthedocs as well.

http://pygorithm-fork.readthedocs.io/en/latest/Geometry.html

Data Structures and Searching UnitTests Failing

test_data_structures and test_searching.py are failing their UnitTests

test_data_structures

Error
Traceback (most recent call last):
  File "C:\Users\doarni\AppData\Local\Continuum\Anaconda3\lib\unittest\case.py", line 58, in testPartExecutor
    yield
  File "C:\Users\doarni\AppData\Local\Continuum\Anaconda3\lib\unittest\case.py", line 600, in run
    testMethod()
  File "C:\Users\doarni\Dev\pygorithm\tests\test_data_structure.py", line 39, in test_infix_to_postfix
    resultString = result.infix_to_postfix()
  File "C:\Users\doarni\Dev\pygorithm\pygorithm\data_structures\stack.py", line 131, in infix_to_postfix
    and self.__precedence(self.expression[i] <= self.__precedence(self.my_stack.peek())):
TypeError: unorderable types: str() <= int()

.....
======================================================================
ERROR: test_infix_to_postfix (tests.test_data_structure.TestInfixToPostfix)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\doarni\Dev\pygorithm\tests\test_data_structure.py", line 39, in test_infix_to_postfix
    resultString = result.infix_to_postfix()
  File "C:\Users\doarni\Dev\pygorithm\pygorithm\data_structures\stack.py", line 131, in infix_to_postfix
    and self.__precedence(self.expression[i] <= self.__precedence(self.my_stack.peek())):
TypeError: unorderable types: str() <= int()

----------------------------------------------------------------------
Ran 14 tests in 0.031s

FAILED (errors=1)

test_searching

EE.
======================================================================
ERROR: test_binary_search (tests.test_searching.TestBinarySearch)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\doarni\Dev\pygorithm\tests\test_searching.py", line 40, in test_binary_search
    alpha_result = binary_search.search(self.array, 'n')
  File "C:\Users\doarni\Dev\pygorithm\pygorithm\searching\binary_search.py", line 37, in search
    elif target < _list[mid]:
TypeError: unorderable types: str() < int()

======================================================================
ERROR: test_dfs (tests.test_searching.TestDFSSearch)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\doarni\Dev\pygorithm\tests\test_searching.py", line 72, in test_dfs
    result = depth_first_search.search(self.graph, 'A')
  File "C:\Users\doarni\Dev\pygorithm\pygorithm\searching\depth_first_search.py", line 21, in search
    _path = path + [start]
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'

----------------------------------------------------------------------
Ran 4 tests in 0.016s

FAILED (errors=2)

[enhancement] Removal/Rework of get_code(), time_complexities(), and modules.py

  • I've noticed that every directory/package has a modules.py file, is this truly necessary now that the documentation and README both state using help() to view the modules? I feel these can be outright removed, and the supported algorithms for each section can be simply listed on the README or we can point the user to the Documentation

  • I've also noticed that every file and every class has this get_code() method and most files have time_complexities() method. Are these truly necessary? Since python is open source, any user can simply open the file up and view the code.

  • time_complexities() seems somewhat unnecessary. Instead of storing the time complexity information in a method, why not store it in the file's docstrings or the methods docstrings?
    Example:

from pygorithm.sorting import bubble_sort
help(bubble_sort)

Help on module pygorithm.sorting.bubble_sort in pygorithm.sorting:

"""
NAME
    pygorithm.sorting.bubble_sort

DESCRIPTION
    Author: OMKAR PATHAK
    Contributors: Mohamed Kiouaz
    Created On: 31st July 2017
    
    Time Complexities:
     - Best O(n)
     - Average O(n*(n-1)/4)
     - Worst O(n^2)
"""

OR

from pygorithm.sorting import bubble_sort
help(bubble_sort.sort)
"""
Help on function sort in module pygorithm.sorting.bubble_sort:
sort(_list)
    Bubble Sorting algorithm
    
    Time Complexities:
     - Best O(n)
     - Average O(n*(n-1)/4)
     - Worst O(n^2)
    :param _list: list of values to sort
    :return: sorted values
"""

Strassen' Algorithm

Would it be okay to make a PR with this algorithm? Since it doesn't come under any existing algorithms.

Inconsistent function names

Breadth First Search and Depth First Search have their respective abbreviation as function names. The other search functions have the name search. This is simpler and easier for both the user and the developer.

I have made a pull request to fix this.

Syntax error in test.test_geometry

Hi, Omkar
Great work on the pygorithm project.
I am trying to run the unit test of the project and hit an syntax error in test.test_geometry.
It seems in line 1982, there is a missing left parentheses behind fn. Please check the code below

`# at03

intr, msg = fn((9.5, 8.5), (8.5, 7.5), (9.5, 5), (10.5, 7)), (0, 0), (-9, -9), ((2, 5), (-1, 5), (-2, 3), (2, 1), (3, 2)), reverse=True)

self.assertFalse(intr, msg=msg)`

Hope it helps. Thanks a lot.

Tests for different versions of Python

How about using tox to run unittests for different versions of Python?

Besides, when I run python3 -m unittest (as suggested in README) all tests are passed, but there are some errors for python2.7 -m unittest discover.

So, I'm not sure that Python 2.7 is fully supported, but it's stated in README that "If you are using Python 2.7 use pip instead".

So, I could try to add support for Python 2.x in PR and add a special note in README that only Python3.6 is supported for now.

Some tests are failing

including

 ERROR: test_one_moving_many_stationary_no_intr (tests.test_geometry.TestExtrapolatedIntersection)

Branches, Deprication

To everyone who has contributed.

We've been making quite a few changes recently and generally all the time now. Most of what I've been doing is fixing syntaxing to comply with PEP and in turn have been renaming quite a few things. I've noticed we've been renaming things or restructuring things.

Here's my question(s) to you all:

Who all actively use this?

We change things a lot and this main repository does not have dev branches. Also, and I'm guilty of this, renaming things breaks code. Maybe we should have a dev branch now and also implement a way of warning the user of deprecation. In an old project of mine I implemented decorators for functions that where or were being deprecated.

Just my two cents!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.