# Path: loom/util.py
# def cp_ns(source, destin):
#     'like cp -ns, link destin to source if destin does not exist'
#     if not os.path.exists(destin):
#         assert os.path.exists(source), source
#         dirname = os.path.dirname(destin)
#         if dirname:
#             mkdir_p(dirname)
#         try:
#             os.symlink(source, destin)
#         except OSError as e:
#             if not os.path.exists(destin):
#                 raise e
# 
# Path: loom/util.py
# def mkdir_p(dirname):
#     'like mkdir -p'
#     if not os.path.exists(dirname):
#         try:
#             os.makedirs(dirname)
#         except OSError as e:
#             if not os.path.exists(dirname):
#                 raise e
# 
# Path: loom/util.py
# def parallel_map(fun, args):
#     if not isinstance(args, list):
#         args = list(args)
#     is_daemon = multiprocessing.current_process().daemon
#     if THREADS == 1 or len(args) < 2 or is_daemon:
#         print 'Running {} in this thread'.format(fun.__name__)
#         return map(fun, args)
#     else:
#         print 'Running {} in {:d} threads'.format(fun.__name__, THREADS)
#         pool = multiprocessing.Pool(THREADS)
#         fun_args = [(fun, arg) for arg in args]
#         return pool.map(print_trace, fun_args, chunksize=1)
# 
# Path: loom/util.py
# def rm_rf(path):
#     'like rm -rf'
#     if os.path.exists(path):
#         if os.path.isdir(path):
#             shutil.rmtree(path)
#         else:
#             os.remove(path)


import os
import loom
import loom.config
import loom.consensus
import loom.generate
import loom.transforms
import loom.format
import loom.runner
import loom.store
import parsable
from distributions.io.stream import json_dump
from distributions.io.stream import json_load
from distributions.io.stream import open_compressed
from distributions.io.stream import protobuf_stream_dump
from loom.util import cp_ns
from loom.util import mkdir_p
from loom.util import parallel_map
from loom.util import rm_rf
        'row_count': row_count,
        'feature_count': feature_count,
        'density': density,
    }
    for feature_type in FEATURE_TYPES
    for row_count in [10 ** r for r in [1, 2, 3, 4, 5, 6]]
    for feature_count in [10 ** c for c in [1, 2, 3, 4]]
    for density in [0.05, 0.5]
    if density * row_count > 1
]
CONFIGS = {
    '{feature_type}-{row_count}-{feature_count}-{density}'.format(**c): c
    for c in CONFIG_VALUES
    if get_cost(c) <= 10 ** 7
}

TEST_CONFIGS = [
    name
    for name, config in CONFIGS.iteritems()
    if get_cell_count(config) < LOOM_TEST_COST
]
TEST_CONFIGS.sort(key=lambda c: get_cost(CONFIGS[c]))


@parsable.command
def init(sample_count=1, force=False, debug=False):
    '''
    Generate synthetic datasets for testing and benchmarking.
    '''
    configs = sorted(CONFIGS.keys(), key=(lambda c: -get_cost(CONFIGS[c])))

# Path: loom/util.py
# def cp_ns(source, destin):
#     'like cp -ns, link destin to source if destin does not exist'
#     if not os.path.exists(destin):
#         assert os.path.exists(source), source
#         dirname = os.path.dirname(destin)
#         if dirname:
#             mkdir_p(dirname)
#         try:
#             os.symlink(source, destin)
#         except OSError as e:
#             if not os.path.exists(destin):
#                 raise e
# 
# Path: loom/util.py
# def mkdir_p(dirname):
#     'like mkdir -p'
#     if not os.path.exists(dirname):
#         try:
#             os.makedirs(dirname)
#         except OSError as e:
#             if not os.path.exists(dirname):
#                 raise e
# 
# Path: loom/util.py
# def parallel_map(fun, args):
#     if not isinstance(args, list):
#         args = list(args)
#     is_daemon = multiprocessing.current_process().daemon
#     if THREADS == 1 or len(args) < 2 or is_daemon:
#         print 'Running {} in this thread'.format(fun.__name__)
#         return map(fun, args)
#     else:
#         print 'Running {} in {:d} threads'.format(fun.__name__, THREADS)
#         pool = multiprocessing.Pool(THREADS)
#         fun_args = [(fun, arg) for arg in args]
#         return pool.map(print_trace, fun_args, chunksize=1)
# 
# Path: loom/util.py
# def rm_rf(path):
#     'like rm -rf'
#     if os.path.exists(path):
#         if os.path.isdir(path):
#             shutil.rmtree(path)
#         else:
#             os.remove(path)


# Path: loom/datasets.py
import os
import loom
import loom.config
import loom.consensus
import loom.generate
import loom.transforms
import loom.format
import loom.runner
import loom.store
import parsable
from distributions.io.stream import json_dump
from distributions.io.stream import json_load
from distributions.io.stream import open_compressed
from distributions.io.stream import protobuf_stream_dump
from loom.util import cp_ns
from loom.util import mkdir_p
from loom.util import parallel_map
from loom.util import rm_rf

        'row_count': row_count,
        'feature_count': feature_count,
        'density': density,
    }
    for feature_type in FEATURE_TYPES
    for row_count in [10 ** r for r in [1, 2, 3, 4, 5, 6]]
    for feature_count in [10 ** c for c in [1, 2, 3, 4]]
    for density in [0.05, 0.5]
    if density * row_count > 1
]
CONFIGS = {
    '{feature_type}-{row_count}-{feature_count}-{density}'.format(**c): c
    for c in CONFIG_VALUES
    if get_cost(c) <= 10 ** 7
}

TEST_CONFIGS = [
    name
    for name, config in CONFIGS.iteritems()
    if get_cell_count(config) < LOOM_TEST_COST
]
TEST_CONFIGS.sort(key=lambda c: get_cost(CONFIGS[c]))


@parsable.command
def init(sample_count=1, force=False, debug=False):
    '''
    Generate synthetic datasets for testing and benchmarking.
    '''
    configs = sorted(CONFIGS.keys(), key=(lambda c: -get_cost(CONFIGS[c])))

    parallel_map(generate_one, [