MCPcopy Create free account
hub / github.com/pydata/numexpr / test_Auto

Method test_Auto

code_generators/interp_generator.py:744–843  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

742
743 @property
744 def test_Auto(self) -> str:
745 # Try to write a test function that compares our function to NumPy.
746 if type(self.py_Name) == type: # Ast node
747 funcName = self.py_Name.__name__.lower()
748 else: # Function name
749 funcName = self.py_Name
750
751 required = None # Do we require anything other than numpy for this test block?
752 testCode = ['']
753 evalFunc = None
754 # There are a number of sample arrays in the autotest stub,
755 # A_x, B_x, and C_x where 'x' is the dchar.
756
757
758 for lib in self.libs:
759 for I, retChar in enumerate( self.retFam ):
760 required = 'np' # The default module to test against is NumPy
761 passedArgs = [ arg[I] for arg in self.argFams ]
762 idArgs = [ arg.replace('?','1') for arg in passedArgs ]
763
764 if funcName == 'cast' or funcName == 'copy':
765 return ''
766
767 if AUTOTEST_DICT[funcName]:
768 evalFunc = AUTOTEST_DICT[funcName]
769 elif not hasattr( np, funcName ):
770 # Cycle through optional modules like scipy.special
771 for modName in OPTIONAL_TEST_MODULES:
772 try:
773 optMod = importlib.import_module(modName)
774 if hasattr( optMod, funcName ):
775 required = modName
776 # print( "Found {} in {}".format(funcName, optMod) )
777 break
778
779 except: # This changed from an ImportError <= 3.5 to a ModuleNotFoundError in 3.6
780 pass
781
782 else:
783 if not funcName.startswith('unsafe'):
784 print( "Could not generate test for function {} in numpy, {}".format(funcName, OPTIONAL_TEST_MODULES))
785 return ''
786
787 funcNameUnique = ''.join([funcName,'_',retChar.replace('?','1') ] + idArgs)
788 # I wonder if it would be easier to build the program by hand
789 # and not parse anything? Or maybe I should put aliases
790 # in the OPTABLE?
791 if evalFunc == None:
792 if len(idArgs) == 0:
793 evalFunc = '{0}()'.format(funcName)
794 elif len(idArgs) == 1:
795 evalFunc = '{0}(self.A_{1})'.format(funcName, idArgs[0])
796 elif len(idArgs) == 2:
797 evalFunc = '{0}(self.A_{1}, self.B_{2})'.format(funcName, idArgs[0], idArgs[1])
798 elif len(idArgs) == 3:
799 evalFunc = '{0}(self.A_{1}, self.B_{2}, self.C_{3})'.format(funcName, idArgs[0], idArgs[1], idArgs[2])
800 externFunc = '.'.join( [required, evalFunc] )
801 else:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected