Re: [eigen] cast ArrayXd* to ArrayXXd* |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] cast ArrayXd* to ArrayXXd*
- From: Holger Herrlich <holgerherrlich05@xxxxxxxx>
- Date: Thu, 27 Sep 2012 14:05:44 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=arcor.de; s=mail-in; t=1348747598; bh=X5mg2HsQeyFyqJDZ17q+ErlrqwZTEQTuJWtVY7/pyS4=; h=Message-ID:Date:From:MIME-Version:To:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=cgk1vryl5Oujze1yu4eAqI5qDdqE1ZtKR533huoqIB/Qi/A7eLlDGnbG6nazjRMIT huMLeKgVOYMgnuU8XiKMpdmBrCY1fT0nPNdNMQzQYkpamf8wjr/aCPqZnM1V9SOw2K fQglK+/T6itS2YwmO6jYoWclg9YonUFT7+jzLi74=
Do not know exactly how to provide more context.
The pointers deal with the problem to return an array from a function at
the context of my application.
This is such a function:
--8<---8<----
union TIntensity { double number;
Eigen::ArrayXd* arrayXd;
Eigen::ArrayXXd* arrayXXd;
};
Eigen::ArrayXXd*
CRecord::calc_reflectivity( OUTCOME outcome,
bool respect_tofRange,
bool respect_qzRange
) {
assert(outcome==TOF_SCALE || outcome==MATRIX);
TRANGE tRange;
XRANGE smXRange;
if(respect_qzRange==true)
tRange = TRANGE_QZ;
else
if(respect_tofRange==true)
tRange = TRANGE_TOF;
else
tRange = TRANGE_NONE;
if(outcome==MATRIX)
smXRange = XRANGE_NONE;
else
smXRange = XRANGE_SPX;
Eigen::ArrayXXd* smInt;
TIntensity tmp = this->calc_intensity( ITEM_SM,
outcome,
smXRange,
tRange );
if( outcome==TOF_SCALE ) {
smInt = new Eigen::ArrayXXd( *(tmp.arrayXd) );
delete(tmp.arrayXd);
}
else {
smInt = tmp.arrayXXd;
}
Eigen::ArrayXd* mtInt = (this->calc_intensity( ITEM_MT,
TOF_SCALE,
XRANGE_MPX,
tRange )).arrayXd;
double smNoise = (this->calc_intensity( ITEM_SM,
NUMBER,
XRANGE_NX,
tRange )).number;
double mtNoise = (this->calc_intensity( ITEM_MT,
NUMBER,
XRANGE_NX,
tRange )).number;
// intensity = intensity - noise (remove noise)
*smInt = (*smInt)-smNoise;
*mtInt = (*mtInt)-mtNoise;
// removing of noise might create bad values so:
Eigen::ArrayXXd* mtInt2D = new Eigen::ArrayXXd( smInt->rows(),
smInt->cols() );
mtInt2D->colwise() = *mtInt;
*smInt = smInt->binaryExpr(
*mtInt2D, ptr_fun<double,double,double>(auxFn_setSmToZero));
*mtInt2D = smInt->binaryExpr(
*mtInt2D, ptr_fun<double,double,double>(auxFn_setMtToNearZero ));
// refl = sm / mt * fact
*smInt = (*smInt)/(*mtInt2D)*this->getReflFactor();
delete(mtInt );
delete(mtInt2D );
return smInt;
}
--8<---8<----
Lg Holger
On 09/26/2012 04:22 PM, Christoph Hertzberg wrote:
> On 26.09.2012 14:50, Holger Herrlich wrote:
>>
>> Hi, did I really have to:
>>
>> Eigen::ArrayXXd* smInt;
>> Eigen::ArrayXd* tmp = fn_create();
>> smInt = new Eigen::ArrayXXd( *(tmp) );
>> delete(tmp.arrayXd);
>>
>> to cast from Array<double,len> to Array<double,len,1> when using
>> pointers?
>
> Well, there are many ways, but it would require a bit more context to
> find the best way in your case.
> Quite likely you don't need to use pointers at all (using plain pointers
> always bears the risk of memory leaks) and I don't know (m)any cases
> where ArrayXXd is accepted but ArrayXd is not (meaning I don't see why
> you need this cast).
>
> Christoph
>
>
>