ParvoRetinaFilter::ParvoRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns) :BasicRetinaFilter(NBrows, NBcolumns, 3), _photoreceptorsOutput(NBrows*NBcolumns), _horizontalCellsOutput(NBrows*NBcolumns), _parvocellularOutputON(NBrows*NBcolumns), _parvocellularOutputOFF(NBrows*NBcolumns), _bipolarCellsOutputON(NBrows*NBcolumns), _bipolarCellsOutputOFF(NBrows*NBcolumns), _localAdaptationOFF(NBrows*NBcolumns) { // link to the required local parent adaptation buffers _localAdaptationON=&_localBuffer; _parvocellularOutputONminusOFF=&_filterOutput; // (*_localAdaptationON)=&_localBuffer; // (*_parvocellularOutputONminusOFF)=&(BasicRetinaFilter::TemplateBuffer); // init: set all the values to 0 clearAllBuffers(); #ifdef OPL_RETINA_ELEMENT_DEBUG std::cout<<"ParvoRetinaFilter::Init OPL retina filter at specified frame size OK\n"<<std::endl; #endif }
// constructor ImageLogPolProjection::ImageLogPolProjection(const unsigned int nbRows, const unsigned int nbColumns, const PROJECTIONTYPE projection, const bool colorModeCapable) :BasicRetinaFilter(nbRows, nbColumns), _sampledFrame(0), _tempBuffer(_localBuffer), _transformTable(0), _irregularLPfilteredFrame(_filterOutput) { _inputDoubleNBpixels=nbRows*nbColumns*2; _selectedProjection = projection; _reductionFactor=0; _initOK=false; _usefullpixelIndex=0; _colorModeCapable=colorModeCapable; #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"ImageLogPolProjection::allocating"<<std::endl; #endif if (_colorModeCapable) { _tempBuffer.resize(nbRows*nbColumns*3); } #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"ImageLogPolProjection::done"<<std::endl; #endif clearAllBuffers(); }
ossimPlanetIoSocketServerChannel::~ossimPlanetIoSocketServerChannel() { theIoListMutex.lock(); theIoList.clear(); theIoListMutex.unlock(); clearAllBuffers(); close(); }
/** * resize retina color filter object (resize all allocated buffers) * @param NBrows: the new height size * @param NBcolumns: the new width size */ void ImageLogPolProjection::resize(const unsigned int NBrows, const unsigned int NBcolumns) { BasicRetinaFilter::resize(NBrows, NBcolumns); initProjection(_reductionFactor, _samplingStrenght); // reset buffers method clearAllBuffers(); }
// standard constructor without any log sampling of the input frame RetinaFilter::RetinaFilter(const unsigned int sizeRows, const unsigned int sizeColumns, const bool colorMode, const RETINA_COLORSAMPLINGMETHOD samplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght) : _retinaParvoMagnoMappedFrame(0), _retinaParvoMagnoMapCoefTable(0), _photoreceptorsPrefilter((1-(int)useRetinaLogSampling)*sizeRows+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeRows, reductionFactor), (1-(int)useRetinaLogSampling)*sizeColumns+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeColumns, reductionFactor), 4), _ParvoRetinaFilter((1-(int)useRetinaLogSampling)*sizeRows+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeRows, reductionFactor), (1-(int)useRetinaLogSampling)*sizeColumns+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeColumns, reductionFactor)), _MagnoRetinaFilter((1-(int)useRetinaLogSampling)*sizeRows+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeRows, reductionFactor), (1-(int)useRetinaLogSampling)*sizeColumns+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeColumns, reductionFactor)), _colorEngine((1-(int)useRetinaLogSampling)*sizeRows+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeRows, reductionFactor), (1-(int)useRetinaLogSampling)*sizeColumns+useRetinaLogSampling*ImageLogPolProjection::predictOutputSize(sizeColumns, reductionFactor), samplingMethod), // configure retina photoreceptors log sampling... if necessary _photoreceptorsLogSampling(NULL) { #ifdef RETINADEBUG std::cout<<"RetinaFilter::size( "<<_photoreceptorsPrefilter.getNBrows()<<", "<<_photoreceptorsPrefilter.getNBcolumns()<<")"<<" =? "<<_photoreceptorsPrefilter.getNBpixels()<<std::endl; #endif if (useRetinaLogSampling) { _photoreceptorsLogSampling = new ImageLogPolProjection(sizeRows, sizeColumns, ImageLogPolProjection::RETINALOGPROJECTION, true); if (!_photoreceptorsLogSampling->initProjection(reductionFactor, samplingStrenght)) { std::cerr<<"RetinaFilter::Problem initializing photoreceptors log sampling, could not setup retina filter"<<std::endl; delete _photoreceptorsLogSampling; _photoreceptorsLogSampling=NULL; } else { #ifdef RETINADEBUG std::cout<<"_photoreceptorsLogSampling::size( "<<_photoreceptorsLogSampling->getNBrows()<<", "<<_photoreceptorsLogSampling->getNBcolumns()<<")"<<" =? "<<_photoreceptorsLogSampling->getNBpixels()<<std::endl; #endif } } // set default processing activities _useParvoOutput=true; _useMagnoOutput=true; _useColorMode=colorMode; // create hybrid output and related coefficient table _createHybridTable(); // set default parameters setGlobalParameters(); // stability controls values init _setInitPeriodCount(); _globalTemporalConstant=25; // reset all buffers clearAllBuffers(); // std::cout<<"RetinaFilter::size( "<<this->getNBrows()<<", "<<this->getNBcolumns()<<")"<<_filterOutput.size()<<" =? "<<_filterOutput.getNBpixels()<<std::endl; }
// Constructor and destructors TransientAreasSegmentationModuleImpl::TransientAreasSegmentationModuleImpl(const Size size) :BasicRetinaFilter(size.height, size.width, 3), // allocate the output of the class _inputToSegment(size.height*size.width), _contextMotionEnergy(size.height*size.width), _segmentedAreas(size.height*size.width), // set the pointer to the 2 frame buffer to the correct adress: // -> the first low pass filter buffer will be _localBuffer // -> the second will be _filterOutput; _localMotion(_localBuffer), _neighborhoodMotion(_filterOutput) { // default parameters setup setup(_segmentationParameters); //clean before running clearAllBuffers(); }
/** * resize parvo retina filter object (resize all allocated buffers * @param NBrows: the new height size * @param NBcolumns: the new width size */ void ParvoRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumns) { BasicRetinaFilter::resize(NBrows, NBcolumns); _photoreceptorsOutput.resize(NBrows*NBcolumns); _horizontalCellsOutput.resize(NBrows*NBcolumns); _parvocellularOutputON.resize(NBrows*NBcolumns); _parvocellularOutputOFF.resize(NBrows*NBcolumns); _bipolarCellsOutputON.resize(NBrows*NBcolumns); _bipolarCellsOutputOFF.resize(NBrows*NBcolumns); _localAdaptationOFF.resize(NBrows*NBcolumns); // link to the required local parent adaptation buffers _localAdaptationON=&_localBuffer; _parvocellularOutputONminusOFF=&_filterOutput; // clean buffers clearAllBuffers(); }
/** * resize retina magno filter object (resize all allocated buffers * @param NBrows: the new height size * @param NBcolumns: the new width size */ void MagnoRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumns) { BasicRetinaFilter::resize(NBrows, NBcolumns); _previousInput_ON.resize(NBrows*NBcolumns); _previousInput_OFF.resize(NBrows*NBcolumns); _amacrinCellsTempOutput_ON.resize(NBrows*NBcolumns); _amacrinCellsTempOutput_OFF.resize(NBrows*NBcolumns); _magnoXOutputON.resize(NBrows*NBcolumns); _magnoXOutputOFF.resize(NBrows*NBcolumns); _localProcessBufferON.resize(NBrows*NBcolumns); _localProcessBufferOFF.resize(NBrows*NBcolumns); // to be sure, relink buffers _magnoYOutput=&_filterOutput; _magnoYsaturated=&_localBuffer; // reset all buffers clearAllBuffers(); }
// Constructor and Desctructor of the OPL retina filter MagnoRetinaFilter::MagnoRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns) :BasicRetinaFilter(NBrows, NBcolumns, 2), _previousInput_ON(NBrows*NBcolumns), _previousInput_OFF(NBrows*NBcolumns), _amacrinCellsTempOutput_ON(NBrows*NBcolumns), _amacrinCellsTempOutput_OFF(NBrows*NBcolumns), _magnoXOutputON(NBrows*NBcolumns), _magnoXOutputOFF(NBrows*NBcolumns), _localProcessBufferON(NBrows*NBcolumns), _localProcessBufferOFF(NBrows*NBcolumns) { _magnoYOutput=&_filterOutput; _magnoYsaturated=&_localBuffer; clearAllBuffers(); #ifdef IPL_RETINA_ELEMENT_DEBUG std::cout<<"MagnoRetinaFilter::Init IPL retina filter at specified frame size OK"<<std::endl; #endif }
// resize all allocated buffers void BasicRetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumns) { std::cout<<"BasicRetinaFilter::resize( "<<NBrows<<", "<<NBcolumns<<")"<<std::endl; // resizing buffers _filterOutput.resizeBuffer(NBrows, NBcolumns); // updating variables _halfNBrows=_filterOutput.getNBrows()/2; _halfNBcolumns=_filterOutput.getNBcolumns()/2; _localBuffer.resize(_filterOutput.size()); // in case of spatial adapted filter if (_progressiveSpatialConstant.size()>0) { _progressiveSpatialConstant.resize(_filterOutput.size()); _progressiveGain.resize(_filterOutput.size()); } // reset buffers clearAllBuffers(); }
// Constructor and Desctructor of the basic retina filter BasicRetinaFilter::BasicRetinaFilter(const unsigned int NBrows, const unsigned int NBcolumns, const unsigned int parametersListSize, const bool useProgressiveFilter) :_filterOutput(NBrows, NBcolumns), _localBuffer(NBrows*NBcolumns), _filteringCoeficientsTable(3*parametersListSize), _progressiveSpatialConstant(0),// pointer to a local table containing local spatial constant (allocated with the object) _progressiveGain(0) { #ifdef T_BASIC_RETINA_ELEMENT_DEBUG std::cout<<"BasicRetinaFilter::BasicRetinaFilter: new filter, size="<<NBrows<<", "<<NBcolumns<<std::endl; #endif _halfNBrows=_filterOutput.getNBrows()/2; _halfNBcolumns=_filterOutput.getNBcolumns()/2; if (useProgressiveFilter) { #ifdef T_BASIC_RETINA_ELEMENT_DEBUG std::cout<<"BasicRetinaFilter::BasicRetinaFilter: _progressiveSpatialConstant_Tbuffer"<<std::endl; #endif _progressiveSpatialConstant.resize(_filterOutput.size()); #ifdef T_BASIC_RETINA_ELEMENT_DEBUG std::cout<<"BasicRetinaFilter::BasicRetinaFilter: new _progressiveGain_Tbuffer"<<NBrows<<", "<<NBcolumns<<std::endl; #endif _progressiveGain.resize(_filterOutput.size()); } #ifdef T_BASIC_RETINA_ELEMENT_DEBUG std::cout<<"BasicRetinaFilter::BasicRetinaFilter: new filter, size="<<NBrows<<", "<<NBcolumns<<std::endl; #endif // set default values _maxInputValue=256.0; // reset all buffers clearAllBuffers(); #ifdef T_BASIC_RETINA_ELEMENT_DEBUG std::cout<<"BasicRetinaFilter::Init BasicRetinaElement at specified frame size OK, size="<<this->size()<<std::endl; #endif }
/** * resize retina filter object (resize all allocated buffers * @param NBrows: the new height size * @param NBcolumns: the new width size */ void RetinaFilter::resize(const unsigned int NBrows, const unsigned int NBcolumns) { unsigned int rows=NBrows, cols=NBcolumns; // resize optionnal member and adjust other modules size if required if (_photoreceptorsLogSampling) { _photoreceptorsLogSampling->resize(NBrows, NBcolumns); rows=_photoreceptorsLogSampling->getOutputNBrows(); cols=_photoreceptorsLogSampling->getOutputNBcolumns(); } _photoreceptorsPrefilter.resize(rows, cols); _ParvoRetinaFilter.resize(rows, cols); _MagnoRetinaFilter.resize(rows, cols); _colorEngine.resize(rows, cols); // reset parvo magno mapping _createHybridTable(); // clean buffers clearAllBuffers(); }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->open, history->nbBars ); setInputBuffer( 1, history->high, history->nbBars ); setInputBuffer( 2, history->low, history->nbBars ); setInputBuffer( 3, history->close, history->nbBars ); /* Make a simple first call. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; default: retCode = TA_INTERNAL_ERROR(172); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->open,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->low,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[3].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; default: retCode = TA_INTERNAL_ERROR(173); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[1].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->low,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[3].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); setInputBuffer( 0, history->open, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[1].in ); break; default: retCode = TA_INTERNAL_ERROR(174); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->open,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->low,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[3].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); setInputBuffer( 1, history->high, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[2].in ); break; default: retCode = TA_INTERNAL_ERROR(175); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->open,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[3].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[2].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[2].in, 0 ); setInputBuffer( 2, history->low, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[3].in ); break; default: retCode = TA_INTERNAL_ERROR(176); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->open,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[3].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[3].in, 0 ); setInputBuffer( 3, history->close, history->nbBars ); /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.open = history->open; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RangeTestParam testParam; ErrorNumber errNb; TA_RetCode retCode; (void)test; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->open, history->nbBars ); setInputBuffer( 1, history->high, history->nbBars ); setInputBuffer( 2, history->low, history->nbBars ); setInputBuffer( 3, history->close, history->nbBars ); #if 0 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Test for specific value not yet implemented */ /* Make a simple first call. */ switch( test->theFunction ) { case TA_CCI_TEST: retCode = TA_CCI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_WILLR_TEST: retCode = TA_WILLR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; default: retCode = TA_INTERNAL_ERROR(133); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_CCI_TEST: retCode = TA_CCI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_WILLR_TEST: retCode = TA_WILLR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].in ); break; default: retCode = TA_INTERNAL_ERROR(134); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call to TA_MA should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); setInputBuffer( 0, history->high, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_CCI_TEST: retCode = TA_CCI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_WILLR_TEST: retCode = TA_WILLR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[1].in ); break; default: retCode = TA_INTERNAL_ERROR(135); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); setInputBuffer( 1, history->low, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_CCI_TEST: retCode = TA_CCI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_WILLR_TEST: retCode = TA_WILLR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[2].in ); break; default: retCode = TA_INTERNAL_ERROR(136); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call to TA_MA should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[2].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[2].in, 0 ); setInputBuffer( 2, history->close, history->nbBars ); #endif /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.open = history->open; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; testParam.paramHolder = NULL; if( test->doRangeTestFlag ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); if( testParam.paramHolder ) { retCode = TA_ParamHolderFree( testParam.paramHolder ); if( retCode != TA_SUCCESS ) { printf( "TA_ParamHolderFree failed [%d]\n", retCode ); return TA_TSTCDL_PARAMHOLDERFREE_FAIL; } } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); setInputBuffer( 1, history->close, history->nbBars ); /* Make a simple first call. */ retCode = TA_STDDEV( test->startIdx, test->endIdx, gBuffer[0].in, test->optInTimePeriod, test->optInNbDeviation_1, &outBegIdx, &outNbElement, gBuffer[0].out0 ); errNb = checkDataSame( gBuffer[0].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_STDDEV( test->startIdx, test->endIdx, gBuffer[1].in, test->optInTimePeriod, test->optInNbDeviation_1, &outBegIdx, &outNbElement, gBuffer[1].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( TA_Libc *libHandle, const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); /* Set the unstable period requested for that test. */ switch( test->optInMethod_3 ) { case TA_STOCH_EXPONENTIAL: retCode = TA_SetUnstablePeriod( libHandle, TA_FUNC_UNST_EMA, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; break; default: /* No unstable period for other methods. */ break; } /* Make a simple first call. */ retCode = TA_STOCH( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInKPeriod_0, test->optInKSlowPeriod_1, test->optInDPeriod_2, test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[0].out0, gBuffer[0].out1 ); errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[0].out1, 1 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_STOCH( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInKPeriod_0, test->optInKSlowPeriod_1, test->optInDPeriod_2, test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[0].in, gBuffer[1].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkSameContent( gBuffer[0].out1, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); CHECK_EXPECTED_VALUE( gBuffer[1].in, 1 ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( libHandle, rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 2 ); if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; const TA_Real *referenceInput; TA_Integer *intBuffer; int size, i; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); /* Change the input to MEDPRICE for some tests. */ switch( test->theFunction ) { case TA_HT_DCPERIOD_TEST: case TA_HT_DCPHASE_TEST: case TA_HT_TRENDLINE_TEST: case TA_HT_TRENDMODE_TEST: TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low, &outBegIdx, &outNbElement, gBuffer[0].in ); /* Will be use as reference */ TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low, &outBegIdx, &outNbElement, gBuffer[1].in ); referenceInput = gBuffer[1].in; break; default: referenceInput = history->close; } /* Make a simple first call. */ size = (test->endIdx-test->startIdx)+1; switch( test->theFunction ) { case TA_HT_DCPERIOD_TEST: retCode = TA_HT_DCPERIOD( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_HT_DCPHASE_TEST: retCode = TA_HT_DCPHASE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_HT_TRENDLINE_TEST: retCode = TA_HT_TRENDLINE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_HT_TRENDMODE_TEST: ALLOC_INT_BUFFER(size); retCode = TA_HT_TRENDMODE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, &intBuffer[1] ); FREE_INT_BUFFER( gBuffer[0].out0, outNbElement ); break; default: retCode = TA_INTERNAL_ERROR(133); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, referenceInput, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output * are the same buffer. */ switch( test->theFunction ) { case TA_HT_DCPERIOD_TEST: retCode = TA_HT_DCPERIOD( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_HT_DCPHASE_TEST: retCode = TA_HT_DCPHASE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_HT_TRENDLINE_TEST: retCode = TA_HT_TRENDLINE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_HT_TRENDMODE_TEST: ALLOC_INT_BUFFER(size); retCode = TA_HT_TRENDMODE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, &intBuffer[1] ); FREE_INT_BUFFER( gBuffer[0].in, outNbElement ); break; default: retCode = TA_INTERNAL_ERROR(134); } /* The previous call should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.price = referenceInput; if( test->doRangeTestFlag ) { switch( test->theFunction ) { case TA_HT_DCPERIOD_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_HT_DCPERIOD, (void *)&testParam, 1, 0 ); break; case TA_HT_DCPHASE_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_HT_DCPHASE, (void *)&testParam, 1, 360 ); break; case TA_HT_TRENDLINE_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_HT_TRENDLINE, (void *)&testParam, 1, 0 ); break; case TA_HT_TRENDMODE_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_HT_TRENDMODE, (void *)&testParam, 1, 0 ); break; default: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_EMA, 0 ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); setInputBuffer( 1, history->close, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); setInputBuffer( 3, history->close, history->nbBars ); TA_SetCompatibility( (TA_Compatibility)test->compatibility ); /* Make a simple first call. */ retCode = TA_BBANDS( test->startIdx, test->endIdx, gBuffer[0].in, test->optInTimePeriod, test->optInNbDevUp, test->optInNbDevDn, (TA_MAType)test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[0].out0, gBuffer[0].out1, gBuffer[0].out2 ); errNb = checkDataSame( gBuffer[0].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[0].out1, 1 ); CHECK_EXPECTED_VALUE( gBuffer[0].out2, 2 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_BBANDS( test->startIdx, test->endIdx, gBuffer[1].in, test->optInTimePeriod, test->optInNbDevUp, test->optInNbDevDn, (TA_MAType)test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[1].in, gBuffer[1].out1, gBuffer[1].out2 ); /* The previous call should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); CHECK_EXPECTED_VALUE( gBuffer[1].out1, 1 ); CHECK_EXPECTED_VALUE( gBuffer[1].out2, 2 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_BBANDS( test->startIdx, test->endIdx, gBuffer[2].in, test->optInTimePeriod, test->optInNbDevUp, test->optInNbDevDn, (TA_MAType)test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[2].out1, gBuffer[2].in, gBuffer[2].out2 ); /* The previous call should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[1].out1, gBuffer[2].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[2].out1, 0 ); CHECK_EXPECTED_VALUE( gBuffer[2].in, 1 ); CHECK_EXPECTED_VALUE( gBuffer[2].out2, 2 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_BBANDS( test->startIdx, test->endIdx, gBuffer[3].in, test->optInTimePeriod, test->optInNbDevUp, test->optInNbDevDn, (TA_MAType)test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[3].out0, gBuffer[3].out1, gBuffer[3].in ); /* The previous call should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[2].out2, gBuffer[3].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[3].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[3].out1, 1 ); CHECK_EXPECTED_VALUE( gBuffer[3].in, 2 ); /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.close = history->close; if( test->doRangeTestFlag ) { if( test->optInMethod_3 == TA_MAType_EMA ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 3, 0 ); } else { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 3, 0 ); } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
// -> private init functions dedicated to each projection bool ImageLogPolProjection::_initLogRetinaSampling(const double reductionFactor, const double samplingStrenght) { _initOK=false; if (_selectedProjection!=RETINALOGPROJECTION) { std::cerr<<"ImageLogPolProjection::initLogRetinaSampling: could not initialize logPolar projection for a log projection system\n -> you probably chose the wrong init function, use initLogPolarCortexSampling() instead"<<std::endl; return false; } if (reductionFactor<1.0) { std::cerr<<"ImageLogPolProjection::initLogRetinaSampling: reduction factor must be superior to 0, skeeping initialisation..."<<std::endl; return false; } // compute image output size _outputNBrows=predictOutputSize(this->getNBrows(), reductionFactor); _outputNBcolumns=predictOutputSize(this->getNBcolumns(), reductionFactor); _outputNBpixels=_outputNBrows*_outputNBcolumns; _outputDoubleNBpixels=_outputNBrows*_outputNBcolumns*2; #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"ImageLogPolProjection::initLogRetinaSampling: Log resampled image resampling factor: "<<reductionFactor<<", strenght:"<<samplingStrenght<<std::endl; std::cout<<"ImageLogPolProjection::initLogRetinaSampling: Log resampled image size: "<<_outputNBrows<<"*"<<_outputNBcolumns<<std::endl; #endif // setup progressive prefilter that will be applied BEFORE log sampling setProgressiveFilterConstants_CentredAccuracy(0.f, 0.f, 0.99f); // (re)create the image output buffer and transform table if the reduction factor changed _sampledFrame.resize(_outputNBpixels*(1+(unsigned int)_colorModeCapable*2)); // specifiying new reduction factor after preliminar checks _reductionFactor=reductionFactor; _samplingStrenght=samplingStrenght; // compute the rlim for symetric rows/columns sampling, then, the rlim is based on the smallest dimension _minDimension=(double)(_filterOutput.getNBrows() < _filterOutput.getNBcolumns() ? _filterOutput.getNBrows() : _filterOutput.getNBcolumns()); // input frame dimensions dependent log sampling: //double rlim=1.0/reductionFactor*(minDimension/2.0+samplingStrenght); // input frame dimensions INdependent log sampling: _azero=(1.0+reductionFactor*std::sqrt(samplingStrenght))/(reductionFactor*reductionFactor*samplingStrenght-1.0); _alim=(1.0+_azero)/reductionFactor; #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"ImageLogPolProjection::initLogRetinaSampling: rlim= "<<rlim<<std::endl; std::cout<<"ImageLogPolProjection::initLogRetinaSampling: alim= "<<alim<<std::endl; #endif // get half frame size unsigned int halfOutputRows = _outputNBrows/2-1; unsigned int halfOutputColumns = _outputNBcolumns/2-1; unsigned int halfInputRows = _filterOutput.getNBrows()/2-1; unsigned int halfInputColumns = _filterOutput.getNBcolumns()/2-1; // computing log sampling matrix by computing quarters of images // the original new image center (_filterOutput.getNBrows()/2, _filterOutput.getNBcolumns()/2) being at coordinate (_filterOutput.getNBrows()/(2*_reductionFactor), _filterOutput.getNBcolumns()/(2*_reductionFactor)) // -> use a temporary transform table which is bigger than the final one, we only report pixels coordinates that are included in the sampled picture std::valarray<unsigned int> tempTransformTable(2*_outputNBpixels); // the structure would be: (pixelInputCoordinate n)(pixelOutputCoordinate n)(pixelInputCoordinate n+1)(pixelOutputCoordinate n+1) _usefullpixelIndex=0; double rMax=0; halfInputRows<halfInputColumns ? rMax=(double)(halfInputRows*halfInputRows):rMax=(double)(halfInputColumns*halfInputColumns); for (unsigned int idRow=0;idRow<halfOutputRows; ++idRow) { for (unsigned int idColumn=0;idColumn<halfOutputColumns; ++idColumn) { // get the pixel position in the original picture // -> input frame dimensions dependent log sampling: //double scale = samplingStrenght/(rlim-(double)std::sqrt(idRow*idRow+idColumn*idColumn)); // -> input frame dimensions INdependent log sampling: double scale=getOriginalRadiusLength((double)std::sqrt((double)(idRow*idRow+idColumn*idColumn))); #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"ImageLogPolProjection::initLogRetinaSampling: scale= "<<scale<<std::endl; std::cout<<"ImageLogPolProjection::initLogRetinaSampling: scale2= "<<scale2<<std::endl; #endif if (scale < 0) ///check it later scale = 10000; #ifdef IMAGELOGPOLPROJECTION_DEBUG // std::cout<<"ImageLogPolProjection::initLogRetinaSampling: scale= "<<scale<<std::endl; #endif unsigned int u=(unsigned int)floor((double)idRow*scale); unsigned int v=(unsigned int)floor((double)idColumn*scale); // manage border effects double length=u*u+v*v; double radiusRatio=std::sqrt(rMax/length); #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"ImageLogPolProjection::(inputH, inputW)="<<halfInputRows<<", "<<halfInputColumns<<", Rmax2="<<rMax<<std::endl; std::cout<<"before ==> ImageLogPolProjection::(u, v)="<<u<<", "<<v<<", r="<<u*u+v*v<<std::endl; std::cout<<"ratio ="<<radiusRatio<<std::endl; #endif if (radiusRatio < 1.0) { u=(unsigned int)floor(radiusRatio*double(u)); v=(unsigned int)floor(radiusRatio*double(v)); } #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"after ==> ImageLogPolProjection::(u, v)="<<u<<", "<<v<<", r="<<u*u+v*v<<std::endl; std::cout<<"ImageLogPolProjection::("<<(halfOutputRows-idRow)<<", "<<idColumn+halfOutputColumns<<") <- ("<<halfInputRows-u<<", "<<v+halfInputColumns<<")"<<std::endl; std::cout<<(halfOutputRows-idRow)+(halfOutputColumns+idColumn)*_outputNBrows<<" -> "<<(halfInputRows-u)+_filterOutput.getNBrows()*(halfInputColumns+v)<<std::endl; #endif if ((u<halfInputRows)&&(v<halfInputColumns)) { #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"*** VALID ***"<<std::endl; #endif // set pixel coordinate of the input picture in the transform table at the current log sampled pixel // 1st quadrant tempTransformTable[_usefullpixelIndex++]=(halfOutputColumns+idColumn)+(halfOutputRows-idRow)*_outputNBcolumns; tempTransformTable[_usefullpixelIndex++]=_filterOutput.getNBcolumns()*(halfInputRows-u)+(halfInputColumns+v); // 2nd quadrant tempTransformTable[_usefullpixelIndex++]=(halfOutputColumns+idColumn)+(halfOutputRows+idRow)*_outputNBcolumns; tempTransformTable[_usefullpixelIndex++]=_filterOutput.getNBcolumns()*(halfInputRows+u)+(halfInputColumns+v); // 3rd quadrant tempTransformTable[_usefullpixelIndex++]=(halfOutputColumns-idColumn)+(halfOutputRows-idRow)*_outputNBcolumns; tempTransformTable[_usefullpixelIndex++]=_filterOutput.getNBcolumns()*(halfInputRows-u)+(halfInputColumns-v); // 4td quadrant tempTransformTable[_usefullpixelIndex++]=(halfOutputColumns-idColumn)+(halfOutputRows+idRow)*_outputNBcolumns; tempTransformTable[_usefullpixelIndex++]=_filterOutput.getNBcolumns()*(halfInputRows+u)+(halfInputColumns-v); } } } // (re)creating and filling the transform table _transformTable.resize(_usefullpixelIndex); memcpy(&_transformTable[0], &tempTransformTable[0], sizeof(unsigned int)*_usefullpixelIndex); // reset all buffers clearAllBuffers(); #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"ImageLogPolProjection::initLogRetinaSampling: init done successfully"<<std::endl; #endif _initOK=true; return _initOK; }
bool ImageLogPolProjection::_initLogPolarCortexSampling(const double reductionFactor, const double) { _initOK=false; if (_selectedProjection!=CORTEXLOGPOLARPROJECTION) { std::cerr<<"ImageLogPolProjection::could not initialize log projection for a logPolar projection system\n -> you probably chose the wrong init function, use initLogRetinaSampling() instead"<<std::endl; return false; } if (reductionFactor<1.0) { std::cerr<<"ImageLogPolProjection::reduction factor must be superior to 0, skeeping initialisation..."<<std::endl; return false; } // compute the smallest image size unsigned int minDimension=(_filterOutput.getNBrows() < _filterOutput.getNBcolumns() ? _filterOutput.getNBrows() : _filterOutput.getNBcolumns()); // specifiying new reduction factor after preliminar checks _reductionFactor=reductionFactor; // compute image output size _outputNBrows=(unsigned int)((double)minDimension/reductionFactor); _outputNBcolumns=(unsigned int)((double)minDimension/reductionFactor); _outputNBpixels=_outputNBrows*_outputNBcolumns; _outputDoubleNBpixels=_outputNBrows*_outputNBcolumns*2; // get half frame size //unsigned int halfOutputRows = _outputNBrows/2-1; //unsigned int halfOutputColumns = _outputNBcolumns/2-1; unsigned int halfInputRows = _filterOutput.getNBrows()/2-1; unsigned int halfInputColumns = _filterOutput.getNBcolumns()/2-1; #ifdef IMAGELOGPOLPROJECTION_DEBUG std::cout<<"ImageLogPolProjection::Log resampled image size: "<<_outputNBrows<<"*"<<_outputNBcolumns<<std::endl; #endif // setup progressive prefilter that will be applied BEFORE log sampling setProgressiveFilterConstants_CentredAccuracy(0.f, 0.f, 0.99f); // (re)create the image output buffer and transform table if the reduction factor changed _sampledFrame.resize(_outputNBpixels*(1+(unsigned int)_colorModeCapable*2)); // create the radius and orientation axis and fill them, radius E [0;1], orientation E[-pi, pi] std::valarray<double> radiusAxis(_outputNBcolumns); double radiusStep=2.30/(double)_outputNBcolumns; for (unsigned int i=0;i<_outputNBcolumns;++i) { radiusAxis[i]=i*radiusStep; } std::valarray<double> orientationAxis(_outputNBrows); double orientationStep=-2.0*CV_PI/(double)_outputNBrows; for (unsigned int io=0;io<_outputNBrows;++io) { orientationAxis[io]=io*orientationStep; } // -> use a temporay transform table which is bigger than the final one, we only report pixels coordinates that are included in the sampled picture std::valarray<unsigned int> tempTransformTable(2*_outputNBpixels); // the structure would be: (pixelInputCoordinate n)(pixelOutputCoordinate n)(pixelInputCoordinate n+1)(pixelOutputCoordinate n+1) _usefullpixelIndex=0; //std::cout<<"ImageLogPolProjection::Starting cortex projection"<<std::endl; // compute transformation, get theta and Radius in reagrd of the output sampled pixel double diagonalLenght=std::sqrt((double)(_outputNBcolumns*_outputNBcolumns+_outputNBrows*_outputNBrows)); for (unsigned int radiusIndex=0;radiusIndex<_outputNBcolumns;++radiusIndex) for(unsigned int orientationIndex=0;orientationIndex<_outputNBrows;++orientationIndex) { double x=1.0+sinh(radiusAxis[radiusIndex])*cos(orientationAxis[orientationIndex]); double y=sinh(radiusAxis[radiusIndex])*sin(orientationAxis[orientationIndex]); // get the input picture coordinate double R=diagonalLenght*std::sqrt(x*x+y*y)/(5.0+std::sqrt(x*x+y*y)); double theta=atan2(y,x); // convert input polar coord into cartesian/C compatble coordinate unsigned int columnIndex=(unsigned int)(cos(theta)*R)+halfInputColumns; unsigned int rowIndex=(unsigned int)(sin(theta)*R)+halfInputRows; //std::cout<<"ImageLogPolProjection::R="<<R<<" / Theta="<<theta<<" / (x, y)="<<columnIndex<<", "<<rowIndex<<std::endl; if ((columnIndex<_filterOutput.getNBcolumns())&&(columnIndex>0)&&(rowIndex<_filterOutput.getNBrows())&&(rowIndex>0)) { // set coordinate tempTransformTable[_usefullpixelIndex++]=radiusIndex+orientationIndex*_outputNBcolumns; tempTransformTable[_usefullpixelIndex++]= columnIndex+rowIndex*_filterOutput.getNBcolumns(); } } // (re)creating and filling the transform table _transformTable.resize(_usefullpixelIndex); memcpy(&_transformTable[0], &tempTransformTable[0], sizeof(unsigned int)*_usefullpixelIndex); // reset all buffers clearAllBuffers(); _initOK=true; return true; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); setInputBuffer( 3, history->high, history->nbBars ); /* Make a simple first call. */ switch( test->id ) { case TST_MINUS_DM: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MINUS_DM, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_MINUS_DM( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_MINUS_DI: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MINUS_DI, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_MINUS_DI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_DX: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_DX, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_DX( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_ADX: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_ADX, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_ADX( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_PLUS_DM: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_PLUS_DM, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_PLUS_DM( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_PLUS_DI: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_PLUS_DI, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_PLUS_DI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_ADXR: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_ADX, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_ADXR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; default: retCode = TA_BAD_PARAM; } /* Verify that the inputs were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->id ) { case TST_MINUS_DM: retCode = TA_MINUS_DM( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_MINUS_DI: retCode = TA_MINUS_DI( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_DX: retCode = TA_DX( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_ADX: retCode = TA_ADX( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_PLUS_DM: retCode = TA_PLUS_DM( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_PLUS_DI: retCode = TA_PLUS_DI( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_ADXR: retCode = TA_ADXR( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; default: retCode = TA_BAD_PARAM; } /* Verify that the inputs were preserved. */ errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[3].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[3].in, 0 ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { switch( test->id ) { case TST_MINUS_DM: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_MINUS_DM, (void *)&testParam, 1, 0 ); break; case TST_MINUS_DI: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_MINUS_DI, (void *)&testParam, 1, 2 ); break; case TST_DX: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_DX, (void *)&testParam, 1, 2 ); break; case TST_ADX: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_ADX, (void *)&testParam, 1, 2 ); break; case TST_PLUS_DM: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_PLUS_DM, (void *)&testParam, 1, 0 ); break; case TST_PLUS_DI: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_PLUS_DI, (void *)&testParam, 1, 2 ); break; case TST_ADXR: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_ADX, (void *)&testParam, 1, 2 ); break; } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); TA_SetCompatibility( (TA_Compatibility)test->compatibility ); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); setInputBuffer( 1, history->close, history->nbBars ); TA_SetUnstablePeriod( TA_FUNC_UNST_EMA, 0 ); /* Make a simple first call. */ if( test->doPercentage ) { retCode = TA_PPO( test->startIdx, test->endIdx, gBuffer[0].in, test->optInFastPeriod, test->optInSlowPeriod, (TA_MAType)test->optInMethod_2, &outBegIdx, &outNbElement, gBuffer[0].out0 ); } else { retCode = TA_APO( test->startIdx, test->endIdx, gBuffer[0].in, test->optInFastPeriod, test->optInSlowPeriod, (TA_MAType)test->optInMethod_2, &outBegIdx, &outNbElement, gBuffer[0].out0 ); } errNb = checkDataSame( gBuffer[0].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkExpectedValue( gBuffer[0].out0, retCode, test->expectedRetCode, outBegIdx, test->expectedBegIdx, outNbElement, test->expectedNbElement, test->oneOfTheExpectedOutReal, test->oneOfTheExpectedOutRealIndex ); if( errNb != TA_TEST_PASS ) return errNb; outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ if( test->doPercentage ) { retCode = TA_PPO( test->startIdx, test->endIdx, gBuffer[1].in, test->optInFastPeriod, test->optInSlowPeriod, (TA_MAType)test->optInMethod_2, &outBegIdx, &outNbElement, gBuffer[1].in ); } else { retCode = TA_APO( test->startIdx, test->endIdx, gBuffer[1].in, test->optInFastPeriod, test->optInSlowPeriod, (TA_MAType)test->optInMethod_2, &outBegIdx, &outNbElement, gBuffer[1].in ); } /* The previous call should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkExpectedValue( gBuffer[1].in, retCode, test->expectedRetCode, outBegIdx, test->expectedBegIdx, outNbElement, test->expectedNbElement, test->oneOfTheExpectedOutReal, test->oneOfTheExpectedOutRealIndex ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.close = history->close; if( test->doRangeTestFlag ) { if( test->optInMethod_2 == TA_MAType_EMA ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } else { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } } return TA_TEST_PASS; }
static ErrorNumber do_test_ma( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; TA_Integer temp, temp2; const TA_Real *referenceInput; TA_SetCompatibility( test->compatibility ); /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); setInputBuffer( 1, history->close, history->nbBars ); /* Re-initialize all the unstable period to zero. */ TA_SetUnstablePeriod( TA_FUNC_UNST_ALL, 0 ); /* Set the unstable period requested for that test. */ switch( test->optInMAType_1 ) { case TA_MAType_TEMA: case TA_MAType_DEMA: case TA_MAType_EMA: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_EMA, test->unstablePeriod ); break; case TA_MAType_KAMA: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_KAMA, test->unstablePeriod ); break; case TA_MAType_MAMA: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MAMA, test->unstablePeriod ); break; case TA_MAType_T3: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_T3, test->unstablePeriod ); break; default: retCode = TA_SUCCESS; break; } if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; /* Transform the inputs for MAMA (it is an AVGPRICE in John Ehlers book). */ if( test->optInMAType_1 == TA_MAType_MAMA ) { TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low, &outBegIdx, &outNbElement, gBuffer[0].in ); TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low, &outBegIdx, &outNbElement, gBuffer[1].in ); /* Will be use as reference */ TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low, &outBegIdx, &outNbElement, gBuffer[2].in ); referenceInput = gBuffer[2].in; } else referenceInput = history->close; /* Make a simple first call. */ switch( test->id ) { case TA_ANY_MA_TEST: retCode = TA_MA( test->startIdx, test->endIdx, gBuffer[0].in, test->optInTimePeriod_0, test->optInMAType_1, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_MAMA_TEST: retCode = TA_MAMA( test->startIdx, test->endIdx, gBuffer[0].in, 0.5, 0.05, &outBegIdx, &outNbElement, gBuffer[0].out0, gBuffer[0].out2 ); break; case TA_FAMA_TEST: retCode = TA_MAMA( test->startIdx, test->endIdx, gBuffer[0].in, 0.5, 0.05, &outBegIdx, &outNbElement, gBuffer[0].out2, gBuffer[0].out0 ); break; } errNb = checkDataSame( gBuffer[0].in, referenceInput, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkExpectedValue( gBuffer[0].out0, retCode, test->expectedRetCode, outBegIdx, test->expectedBegIdx, outNbElement, test->expectedNbElement, test->oneOfTheExpectedOutReal, test->oneOfTheExpectedOutRealIndex ); if( errNb != TA_TEST_PASS ) return errNb; outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->id ) { case TA_ANY_MA_TEST: retCode = TA_MA( test->startIdx, test->endIdx, gBuffer[1].in, test->optInTimePeriod_0, test->optInMAType_1, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_MAMA_TEST: retCode = TA_MAMA( test->startIdx, test->endIdx, gBuffer[1].in, 0.5, 0.05, &outBegIdx, &outNbElement, gBuffer[1].in, gBuffer[0].out2 ); break; case TA_FAMA_TEST: retCode = TA_MAMA( test->startIdx, test->endIdx, gBuffer[1].in, 0.5, 0.05, &outBegIdx, &outNbElement, gBuffer[0].out2, gBuffer[1].in ); break; } /* The previous call to TA_MA should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkExpectedValue( gBuffer[1].in, retCode, test->expectedRetCode, outBegIdx, test->expectedBegIdx, outNbElement, test->expectedNbElement, test->oneOfTheExpectedOutReal, test->oneOfTheExpectedOutRealIndex ); if( errNb != TA_TEST_PASS ) return errNb; /* Verify that the "all-purpose" TA_MA_Lookback is consistent * with the corresponding moving average lookback function. */ switch( test->optInMAType_1 ) { case TA_MAType_WMA: temp = TA_WMA_Lookback( test->optInTimePeriod_0 ); break; case TA_MAType_SMA: temp = TA_SMA_Lookback( test->optInTimePeriod_0 ); break; case TA_MAType_EMA: temp = TA_EMA_Lookback( test->optInTimePeriod_0 ); break; case TA_MAType_DEMA: temp = TA_DEMA_Lookback( test->optInTimePeriod_0 ); break; case TA_MAType_TEMA: temp = TA_TEMA_Lookback( test->optInTimePeriod_0 ); break; case TA_MAType_KAMA: temp = TA_KAMA_Lookback( test->optInTimePeriod_0 ); break; case TA_MAType_MAMA: temp = TA_MAMA_Lookback( 0.5, 0.05 ); break; case TA_MAType_TRIMA: temp = TA_TRIMA_Lookback( test->optInTimePeriod_0 ); break; case TA_MAType_T3: temp = TA_T3_Lookback( test->optInTimePeriod_0, 0.7 ); break; default: return TA_TEST_TFRR_BAD_MA_TYPE; } temp2 = TA_MA_Lookback( test->optInTimePeriod_0, test->optInMAType_1 ); if( temp != temp2 ) return TA_TEST_TFFR_BAD_MA_LOOKBACK; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.close = referenceInput; if( test->doRangeTestFlag ) { switch( test->optInMAType_1 ) { case TA_MAType_TEMA: case TA_MAType_DEMA: case TA_MAType_EMA: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 1, 0 ); break; case TA_MAType_T3: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_T3, (void *)&testParam, 1, 0 ); break; case TA_MAType_KAMA: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_KAMA, (void *)&testParam, 1, 0 ); break; case TA_MAType_MAMA: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_MAMA, (void *)&testParam, 2, 0 ); break; default: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber testCompareToReference( const TA_Real *input, int nbElement ) { TA_Integer outBegIdx, outNbElement; TA_RetCode retCode; TA_Integer outBegIdxRef, outNbElementRef; TA_RetCode retCodeRef; int period, startIdx, endIdx, testNb; ErrorNumber errNb; /* Do a systematic tests, even for failure cases. */ for( testNb=0; testNb <= 1; testNb++ ) /* 0=TA_MIN, 1=TA_MAX */ { for( period=2; period <= nbElement; period++ ) { for( startIdx=0; startIdx < nbElement; startIdx++ ) { for( endIdx=0; (endIdx < nbElement) && (startIdx <= endIdx); endIdx++ ) { /* Set to NAN all the elements of the gBuffers. * Note: These buffer are used as an attempt to detect * out-of-bound writing in the output. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, input, nbElement ); /* Get the reference output. */ if( testNb == 0 ) retCodeRef = referenceMin( startIdx, endIdx, input, period, &outBegIdxRef, &outNbElementRef, gBuffer[0].out0 ); else retCodeRef = referenceMax( startIdx, endIdx, input, period, &outBegIdxRef, &outNbElementRef, gBuffer[0].out0 ); /* Verify that the input was preserved */ errNb = checkDataSame( gBuffer[0].in, input, nbElement ); if( errNb != TA_TEST_PASS ) return errNb; /* Get the TA-Lib implementation output. */ if( testNb == 0 ) retCode = TA_MIN( startIdx, endIdx, input, period, &outBegIdx, &outNbElement, gBuffer[1].out0 ); else retCode = TA_MAX( startIdx, endIdx, input, period, &outBegIdx, &outNbElement, gBuffer[1].out0 ); /* Verify that the input was preserved */ errNb = checkDataSame( gBuffer[0].in, input, nbElement ); if( errNb != TA_TEST_PASS ) return errNb; /* The reference and TA-LIB should have the same output. */ if( retCode != retCodeRef ) { printf( "Failure: retCode != retCodeRef\n" ); return TA_REGTEST_OPTIMIZATION_REF_ERROR; } if( outBegIdx != outBegIdxRef ) { printf( "Failure: outBegIdx != outBegIdxRef\n" ); return TA_REGTEST_OPTIMIZATION_REF_ERROR; } if( outNbElement != outNbElementRef ) { printf( "Failure: outNbElement != outNbElementRef\n" ); return TA_REGTEST_OPTIMIZATION_REF_ERROR; } /* checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].out0 ); if( errNb != TA_TEST_PASS ) return errNb; if( retCode == TA_SUCCESS ) { /* Make another test using the same input/output buffer. * The output should still be the same. */ if( testNb == 0 ) retCode = TA_MIN( startIdx, endIdx, gBuffer[0].in, period, &outBegIdx, &outNbElement, gBuffer[0].in ); else retCode = TA_MAX( startIdx, endIdx, gBuffer[0].in, period, &outBegIdx, &outNbElement, gBuffer[0].in ); /* The reference and TA-LIB should have the same output. */ if( retCode != retCodeRef ) { printf( "Failure: retCode != retCodeRef (2)\n" ); return TA_REGTEST_OPTIMIZATION_REF_ERROR; } if( outBegIdx != outBegIdxRef ) { printf( "Failure: outBegIdx != outBegIdxRef (2)\n" ); return TA_REGTEST_OPTIMIZATION_REF_ERROR; } if( outNbElement != outNbElementRef ) { printf( "Failure: outNbElement != outNbElementRef (2)\n" ); return TA_REGTEST_OPTIMIZATION_REF_ERROR; } /* checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; } } } } } return TA_SUCCESS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); if( test->doAverage ) { TA_SetUnstablePeriod( TA_FUNC_UNST_ATR, test->unstablePeriod ); retCode = TA_ATR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[0].out0 ); } else { retCode = TA_TRANGE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); } errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkExpectedValue( gBuffer[0].out0, retCode, test->expectedRetCode, outBegIdx, test->expectedBegIdx, outNbElement, test->expectedNbElement, test->oneOfTheExpectedOutReal, test->oneOfTheExpectedOutRealIndex ); if( errNb != TA_TEST_PASS ) return errNb; outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ if( test->doAverage ) { TA_SetUnstablePeriod( TA_FUNC_UNST_ATR, test->unstablePeriod ); retCode = TA_ATR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[0].in ); } else { retCode = TA_TRANGE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, &outBegIdx, &outNbElement, gBuffer[0].in ); } /* The previous call to TA_MA should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkExpectedValue( gBuffer[0].in, retCode, test->expectedRetCode, outBegIdx, test->expectedBegIdx, outNbElement, test->expectedNbElement, test->oneOfTheExpectedOutReal, test->oneOfTheExpectedOutRealIndex ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_ATR, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test_per_ema( TA_Libc *libHandle, const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); setInputBuffer( 1, history->close, history->nbBars ); /* Set the unstable period requested for that test. */ retCode = TA_SetUnstablePeriod( libHandle, TA_FUNC_UNST_EMA, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; /* Make a simple first call. */ switch( test->theFunction ) { case TA_TRIX_TEST: retCode = TA_TRIX( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[0].out0 ); } errNb = checkDataSame( gBuffer[0].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkExpectedValue( gBuffer[0].out0, retCode, test->expectedRetCode, outBegIdx, test->expectedBegIdx, outNbElement, test->expectedNbElement, test->oneOfTheExpectedOutReal, test->oneOfTheExpectedOutRealIndex ); if( errNb != TA_TEST_PASS ) return errNb; outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_TRIX_TEST: retCode = TA_TRIX( libHandle, test->startIdx, test->endIdx, gBuffer[1].in, test->optInTimePeriod_0, &outBegIdx, &outNbElement, gBuffer[1].in ); } /* The previous call to TA_MA should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkExpectedValue( gBuffer[1].in, retCode, test->expectedRetCode, outBegIdx, test->expectedBegIdx, outNbElement, test->expectedNbElement, test->oneOfTheExpectedOutReal, test->oneOfTheExpectedOutRealIndex ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( libHandle, rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( TA_Libc *libHandle, const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; const TA_Real *highPtr; const TA_Real *lowPtr; TA_Integer nbPriceBar; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ if( test->useWilderData ) { highPtr = wilderHigh; lowPtr = wilderLow; nbPriceBar = WILDER_NB_BAR; } else { highPtr = history->high; lowPtr = history->low; nbPriceBar = history->nbBars; } setInputBuffer( 0, highPtr, nbPriceBar ); setInputBuffer( 1, lowPtr, nbPriceBar ); /* Make a simple first call. */ retCode = TA_SAR( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInAcceleration, test->optInMaximum, &outBegIdx, &outNbElement, gBuffer[0].out0 ); errNb = checkDataSame( gBuffer[0].in, highPtr, nbPriceBar ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, lowPtr, nbPriceBar ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_SAR( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInAcceleration, test->optInMaximum, &outBegIdx, &outNbElement, gBuffer[1].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); if( errNb != TA_TEST_PASS ) return errNb; /* Make sure the other input is untouched. */ errNb = checkDataSame( gBuffer[0].in, highPtr, nbPriceBar ); if( errNb != TA_TEST_PASS ) return errNb; /* Repeat that last test but with the first parameter this time. */ /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, highPtr, nbPriceBar ); setInputBuffer( 1, lowPtr, nbPriceBar ); /* Make another call where the input and the output are the * same buffer. */ retCode = TA_SAR( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInAcceleration, test->optInMaximum, &outBegIdx, &outNbElement, gBuffer[0].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); if( errNb != TA_TEST_PASS ) return errNb; /* Make sure the other input is untouched. */ errNb = checkDataSame( gBuffer[1].in, lowPtr, nbPriceBar); if( errNb != TA_TEST_PASS ) return errNb; return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); /* Clear the unstable periods from previous tests. */ retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MFI, 0 ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; /* Make a simple first call. */ switch( test->theFunction ) { case TA_MFI_TEST: retCode = TA_MFI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_AD_TEST: retCode = TA_AD( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_ADOSC_3_10_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 3, 10, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_ADOSC_5_2_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 5, 2, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; default: retCode = TA_INTERNAL_ERROR(133); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_MFI_TEST: retCode = TA_MFI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_AD_TEST: retCode = TA_AD( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_ADOSC_3_10_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 3, 10, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_ADOSC_5_2_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 5, 2, &outBegIdx, &outNbElement, gBuffer[0].in ); break; default: retCode = TA_INTERNAL_ERROR(134); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); setInputBuffer( 0, history->high, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_MFI_TEST: retCode = TA_MFI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_AD_TEST: retCode = TA_AD( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_ADOSC_3_10_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 3, 10, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_ADOSC_5_2_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 5, 2, &outBegIdx, &outNbElement, gBuffer[1].in ); break; default: retCode = TA_INTERNAL_ERROR(135); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call to TA_MA should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); setInputBuffer( 1, history->low, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_MFI_TEST: retCode = TA_MFI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_AD_TEST: retCode = TA_AD( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_ADOSC_3_10_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 3, 10, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_ADOSC_5_2_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 5, 2, &outBegIdx, &outNbElement, gBuffer[2].in ); break; default: retCode = TA_INTERNAL_ERROR(136); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[2].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[2].in, 0 ); setInputBuffer( 2, history->close, history->nbBars ); if( test->doRangeTestFlag ) { /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; testParam.volume = history->volume; switch( test->theFunction ) { case TA_MFI_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_MFI, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; break; case TA_AD_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, TA_DO_NOT_COMPARE ); if( errNb != TA_TEST_PASS ) return errNb; break; case TA_ADOSC_3_10_TEST: case TA_ADOSC_5_2_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 1, TA_DO_NOT_COMPARE ); if( errNb != TA_TEST_PASS ) return errNb; break; default: break; } } /* Check for fix #1359452 - AD RAnge not working as expected. */ if( test->theFunction == TA_AD_TEST ) { gBuffer[0].out0[0] = -1.0; gBuffer[0].out0[1] = -1.0; retCode = TA_AD( 0, 0, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, &gBuffer[0].out0[0] ); if( retCode != TA_SUCCESS ) { printf( "Failed AD call for fix #1359452 [%d]\n", retCode ); return TA_TEST_FAIL_BUG1359452_1; } if( gBuffer[0].out0[0] == -1.0 ) { printf( "Failed AD call for fix #1359452 out0[0] == -1\n" ); return TA_TEST_FAIL_BUG1359452_2; } retCode = TA_AD( 1, 1, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, &gBuffer[0].out0[1] ); if( retCode != TA_SUCCESS ) { printf( "Failed AD call for fix #1359452 [%d]\n", retCode ); return TA_TEST_FAIL_BUG1359452_3; } if( gBuffer[0].out0[1] == -1.0 ) { printf( "Failed AD call for fix #1359452 out0[1] == -1\n" ); return TA_TEST_FAIL_BUG1359452_4; } /* The two values are to be different. */ if( gBuffer[0].out0[1] == gBuffer[0].out0[0] ) { printf( "Failed AD logic for fix #1359452\n" ); return TA_TEST_FAIL_BUG1359452_5; } } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); /* Set the unstable period requested for that test. */ switch( test->optInSlowK_MAType_2 ) { case TA_MAType_EMA: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_EMA, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; break; default: /* No unstable period for other methods. */ break; } /* Make a simple first call. */ retCode = TA_STOCH( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInFastK_Period_0, test->optInSlowK_Period_1, test->optInSlowK_MAType_2, test->optInSlowD_Period_3, test->optInSlowD_MAType_4, &outBegIdx, &outNbElement, gBuffer[0].out0, gBuffer[0].out1 ); errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[0].out1, 1 ); outBegIdx = outNbElement = 0; /* Compare to the non-optimized version */ retCode = referenceStoch( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInFastK_Period_0, test->optInSlowK_Period_1, test->optInSlowK_MAType_2, test->optInSlowD_Period_3, test->optInSlowD_MAType_4, &outBegIdx, &outNbElement, gBuffer[1].out0, gBuffer[1].out1 ); errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[1].out1, 1 ); /* The non-optimized reference shall be identical to the optimzied TA-Lib * implementation. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[1].out0, gBuffer[0].out0 ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkSameContent( gBuffer[1].out1, gBuffer[0].out1 ); if( errNb != TA_TEST_PASS ) return errNb; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_STOCH( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInFastK_Period_0, test->optInSlowK_Period_1, test->optInSlowK_MAType_2, test->optInSlowD_Period_3, test->optInSlowD_MAType_4, &outBegIdx, &outNbElement, gBuffer[0].in, gBuffer[1].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkSameContent( gBuffer[0].out1, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); CHECK_EXPECTED_VALUE( gBuffer[1].in, 1 ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 2, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } /* Call a local non-optimized version of the function. * This way, we make sure that the currently speed optimized * version in TA-Lib is not broken. */ return TA_TEST_PASS; }