Skip to content

Commit

Permalink
reverted to old formatting, no need to get differences on that.
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesDuvert committed Aug 26, 2023
1 parent 891b819 commit 1ef252f
Showing 1 changed file with 138 additions and 61 deletions.
199 changes: 138 additions & 61 deletions src/prognodeexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,47 +1265,59 @@ BaseGDL* MOD_OPNode::Eval()
return res;
}

BaseGDL* POWNode::Eval() {
BaseGDL* res;

BaseGDL* POWNode::Eval()
{ BaseGDL* res;
Guard<BaseGDL> e1(op1->Eval());
Guard<BaseGDL> e2(op2->Eval());
// special handling for aTy == complex && bTy != complex
DType aTy = e1->Type();
DType bTy = e2->Type();
if (aTy == GDL_STRING) {
if( aTy == GDL_STRING)
{
e1.reset(e1->Convert2(GDL_FLOAT, BaseGDL::COPY));

Check warning on line 1278 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1278

Added line #L1278 was not covered by tests
aTy = GDL_FLOAT;
}
if (bTy == GDL_STRING) {
if( bTy == GDL_STRING)
{
e2.reset(e2->Convert2(GDL_FLOAT, BaseGDL::COPY));

Check warning on line 1283 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1283

Added line #L1283 was not covered by tests
bTy = GDL_FLOAT;
}
//powers of complex must use std::pow always, no "integer power" refinement possible.
if (ComplexType(aTy)) {
if (IntType(bTy)) {
if( ComplexType( aTy))
{
if( IntType( bTy))
{
e2.reset(e2.release()->Convert2(GDL_LONG));
res = e1->Pow(e2.get());

Check warning on line 1292 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1291-L1292

Added lines #L1291 - L1292 were not covered by tests
if (res == e1.get())
e1.release();
return res;

Check warning on line 1295 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1295

Added line #L1295 was not covered by tests
}
if (aTy == GDL_COMPLEX) {
if (bTy == GDL_DOUBLE) {
if( aTy == GDL_COMPLEX)
{
if( bTy == GDL_DOUBLE)
{
e1.reset(e1.release()->Convert2(GDL_COMPLEXDBL));

Check warning on line 1301 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1301

Added line #L1301 was not covered by tests
aTy = GDL_COMPLEXDBL;
} else if (bTy == GDL_FLOAT) {
}
else if( bTy == GDL_FLOAT)
{
res = e1->Pow(e2.get());

Check warning on line 1306 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1306

Added line #L1306 was not covered by tests
if (res == e1.get())
e1.release();
return res;

Check warning on line 1309 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1309

Added line #L1309 was not covered by tests
}
}
if (aTy == GDL_COMPLEXDBL) {
if (bTy == GDL_FLOAT) {
if( aTy == GDL_COMPLEXDBL)
{
if( bTy == GDL_FLOAT)
{
e2.reset(e2.release()->Convert2(GDL_DOUBLE));

Check warning on line 1316 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1316

Added line #L1316 was not covered by tests
bTy = GDL_DOUBLE;
}
if (bTy == GDL_DOUBLE) {
if( bTy == GDL_DOUBLE)
{
res = e1->Pow(e2.get());

Check warning on line 1321 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1321

Added line #L1321 was not covered by tests
if (res == e1.get())
e1.release();
Expand All @@ -1315,7 +1327,8 @@ BaseGDL* POWNode::Eval() {
}

// GD: simplify: force use of PowInt for all integer powers, not only integer powers of float types as previously
if (IntType(bTy)) {
if (IntType(bTy))
{
e2.reset(e2.release()->Convert2(GDL_LONG));

Check warning on line 1332 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1332

Added line #L1332 was not covered by tests

res = e1->PowInt(e2.get());

Check warning on line 1334 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1334

Added line #L1334 was not covered by tests
Expand All @@ -1338,22 +1351,30 @@ BaseGDL* POWNode::Eval() {
// AdjustTypes(e2,e1); // order crucial here (for converting back)
AdjustTypes(e1, e2); // order crucial here (for converting back)

if (e1->StrictScalar()) {
if( e1->StrictScalar())
{
res = e2->PowInvS(e1.get()); // scalar+scalar or array+scalar
e2.release();
} else
if (e2->StrictScalar()) {
}
else
if( e2->StrictScalar())
{
res = e1->PowS(e2.get()); // array+scalar

Check warning on line 1362 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1362

Added line #L1362 was not covered by tests
e1.release();
} else
if (e1->N_Elements() <= e2->N_Elements()) {
}
else
if( e1->N_Elements() <= e2->N_Elements())
{
res = e1->Pow(e2.get()); // smaller_array + larger_array or same size

Check warning on line 1368 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1368

Added line #L1368 was not covered by tests
e1.release();
} else {
}
else
{
res = e2->PowInv(e1.get()); // smaller + larger

Check warning on line 1373 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L1373

Added line #L1373 was not covered by tests
e2.release();
}
if (convertBackT != GDL_UNDEF) {
if( convertBackT != GDL_UNDEF)
{
res = res->Convert2(convertBackT, BaseGDL::CONVERT);
}
return res;
Expand Down Expand Up @@ -2854,79 +2875,108 @@ else if( e1->N_Elements() < e2->N_Elements())
return res;
}

BaseGDL* POWNCNode::Eval() {

BaseGDL* POWNCNode::Eval()
{
BaseGDL* res;
Guard<BaseGDL> g1;
Guard<BaseGDL> g2;
BaseGDL *e1, *e2;
if (op1NC) {
if( op1NC)
{
e1 = op1->EvalNC();
} else {
}
else
{
e1 = op1->Eval();
g1.reset(e1);
}
if (op2NC) {
if( op2NC)
{
e2 = op2->EvalNC();
} else {
}
else
{
e2 = op2->Eval();
g2.reset(e2);
}

DType aTy = e1->Type();
DType bTy = e2->Type();

if (aTy == GDL_STRING) {
if( aTy == GDL_STRING)
{
e1 = e1->Convert2(GDL_FLOAT, BaseGDL::COPY);

Check warning on line 2909 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2909

Added line #L2909 was not covered by tests
g1.reset(e1); // deletes old e1
aTy = GDL_FLOAT;
}
if (bTy == GDL_STRING) {
if( bTy == GDL_STRING)
{
e2 = e2->Convert2(GDL_FLOAT, BaseGDL::COPY);

Check warning on line 2915 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2915

Added line #L2915 was not covered by tests
g2.reset(e2); // deletes old e2
bTy = GDL_FLOAT;
}
//powers of complex must use std::pow always, no "integer power" refinement possible.
if (ComplexType(aTy)) {
if (IntType(bTy)) {
if (bTy != GDL_LONG) {
if( ComplexType(aTy))
{
if( IntType( bTy))
{
if( bTy != GDL_LONG)
{
e2 = e2->Convert2(GDL_LONG, BaseGDL::COPY);
g2.reset(e2);
}
if (g1.get() == NULL) {
if( g1.get() == NULL)
{
return e1->PowNew(e2);
} else {
}
else
{
res = g1->Pow(e2);

Check warning on line 2935 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2935

Added line #L2935 was not covered by tests
if (res == g1.get())
g1.release();
return res;

Check warning on line 2938 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2938

Added line #L2938 was not covered by tests
}
}
if (aTy == GDL_COMPLEX) {
if (bTy == GDL_DOUBLE) {
if( aTy == GDL_COMPLEX)
{
if( bTy == GDL_DOUBLE)
{
e1 = e1->Convert2(GDL_COMPLEXDBL, BaseGDL::COPY);

Check warning on line 2945 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2945

Added line #L2945 was not covered by tests
g1.reset(e1);
aTy = GDL_COMPLEXDBL;
} else if (bTy == GDL_FLOAT) {
if (g1.get() == NULL) {
}
else if( bTy == GDL_FLOAT)
{
if( g1.get() == NULL)
{
return e1->PowNew(e2);

Check warning on line 2953 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2953

Added line #L2953 was not covered by tests
} else {
}
else
{
res = g1->Pow(e2);

Check warning on line 2957 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2957

Added line #L2957 was not covered by tests
if (res == g1.get())
g1.release();
return res;

Check warning on line 2960 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2960

Added line #L2960 was not covered by tests
}
}
}
if (aTy == GDL_COMPLEXDBL) {
if (bTy == GDL_FLOAT) {
if( aTy == GDL_COMPLEXDBL)
{
if( bTy == GDL_FLOAT)
{
e2 = e2->Convert2(GDL_DOUBLE, BaseGDL::COPY);

Check warning on line 2968 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2968

Added line #L2968 was not covered by tests
g2.reset(e2);
bTy = GDL_DOUBLE;
}
if (bTy == GDL_DOUBLE) {
if (g1.get() == NULL) {
if( bTy == GDL_DOUBLE)
{
if( g1.get() == NULL)
{
return e1->PowNew(e2);

Check warning on line 2976 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2976

Added line #L2976 was not covered by tests
} else {
}
else
{
res = g1->Pow(e2);

Check warning on line 2980 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L2980

Added line #L2980 was not covered by tests
if (res == g1.get())
g1.release();
Expand Down Expand Up @@ -2961,19 +3011,23 @@ BaseGDL* POWNCNode::Eval() {
else
convertBackT = GDL_UNDEF;

if (aTy != bTy) {
if( aTy != bTy)
{
if (aTyGEbTy) // crucial: '>' -> '>='
{
if (DTypeOrder[aTy] > 100) {
if( DTypeOrder[aTy] > 100)
{
throw GDLException("Expressions of this type cannot be converted.");

Check warning on line 3020 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3020

Added line #L3020 was not covered by tests
}

// convert e2 to e1
e2 = e2->Convert2(aTy, BaseGDL::COPY);

Check warning on line 3024 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3024

Added line #L3024 was not covered by tests
g2.reset(e2); // delete former e2
} else // bTy > aTy (order)
}
else // bTy > aTy (order)
{
if (DTypeOrder[bTy] > 100) {
if( DTypeOrder[bTy] > 100)
{
throw GDLException("Expressions of this type cannot be converted.");

Check warning on line 3031 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3031

Added line #L3031 was not covered by tests
}

Expand All @@ -2984,50 +3038,73 @@ BaseGDL* POWNCNode::Eval() {
}

// AdjustTypes(e2,e1); // order crucial here (for converting back)
if (e1->StrictScalar()) {
if( e1->StrictScalar())
{
if (g2.get() == NULL)
res = e2->PowInvSNew(e1);
else {
else
{
g2.release();
res = e2->PowInvS(e1); // scalar+scalar or array+scalar

Check warning on line 3048 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3048

Added line #L3048 was not covered by tests
}
} else if (e2->StrictScalar()) {
if (g1.get() == NULL) {
}
else if( e2->StrictScalar())
{
if( g1.get() == NULL)
{
res = e1->PowSNew(e2);

Check warning on line 3055 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3055

Added line #L3055 was not covered by tests
// res = e1->PowS(e2); // array+scalar
} else {
}
else
{
g1.release();
res = e1->PowS(e2); // array+scalar
}
} else if (e1->N_Elements() == e2->N_Elements()) {
if (g1.get() != NULL) {
}
else if( e1->N_Elements() == e2->N_Elements())
{
if( g1.get() != NULL)
{
g1.release();
res = e1->Pow(e2);

Check warning on line 3069 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3069

Added line #L3069 was not covered by tests
} else if (g2.get() != NULL) {
}
else if( g2.get() != NULL)
{
g2.release();
res = e2->PowInv(e1);

Check warning on line 3074 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3074

Added line #L3074 was not covered by tests
res->SetDim(e1->Dim());
} else {
}
else
{
res = e1->PowNew(e2);

Check warning on line 3079 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3079

Added line #L3079 was not covered by tests
// res = e1->Pow(e2);
}
} else if (e1->N_Elements() < e2->N_Elements()) {
if (g1.get() == NULL) {
}
else if( e1->N_Elements() < e2->N_Elements())
{
if( g1.get() == NULL)
{
res = e1->PowNew(e2);

Check warning on line 3087 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3087

Added line #L3087 was not covered by tests
// res= e1->Pow(e2); // smaller_array + larger_array or same size
} else {
}
else
{
g1.release();
res = e1->Pow(e2); // smaller_array + larger_array or same size

Check warning on line 3093 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3093

Added line #L3093 was not covered by tests
}
} else {
}
else
{
if (g2.get() == NULL)
res = e2->PowInvNew(e1);

Check warning on line 3099 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3099

Added line #L3099 was not covered by tests
else {
else
{
g2.release();
res = e2->PowInv(e1); // smaller + larger

Check warning on line 3103 in src/prognodeexpr.cpp

View check run for this annotation

Codecov / codecov/patch

src/prognodeexpr.cpp#L3103

Added line #L3103 was not covered by tests
}
}
if (convertBackT != GDL_UNDEF) {
if( convertBackT != GDL_UNDEF)
{
res = res->Convert2(convertBackT, BaseGDL::CONVERT);
}
return res;
Expand Down

0 comments on commit 1ef252f

Please sign in to comment.