Add setblockcomplex value
This commit is contained in:
@@ -658,6 +658,10 @@ namespace Aurora {
|
||||
std::cerr<<"setBlockValue only support 1D-3D data!"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
if(isComplex()){
|
||||
std::cerr<<"Comple matrix please use setBlockComplexValue!"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
//横向vector,切面为0,为1,都强制设置aDim为1来处理
|
||||
if (isVector() && aDim == 0 && getDimSize(1)>1){
|
||||
aDim = 1;
|
||||
@@ -711,6 +715,70 @@ namespace Aurora {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool Matrix::setBlockComplexValue(int aDim,int aBeginIndex, int aEndIndex, std::complex<double> value) {
|
||||
if(aDim>2 ){
|
||||
std::cerr<<"setBlockValue only support 1D-3D data!"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
if(!isComplex()){
|
||||
std::cerr<<"Normal matrix please use setBlockValue!"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
//横向vector,切面为0,为1,都强制设置aDim为1来处理
|
||||
if (isVector() && aDim == 0 && getDimSize(1)>1){
|
||||
aDim = 1;
|
||||
}
|
||||
if (aBeginIndex>=getDimSize(aDim) || aBeginIndex<0){
|
||||
std::cerr<<"setBlockValue BeginIndx error!BeginIndx:"<<aBeginIndex<<std::endl;
|
||||
return false;
|
||||
}
|
||||
if (aEndIndex>=getDimSize(aDim) || aEndIndex<0){
|
||||
std::cerr<<"setBlockValue EndIndex error!EndIndex:"<<aEndIndex<<std::endl;
|
||||
return false;
|
||||
}
|
||||
int dimLength = std::abs(aEndIndex-aBeginIndex)+1;
|
||||
int dataSize = getDataSize()/getDimSize(aDim)*dimLength;
|
||||
int colStride = getDimSize(0);
|
||||
int sliceStride = getDimSize(0)*getDimSize(1);
|
||||
switch (aDim) {
|
||||
case 0:{
|
||||
for (size_t i = 0; i < getDimSize(2); i++)
|
||||
{
|
||||
for (size_t j = 0; j < getDimSize(1); j++)
|
||||
{
|
||||
cblas_zcopy(
|
||||
dimLength,
|
||||
&value,0,
|
||||
getData() + aBeginIndex*2 + j * colStride*2 +
|
||||
i * sliceStride*2,
|
||||
1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case 1:{
|
||||
int colStride2 = getDimSize(0);
|
||||
int sliceStride2 = dimLength*getDimSize(0);
|
||||
int copySize = sliceStride2;
|
||||
for (size_t i = 0; i < getDimSize(2); i++)
|
||||
{
|
||||
cblas_zcopy(copySize,
|
||||
&value, 0 ,
|
||||
getData() + aBeginIndex * colStride*2 +
|
||||
i * sliceStride*2, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case 2:{
|
||||
int copySize = dimLength*sliceStride;
|
||||
cblas_zcopy(copySize, &value, 0 ,getData() + aBeginIndex * sliceStride*2 ,1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool Matrix::setBlock(int aDim,int aBeginIndex, int aEndIndex, const Matrix& src){
|
||||
@@ -779,10 +847,14 @@ namespace Aurora {
|
||||
{
|
||||
for (size_t j = 0; j < getDimSize(1); j++)
|
||||
{
|
||||
cblas_dcopy(
|
||||
dimLength,
|
||||
src.getData()+j * colStride2 + i * sliceStride2, 1,
|
||||
getData() + aBeginIndex + j * colStride + i * sliceStride,
|
||||
cblas_dcopy(dimLength * getValueType(),
|
||||
src.getData() +
|
||||
j * colStride2 * getValueType() +
|
||||
i * sliceStride2 * getValueType(),
|
||||
1,
|
||||
getData() + aBeginIndex * getValueType() +
|
||||
j * colStride * getValueType() +
|
||||
i * sliceStride * getValueType(),
|
||||
1);
|
||||
}
|
||||
}
|
||||
@@ -795,17 +867,17 @@ namespace Aurora {
|
||||
int copySize = sliceStride2;
|
||||
for (size_t i = 0; i < getDimSize(2); i++)
|
||||
{
|
||||
cblas_dcopy(copySize,
|
||||
src.getData()+i * sliceStride2,1,
|
||||
getData() + aBeginIndex * colStride +
|
||||
i * sliceStride, 1);
|
||||
cblas_dcopy(copySize*getValueType(),
|
||||
src.getData()+i * sliceStride2*getValueType(),1,
|
||||
getData() + aBeginIndex * colStride*getValueType() +
|
||||
i * sliceStride*getValueType(), 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//copy slice
|
||||
case 2:{
|
||||
int copySize = dimLength*sliceStride;
|
||||
cblas_dcopy(copySize,src.getData(),1,getData() + aBeginIndex * sliceStride ,1);
|
||||
cblas_dcopy(copySize*getValueType(),src.getData(),1,getData() + aBeginIndex * sliceStride*getValueType() ,1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +188,8 @@ namespace Aurora {
|
||||
Matrix block(int aDim,int aBeginIndx, int aEndIndex) const;
|
||||
|
||||
bool setBlockValue(int aDim,int aBeginIndx, int aEndIndex,double value);
|
||||
bool setBlockComplexValue(int aDim,int aBeginIndx, int aEndIndex,std::complex<double> value);
|
||||
|
||||
|
||||
bool setBlock(int aDim,int aBeginIndx, int aEndIndex,const Matrix& src);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user