当前位置: 首页>>代码示例>>C++>>正文


C++ WolframLibraryData::MTensor_free方法代码示例

本文整理汇总了C++中WolframLibraryData::MTensor_free方法的典型用法代码示例。如果您正苦于以下问题:C++ WolframLibraryData::MTensor_free方法的具体用法?C++ WolframLibraryData::MTensor_free怎么用?C++ WolframLibraryData::MTensor_free使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WolframLibraryData的用法示例。


在下文中一共展示了WolframLibraryData::MTensor_free方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

/**
 * Same as demo_TI_R, but pass in a packed array then manually free it.
 **/
DLLEXPORT int demo1_TI_R(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
	MTensor T0;
	mint I0;
	mreal R0;
	int err = LIBRARY_NO_ERROR;
	T0 = MArgument_getMTensor(Args[0]);
	I0 = MArgument_getInteger(Args[1]);
	
	err = libData->MTensor_getReal( T0, &I0, &R0);
	libData->MTensor_free(T0);
	if (err) return err;

	MArgument_setReal(Res, R0);
	return LIBRARY_NO_ERROR;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:18,代码来源:demo.c

示例2: findFirstAndSecondOrderSidebandPeaks

bool MathematicaPeakFinder::findFirstAndSecondOrderSidebandPeaks(const STI::Types::TDataMixedSeq& rawSidebandData, 
														const CalibrationResults_ptr& calibration, 
														double firstOrderSidebandSpacing, 
														double secondOrderSidebandSpacing, 
														double minimumX,
														double targetRange,
														MixedData& peaks,
														double carrierOffset)
{
	WolframLibraryData libData = 0;
	WolframRTL_initialize(WolframLibraryVersion);
	libData = WolframLibraryData_new(WolframLibraryVersion);

	//Setup arguments

	MTensor formatedSidebandData;		//List of {x,y} pairs, with gaps when y is below threshold

	if(!convertRawScopeData(libData, rawSidebandData, formatedSidebandData)) {
		return false;
	}

	//Initialize calibration tensor
	MTensor calTensor;
	int err;
	mint type = MType_Real;
	mint rank = 2;
	mint dims[2];
	dims[0] = 2;
	dims[1] = 2;
	err = libData->MTensor_new(type, rank, dims, &calTensor);

	if(err != 0)
		return false;

	if(!calibration->getPeaks(libData, &calTensor))
		return false;

	//Initialize results tensor
	MTensor peakResults;
	type = MType_Real;
	rank = 2;
	dims[2];
	dims[0] = 4;	//First and second order sidebands: { {+1, -1}, {+2, -2} }
	dims[1] = 2;	//{time, peak height}
	err = libData->MTensor_new(type, rank, dims, &peakResults);

	mreal firstOrderSidebandSpacingArg = firstOrderSidebandSpacing;
	mreal secondOrderSidebandSpacingArg = secondOrderSidebandSpacing;
	mreal minX = minimumX;
	mreal targetRangeArg = targetRange;
	mreal carrierOffsetArg = carrierOffset;

	if(err == 0) {
		Initialize_findFirstAndSecondOrderSidebands(libData);		//Begin call to Mathematica code

		err = findFirstAndSecondOrderSidebands(libData, formatedSidebandData, calTensor, firstOrderSidebandSpacingArg, secondOrderSidebandSpacingArg, minX, targetRangeArg, carrierOffsetArg, &peakResults);

		Uninitialize_findFirstAndSecondOrderSidebands(libData);		//End call to Mathematica code
	}
	
	if( err == 0) {
		//Copy results of peak search

		double value = 0;
		mint pos[2];
		peaks.clear();
		MixedData peak;
		for(int i = 1; i <= 4; i++) {
			pos[0] = i;
			peak.clear();
			for(int j = 1; j <= 2; j++) {
				pos[1] = j;
				err = libData->MTensor_getReal(peakResults, pos, &value);
				peak.addValue(value);
			}
			peaks.addValue(peak);
		}
	}

	cout << "Peak find results:" << endl;
	cout << peaks.print() << endl;
	

	libData->MTensor_free(formatedSidebandData);
	libData->MTensor_free(calTensor);
	libData->MTensor_free(peakResults);

	return (err == 0);

}
开发者ID:jasonhogan,项目名称:sti-deprecated,代码行数:90,代码来源:MathematicaPeakFinder.cpp

示例3: calculateFeedbackSignalsFromFirstAndSecondSideband

bool MathematicaPeakFinder::calculateFeedbackSignalsFromFirstAndSecondSideband(const MixedData& peaks, MixedData& feedback)
{
	WolframLibraryData libData = 0;
	WolframRTL_initialize(WolframLibraryVersion);
	libData = WolframLibraryData_new(WolframLibraryVersion);

	//Setup arguments

	//Initialize peak tensor
	MTensor peakTensor;
	int err;
	mint type = MType_Real;
	mint rank = 2;
	mint dims[2];
	dims[0] = 4;
	dims[1] = 2;
	err = libData->MTensor_new(type, rank, dims, &peakTensor);

	if(err != 0)
		return false;

	mint peakPos[2];

	for(int i = 1; i <= dims[0]; i++) {
		peakPos[0] = i;
		for(int j = 1; j <= dims[1]; j++) {
			peakPos[1] = j;
			err = libData->MTensor_setReal(peakTensor, peakPos, 
				peaks.getVector().at(i-1).getVector().at(j-1).getDouble());
		}
	}

	if(err != 0)
		return false;

	//Initialize result tensor
	MTensor feedbackResults;
	type = MType_Real;
	rank = 1;
	mint dimsRes[1];
	dimsRes[0] = 2;
	err = libData->MTensor_new(type, rank, dimsRes, &feedbackResults);

	if(err != 0)
		return false;

	Initialize_getFeedbackSignalsFromFirstAndSecondSidebands(libData);			//Begin call to Mathematica code

	err = getFeedbackSignalsFromFirstAndSecondSidebands(libData, peakTensor, &feedbackResults);

	Uninitialize_getFeedbackSignalsFromFirstAndSecondSidebands(libData);		//End call to Mathematica code

		
	if( err == 0) {
		//Copy results of the feedback function

		double value = 0;
		mint pos[1];
		feedback.clear();
		
		for(int j = 1; j <= 2; j++) {
			pos[0] = j;
			err = libData->MTensor_getReal(feedbackResults, pos, &value);
			feedback.addValue(value);
		}
	}
	
	cout << "Feedback results:" << endl;
	cout << feedback.print() << endl;

	libData->MTensor_free(peakTensor);
	libData->MTensor_free(feedbackResults);

	return (err == 0);
}
开发者ID:jasonhogan,项目名称:sti-deprecated,代码行数:75,代码来源:MathematicaPeakFinder.cpp

示例4: findCalibrationPeaks

bool MathematicaPeakFinder::findCalibrationPeaks(const STI::Types::TDataMixedSeq& rawCalData, double FSR_s, double minimumX,
												 const CalibrationResults_ptr& calResults)
{
	WolframLibraryData libData = 0;
	WolframRTL_initialize(WolframLibraryVersion);
	libData = WolframLibraryData_new(WolframLibraryVersion);

	//Setup arguments

	MTensor formatedScopeCalibrationData;		//List of {x,y} pairs, with gaps when y is below threshold

	if(!convertRawScopeData(libData, rawCalData, formatedScopeCalibrationData)) {
		return false;
	}

	////test
	//mint lens[2];
	//int err2;
	//double value;
	//
	//lens[0] = 4;
	//for(unsigned j = 1; j < 50; j++) {
	//	lens[0] = j;

	//	lens[1] = 1;
	//	err2 = libData->MTensor_getReal(formatedScopeCalibrationData, lens, &value);
	//	cout << "(" << value <<", ";
	//	lens[1] = 2;
	//	err2 = libData->MTensor_getReal(formatedScopeCalibrationData, lens, &value);
	//	cout << value << ")" << endl;
	//}


	MTensor calibration;
	int err;
	mint type = MType_Real;
	mint rank = 2;
	mint dims[2];
	dims[0] = 2;
	dims[1] = 2;
	err = libData->MTensor_new(type, rank, dims, &calibration);
	MTensor* result = &calibration;
	
	cout << "In Peak Finder: error = " << err << endl;

	if(err == 0) {
		Initialize_findCalibration(libData);		//Begin call to Mathematica code

		mreal fsrTime = FSR_s;
		mreal minX = minimumX;

		err = findCalibration(libData, formatedScopeCalibrationData, fsrTime, minX, &calibration);

		cout << "Calibration Result:" << endl;
		mint lens[2];
		int err2;
		double value = 0;
		for(unsigned j = 1; j <= 2; j++) {
			lens[0] = j;

			lens[1] = 1;
			err2 = libData->MTensor_getReal(calibration, lens, &value);
			cout << "(" << value <<", ";
			lens[1] = 2;
			err2 = libData->MTensor_getReal(calibration, lens, &value);
			cout << value << ")" << endl;
		}


		if(err == 0) {
			calResults->savePeaks(libData, &calibration);
		}

		Uninitialize_findCalibration(libData);		//End call to Mathematica code
	}
	

	libData->MTensor_free(formatedScopeCalibrationData);
	libData->MTensor_free(calibration);
	result = 0;

	return (err == 0);
}
开发者ID:jasonhogan,项目名称:sti-deprecated,代码行数:83,代码来源:MathematicaPeakFinder.cpp


注:本文中的WolframLibraryData::MTensor_free方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。