• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ WolframLibraryData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: demo1_TI_R

/**
 * 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: reverseString

DLLEXPORT int reverseString(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) 
{
	mint i = 0, len = 0, n;
	
	if (string) 
		libData->UTF8String_disown(string);

	string = MArgument_getUTF8String(Args[0]);

	while (string[len]) {
		/* Error for non ASCII string */
		if (string[len] & 128) return LIBRARY_FUNCTION_ERROR;
		len++;
	}

	n = len/2;
	len--; /* For index origin 0 */
	for (i = 0; i < n; i++) {
		char ci = string[i];
		string[i] = string[len - i];
		string[len - i] = ci;
	}

	MArgument_setUTF8String(Res, string);
	return 0;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:26,代码来源:demo_string.c


示例3: runODE

// Parameter order:
// inits
// params
// duration
EXTERN_C DLLEXPORT int runODE(WolframLibraryData libData, mint argc, MArgument *argv, MArgument aResult)
    {
    MTensor tensorInits  = MArgument_getMTensor(argv[0]);
    MTensor tensorParams = MArgument_getMTensor(argv[1]);
    double  duration     = MArgument_getReal(argv[2]);
    double  dt           = MArgument_getReal(argv[3]);

    mint rankState  = (mint)(sizeof(ODESTATE)      / sizeof(double));
    mint rankParams = (mint)(sizeof(ODEPARAMETERS) / sizeof(double));

    // Trace("state:%d params:%d", rankState, rankParams);

    ODESTATE inits;
    ODEPARAMETERS parameters;

    copyFromTensor(libData, (double*)&inits, rankState, tensorInits);
    copyFromTensor(libData, (double*)&parameters, rankParams, tensorParams);
    
    ODESTATE result = runODECore(inits, parameters, duration, dt);

    MTensor tensorResult;
    libData->MTensor_new(MType_Real, 1, &rankState, &tensorResult);
    copyToTensor(libData, tensorResult, (double*)&result, rankState);

    MArgument_setMTensor(aResult, tensorResult);

    return LIBRARY_NO_ERROR;
    }
开发者ID:rgatkinson,项目名称:PCRModelling,代码行数:32,代码来源:odeSkeleton.cpp


示例4: encodeString

DLLEXPORT int encodeString(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) 
{
	mint i = 0, shift;
	
	if (string) 
		libData->UTF8String_disown(string);

	string = MArgument_getUTF8String(Args[0]);
	shift = MArgument_getInteger(Args[1]);

	/* Find shift mod 127 so we only 
	   deal with positive numbers below */
	shift = shift % 127;
	if (shift < 0) 
		shift += 127;

	shift -= 1; 
		
	while (string[i]) {
		mint c = (mint) string[i];
		/* Error for non ASCII string */
		if (c & 128) return LIBRARY_FUNCTION_ERROR;
		c = ((c + shift) % 127) + 1;
		string[i++] = (char) c;
	}
	MArgument_setUTF8String(Res, string);
	return 0;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:28,代码来源:demo_string.c


示例5: brusselator_pde_jacobian_positions

DLLEXPORT int brusselator_pde_jacobian_positions(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) 
{
	int err;
	mint dims[2];
    mint i, j, k, n, nr;
	mint *jpos;
    MTensor Tres, Targ;
    Targ = MArgument_getMTensor(Args[1]);
    if (libData->MTensor_getType(Targ) != MType_Real) return LIBRARY_TYPE_ERROR;
    if (libData->MTensor_getRank(Targ) != 1) return LIBRARY_RANK_ERROR;
    nr = libData->MTensor_getFlattenedLength(Targ);
    n = nr/2;

	dims[0] = 4 + 8*(n - 2);
	dims[1] = 2;
    err = libData->MTensor_new(MType_Integer, 2, dims, &Tres);
	if (err) return err;
    jpos = libData->MTensor_getIntegerData(Tres);

    /* Decrement n so loop excludes boundaries */
    n--;
	k = 0;

	jpos[k++] = 1; jpos[k++] = 1; /* u[0] bc */
    for (i = 1; i < n; i++) {	
		/* u equations */
		mint r = i + 1;
		jpos[k++] = r; jpos[k++] = i;
		jpos[k++] = r; jpos[k++] = i + 1;
		jpos[k++] = r; jpos[k++] = i + 2;
		jpos[k++] = r; jpos[k++] = i + n + 2;
	}
	jpos[k++] = n + 1; jpos[k++] = n + 1; /* u[n] bc */
	jpos[k++] = n + 2; jpos[k++] = n + 2; /* v[0] bc */
    for (i = 1; i < n; i++) {	
		/* v equations */
		mint r = i + n + 2;
		jpos[k++] = r; jpos[k++] = i + 1;
		jpos[k++] = r; jpos[k++] = i + n + 1;
		jpos[k++] = r; jpos[k++] = i + n + 2;
		jpos[k++] = r; jpos[k++] = i + n + 3;
	}
	jpos[k++] = 2*(n + 1); jpos[k++] = 2*(n + 1); /* v[n] bc */

    MArgument_setMTensor(Res, Tres);
    return 0;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:47,代码来源:demo_numerical.c


示例6: demoNoResult

/* Accepts inputs, but returns nothing */
DLLEXPORT int demoNoResult(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res)
{
	MTensor T = MArgument_getMTensor(Args[0]);
	mint *p = libData->MTensor_getIntegerData(T);

	*p = MArgument_getAddress(Res) == 0? 0:1;
	return LIBRARY_NO_ERROR;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:9,代码来源:demo.c


示例7: demo_TT_T

/**
 * Same as demo_TI_R, but just to avoid copying
 **/
DLLEXPORT int demo_TT_T(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
	MTensor T0, T1, T2;
	mint I0;
	mreal R0;
	int err = LIBRARY_NO_ERROR;
	T0 = MArgument_getMTensor(Args[0]);
	T1 = MArgument_getMTensor(Args[1]);
	I0 = (libData->MTensor_getIntegerData(T1))[0];	
	err = libData->MTensor_getReal( T0, &I0, &R0);
	if (err) return err;

	err = libData->MTensor_new(MType_Real, 0, NULL, &T2);
	if (err) return err;
	(libData->MTensor_getRealData(T2))[0] = R0;
	
	MArgument_setMTensor(Res, T2);
	return LIBRARY_NO_ERROR;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:21,代码来源:demo.c


示例8: demo_TIII_I

/* Sets the I0,I1 th integer element of T0 with value, returning that position */
DLLEXPORT int demo_TIII_I(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
	MTensor T0;
	mint I0, I1, value, res;
	mint dims[2];
	int err = LIBRARY_NO_ERROR;

	T0 = MArgument_getMTensor(Args[0]);
	I0 = MArgument_getInteger(Args[1]);
	I1 = MArgument_getInteger(Args[2]);
	value = MArgument_getInteger(Args[3]);
	dims[0] = I0;
	dims[1] = I1;
	err = libData->MTensor_setInteger(T0, dims, value);
	if (err) return err;
	err = libData->MTensor_getInteger(T0, dims, &res);
	MArgument_setInteger(Res, res);
	return err;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:19,代码来源:demo.c


示例9: demo1_I_T

/**
 * Constructs a new rank 1 tensor with dimension I0, and sets the
 * ith element with the value 2*i. The newly constructed tensor is
 * returned.
 **/
DLLEXPORT int demo1_I_T(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
	MTensor T0, T1;
	mint i, I0, dims[1];
	int err = LIBRARY_NO_ERROR;

	I0 = MArgument_getInteger(Args[0]);
	dims[0] = I0;
	
	err = libData->MTensor_new(MType_Integer, 1, dims, &T1);
	if (err) return err;
	libData->MTensor_free(T1);
	
	err = libData->MTensor_new(MType_Integer, 1, dims, &T0);
	for ( i = 1; i <= I0 && !err; i++) {
		err = libData->MTensor_setInteger( T0, &i, i*2);
	}
	MArgument_setMTensor(Res, T0);
	return LIBRARY_NO_ERROR;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:24,代码来源:demo.c


示例10: WolframLibrary_initialize

EXTERN_C DLLEXPORT int WolframLibrary_initialize(WolframLibraryData libData) {
   
	// Initialize the COM library
	hr = CoInitialize(NULL);
	if (FAILED(hr))
	{
		libData->Message("cominitfail");
		return LIBRARY_FUNCTION_ERROR;
	}

	// Initialize Media Foundation.
	hr = MFStartup(MF_VERSION);
	if (FAILED(hr))
    {
		libData->Message("mfinitfail");
		return LIBRARY_FUNCTION_ERROR;    
    }

	return LIBRARY_NO_ERROR;
}
开发者ID:SimonWoods,项目名称:MathMF,代码行数:20,代码来源:MathMF.cpp


示例11: demo_TI_T

/* Gets the subpart of the input tensor starting at the I0 th position */
DLLEXPORT int demo_TI_T(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
	MTensor T0, T1 = 0;
	mint I0;
	int err = LIBRARY_NO_ERROR;

	T0 = MArgument_getMTensor(Args[0]);
	I0 = MArgument_getInteger(Args[1]);
	err = libData->MTensor_getMTensor(T0, &I0, 1, &T1);
	MArgument_setMTensor(Res, T1);
	return err;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:12,代码来源:demo.c


示例12: copyToTensor

void copyToTensor(WolframLibraryData libData, MTensor tensor, double* pSource, mint cSrc)
    {
    double* pDest = libData->MTensor_getRealData(tensor);

    mint cDest = arraySize(libData, tensor);
    mint cb = min(cDest, cSrc) * sizeof(double);
    mint cbDest = cDest * sizeof(double);

    memcpy(pDest, pSource, cb);
    memset(&pDest[cSrc], 0, cbDest - cb);
    }
开发者ID:rgatkinson,项目名称:PCRModelling,代码行数:11,代码来源:odeSkeleton.cpp


示例13: FinaliseSink

EXTERN_C DLLEXPORT int FinaliseSink(WolframLibraryData libData, mint Argc, MArgument * Args, MArgument Res) {

	hr = VW.finalise();

	if (FAILED(hr))
	{
		libData->Message("finalisefail");
		return LIBRARY_FUNCTION_ERROR;
	}

	return LIBRARY_NO_ERROR;
} 
开发者ID:SimonWoods,项目名称:MathMF,代码行数:12,代码来源:MathMF.cpp


示例14: demo_TTT_T

/**
 * Intended to demonstrate working with rank 0 tensors.
 *
 * The arguments are three tensors.  
 * The first is a rank > 0 real tensor.
 * The second is a rank 0 integer tensor.
 * The third a rank 0 real tensor.
 *
 * The second argument is used as an index to find
 * an element of the first, which is added to the
 * third argument to form the result.
 *
 * The result is returned as a rank 0 real tensor.
 **/
DLLEXPORT int demo_TTT_T(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
	MTensor T_arg, T_I_arg, T_R_arg, T_res;
	mint I0;
	mreal R0, R1;
	int err = LIBRARY_NO_ERROR;
	T_arg = MArgument_getMTensor(Args[0]);
	T_I_arg = MArgument_getMTensor(Args[1]);
	T_R_arg = MArgument_getMTensor(Args[2]);
	I0 = (libData->MTensor_getIntegerData(T_I_arg))[0];
	R0 = (libData->MTensor_getRealData(T_R_arg))[0];	
	err = libData->MTensor_getReal( T_arg, &I0, &R1);
	if (err) return err;
	R0 = R0 + R1;

	err = libData->MTensor_new(MType_Integer, 0, NULL, &T_res);
	if (err) return err;
	(libData->MTensor_getIntegerData( T_res))[0] = (mint) R0;
	
	MArgument_setMTensor(Res, T_res);
	return LIBRARY_NO_ERROR;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:35,代码来源:demo.c


示例15: InitSinkWriter

EXTERN_C DLLEXPORT int InitSinkWriter(WolframLibraryData libData, mint Argc, MArgument * Args, MArgument Res) {

	// Get the arguments from MArgument
	char *videofile = MArgument_getUTF8String(Args[0]);

	// convert UTF8 filename to wide chars
	int size = MultiByteToWideChar(CP_ACP, 0, videofile, -1, NULL, 0);
	WCHAR* videofileW = new WCHAR[size];
	size = MultiByteToWideChar(CP_ACP, 0, videofile, -1, videofileW, size);
	
	// extract the sink parameters
	mint encoder =		MArgument_getInteger(Args[1]);
	mint width =		MArgument_getInteger(Args[2]);
	mint height =		MArgument_getInteger(Args[3]);
	mreal framerate =	MArgument_getReal(Args[4]);
	mint kbps =			MArgument_getInteger(Args[5]);

	hr = VW.setParams(encoder, width, height, framerate, kbps);
	if (FAILED(hr))
	{
		libData->Message("setsinkparamsfail");
		return LIBRARY_FUNCTION_ERROR;
	}

	// Initialise the sink writer
	hr = VW.initSinkWriter(videofileW);

	// finished with the filename now
	delete videofileW;	
	
	if (FAILED(hr))
	{
		libData->Message("initsinkfail");
		return LIBRARY_FUNCTION_ERROR;
	}

	return LIBRARY_NO_ERROR;
} 
开发者ID:SimonWoods,项目名称:MathMF,代码行数:38,代码来源:MathMF.cpp


示例16: countSubstring

DLLEXPORT int countSubstring(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res)
{
	char *instring = MArgument_getUTF8String(Args[0]);
	char *substring = MArgument_getUTF8String(Args[1]);
	mint i, n = strlen(instring);
	mint slen = strlen(substring);
	mint c = 0;

	if (n > slen) {
		n -= slen;
		for (i = 0; i <= n; i++) {
			if (!strncmp(instring + i, substring, slen)) {
				c++;
			}
		}
	}

	MArgument_setInteger(Res, c);

	libData->UTF8String_disown(instring);
	libData->UTF8String_disown(substring);
	
	return 0;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:24,代码来源:demo_string.c


示例17: WolframLibrary_uninitialize

EXTERN_C DLLEXPORT void WolframLibrary_uninitialize(WolframLibraryData libData) {

	VR.~VidReader(); // destruct the class instances
	VW.~VidWriter(); 

	// Shut down media foundation and close the COM library
	hr = MFShutdown();
	if (FAILED(hr))
	{
		libData->Message("mfshutdownfail");
	} 
	CoUninitialize();
	
	return;
}
开发者ID:SimonWoods,项目名称:MathMF,代码行数:15,代码来源:MathMF.cpp


示例18: demo_TTII_T

/* Sets the element in the I0,I1 position in T0 to its value in T1, returning T0 */
DLLEXPORT int demo_TTII_T(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {
	MTensor T0, T1;
	mint I0, I1;
	mint pos[2];
	int err = LIBRARY_NO_ERROR;

	T0 = MArgument_getMTensor(Args[0]);
	T1 = MArgument_getMTensor(Args[1]);
	I0 = MArgument_getInteger(Args[2]);
	I1 = MArgument_getInteger(Args[3]);
	pos[0] = I0;
	pos[1] = I1;
	err = libData->MTensor_setMTensor(T0, T1, pos, 2);
	MArgument_setMTensor(Res, T0);
	return err;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:17,代码来源:demo.c


示例19: read_raw_image

EXTERN_C DLLEXPORT int read_raw_image(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument res) {
	int err;
	int check;
	MImage out;
	char * file;
	libraw_data_t *iprc = libraw_init(0);
	libraw_processed_image_t * img;
	WolframImageLibrary_Functions imgFuns = libData->imageLibraryFunctions;

	err = LIBRARY_FUNCTION_ERROR;
	file = MArgument_getUTF8String(Args[0]);

	libraw_open_file(iprc, file);
	libraw_unpack(iprc);

	iprc->params.output_bps = 8;

	check = libraw_dcraw_process(iprc);
	if (check != LIBRAW_SUCCESS) goto cleanup;

	img = libraw_dcraw_make_mem_image(iprc, &check);
	if (img == NULL) goto cleanup;
	if (img->type != LIBRAW_IMAGE_BITMAP || img->colors != 3) goto cleanup;
	
	if (img->bits == 16) {
		raw_t_ubit16 * raw_data = (raw_t_ubit16*)img->data;
		imgFuns->MImage_new2D(img->width, img->height, 3, MImage_Type_Bit16, MImage_CS_RGB, 1, &out);
		memcpy(imgFuns->MImage_getBit16Data(out), raw_data, img->width * img->height * 3 * sizeof(raw_t_ubit16));
	} else if (img->bits == 8) {
		raw_t_ubit8 * raw_data = (raw_t_ubit8*)img->data;
		imgFuns->MImage_new2D(img->width, img->height, 3, MImage_Type_Bit8, MImage_CS_RGB, 1, &out);
		memcpy(imgFuns->MImage_getByteData(out), raw_data, img->width * img->height * 3 * sizeof(raw_t_ubit8));
	} else {
		goto cleanup;
	}
	
	MArgument_setMImage(res, out);
	err = LIBRARY_NO_ERROR;

cleanup:
	libData->UTF8String_disown(file);
	libraw_dcraw_clear_mem(img);
	return err;
}
开发者ID:Jazmann,项目名称:Color-Space-WriteUp,代码行数:44,代码来源:image_external.c


示例20: brusselator_pde_jacobian_values

DLLEXPORT int brusselator_pde_jacobian_values(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) 
{
	int err;
    mint i, j, k, n, nr;
    mreal dm;
    mreal *u, *v, *jval;
    MTensor Tres, Targ;
    Targ = MArgument_getMTensor(Args[1]);
    if (libData->MTensor_getType(Targ) != MType_Real) return LIBRARY_TYPE_ERROR;
    if (libData->MTensor_getRank(Targ) != 1) return LIBRARY_RANK_ERROR;
    nr = libData->MTensor_getFlattenedLength(Targ);
    n = nr/2;
    u = libData->MTensor_getRealData(Targ);
    v = u + n;

	nr = 4 + 8*(n - 2);
    err = libData->MTensor_new(MType_Real, 1, &nr, &Tres);
	if (err) return err;
    jval = libData->MTensor_getRealData(Tres);

    /* Decrement n so loop excludes boundaries */
    n--;
    dm = (mreal) n;
    dm *= alpha*dm;

	k = 0;

	jval[k++] = -1.; /* u[0] bc */
    for (i = 1; i < n; i++) {	
		/* u equations */
		jval[k++] = dm;
		jval[k++] = 2.*u[i]*v[i] - 4. - 2.*dm;
		jval[k++] = dm;
		jval[k++] = u[i]*u[i]; 
	}
	jval[k++] = -1.; /* u[n] bc */
	jval[k++] = -1.; /* v[0] bc */
    for (i = 1; i < n; i++) {	
		/* v equations */
		jval[k++] = 3. - 2.*u[i]*v[i];
		jval[k++] = dm;
		jval[k++] = -u[i]*u[i] - 2.*dm;
		jval[k++] = dm;
	}
	jval[k++] = -1.; /* v[n] bc */

    MArgument_setMTensor(Res, Tres);
    return 0;
}
开发者ID:qzmfranklin,项目名称:test,代码行数:49,代码来源:demo_numerical.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Word类代码示例发布时间:2022-05-31
下一篇:
C++ WndProperty类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap