<s> from __future__ import absolute_import , division , print_function <EOL> from functools import partial <EOL> from itertools import product <EOL> import numpy as np <EOL> from toolz import curry <EOL> from . . base import tokenize <EOL> from . core import Array , normalize_chunks <EOL> from . numpy_compat import full <EOL> def dims_from_size ( size , blocksize ) : <EOL> """<STR_LIT>""" <EOL> result = ( blocksize , ) * ( size // blocksize ) <EOL> if size % blocksize : <EOL> result = result + ( size % blocksize , ) <EOL> return result <EOL> def wrap_func_shape_as_first_arg ( func , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in kwargs : <EOL> shape , args = args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> : ] <EOL> else : <EOL> shape = kwargs . pop ( '<STR_LIT>' ) <EOL> if not isinstance ( shape , ( tuple , list ) ) : <EOL> shape = ( shape , ) <EOL> chunks = kwargs . pop ( '<STR_LIT>' , None ) <EOL> chunks = normalize_chunks ( chunks , shape ) <EOL> name = kwargs . pop ( '<STR_LIT:name>' , None ) <EOL> dtype = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if dtype is None : <EOL> dtype = func ( shape , * args , ** kwargs ) . dtype <EOL> name = name or '<STR_LIT>' + tokenize ( func , shape , chunks , dtype , args , kwargs ) <EOL> keys = product ( [ name ] , * [ range ( len ( bd ) ) for bd in chunks ] ) <EOL> shapes = product ( * chunks ) <EOL> func = partial ( func , dtype = dtype , ** kwargs ) <EOL> vals = ( ( func , ) + ( s , ) + args for s in shapes ) <EOL> dsk = dict ( zip ( keys , vals ) ) <EOL> return Array ( dsk , name , chunks , dtype = dtype ) <EOL> @ curry <EOL> def wrap ( wrap_func , func , ** kwargs ) : <EOL> f = partial ( wrap_func , func , ** kwargs ) <EOL> f . __doc__ = """<STR_LIT>""" % { '<STR_LIT:name>' : func . __name__ } + func . __doc__ <EOL> f . __name__ = '<STR_LIT>' + func . __name__ <EOL> return f <EOL> w = wrap ( wrap_func_shape_as_first_arg ) <EOL> ones = w ( np . ones , dtype = '<STR_LIT>' ) <EOL> zeros = w ( np . zeros , dtype = '<STR_LIT>' ) <EOL> empty = w ( np . empty , dtype = '<STR_LIT>' ) <EOL> full = w ( full ) </s>
