6
6
__all__ = [
7
7
'OneDimensionalArray' ,
8
8
'MultiDimensionalArray' ,
9
- 'DynamicOneDimensionalArray'
9
+ 'DynamicOneDimensionalArray' ,
10
+ 'OneDimensionalImplicitArray' ,
10
11
]
11
12
12
13
class Array (object ):
@@ -486,11 +487,11 @@ class OneDimensionalImplicitArray(ImplicitArray):
486
487
487
488
Parameters
488
489
==========
490
+ dtype: type
491
+ A valid object type.
489
492
function: function
490
493
A function which takes an integer as input and returns
491
494
the value of the element at that index.
492
- dtype: type
493
- A valid object type.
494
495
size: int
495
496
The number of elements in the array.
496
497
init: a python type
@@ -541,34 +542,31 @@ def __new__(cls, dtype=NoneType, *args, **kwargs):
541
542
return _arrays .OneDimensionalImplicitArray (dtype , * args , ** kwargs )
542
543
if dtype is NoneType :
543
544
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" )
547
551
if len (args ) > 2 :
548
552
raise ValueError ("Too many arguments to create a implicit 1D array, "
549
553
"pass the function of the array "
550
- "and optionally the size of the array" )
554
+ "and the size of the array" )
551
555
552
556
obj = Array .__new__ (cls )
553
557
obj ._dtype = dtype
554
558
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" )
572
570
573
571
return obj
574
572
@@ -580,3 +578,7 @@ def __getitem__(self, i):
580
578
581
579
def __len__ (self ):
582
580
return self ._size
581
+
582
+ @property
583
+ def _data (self ):
584
+ return [self ._function (i ) for i in range (self ._size )]
0 commit comments