Skip to content

Close 1353 and 1928 make /NAN implied for several functions #1945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/basic_fun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,7 @@ namespace lib {
downgradeDoubleResult = !doublePrecision;
}

bool nan = e->KeywordSet(nanIx);
bool nan = e->BooleanKeywordAbsentOrSet(nanIx);
bool preserve = e->KeywordSet(preserveIx);

DLong sumDim = 0;
Expand Down Expand Up @@ -3531,7 +3531,7 @@ namespace lib {
static int intIx = e->KeywordIx("INTEGER");
static int preIx = e->KeywordIx("PRESERVE_TYPE");
bool KwCumul = e->KeywordSet(cumIx);
bool KwNaN = e->KeywordSet(nanIx);
bool KwNaN = e->BooleanKeywordAbsentOrSet(nanIx);
bool KwInt = e->KeywordSet(intIx);
bool KwPre = e->KeywordSet(preIx);
bool nanInt = false;
Expand Down Expand Up @@ -3916,7 +3916,7 @@ namespace lib {
BaseGDL* searchArr = e->GetParDefined(0);

static int omitNaNIx = e->KeywordIx("NAN");
bool omitNaN = e->KeywordSet(omitNaNIx);
bool omitNaN = e->BooleanKeywordAbsentOrSet(omitNaNIx);

static int subIx = e->KeywordIx("SUBSCRIPT_MAX");
bool subMax = e->WriteableKeywordPresent(subIx); //insure the output variable exist and is of 'good' type
Expand Down Expand Up @@ -4017,7 +4017,7 @@ namespace lib {
BaseGDL* searchArr = e->GetParDefined(0);

static int omitNaNIx = e->KeywordIx("NAN");
bool omitNaN = e->KeywordSet(omitNaNIx);
bool omitNaN = e->BooleanKeywordAbsentOrSet(omitNaNIx);

static int subIx = e->KeywordIx("SUBSCRIPT_MIN");
bool subMin = e->WriteableKeywordPresent(subIx);
Expand Down Expand Up @@ -5502,7 +5502,7 @@ namespace lib {
p0->Type() == GDL_FLOAT ||
p0->Type() == GDL_COMPLEX ||
p0->Type() == GDL_COMPLEXDBL);
bool omitNaN = (e->KeywordPresent(nanIx) && possibleNaN);
bool omitNaN = (e->BooleanKeywordAbsentOrSet(nanIx) && possibleNaN);

//DIMENSION Kw
static int dimIx = e->KeywordIx("DIMENSION");
Expand Down Expand Up @@ -6076,7 +6076,7 @@ namespace lib {
p0->Type() == GDL_FLOAT ||
p0->Type() == GDL_COMPLEX ||
p0->Type() == GDL_COMPLEXDBL);
bool omitNaN = (e->KeywordPresent(nanIx) && possibleNaN);
bool omitNaN = (e->BooleanKeywordAbsentOrSet(nanIx) && possibleNaN);

//DIMENSION Kw
static int dimIx = e->KeywordIx("DIMENSION");
Expand Down Expand Up @@ -7154,7 +7154,11 @@ namespace lib {
static int maxIx = e->KeywordIx("MAX");
static int topIx = e->KeywordIx("TOP");
static int nanIx = e->KeywordIx("NAN");
bool omitNaN = e->KeywordPresent(nanIx);
bool possibleNaN = (p0->Type() == GDL_DOUBLE ||
p0->Type() == GDL_FLOAT ||
p0->Type() == GDL_COMPLEX ||
p0->Type() == GDL_COMPLEXDBL);
bool omitNaN = (e->BooleanKeywordAbsentOrSet(nanIx) && possibleNaN);

//the following is going to be wrong in cases where TOP is so negative that a Long does not suffice.
//Besides, a template version for each different type would be faster and probably the only solution to get the
Expand Down
6 changes: 5 additions & 1 deletion src/convol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,11 @@ namespace lib {
/***********************************Parameter NAN****************************************/

static int nanIx = e->KeywordIx( "NAN");
bool doNan = e->KeywordSet( nanIx);
bool possibleNaN = (p0->Type() == GDL_DOUBLE ||
p0->Type() == GDL_FLOAT ||
p0->Type() == GDL_COMPLEX ||
p0->Type() == GDL_COMPLEXDBL);
bool doNan = (e->BooleanKeywordAbsentOrSet(nanIx) && possibleNaN);

/***********************************Parameter MISSING************************************/
static int missingIx = e->KeywordIx("MISSING");
Expand Down
271 changes: 0 additions & 271 deletions src/convol_inc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,275 +764,4 @@ if (normalize) {
#undef CONVOL_TRUNCATE_MIN
#undef CONVOL_TRUNCATE_MAX

//#if !defined(CONVOL_BYTE__) && !defined(CONVOL_UINT__) && !defined(CONVOL_INT__) && !defined(CONVOL_ULONG__) && !defined(CONVOL_ULONG64__)
//
//namespace lib {
//
///*****************************************convol_fun*********************************************************/
// BaseGDL* convol_fun( EnvT* e)
// {
// long nParam=e->NParam( 2);
//
// /************************************Checking_parameters************************************************/
//
// BaseGDL* p0 = e->GetNumericParDefined( 0);
// if( p0->Rank() == 0)
// e->Throw( "Expression must be an array in this context: "+
// e->GetParString(0));
//
// BaseGDL* p1 = e->GetNumericParDefined( 1);
// if( p1->Rank() == 0)
// e->Throw( "Expression must be an array in this context: "+
// e->GetParString(1));
//
// if( p0->N_Elements() < p1->N_Elements())
// e->Throw( "Incompatible dimensions for Array and Kernel.");
//
// // rank 1 for kernel works always
// if( p1->Rank() != 1) {
// long rank = p0->Rank();
// if (rank != p1->Rank())
// e->Throw("Incompatible dimensions for Array and Kernel.");
//
// for (long r = 0; r < rank; ++r)
// if (p0->Dim(r) < p1->Dim(r))
// e->Throw("Incompatible dimensions for Array and Kernel.");
// } else { //check however that kernel is not too big...
// if (p0->Dim(0) < p1->Dim(0)) e->Throw("Incompatible dimensions for Array and Kernel.");
// }
//
// //compute some interesting values about kernel and array dimensions
// int maxposK=0,curdimK,sumofdimsK=0,maxdimK=-1;
// int maxpos=0, curdimprod, maxdimprod=-1;
//
// for (int i=0; i<p1->Rank(); ++i) {
// curdimK=p1->Dim(i);
// sumofdimsK+=curdimK;
// if (curdimK>maxdimK) {
// maxdimK=curdimK;
// maxposK=i;
// }
// }
//
// // If kernel is not 1-D, test which dimension is larger. Transposing the data and kernel to have this dimension first is faster since
// // it is the kernel sum which is parallelized here.
// // Probably there is a minimum difference in size (magicfactor=1.2 ? 1.5?) at which one would benefit given the added complexity of transposition.
// bool doTranspose=false;
// if (sumofdimsK > maxdimK+(p1->Rank())-1) {
//
// // Now about dimensions.
// // convolution code (in convol_inc*.pro) is quite tricky. Only the inner part of the loop can be safely parallelized.
// // It is a double loop on the first dimension of kernel (kDim0) times the first dimension of the array (dim0 or aEnd0-aBeg0).
// // To benefit from this speedup, we need to have dim0*kDim0 maximum:
// // find largest array or kernel dimension; transpose array, makes for faster convol, will be
// // transposed back at end.
//
// // find maximum of dim0xkDim0
// for (int i = 0; i < p1->Rank(); ++i) { //0->Rank and p1->Rank same here
// curdimprod = p1->Dim(i)*p0->Dim(i);
// if (curdimprod > maxdimprod) {
// maxdimprod = curdimprod;
// maxpos = i;
// }
// }
// float magicfactor=2.0;
// if ( maxdimprod > magicfactor*p1->Dim(0)*p0->Dim(0) ) doTranspose=true;
// }
// // array of dims for transpose
// DUInt* perm = new DUInt[p0->Rank()]; //direct
// DUInt* mrep = new DUInt[p0->Rank()]; //reverse
// ArrayGuard<DUInt> perm_guard(perm);
// ArrayGuard<DUInt> mrep_guard(mrep);
// if (doTranspose) {
//
// DUInt i = 0, j = 0;
// for (i = 0; i < p0->Rank(); ++i) if (i != maxpos) {
// perm[j + 1] = i;
// j++;
// }
// perm[0] = maxpos;
// for (i = 0; i < p0->Rank(); ++i) mrep[i]=i; //populate reverse
// for (i = 0; i < maxpos+1; ++i) mrep[i]=i+1; //this and the following line should give the reverse transpose order.
// mrep[maxpos]=0;
// }
// /***************************************Preparing_matrices*************************************************/
//
// //Computations for REAL and COMPLEX are better made in double precision if we do not want to lose precision
// //Apparently IDL has severe problems regarding this loss of precision.
// // try for example the following, which should give exactly ZERO:
// // C=32*32*0.34564 & a=findgen(100,100)*0.0+1 & b=convol(a,fltarr(32,32)+0.34564) & print,(b-c)[20:80,50],format='(4(F20.12))'
// //So, we convert p0 to Double precision if necessary and convert back result.
// //Do it here since all other parameters are converted to p0's type.
// Guard<BaseGDL> p0Guard;
// bool deprecise=false;
// if (p0->Type() == GDL_FLOAT) {
// p0 = p0->Convert2(GDL_DOUBLE, BaseGDL::COPY);
// p0Guard.Reset(p0);
// deprecise=true;
// } else if (p0->Type() == GDL_COMPLEX) {
// p0 = p0->Convert2(GDL_COMPLEXDBL, BaseGDL::COPY);
// p0Guard.Reset(p0);
// deprecise=true;
// }
//
// // convert kernel to array type
// Guard<BaseGDL> p1Guard;
// if (p0->Type() == GDL_BYTE || p0->Type() == GDL_UINT || p0->Type() == GDL_INT) {
// if (p1->Type() != GDL_LONG) {
// p1 = p1->Convert2(GDL_LONG, BaseGDL::COPY);
// p1Guard.Reset(p1);
// }
// } else if (p0->Type() != p1->Type()) {
// p1 = p1->Convert2(p0->Type(), BaseGDL::COPY);
// p1Guard.Reset(p1);
// }
//
// BaseGDL* scale;
// Guard<BaseGDL> scaleGuard;
// if (nParam > 2) {
// scale = e->GetParDefined(2);
// if (scale->Rank() > 0)
// e->Throw("Expression must be a scalar in this context: " +
// e->GetParString(2));
//
// // p1 here handles GDL_BYTE||GDL_UINT||GDL_INT case also
// if (p1->Type() != scale->Type()) {
// scale = scale->Convert2(p1->Type(), BaseGDL::COPY);
// scaleGuard.Reset(scale);
// }
// } else {
// scale = p1->New(1, BaseGDL::ZERO);
// }
// /********************************************Arguments_treatement***********************************/
// bool center = true;
// static int centerIx = e->KeywordIx( "CENTER");
// if( e->KeywordPresent( centerIx))
// {
// DLong c;
// e->AssureLongScalarKW( centerIx, c);
// center = (c != 0);
// }
//
// // overrides EDGE_TRUNCATE
// static int edge_wrapIx = e->KeywordIx( "EDGE_WRAP");
// bool edge_wrap = e->KeywordSet( edge_wrapIx);
// static int edge_truncateIx = e->KeywordIx( "EDGE_TRUNCATE");
// bool edge_truncate = e->KeywordSet( edge_truncateIx);
// static int edge_zeroIx = e->KeywordIx( "EDGE_ZERO");
// bool edge_zero = e->KeywordSet( edge_zeroIx);
// static int edge_mirrorIx = e->KeywordIx( "EDGE_MIRROR");
// bool edge_mirror = e->KeywordSet( edge_mirrorIx);
// int edgeMode = 0;
// if( edge_wrap)
// edgeMode = 1;
// else if( edge_truncate)
// edgeMode = 2;
// else if( edge_zero)
// edgeMode = 3;
// else if(edge_mirror)
// edgeMode = 4;
//
// // p0, p1 and scale have same type
// // p1 has rank of 1 or same rank as p0 with each dimension smaller than p0
// // scale is a scalar
//
// /***********************************Parameter_BIAS**************************************/
// static int biasIx = e->KeywordIx("BIAS");
// bool statusBias = e->KeywordPresent(biasIx);
// // DLong bias=0;
// BaseGDL* bias;
// Guard<BaseGDL> biasGuard;
// if (statusBias) {
// bias = e->GetKW(biasIx);
//
// // p1 here handles GDL_BYTE||GDL_UINT||GDL_INT case also
// if (p1->Type() != bias->Type()) {
// bias = bias->Convert2(p1->Type(), BaseGDL::COPY);
// biasGuard.Reset(bias);
// }
// } else bias = p1->New(1, BaseGDL::ZERO);
//
// /***********************************Parameter_Normalize**********************************/
//
// static int normalIx = e->KeywordIx( "NORMALIZE");
// bool normalize = e->KeywordPresent( normalIx);
//
// /***********************************Parameter NAN****************************************/
//
// static int nanIx = e->KeywordIx( "NAN");
// bool doNan = e->KeywordSet( nanIx);
//
// /***********************************Parameter MISSING************************************/
// static int missingIx = e->KeywordIx("MISSING");
// bool doMissing = e->KeywordPresent(missingIx);
// BaseGDL* missing;
// Guard<BaseGDL> missGuard;
// if (doMissing) {
// missing = e->GetKW(missingIx);
// if (p0->Type() != missing->Type()) {
// missing = missing->Convert2(p0->Type(), BaseGDL::COPY);
// missGuard.Reset(missing);
// }
// } else missing = p0->New(1, BaseGDL::ZERO);
// /***********************************Parameter INVALID************************************/
// static int invalidIx = e->KeywordIx("INVALID");
// bool doInvalid = e->KeywordPresent( invalidIx );
// BaseGDL* invalid;
// Guard<BaseGDL> invalGuard;
// if (doInvalid) {
// invalid = e->GetKW(invalidIx);
// if (p0->Type() != invalid->Type()) {
// invalid = invalid->Convert2(p0->Type(), BaseGDL::COPY);
// invalGuard.Reset(invalid);
// }
// } else invalid = p0->New(1, BaseGDL::ZERO);
// if (!doNan && !doInvalid) doMissing=false;
// if (!doMissing && p0->Type()==GDL_FLOAT) {
// DFloat tmp=std::numeric_limits<float>::quiet_NaN();
// memcpy((*missing).DataAddr(), &tmp, sizeof(tmp));
// }
// if (!doMissing && p0->Type()==GDL_DOUBLE){
// DDouble tmp=std::numeric_limits<double>::quiet_NaN();
// memcpy((*missing).DataAddr(), &tmp, sizeof(tmp));
// }
// //populating a Complex with Nans is not easy as there is no objective method for that.
// if (!doMissing && p0->Type()==GDL_COMPLEX) {
// DComplex tmp=std::complex<DFloat>(std::numeric_limits<float>::quiet_NaN(),std::numeric_limits<float>::quiet_NaN());
// memcpy((*missing).DataAddr(), &tmp, sizeof(tmp));
// }
// if (!doMissing && p0->Type()==GDL_COMPLEXDBL) {
// DComplexDbl tmp=std::complex<DDouble>(std::numeric_limits<double>::quiet_NaN(),std::numeric_limits<double>::quiet_NaN());
// memcpy((*missing).DataAddr(), &tmp, sizeof(tmp));
// }
// BaseGDL* result;
// //handle transpositions
// if (doTranspose) {
// BaseGDL* input;
// Guard<BaseGDL> inputGuard;
// input = p0->Transpose(perm);
// inputGuard.Reset(input);
// BaseGDL* transpP1;
// Guard<BaseGDL> transpP1Guard;
// transpP1=p1->Transpose(perm);
// transpP1Guard.Reset(transpP1);
// result=input->Convol(transpP1, scale, bias, center, normalize, edgeMode, doNan, missing, doMissing, invalid, doInvalid, DDouble edgeVal)->Transpose(mrep);
// } else result=p0->Convol( p1, scale, bias, center, normalize, edgeMode, doNan, missing, doMissing, invalid, doInvalid, DDouble edgeVal);
//
// if (deprecise) {
// Guard<BaseGDL> resultGuard;
// resultGuard.reset(result);
// if (p0->Type() == GDL_DOUBLE) return result->Convert2(GDL_FLOAT, BaseGDL::COPY);
// else if (p0->Type() == GDL_COMPLEXDBL) return result->Convert2(GDL_COMPLEX, BaseGDL::COPY);
// else return result; //should not happen!
// } else
//
// return result;
//
// } //end of convol_fun
//
//
// }//end of namespace
//
//#endif

#endif // #ifdef INCLUDE_CONVOL_CPP
2 changes: 1 addition & 1 deletion src/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static BaseGDL* do_histogram_fun(EnvT* e, BaseGDL* p0) {
if (FloatType(p0->Type())) {
static int nanIx = e->KeywordIx("NAN");
// minArrayVal/maxArrayVal
if (e->KeywordSet(nanIx)) {
if (e->BooleanKeywordAbsentOrSet(nanIx)) {
DLong minEl, maxEl;
array->MinMax(&minEl, &maxEl, NULL, NULL, true);
minArrayVal = (*array)[minEl];
Expand Down
2 changes: 1 addition & 1 deletion src/initsysvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ namespace SysVar
ver->NewTag("OS_NAME", new DStringGDL(SysName));
#endif

ver->NewTag("RELEASE", new DStringGDL( "8.2")); //we are at least 6.4
ver->NewTag("RELEASE", new DStringGDL( "8.5.1")); //changed since /NAN is no mere needed.
ver->NewTag("BUILD_DATE", new DStringGDL(BUILD_DATE));
ver->NewTag("MEMORY_BITS", new DIntGDL( sizeof(BaseGDL*)*8));
ver->NewTag("FILE_OFFSET_BITS", new DIntGDL( sizeof(SizeT)*8));
Expand Down
8 changes: 6 additions & 2 deletions src/interpol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,19 @@
#else
if (e->KeywordSet(SPLINE)) interpol=gdl_interpol_spline;
#endif
static int NANIx = e->KeywordIx("NAN");
bool doNan=e->KeywordSet(NANIx);
unsigned int nmin=gdl_interpol_type_min_size(interpol);

//dimensions
BaseGDL* p0 = e->GetParDefined(0);
DType type=p0->Type();
if (type==GDL_STRING) e->Throw("Internal Error, string value not allowed when calling GDL_INTERPOL, please report.");
if (ComplexType(type)) e->Throw("Internal Error, complex value not allowed when calling GDL_INTERPOL, please report.");

static int NANIx = e->KeywordIx("NAN");
bool possibleNaN = (p0->Type() == GDL_DOUBLE || p0->Type() == GDL_FLOAT);
bool doNan = (e->BooleanKeywordAbsentOrSet(NANIx) && possibleNaN);

Check warning on line 380 in src/interpol.cpp

View check run for this annotation

Codecov / codecov/patch

src/interpol.cpp#L378-L380

Added lines #L378 - L380 were not covered by tests


SizeT nV=p0->N_Elements();
SizeT orig_nV=nV;
if (nV <nmin) e->Throw("V has too few elements for this kind of interpolation.");
Expand Down
Loading
Loading