本文整理汇总了C++中TBuffer::alloc方法的典型用法代码示例。如果您正苦于以下问题:C++ TBuffer::alloc方法的具体用法?C++ TBuffer::alloc怎么用?C++ TBuffer::alloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBuffer
的用法示例。
在下文中一共展示了TBuffer::alloc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// ADD-BY-LEETEN 07/22/2011-BEGIN
void
ITLRandomField::_CollectRandomSamplesInBlock
(
const int iBlock,
const int iRandomVariable, // CRandomVariable& cRandomVariable,
float pfRandomSamples[],
// ADD-BY-LEETEN 07/31/2011-BEGIN
const bool bIsMappingToBins
// ADD-BY-LEETEN 07/31/2011-END
)
{
const CRandomVariable& cRandomVariable = this->CGetRandomVariable(iRandomVariable);
int iFeatureLength = cRandomVariable.piFeatureVector.USize();
// allocate the feature vector
TBuffer<double> pdFeatureVector;
pdFeatureVector.alloc(iFeatureLength);
const CBlock& cBlock = this->CGetBlock(iBlock);
int iNrOfCells = 1;
for(int d = 0; d < CBlock::MAX_DIM; d++)
iNrOfCells *= cBlock.piDimLengths[d];
for(int c = 0; c < iNrOfCells; c++)
{
// collect the feature vector
for(int f = 0; f < iFeatureLength; f++)
{
int iDataComponent = cRandomVariable.piFeatureVector[f];
const CDataComponent& cDataComponent = this->CGetDataComponent(iDataComponent);
const CArray &cArray = this->CGetArray(iBlock, iDataComponent);
const double *pdData = cArray.pdData;
int iBase = cArray.iBase;
int iStep = cArray.iStep;
double dValue = pdData[iBase + c * iStep];
pdFeatureVector[f] = cDataComponent.cRange.DClamp(dValue);
}
double dSample = cRandomVariable.DGetRandomVariable(&pdFeatureVector[0]);
dSample = cRandomVariable.cRange.DClamp(dSample);
if( bIsMappingToBins )
{
dSample = cRandomVariable.DMapToBin(dSample);
}
pfRandomSamples[c] = (float)dSample;
}
}
示例2: CGetDataComponent
void
ITLRandomField::_DumpData2NetCdf
(
)
{
for(int b = 0; b < IGetNrOfBlocks(); b++)
{
const CBlock& cBlock = this->CGetBlock(b);
int iNrOfCells = 1;
for(int d = 0; d < CBlock::MAX_DIM; d++)
iNrOfCells *= cBlock.piDimLengths[d];
TBuffer<double> pdTemp;
pdTemp.alloc(iNrOfCells);
#ifndef WITH_PNETCDF // ADD-BY-LEETEN 09/01/2011
size_t puStart[6];
size_t puCount[6];
// ADD-BY-LEETEN 09/01/2011-BEGIN
#else // #ifndef WITH_PNETCDF
MPI_Offset puStart[6];
MPI_Offset puCount[6];
MPI_Offset puStride[6];
for(int d = 0; d < sizeof(puStride)/sizeof(puStride[0]); d ++)
puStride[d] = 1;
#endif // #ifndef WITH_PNETCDF
// ADD-BY-LEETEN 09/01/2011-END
// time
puStart[0] = this->IGetNrOfTimeStamps() - 1;
puCount[0] = 1;
// block
#ifndef WITH_PNETCDF // ADD-BY-LEETEN 09/01/2011
puStart[1] = (size_t)b;
// ADD-BY-LEETEN 09/01/2011-BEGIN
#else // #ifndef WITH_PNETCDF
puStart[1] = (size_t)CGetBlock(b).iGlobalId;
#endif // #ifndef WITH_PNETCDF
// ADD-BY-LEETEN 09/01/2011-END
puCount[1] = 1;
for(int d = 0; d < CBlock::MAX_DIM; d++)
{
puStart[2+d] = 0;
puCount[2+d] = (size_t)cBlock.piDimLengths[CBlock::MAX_DIM - 1 - d];
}
for(int c = 0; c < IGetNrOfDataComponents(); c++)
{
const CDataComponent& cDataComponent = CGetDataComponent(c);
const CArray &cArray = this->CGetArray(b, c);
const double *pdData = cArray.pdData;
int iBase = cArray.iBase;
int iStep = cArray.iStep;
for(int v = 0; v < iNrOfCells; v++)
{
double dValue = pdData[iBase + v * iStep];
pdTemp[v] = cDataComponent.cRange.DClamp(dValue);
}
#ifndef WITH_PNETCDF // ADD-BY-LEETEN 08/12/2011
// dump the geometry of the given dim.
ASSERT_NETCDF(nc_put_vara_double(
iNcId,
cDataComponent.iVarId,
puStart,
puCount,
&pdTemp[0]));
// ADD-BY-LEETEN 08/12/2011-BEGIN
#else // #ifndef WITH_PNETCDF
// MOD-BY-LEETEN 09/01/2011-FROM:
// LOG_ERROR(fprintf(stderr, "PNetCDF is not fully supported yet."))
// TO:
ASSERT_NETCDF(ncmpi_put_vars_double_all(
iNcId,
cDataComponent.iVarId,
puStart,
puCount,
puStride,
&pdTemp[0]));
// MOD-BY-LEETEN 09/01/2011-END
#endif // #ifndef WITH_PNETCDF
// ADD-BY-LEETEN 08/12/2011-END
}
}
}
示例3: CGetRandomVariable
void
ITLRandomField::_DumpRandomSamples2NetCdf
(
const int iRandomVariable
)
{
for(int b = 0; b < IGetNrOfBlocks(); b++)
{
const CBlock& cBlock = this->CGetBlock(b);
int iNrOfCells = 1;
for(int d = 0; d < CBlock::MAX_DIM; d++)
iNrOfCells *= cBlock.piDimLengths[d];
TBuffer<float> pfTemp;
pfTemp.alloc(iNrOfCells);
#ifndef WITH_PNETCDF // ADD-BY-LEETEN 09/01/2011
size_t puStart[6];
size_t puCount[6];
// ADD-BY-LEETEN 09/01/2011-BEGIN
#else // #ifndef WITH_PNETCDF
MPI_Offset puStart[6];
MPI_Offset puCount[6];
MPI_Offset puStride[6];
for(int d = 0; d < sizeof(puStride)/sizeof(puStride[0]); d ++)
puStride[d] = 1;
#endif // #ifndef WITH_PNETCDF
// ADD-BY-LEETEN 09/01/2011-END
// time
puStart[0] = this->IGetNrOfTimeStamps() - 1;
puCount[0] = 1;
// block
#ifndef WITH_PNETCDF // ADD-BY-LEETEN 09/01/2011
puStart[1] = (size_t)b;
// ADD-BY-LEETEN 09/01/2011-BEGIN
#else // #ifndef WITH_PNETCDF
puStart[1] = (size_t)CGetBlock(b).iGlobalId;
#endif // #ifndef WITH_PNETCDF
// ADD-BY-LEETEN 09/01/2011-END
puCount[1] = 1;
for(int d = 0; d < CBlock::MAX_DIM; d++)
{
puStart[2+d] = 0;
puCount[2+d] = (size_t)cBlock.piDimLengths[CBlock::MAX_DIM - 1 - d];
}
_CollectRandomSamplesInBlock(b, iRandomVariable, &pfTemp[0], true);
#ifndef WITH_PNETCDF // ADD-BY-LEETEN 08/12/2011
ASSERT_NETCDF(nc_put_vara_float(
iNcId,
CGetRandomVariable(iRandomVariable).iVarId,
puStart,
puCount,
&pfTemp[0]));
// ADD-BY-LEETEN 08/12/2011-BEGIN
#else // #ifndef WITH_PNETCDF
// MOD-BY-LEETEN 09/01/2011-FROM:
// LOG_ERROR(fprintf(stderr, "PNetCDF is not fully supported yet."))
// TO:
ASSERT_NETCDF(ncmpi_put_vars_float_all(
iNcId,
CGetRandomVariable(iRandomVariable).iVarId,
puStart,
puCount,
puStride,
&pfTemp[0]));
// MOD-BY-LEETEN 09/01/2011-END
#endif // #ifndef WITH_PNETCDF
// ADD-BY-LEETEN 08/12/2011-END
}
}