Giter Club home page Giter Club logo

pydatagen's Issues

UnionFindSet shouldn't use classmethod decorator

the attributes are shared across instances in classmethods, causing unexpected bug.

for example,

>>> class Test:
...   @classmethod
...   def __init__(cls,x):
...     cls.x=x
...
>>> a=Test(1)
>>> a.x
1
>>> b=Test(2)
>>> a.x
2
>>>

improve `printf`

try this:

f=open('1.txt','w')
from contextlib import redirect_stdout
with redirect_stdout(f):
    print('hello world')

or

f=open('1.txt','w')
print('hello world', file=f)

Graph only succeeds with less than 20% probability

Using master

Python 3.4.3 (default, Jun 29 2015, 12:16:01) 
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pydatagen import *
>>> def test():
...   try:
...     Graph(6, 12, connected=True, weighed=True, weight_range=range(10, 99))
...     return True
...   except:
...     return False
... 
>>> results = [test() for _ in range(20000)]
>>> results.count(True) / len(results)
0.18835

stop using `queue`

queue is designed for multithreading uses and acquire a lock in every method call. in a word, it's really slow.

just use list instead. it's much (about 50x) faster.

>>> import timeit
>>> timeit.timeit('q.put(123)', 'import queue; q=queue.Queue()', number=10**6)
24.48412793993996
>>> timeit.timeit('q.append(123)', 'q=[]', number=10**6)
0.5576901608900329

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.