vslsparametrizedmatrix.c

来自「使用INTEL矢量统计类库的程序,包括以下功能: &#61623 Raw」· C语言 代码 · 共 144 行

C
144
字号
/*******************************************************************************!                             INTEL CONFIDENTIAL!  Copyright(C) 2008 Intel Corporation. All Rights Reserved.!  The source code contained  or  described herein and all documents related to!  the source code ("Material") are owned by Intel Corporation or its suppliers!  or licensors.  Title to the  Material remains with  Intel Corporation or its!  suppliers and licensors. The Material contains trade secrets and proprietary!  and  confidential  information of  Intel or its suppliers and licensors. The!  Material  is  protected  by  worldwide  copyright  and trade secret laws and!  treaty  provisions. No part of the Material may be used, copied, reproduced,!  modified, published, uploaded, posted, transmitted, distributed or disclosed!  in any way without Intel's prior express written permission.!  No license  under any  patent, copyright, trade secret or other intellectual!  property right is granted to or conferred upon you by disclosure or delivery!  of the Materials,  either expressly, by implication, inducement, estoppel or!  otherwise.  Any  license  under  such  intellectual property  rights must be!  express and approved by Intel in writing.!!*******************************************************************************!  Content:!  Parametrization of correlation matrix  Example Program Text!******************************************************************************/#include <stdio.h>#include "vsl_ss.h"/* parameters of the task */#define DIM 3      /* dimension of the task */#define RETURN_ON_ERROR                 \    if(status<0)                        \    {                                   \        printf("Error: %i\n", status);  \        return 0;                       \    }/* Distorted correlation matrix */static float Cin[DIM*DIM] = { 1.0, 0.9, 0.7,                                0.9, 1.0, 0.29,                                0.7, 0.29, 1.0  };int main(){    VSLSSTaskPtr task=0;    MKL_INT i, j, k1, k2, incx=1;    MKL_INT dim = DIM, lwork = 25*DIM;    MKL_INT cor_storage, parametrized_cor_storage;    int status;    float Cout[DIM*DIM];    float B[DIM*DIM], Work[25*DIM];    float EigenVect[DIM];    char uplo, jobz;    printf("\nDisturbed correlation matrix\n\n");    for( i = 0 ; i < DIM ; i++ )    {        for( j = 0 ; j < DIM ; j++ )        {            printf("%+1.5f ", Cin[i*DIM + j]);        }        printf("\n");    }    printf("\n");        for( j = 0 ; j < DIM*DIM ; j++ )    {        B[j] = Cin[j];    }        uplo = 'U';    jobz = 'N';    ssyev( &jobz, &uplo, &dim, B, &dim, EigenVect, Work, &lwork, &status );    RETURN_ON_ERROR;    printf("Eigenvalue of the disturbed correlation matrix\n\n");    for( j = 0 ; j < DIM ; j++ )    {        printf("%+1.5f ", EigenVect[j]);    }    printf("\n");    /* Create task */    status = vslsSSNewTask( &task, &dim, 0, 0, 0, 0, 0 );    cor_storage = VSL_SS_MATRIX_FULL_STORAGE;    parametrized_cor_storage = VSL_SS_MATRIX_FULL_STORAGE;    /* Register arrays for parameterization of the correlation matrix */    status = vslsSSEditMatrixParameterization( task,             Cin, &cor_storage,             Cout, &parametrized_cor_storage );    RETURN_ON_ERROR;    /* Execute task */    status = vslsSSCompute( task, VSL_SS_MATRIX_PARAMETERIZATION,                            VSL_SS_SPECTRAL_DECOMPOSITION_METHOD );    if( status != 0 )    {        printf("Error/Warning: %i\n", status);    }    /* Delete task */    status = vslSSDeleteTask( &task );    RETURN_ON_ERROR;    printf("\n\nParametrized correlation matrix\n\n");    for ( i = 0 ; i < DIM ; i++ )    {        for( j = 0 ; j < DIM ; j++ )        {            printf("%+1.5f ", Cout[ i*DIM + j ]);        }        printf("\n");    }    for( j = 0 ; j < DIM*DIM ; j++ )    {        B[j] = Cout[j];    }    uplo = 'U';    jobz = 'N';    ssyev( &jobz, &uplo, &dim, B, &dim, EigenVect, Work, &lwork, &status );    RETURN_ON_ERROR;    printf("\nEigenvalue of the parametrized correlation matrix\n\n");    for( j = 0 ; j < DIM ; j++ )    {        printf("%+1.5f ", EigenVect[j]);    }    printf("\n");    if( EigenVect[0] < -1e-6 )    {        printf("\nTEST FAILED\n");    }    else    {        printf("\nTEST PASSED\n");    }    return 0;}

⌨️ 快捷键说明

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