Beispiel #1
0
    // all vectors A, B, C
    QAP_QueryABC(const QAP_SystemPoint<SYS, T>& qap,
                 const unsigned int mask = A | B | C)
        : m_A(mask & A),
          m_B(mask & B),
          m_C(mask & C),
          m_nonzeroA(0),
          m_nonzeroB(0),
          m_nonzeroC(0),
          m_vecA(m_A ? 3 + qap.numVariables() + 1 : 0, T::zero()),
          m_vecB(m_B ? 3 + qap.numVariables() + 1 : 0, T::zero()),
          m_vecC(m_C ? 3 + qap.numVariables() + 1 : 0, T::zero()),
          m_uit(qap.lagrange_coeffs().begin()),
          m_error(false)
    {
        if (m_A) m_vecA[0] = qap.compute_Z();
        if (m_B) m_vecB[1] = qap.compute_Z();
        if (m_C) m_vecC[2] = qap.compute_Z();

        // input consistency (for A only)
        if (m_A) {
            for (std::size_t i = 0; i <= qap.numCircuitInputs(); ++i)
#ifdef PARNO_SOUNDNESS_FIX
                m_vecA[3 + i] = qap.lagrange_coeffs()[qap.numConstraints() + i];
#else
                m_vecA[3 + i] = (*m_uit) * T(i + 1);
#endif
        }

        constraintLoop(qap.constraintSystem());

        if (m_A) m_nonzeroA = count_nonzero(m_vecA);
        if (m_B) m_nonzeroB = count_nonzero(m_vecB);
        if (m_C) m_nonzeroC = count_nonzero(m_vecC);
    }
/* Find stats on an area of an IMAGE ... consider only pixels for which the
 * mask is true.
 */
static DOUBLEMASK *
find_image_stats( IMAGE *in, IMAGE *mask, Rect *area )
{
	DOUBLEMASK *stats;
	IMAGE *t[4];
	gint64 count;

	/* Extract area, build black image, mask out pixels we want.
	 */
	if( im_open_local_array( in, t, 4, "find_image_stats", "p" ) ||
		extract_rect( in, t[0], area ) ||
		im_black( t[1], t[0]->Xsize, t[0]->Ysize, t[0]->Bands ) ||
		im_clip2fmt( t[1], t[2], t[0]->BandFmt ) ||
		im_ifthenelse( mask, t[0], t[2], t[3] ) )
		return( NULL );

	/* Get stats from masked image.
	 */
	if( !(stats = local_mask( in, im_stats( t[3] ) )) ) 
		return( NULL );

	/* Number of non-zero pixels in mask.
	 */
	if( count_nonzero( mask, &count ) )
		return( NULL );

	/* And scale masked average to match.
	 */
	stats->coeff[4] *= (double) count / 
		((double) mask->Xsize * mask->Ysize);

	/* Yuk! Zap the deviation column with the pixel count. Used later to
	 * determine if this is likely to be a significant overlap.
	 */
	stats->coeff[5] = count;

#ifdef DEBUG
	if( count == 0 )
		im_warn( "global_balance", _( "empty overlap!" ) );
#endif /*DEBUG*/

	return( stats );
}
Beispiel #3
0
void shorten_int (int idx)
{
  int i;
  int matched = 0;
  for (i=0; i<toks; i++) {
    if (!matched && tok_list[i].kind == TOK_NUMBER) {
      char *s = tok_list[i].str;
      int l = count_nonzero(s);
      if (idx > l) {
	idx -= l;
      } else {
	
      }
    }
    printf ("%s", tok_list[i].str);
  }
  if (matched) {
    exit (0);
  } else {
    exit (1);
  }
}
Beispiel #4
0
/**
  * Having finished scanning a putatively tabular file, apply heuristics
  * to the column statistics to finally determine the statistical class
  * for each column (quantitative, categorical or (maybe) ordinal).
  *
  * The determination depends primarily on the presence or lack of unanimity
  * in the observed types (integer, float, string) in the column, then
  * devolves to consideration of the many other statistics in the column
  * struct.
  */
void analyze_column( struct column *c ) {

	const int OBSERVED_TYPE_COUNT
		= count_nonzero( c->type_vote+1 /* exclude FTY_EMPTY */, FTY_COUNT-1 );

	c->stat_class = STC_UNK; // ...unless overridden below!

	if( OBSERVED_TYPE_COUNT == 0 /* all must be empty */ ) {

		assert( c->type_vote[ FTY_EMPTY ] > 0 );

	} else
	if( OBSERVED_TYPE_COUNT == 1 /* Unanimity... */ ) {

		// ...doesn't necessarily determine the stat class because...

		switch( find_nonzero( c->type_vote, FTY_COUNT ) ) {

		case FTY_INTEGER: // ...integers can be used in many ways!
			c->stat_class = _integer_inference( c );
			break;

		case FTY_STRING:

			if( ( ! c->excess_values )
				&& set_count( & c->value_set ) <  c->type_vote[ FTY_STRING ] 
				&& c->long_field_count == 0 )
				c->stat_class = STC_CAT;
			break;

		case FTY_FLOAT:
			c->stat_class = STC_QUA;
		}

	} else {

		/**
		  * If more than two types are observed and STRING is one of them,
		  * then everything hinges on the cardinality of observed strings
		  * (the contents of value_set EXCLUDING any integers it contains).
		  * 1. If exactly one string value is observed AND it's a potential
		  *    missing data indicator, then inference devolves to that for
		  *    numeric types.
		  * 2. If more than one string value is observed all bets are off;
		  *    the column remains STC_UNKnown.
		  */

		const char *sval[2];
		const bool UNIQUE_STRING
			= c->type_vote[ FTY_STRING ] > 0
			&& _fetch_string_values( & c->value_set, sval, 2 ) == 1;
		const bool HAS_CANDIDATE_MISSING_DATA_PLACEHOLDER
			= UNIQUE_STRING
			&& regexec( &_compiled_re_NA, sval[0], 0, NULL, 0 ) == 0;

		if( OBSERVED_TYPE_COUNT == 2 ) {

			if( c->type_vote[ FTY_STRING ] > 0 ) {

				if( HAS_CANDIDATE_MISSING_DATA_PLACEHOLDER ) {
					if( c->type_vote[ FTY_INTEGER ] > 0 ) {
						c->stat_class = _integer_inference( c );
					} else {
						assert( c->type_vote[ FTY_FLOAT ] > 0 );
						c->stat_class = STC_QUA;
					}
				}

			} else { // no string, just ints and floats

				assert( c->type_vote[ FTY_INTEGER ] > 0 &&
						c->type_vote[ FTY_FLOAT ]   > 0 );

				c->stat_class = STC_QUA;
			}

		} else { // Column contains int(s), float(s) AND string(s).

			if( HAS_CANDIDATE_MISSING_DATA_PLACEHOLDER )
				c->stat_class = STC_QUA;

		} // 3 types observed

	} // > 1 type observed.
}