66__all__ = [
77 'OneDimensionalArray' ,
88 'MultiDimensionalArray' ,
9- 'DynamicOneDimensionalArray'
9+ 'DynamicOneDimensionalArray' ,
10+ 'OneDimensionalImplicitArray' ,
1011]
1112
1213class Array (object ):
@@ -486,11 +487,11 @@ class OneDimensionalImplicitArray(ImplicitArray):
486487
487488 Parameters
488489 ==========
490+ dtype: type
491+ A valid object type.
489492 function: function
490493 A function which takes an integer as input and returns
491494 the value of the element at that index.
492- dtype: type
493- A valid object type.
494495 size: int
495496 The number of elements in the array.
496497 init: a python type
@@ -541,34 +542,31 @@ def __new__(cls, dtype=NoneType, *args, **kwargs):
541542 return _arrays .OneDimensionalImplicitArray (dtype , * args , ** kwargs )
542543 if dtype is NoneType :
543544 raise ValueError ("Data type is not defined." )
544- if len (args ) < 1 :
545- raise ValueError ("Too few arguments to create a 1D implicit array, "
546- "pass the function of the array" )
545+ elif not _check_type (dtype , type ):
546+ raise TypeError ("Expected type of dtype is type" )
547+ if len (args ) <= 1 :
548+ raise ValueError ("Too many arguments to create a implicit 1D array, "
549+ "pass the function of the array "
550+ "and the size of the array" )
547551 if len (args ) > 2 :
548552 raise ValueError ("Too many arguments to create a implicit 1D array, "
549553 "pass the function of the array "
550- "and optionally the size of the array" )
554+ "and the size of the array" )
551555
552556 obj = Array .__new__ (cls )
553557 obj ._dtype = dtype
554558
555- if len (args ) == 1 :
556- if _check_type (args [0 ], function ):
557- obj ._function = args [0 ]
558- else :
559- raise TypeError ("Expected type of function is function" )
560- elif len (args ) == 2 :
561- if _check_type (args [0 ], function ) and \
562- _check_type (args [1 ], int ):
563- obj ._function = args [0 ]
564- obj ._size = args [1 ]
565- elif _check_type (args [0 ], int ) and \
566- _check_type (args [1 ], function ):
567- obj ._function = args [1 ]
568- obj ._size = args [0 ]
569- else :
570- raise TypeError ("Expected type of function is function "
571- "and expected type of size is int" )
559+ if callable (args [0 ]) and \
560+ _check_type (args [1 ], int ):
561+ obj ._function = args [0 ]
562+ obj ._size = args [1 ]
563+ elif _check_type (args [0 ], int ) and \
564+ callable (args [1 ]):
565+ obj ._function = args [1 ]
566+ obj ._size = args [0 ]
567+ else :
568+ raise TypeError ("Expected type of function is function "
569+ "and expected type of size is int" )
572570
573571 return obj
574572
@@ -580,3 +578,7 @@ def __getitem__(self, i):
580578
581579 def __len__ (self ):
582580 return self ._size
581+
582+ @property
583+ def _data (self ):
584+ return [self ._function (i ) for i in range (self ._size )]
0 commit comments