sekgobela-kevin / prodius Goto Github PK
View Code? Open in Web Editor NEWCalculates cartesian product from iterables without memory error.
License: MIT License
Calculates cartesian product from iterables without memory error.
License: MIT License
Product.to_callable()
method returns callable version of iterable.
But when iterable is passed, the iterable is just wrapped into function.
This can cause problems if the iterable is iterator which will get exausted.
@classmethod
def to_callable(cls, iterable):
# Creates callable_ from iterable if not already callable_.
if callable(iterable):
return iterable
else:
# Problem/bug is here.
# What if iterable get exausted(especially iterator)?
return lambda: iterable
Instead of having result of cartesian poduct as a very large iterator.
The result can be grouped by another iterable items which wil result in 3D iterable instead of 2D iterable.
prodius.product([0,1], [2,3]) -> [(0, 2), [0, 3), (1,2), (1,3)]
# First iterable was used for grouping
product.product_group([0,1], [2,3]) ->[[(0, 2), (0, 3)], [(1,2), (1,3)]]
# Same thing be archieved as
product.product_group([2,3], group=[0,1]) ->[[(0, 2), (0, 3)], [(1,2), (1,3)]]
This is related to issue #17 of perock which was not added to prodius.
This issue depends on issue #3 as grouped cartesian product is not yet available in broote.
What needed is to have multiple grouped items alternating each other over waiting for each other.
As already said, this feature may depend on issue #3 which is not yet implemented.
BEFORE:
prodius.product([0,1], [2,3]) -> [(0, 2), [0, 3), (1,2), (1,3)]
AFTER:
prodius.product([2,3], group=[0,1], max_multiple=2) -> [(0, 2), [1, 2), (0,3), (1,3)]
group
argument as in #3 causes product results to be grouped but here they are not.
max_multiple
argument should create new iterable that flattens everything back normal.
Realise that results are similar but not differ by order.
Iterables supplied to prodius.product()
are limited to 11.
The number needs to atleast be large to hold more iterables.
These two cases wont work as iterables are larger than 11.
import prodius
product = prodius.product(*[range(10)]*12)
import prodius
product = prodius.product(range(10), repeat=12)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.