⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_abstract.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 2 页
字号:
   for( i=0; i < funcInfo->nbInput; i++ )   {      TA_GetInputParameterInfo( handle, i, &inputInfo );	  switch(inputInfo->type)	  {	  case TA_Input_Price:         TA_SetInputParamPricePtr( paramHolder, i,			 inputInfo->flags&TA_IN_PRICE_OPEN?input:NULL,			 inputInfo->flags&TA_IN_PRICE_HIGH?input:NULL,			 inputInfo->flags&TA_IN_PRICE_LOW?input:NULL,			 inputInfo->flags&TA_IN_PRICE_CLOSE?input:NULL,			 inputInfo->flags&TA_IN_PRICE_VOLUME?input:NULL, NULL );		 break;	  case TA_Input_Real:         TA_SetInputParamRealPtr( paramHolder, i, input );		 break;	  case TA_Input_Integer:         TA_SetInputParamIntegerPtr( paramHolder, i, input_int );         break;	  }   }   for( i=0; i < funcInfo->nbOutput; i++ )   {      TA_GetOutputParameterInfo( handle, i, &outputInfo );	  switch(outputInfo->type)	  {	  case TA_Output_Real:	     TA_SetOutputParamRealPtr(paramHolder,i,&output[i][0]);                  for( j=0; j < 2000; j++ )            output[i][j] = TA_REAL_MIN;		 break;	  case TA_Output_Integer:	     TA_SetOutputParamIntegerPtr(paramHolder,i,&output_int[i][0]);         for( j=0; j < 2000; j++ )            output_int[i][j] = TA_INTEGER_MIN;		 break;	  }   }   /* Do the function call. */   retCode = TA_CallFunc(paramHolder,0,size-1,&outBegIdx,&outNbElement);   if( retCode != TA_SUCCESS )   {      printf( "TA_CallFunc() failed zero data test [%d]\n", retCode );      TA_ParamHolderFree( paramHolder );      return TA_ABS_TST_FAIL_CALLFUNC_1;   }         /* Verify consistency with Lookback */   retCode = TA_GetLookback( paramHolder, &lookback );   if( retCode != TA_SUCCESS )   {      printf( "TA_GetLookback() failed zero data test [%d]\n", retCode );      TA_ParamHolderFree( paramHolder );      return TA_ABS_TST_FAIL_CALLFUNC_2;   }      if( outBegIdx != lookback )   {      printf( "TA_GetLookback() != outBegIdx [%d != %d]\n", lookback, outBegIdx );      TA_ParamHolderFree( paramHolder );      return TA_ABS_TST_FAIL_CALLFUNC_3;   }                          /* TODO Add back nan/inf tests.    for( i=0; i < funcInfo->nbOutput; i++ )   {	  switch(outputInfo->type)	  {	  case TA_Output_Real:	     		for( j=0; j < outNbElement; j++ )		{			if( trio_isnan(output[i][j]) ||                trio_isinf(output[i][j]))			{				printf( "Failed for output[%d][%d] = %e\n", i, j, output[i][j] );				return TA_ABS_TST_FAIL_INVALID_OUTPUT;			}		}		break;	  case TA_Output_Integer:	     		break;	  }   }*/   /* Do another function call where startIdx == endIdx == 0.    * In that case, outBegIdx should ALWAYS be zero.    */   retCode = TA_CallFunc(paramHolder,0,0,&outBegIdx,&outNbElement);   if( retCode != TA_SUCCESS )   {      printf( "TA_CallFunc() failed data test 4 [%d]\n", retCode );      TA_ParamHolderFree( paramHolder );      return TA_ABS_TST_FAIL_CALLFUNC_4;   }   if( outBegIdx != 0 )   {      printf( "failed outBegIdx=%d when startIdx==endIdx==0\n", outBegIdx );      TA_ParamHolderFree( paramHolder );      return TA_ABS_TST_FAIL_STARTEND_ZERO;   }   retCode = TA_ParamHolderFree( paramHolder );   if( retCode != TA_SUCCESS )   {      printf( "TA_ParamHolderFree failed [%d]\n", retCode );      return TA_ABS_TST_FAIL_PARAMHOLDERFREE;   }   return TA_TEST_PASS;}static ErrorNumber test_default_calls(void){   ErrorNumber errNumber;   unsigned int i;   unsigned int sign;   double tempDouble;   errNumber = TA_TEST_PASS;   for( i=0; i < sizeof(inputNegData)/sizeof(double); i++ )   {      inputNegData[i] = -((double)((int)i));	  inputNegData_int[i] = -(int)i;   }   for( i=0; i < sizeof(inputZeroData)/sizeof(double); i++ )   {      inputZeroData[i] = 0.0;	  inputZeroData_int[i] = (int)inputZeroData[i];   }   for( i=0; i < sizeof(inputRandomData)/sizeof(double); i++ )   {      /* Make 100% sure input range is ]0..1[ */	  tempDouble = (double)rand() / ((double)(RAND_MAX)+(double)(1));      while( (tempDouble <= 0.0) || (tempDouble >= 1.0) ) 	  {		  tempDouble = (double)rand() / ((double)(RAND_MAX)+(double)(1));	  }      inputRandomData[i] = tempDouble;      inputRandomData_int[i] = (int)inputRandomData[i];   }   for( i=0; i < sizeof(inputRandFltEpsilon)/sizeof(double); i++ )   {       sign= (unsigned int)rand()%2;       inputRandFltEpsilon[i] = (sign?1.0:-1.0)*(FLT_EPSILON);       inputRandFltEpsilon_int[i] = sign?TA_INTEGER_MIN:TA_INTEGER_MAX;   }   for( i=0; i < sizeof(inputRandFltEpsilon)/sizeof(double); i++ )   {       sign= (unsigned int)rand()%2;       inputRandFltEpsilon[i] = (sign?1.0:-1.0)*(DBL_EPSILON);       inputRandFltEpsilon_int[i] = sign?1:-1;   }   if( doExtensiveProfiling )   {		   printf( "\n[PROFILING START]\n" );   }   TA_ForEachFunc( testDefault, &errNumber );   if( doExtensiveProfiling )   {		   printf( "[PROFILING END]\n" );   }      return errNumber;}static ErrorNumber callAndProfile( const char *funcName, ProfilingType type ){   TA_ParamHolder *paramHolder;   const TA_FuncHandle *handle;   const TA_FuncInfo *funcInfo;   const TA_InputParameterInfo *inputInfo;   const TA_OutputParameterInfo *outputInfo;   TA_RetCode retCode;   int h, i, j, k;      int outBegIdx, outNbElement;   /* Variables to control iteration and corresponding input size */   int nbInnerLoop, nbOuterLoop;   int stepSize;   int inputSize;   /* Variables measuring the execution time */#ifdef WIN32   LARGE_INTEGER startClock;   LARGE_INTEGER endClock;#else   clock_t startClock;   clock_t endClock;#endif   double clockDelta;   int nbProfiledCallLocal;   double timeInProfiledCallLocal;   double worstProfiledCallLocal;   nbProfiledCallLocal = 0;   timeInProfiledCallLocal = 0.0;   worstProfiledCallLocal = 0.0;   nbInnerLoop = nbOuterLoop = stepSize = inputSize = 0;   switch( type )   {   case PROFILING_10000:	   nbInnerLoop = 1;	   nbOuterLoop = 100;	   stepSize = 10000;	   inputSize = 10000;	   break;   case PROFILING_8000:	   nbInnerLoop = 2;	   nbOuterLoop = 50;	   stepSize = 2000;	   inputSize = 8000;       break;   case PROFILING_5000:	   nbInnerLoop = 2;	   nbOuterLoop = 50;	   stepSize = 5000;	   inputSize = 5000;	   break;   case PROFILING_2000:	   nbInnerLoop = 5;	   nbOuterLoop = 20;	   stepSize = 2000;	   inputSize = 2000;	   break;   case PROFILING_1000:	   nbInnerLoop = 10;	   nbOuterLoop = 10;	   stepSize = 1000;	   inputSize = 1000;	   break;   case PROFILING_500:	   nbInnerLoop = 20;	   nbOuterLoop = 5;	   stepSize = 500;	   inputSize = 500;	   break;   case PROFILING_100:	   nbInnerLoop = 100;	   nbOuterLoop = 1;	   stepSize = 100;	   inputSize = 100;	   break;   }   retCode = TA_GetFuncHandle( funcName, &handle );   if( retCode != TA_SUCCESS )   {      printf( "Can't get the function handle [%d]\n", retCode );      return TA_ABS_TST_FAIL_GETFUNCHANDLE;      }                                retCode = TA_ParamHolderAlloc( handle, &paramHolder );   if( retCode != TA_SUCCESS )   {      printf( "Can't allocate the param holder [%d]\n", retCode );      return TA_ABS_TST_FAIL_PARAMHOLDERALLOC;   }   TA_GetFuncInfo( handle, &funcInfo );   for( i=0; i < (int)funcInfo->nbOutput; i++ )   {      TA_GetOutputParameterInfo( handle, i, &outputInfo );	  switch(outputInfo->type)	  {	  case TA_Output_Real:	     TA_SetOutputParamRealPtr(paramHolder,i,&output[i][0]);                  for( j=0; j < 2000; j++ )            output[i][j] = TA_REAL_MIN;		 break;	  case TA_Output_Integer:	     TA_SetOutputParamIntegerPtr(paramHolder,i,&output_int[i][0]);         for( j=0; j < 2000; j++ )            output_int[i][j] = TA_INTEGER_MIN;		 break;	  }   }   for( h=0; h < 2; h++ )   {   for( i=0; i < nbOuterLoop; i++ )   {	   for( j=0; j < nbInnerLoop; j++ )	   {		   /* Prepare input. */		   for( k=0; k < (int)funcInfo->nbInput; k++ )		   {			  TA_GetInputParameterInfo( handle, k, &inputInfo );			  switch(inputInfo->type)			  {			  case TA_Input_Price:				 TA_SetInputParamPricePtr( paramHolder, k,					 inputInfo->flags&TA_IN_PRICE_OPEN?&gDataOpen[j*stepSize]:NULL,					 inputInfo->flags&TA_IN_PRICE_HIGH?&gDataHigh[j*stepSize]:NULL,					 inputInfo->flags&TA_IN_PRICE_LOW?&gDataLow[j*stepSize]:NULL,					 inputInfo->flags&TA_IN_PRICE_CLOSE?&gDataClose[j*stepSize]:NULL,					 inputInfo->flags&TA_IN_PRICE_VOLUME?&gDataClose[j*stepSize]:NULL, NULL );				 break;			  case TA_Input_Real:				 TA_SetInputParamRealPtr( paramHolder, k, &gDataClose[j*stepSize] );				 break;			  case TA_Input_Integer:				 printf( "\nError: Integer input not yet supported for profiling.\n" );				 return TA_ABS_TST_FAIL_CALLFUNC_1;				 break;			  }		   }           #ifdef WIN32              QueryPerformanceCounter(&startClock);           #else              startClock = clock();           #endif		   /* Do the function call. */		   retCode = TA_CallFunc(paramHolder,0,inputSize-1,&outBegIdx,&outNbElement);		   if( retCode != TA_SUCCESS )		   {		      printf( "TA_CallFunc() failed zero data test [%d]\n", retCode );		      TA_ParamHolderFree( paramHolder );		      return TA_ABS_TST_FAIL_CALLFUNC_1;		   }		   #ifdef WIN32			   QueryPerformanceCounter(&endClock);			   clockDelta = (double)((__int64)endClock.QuadPart - (__int64) startClock.QuadPart);		   #else			   endClock = clock();			   clockDelta = (double)(endClock - startClock);		   #endif		   /* Setup global profiling info. */		   if( clockDelta <= 0 )		   {			   printf( "Error: Insufficient timer precision to perform benchmarking on this platform.\n" );			   return TA_ABS_TST_FAIL_CALLFUNC_1;		   }		   else		   {	   			   if( clockDelta > worstProfiledCall )			      worstProfiledCall = clockDelta;			   timeInProfiledCall += clockDelta;			   nbProfiledCall++;		   }		   /* Setup local profiling info for this particular function. */		   if( clockDelta > worstProfiledCallLocal )			   worstProfiledCallLocal = clockDelta;		   timeInProfiledCallLocal += clockDelta;		   nbProfiledCallLocal++;	   }   }   }   /* Output statistic (remove worst call, average the others. */   printf( "%g ", (timeInProfiledCallLocal-worstProfiledCallLocal)/(double)(nbProfiledCallLocal-1));   retCode = TA_ParamHolderFree( paramHolder );   if( retCode != TA_SUCCESS )   {      printf( "TA_ParamHolderFree failed [%d]\n", retCode );      return TA_ABS_TST_FAIL_PARAMHOLDERFREE;   }   return TA_TEST_PASS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -