Esempio n. 1
0
static size_t
_emit_opcode(sl_compile_state_t* cs, sl_vm_opcode_t opcode)
{
    sl_vm_insn_t insn;
    insn.threaded_opcode = sl_vm_op_addresses[opcode];
    return _emit(cs, insn);
}
Esempio n. 2
0
static size_t
_emit_opcode(sl_compile_state_t* cs, sl_vm_opcode_t opcode)
{
    sl_vm_insn_t insn;
    insn.opcode = opcode;
    return _emit(cs, insn);
}
Esempio n. 3
0
/***************************************************************************
 * Encapsulates all the decision making regarding actual emission of
 * results.
 */
static void _filter( ANALYSIS_FN_SIG ) {

	struct CovariateAnalysis covan;
	memset( &covan, 0, sizeof(covan) );
	covan_exec( pair, &covan );

	// One last thing to check before filtering to insure corner cases
	// don't fall through the following conditionals....

	if( ! ( isfinite( covan.result.probability ) && fpclassify( covan.result.probability ) != FP_SUBNORMAL ) ) {
		covan.result.probability = 1.0;
		covan.status             = COVAN_E_MATH;
		// The assumption is that if a NaN shows up in the result, it was
		// triggered by an un"pre"detected degeneracy, and so the pair was
		// in fact untestable (how it will be interpreted below).
	}

#ifdef _DEBUG
	if( ! dbg_silent ) {
#endif

		if( ( covan.status & opt_status_mask ) == 0 ) {
			if( covan.result.probability <= opt_p_value )
				_emit( pair, &covan, _fp_output );
			else
				_insignificant += 1;
		} else
			_untested += 1;

#ifdef _DEBUG
	}	
#endif
}
Esempio n. 4
0
static int _analyze_single_pair( const char *csv, const bool HAVE_ROW_LABELS ) {

	static const char *MISSING_MSG
		= "you specified row %s for a matrix without row names.\n";

	int econd;
	char *right, *left = alloca( strlen(csv)+1 );
	struct CovariateAnalysis covan;
	struct feature_pair pair;

	memset( &pair,  0, sizeof(pair) );
	memset( &covan, 0, sizeof(covan) );

	// Split the string in two...

	strcpy( left, csv );
	right = strchr( left, ',' );
	if( NULL == right )
		errx( -1, "missing comma separator in feature pair \"%s\"", left );
	*right++ = '\0';

	// Lookup each part.(They need not be the same format.)

	if( _is_integer( left ) ) {
		pair.l.offset = atoi( left );
		mtm_resort_rowmap( &_matrix, MTM_RESORT_BYROWOFFSET );
		econd = mtm_fetch_by_offset( &_matrix, &(pair.l) );
	} else
	if( HAVE_ROW_LABELS ) {
		pair.l.name   = left;
		if( mtm_resort_rowmap( &_matrix, MTM_RESORT_LEXIGRAPHIC ) )
			errx( -1, NO_ROW_LABELS );
		econd = mtm_fetch_by_name( &_matrix, &(pair.l) );
	} else
		errx( -1, MISSING_MSG, left );

	if( _is_integer( right ) ) {
		pair.r.offset = atoi( right );
		mtm_resort_rowmap( &_matrix, MTM_RESORT_BYROWOFFSET );
		econd = mtm_fetch_by_offset( &_matrix, &(pair.r) );
	} else
	if( HAVE_ROW_LABELS ) {
		pair.r.name = right;
		if( mtm_resort_rowmap( &_matrix, MTM_RESORT_LEXIGRAPHIC ) )
			errx( -1, NO_ROW_LABELS );
		econd = mtm_fetch_by_name( &_matrix, &(pair.r) );
	} else
		errx( -1, MISSING_MSG, right );

	covan_exec( &pair, &covan );

	_emit( &pair, &covan, _fp_output );

	return 0;
}
Esempio n. 5
0
    void UnderWaterBubble::Render()
    {
        _update();
        _emit();
        _geom();

        Camera * cam = World::Instance()->MainCamera();
        RenderSystem * render = RenderSystem::Instance();

        SamplerState state;

        render->SetTexture(0, state, mTex_Bubble0.c_ptr());

        render->Render(mTech, &mRender);
    }
Esempio n. 6
0
Error Assembler::emit(uint32_t code, uint64_t o0) {
  Imm imm(o0);
  return _emit(code, imm, NA, NA, NA);
}
Esempio n. 7
0
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2) {
  return _emit(code, o0, o1, o2, NA);
}
Esempio n. 8
0
Error Assembler::emit(uint32_t code, const Operand& o0) {
  return _emit(code, o0, NA, NA, NA);
}
Esempio n. 9
0
Error Assembler::emit(uint32_t code) {
  return _emit(code, NA, NA, NA, NA);
}
Esempio n. 10
0
Error BaseAssembler::emit(uint32_t code) {
  return _emit(code, no, no, no, no);
}
Esempio n. 11
0
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, uint64_t o3) {
  Imm imm(o3);
  return _emit(code, o0, o1, o2, imm);
}
Esempio n. 12
0
Error BaseAssembler::emit(uint32_t code, const Operand& o0, const Operand& o1, const Operand& o2, int o3_) {
  return _emit(code, o0, o1, o2, Imm(o3_));
}
Esempio n. 13
0
Error BaseAssembler::emit(uint32_t code, const Operand& o0, const Operand& o1, int o2_) {
  return _emit(code, o0, o1, Imm(o2_), no);
}
Esempio n. 14
0
Error BaseAssembler::emit(uint32_t code, int o0_) {
  return _emit(code, Imm(o0_), no, no, no);
}
Esempio n. 15
0
Error BaseAssembler::emit(uint32_t code, const Operand& o0, const Operand& o1) {
  return _emit(code, o0, o1, no, no);
}
Esempio n. 16
0
Error Assembler::emit(uint32_t code, const Operand& o0, uint64_t o1) {
  Imm imm(o1);
  return _emit(code, o0, imm, NA, NA);
}
Esempio n. 17
0
Error Assembler::emit(uint32_t code, const Operand& o0, const Operand& o1, uint64_t o2) {
  Imm imm(o2);
  return _emit(code, o0, o1, imm, NA);
}
Esempio n. 18
0
/**
  * This implements the Benjamini-Hochberg algorithm as described on
  * page 49 of "Large-Scale Inference", Bradley Efron, Cambridge.
  * "...for a fixed value of q in (0,1), let i_max be the largest
  *  index for which
  *                     p_(i) <= (i/N)q
  *
  *  ...and reject H_{0(i)}, the null hypothesis corresponding to
  *  p_(i), if
  *                         i <= i_max,
  *
  *  ...accepting H_{0(i)} otherwise."
  *
  * [...And i is 1-based in this notation!]
  */
static void _fdr_postprocess( FILE *cache, double Q, FILE *final_output, bool minimal_output ) {

	const unsigned CACHED_COUNT
		= ftell( cache ) / sizeof(struct FDRCacheRecord);
	const unsigned TESTED_COUNT
		= CACHED_COUNT
		+ _fdr_uncached_count;

	struct FDRCacheRecord *prec, *sortbuf
		= calloc( CACHED_COUNT, sizeof(struct FDRCacheRecord) );

	const double RATIO
		= Q/TESTED_COUNT;
	int i = 0;

	// Load and sort the cached test records...

	rewind( cache );
	fread( sortbuf, sizeof(struct FDRCacheRecord), CACHED_COUNT, cache );
	qsort( sortbuf, CACHED_COUNT, sizeof(struct FDRCacheRecord), _cmp_fdr_cache_records );

	// ...and recompute the full statistics of all earlier tests that
	// pass the now-established p-value threshold.

	prec = sortbuf;
	if( minimal_output ) {

		while( prec->p <= (i+1)*RATIO && i < CACHED_COUNT) 
			fprintf( final_output, "%d\t%d\t%.3e\n", prec->a, prec->b, prec->p );

	} else {

		while( prec->p <= (i+1)*RATIO && i < CACHED_COUNT) {
		
			struct feature_pair fpair;
			struct CovariateAnalysis covan;
			memset( &covan, 0, sizeof(covan) );

			fpair.l.offset = prec->a;
			fpair.r.offset = prec->b;
			fetch_by_offset( &_matrix, &fpair );

			covan_exec( &fpair, &covan );

			// At this point emission is unconditional; FDR control has
			// already filtered all that will be filtered...

			_emit( &fpair, &covan, final_output );

			if( _sigint_received ) {
				time_t now = time(NULL);
				fprintf( stderr, "# FDR postprocess interrupted @ %s", ctime(&now) );
				break;
			}

			prec += 1;
			i    += 1;
		}
	}

	// However, the preceding loop exited

	if( opt_verbosity >= V_WARNINGS ) {
		if( i > 0 )
			fprintf( final_output, "# max p-value %.3f\n", sortbuf[i-1].p );
		else
			fprintf( final_output, "# no values passed FDR control\n" );
	}
	if( sortbuf )
		free( sortbuf );
}
Esempio n. 19
0
/*
 * Emit an instruction that will be executed unconditionally.
 */
static inline void emit(u32 inst, struct jit_ctx *ctx)
{
	_emit(ARM_COND_AL, inst, ctx);
}
Esempio n. 20
0
int main( int argc, char *argv[] ) {

	int exit_status = EXIT_FAILURE;
	const int FIELD_SEP
		= getenv("SEPARATOR")
		? getenv("SEPARATOR")[0]
		: '\t';

	struct feature f = {
		.length = 0,
		//.buf.num: NULL,
		.expect_row_labels =  true,
		.missing_data_regex = mtm_default_NA_regex,
		.interpret_prefix =   mtm_sclass_by_prefix,
		.max_cardinality =    32,
		.category_labels =    NULL
	};

	char  *line = NULL;
	size_t blen = 0;
	ssize_t llen;
	FILE *input = stdin;
	do {
		static const char *CHAR_OPTIONS 
			= "rm:k:v:?";
		static struct option LONG_OPTIONS[] = {

			{"nolabels",   0,0,'r'},
			{"missing",    1,0,'m'},
			{"maxcats",    1,0,'k'},

			{"verbosity",  1,0,'v'},
			{ NULL,        0,0, 0 }
		};

		int opt_offset = 0;
		const int c = getopt_long( argc, argv, CHAR_OPTIONS, LONG_OPTIONS, &opt_offset );
		switch (c) {

		case 'r': f.expect_row_labels  = false;        break;
		case 'm': f.missing_data_regex = optarg;       break;
		case 'k': f.max_cardinality    = atoi(optarg); break;
		case 'v':
			//opt_verbosity = atoi( optarg );
			break;
		case -1: // ...signals no more options.
			break;
		default:
			printf ("error: unknown option: %c\n", c );
			exit(-1);
		}
		if( -1 == c ) break;

	} while( true );

	if( optind < argc ) {
		const char *fname = argv[optind];
		input = fopen( fname, "r" );
		if( input == NULL )
			err( -1, "opening %s", fname );
	}

	// Note that getline will block until it sees a NL if input is a pipe.

	llen = getline( &line, &blen, input );

	// feature_encode expects NUL-terminated strings, stripped of CR/NL.

	if( line[llen-1] == '\n' ) line[--llen] = '\0';

	if( llen > 0 && line != NULL ) {

		int ec = MTM_OK;
		struct mtm_descriptor d;

		f.length 
			= feature_count_fields( line, FIELD_SEP )
			- ( f.expect_row_labels ? 1 : 0 );

		if( (ec = feature_alloc_encode_state( &f ) ) == 0 ) {

			if( (ec = feature_encode( line, &f, &d ) ) == 0 ) {

				_emit( line, &f, &d, stdout );
				exit_status = EXIT_SUCCESS;

			} else
				warnx( "error %d: feature_encode", ec );

			feature_free_encode_state( &f );

		} else
			warnx( "error %d: feature_alloc_encode_state", ec );

		free( line );

	} else
		warnx( "no input" );

	return exit_status;
}