Ejemplo n.º 1
0
static COMMAND_FUNC( new_col )
{
	Dimension_Set ds1, *dsp=(&ds1);
	const char *obj_name;
	long nr, ncomps;
	Precision *prec_p;

	obj_name=NAMEOF("object name");

	nr = (long) how_many("number of elements");
	ncomps = (long) how_many("number of components");

	prec_p = get_precision(SINGLE_QSP_ARG);

	if( prec_p == NULL ) return;
	INSIST_POSITIVE_DIM(nr,"element","new_col")
	INSIST_POSITIVE_DIM(ncomps,"component","new_col")

	SET_DIMENSION(dsp,4,1);
	SET_DIMENSION(dsp,3,1);
	SET_DIMENSION(dsp,2,nr);
	SET_DIMENSION(dsp,1,1);
	SET_DIMENSION(dsp,0,ncomps);

	finish_obj(obj_name,dsp,prec_p,DT_COLVEC);
}
Ejemplo n.º 2
0
static COMMAND_FUNC( new_frame )
{
	Dimension_Set ds1;
	Dimension_Set *dsp=(&ds1);
	const char *obj_name;
	long nr, nc, ncomps;
	Precision *prec_p;

	obj_name=NAMEOF("object name");

	nr = (long) how_many("number of rows");
	nc = (long) how_many("number of columns");
	ncomps = (long) how_many("number of components");

	prec_p = get_precision(SINGLE_QSP_ARG);

	if( prec_p == NULL ) return;
	INSIST_POSITIVE_DIM(nr,"row","new_frame");
	INSIST_POSITIVE_DIM(nc,"column","new_frame");
	INSIST_POSITIVE_DIM(ncomps,"component","new_frame");

	SET_DIMENSION(dsp,4,1);
	SET_DIMENSION(dsp,3,1);
	SET_DIMENSION(dsp,2,nr);
	SET_DIMENSION(dsp,1,nc);
	SET_DIMENSION(dsp,0,ncomps);

	finish_obj(obj_name,dsp,prec_p,DT_IMAGE);
}
Ejemplo n.º 3
0
static COMMAND_FUNC( new_hyperseq )
{
	Dimension_Set ds1, *dsp=(&ds1);
	const char *obj_name;
	long ns, nf, nr, nc, ncomps;
	Precision *prec_p;

	obj_name=NAMEOF("object name");

	ns = (long) how_many("number of sequences");
	nf = (long) how_many("number of frames");
	nr = (long) how_many("number of rows");
	nc = (long) how_many("number of columns");
	ncomps = (long) how_many("number of components");
	prec_p = get_precision(SINGLE_QSP_ARG);

	if( prec_p == NULL ) return;

	INSIST_POSITIVE_DIM(ns,"sequence","new_hyperseq");

	SET_DIMENSION(dsp,4,ns);
	SET_DIMENSION(dsp,3,nf);
	SET_DIMENSION(dsp,2,nr);
	SET_DIMENSION(dsp,1,nc);
	SET_DIMENSION(dsp,0,ncomps);

	finish_obj(obj_name,dsp,prec_p,DT_HYPER_SEQ);
}
Ejemplo n.º 4
0
static COMMAND_FUNC( equivalence )
{
	const char *obj_name;
	Data_Obj *dp;
	Precision * prec_p;
	Dimension_Set ds1, *dsp=(&ds1);
	long ns,nf,nr,nc,nd;

	obj_name=NAMEOF("name for equivalent image");

	dp=pick_obj(PARENT_PROMPT);

	ns=(long) how_many("number of sequences");
	nf=(long) how_many("number of frames");
	nr=(long) how_many("number of rows");
	nc=(long) how_many("number of columns");
	nd=(long) how_many("number of components");

	prec_p = get_precision(SINGLE_QSP_ARG);

	if( dp==NULL ) return;
	if( prec_p == NULL ) return;

	INSIST_POSITIVE_DIM(ns,"sequence","equivalence")
	INSIST_POSITIVE_DIM(nf,"frame","equivalence")
	INSIST_POSITIVE_DIM(nr,"row","equivalence")
	INSIST_POSITIVE_DIM(nc,"column","equivalence")
	INSIST_POSITIVE_DIM(nd,"component","equivalence")

	SET_DIMENSION(dsp,4,ns);
	SET_DIMENSION(dsp,3,nf);
	SET_DIMENSION(dsp,2,nr);
	SET_DIMENSION(dsp,1,nc);
	SET_DIMENSION(dsp,0,nd);

	if( COMPLEX_PRECISION(PREC_CODE(prec_p)) ){
		if( DIMENSION(dsp,0) != 1 ){
			warn("Sorry, can only have 1 complex component");
			return;
		}
		//SET_DIMENSION(dsp,0,2);
	} else if( QUAT_PRECISION(PREC_CODE(prec_p)) ){
		if( DIMENSION(dsp,0) != 1 ){
			warn("Sorry, can only have 1 quaternion component");
			return;
		}
		//SET_DIMENSION(dsp,0,2);
	} else if( COLOR_PRECISION(PREC_CODE(prec_p)) ){
		if( DIMENSION(dsp,0) != 1 ){
			warn("Sorry, can only have 1 color triple per pixel");
			return;
		}
advise("component dim 3 for color");
		//SET_DIMENSION(dsp,0,3);
	}

	if( make_equivalence(obj_name,dp,dsp,prec_p) == NULL )
		warn("error making equivalence");
}
Ejemplo n.º 5
0
static COMMAND_FUNC( mksubsequence )
{
	const char *obj_name;
	Data_Obj *dp, *newdp;
	index_t offsets[N_DIMENSIONS];
	Dimension_Set ds1, *dsp=(&ds1);
	long x_offset, y_offset, t_offset;
	long nr,nc,nf;

	obj_name=NAMEOF("name for subsequence");

	dp=pick_obj(PARENT_PROMPT);

	nc = (long) how_many("number of columns");
	nr = (long) how_many("number of rows");
	nf = (long) how_many("number of frames");

	x_offset=(long) how_many("x offset");
	y_offset=(long) how_many("y offset");
	t_offset=(long) how_many("t offset");

	if( dp==NULL ) return;

	INSIST_POSITIVE_DIM(nc,"column","mksubsequence");
	INSIST_POSITIVE_DIM(nr,"row","mksubsequence");
	INSIST_POSITIVE_DIM(nf,"frame","mksubsequence");

	INSIST_NONNEGATIVE(x_offset,"x offset","mksubsequence");
	INSIST_NONNEGATIVE(y_offset,"y offset","mksubsequence");
	INSIST_NONNEGATIVE(t_offset,"t offset","mksubsequence");

	offsets[0]=0;
	offsets[1]=(index_t)x_offset;
	offsets[2]=(index_t)y_offset;
	offsets[3]=(index_t)t_offset;
	offsets[4]=0;

	SET_DIMENSION(dsp,0,OBJ_COMPS(dp));
	SET_DIMENSION(dsp,1,nc);
	SET_DIMENSION(dsp,2,nr);
	SET_DIMENSION(dsp,3,nf);
	SET_DIMENSION(dsp,4,1);

	newdp=mk_subseq(obj_name,dp,offsets,dsp);
	if( newdp == NULL )
		warn("couldn't create subimage");
}
Ejemplo n.º 6
0
static COMMAND_FUNC( new_gen_obj )
{
	Dimension_Set ds1, *dsp=(&ds1);
	const char *obj_name;
	long ns, nf, nr, nc, ncomps;
	Precision *prec_p;

	obj_name=NAMEOF("object name");

	ns = (long) how_many("number of sequences");
	nf = (long) how_many("number of frames");
	nr = (long) how_many("number of rows");
	nc = (long) how_many("number of columns");
	ncomps = (long) how_many("number of components");

	prec_p = get_precision(SINGLE_QSP_ARG);

	if( prec_p == NULL ) return;
	INSIST_POSITIVE_DIM(ns,"sequence","new_gen_obj");
	INSIST_POSITIVE_DIM(nf,"frame","new_gen_obj");
	INSIST_POSITIVE_DIM(nr,"row","new_gen_obj");
	INSIST_POSITIVE_DIM(nc,"column","new_gen_obj");
	INSIST_POSITIVE_DIM(ncomps,"component","new_gen_obj");

	SET_DIMENSION(dsp,4,ns);
	SET_DIMENSION(dsp,3,nf);
	SET_DIMENSION(dsp,2,nr);
	SET_DIMENSION(dsp,1,nc);
	SET_DIMENSION(dsp,0,ncomps);

	if( *obj_name == 0 ){
		warn("new_gen_obj:  Null object name!?");
		return;	// shouldn't happen, but can - HOW???
		// If it can, then should move this check to finish_obj???
	}

	finish_obj(obj_name,dsp,prec_p,AUTO_SHAPE);
}
Ejemplo n.º 7
0
static COMMAND_FUNC( mksubscalar )
{
	const char *obj_name;
	Data_Obj *dp, *newdp;
	index_t offsets[N_DIMENSIONS];
	Dimension_Set ds1, *dsp=(&ds1);
	long ncomps, comp_offset;

	obj_name=NAMEOF("name for subscalar");

	dp=pick_obj(PARENT_PROMPT);

	ncomps = (long) how_many("number of components");
	comp_offset = (long) how_many("component offset");

	if( dp==NULL ) return;

	INSIST_POSITIVE_DIM(ncomps,"component","mksubscalar");
	INSIST_NONNEGATIVE(comp_offset,"component offset","mksubscalar");

	SET_DIMENSION(dsp,0,ncomps);
	SET_DIMENSION(dsp,1,1);
	SET_DIMENSION(dsp,2,1);
	SET_DIMENSION(dsp,3,1);
	SET_DIMENSION(dsp,4,1);

	offsets[0]=(index_t)comp_offset;
	offsets[1]=0;
	offsets[2]=0;
	offsets[3]=0;
	offsets[4]=0;

	newdp=mk_subseq(obj_name,dp,offsets,dsp);
	if( newdp == NULL )
		warn("couldn't create subscalar");
}
Ejemplo n.º 8
0
static void _finish_obj(QSP_ARG_DECL  const char *obj_name, Dimension_Set *dsp, Precision *prec_p, uint32_t type_flag)
{
	assert(prec_p!=NULL);

	if( COLOR_PRECISION(PREC_CODE(prec_p)) ){
		if( DIMENSION(dsp,0) != 1 ){
			sprintf(ERROR_STRING,"object %s, number of rgb triples per pixel should be 1",obj_name);
			warn(ERROR_STRING);
		}
		SET_DIMENSION(dsp,0,3);
		prec_p = get_prec("float");
	}

	if( make_dobj_with_shape(obj_name,dsp,prec_p,type_flag) == NULL ) {
		sprintf(ERROR_STRING,"couldn't create data object \"%s\"", obj_name);
		warn(ERROR_STRING);
	}
}
Ejemplo n.º 9
0
void inner(QSP_ARG_DECL  Data_Obj *dpto,Data_Obj *dpfr1,Data_Obj *dpfr2)
{
	//dimension_t _n;		/* dot prod len */
	dimension_t i,j;
	Vec_Obj_Args oa1, *oap=&oa1;
	//Dimension_Set sizes={{1,1,1,1,1}};
	Dimension_Set *sizes;
	index_t dst_indices[N_DIMENSIONS]={0,0,0,0,0};
	index_t src1_indices[N_DIMENSIONS]={0,0,0,0,0};
	index_t src2_indices[N_DIMENSIONS]={0,0,0,0,0};
	Data_Obj *col_dp;

	sizes=NEW_DIMSET;
	for(i=0;i<N_DIMENSIONS;i++)
		SET_DIMENSION(sizes,i,1);

#ifdef CAUTIOUS
	clear_obj_args(oap);
#endif /* CAUTIOUS */

	/* The types and precisions should be whatever is allowed by vdot,
	 * which is float, double, real and complex...
	 */

	if( ! is_good_for_inner(dpto,"inner") ) return;
	if( ! is_good_for_inner(dpfr1,"inner") ) return;
	if( ! is_good_for_inner(dpfr2,"inner") ) return;

	/* we need to make sure that the types and precisions MATCH! */
	if( ! prec_and_type_match(dpto,dpfr1,"inner") ) return;
	if( ! prec_and_type_match(dpto,dpfr2,"inner") ) return;

	if( OBJ_ROWS(dpto) != OBJ_ROWS(dpfr1) ){
		sprintf(DEFAULT_ERROR_STRING,
	"inner:  dpto %s (%d) and first operand %s (%d) must have same # rows",
			OBJ_NAME(dpto),OBJ_ROWS(dpto),OBJ_NAME(dpfr1),OBJ_ROWS(dpfr1));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}
	if( OBJ_COLS(dpto) != OBJ_COLS(dpfr2) ){
		sprintf(DEFAULT_ERROR_STRING,
	"inner:  target %s (%d) and second operand %s (%d) must have same # columns",
			OBJ_NAME(dpto),OBJ_COLS(dpto),OBJ_NAME(dpfr2),OBJ_COLS(dpfr2));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}
	if( OBJ_COLS(dpfr1) != OBJ_ROWS(dpfr2) ){
		sprintf(DEFAULT_ERROR_STRING,
	"inner:  # cols of operand %s (%d) must match # rows of operand %s (%d)",
			OBJ_NAME(dpfr1),OBJ_COLS(dpfr1),OBJ_NAME(dpfr2),OBJ_ROWS(dpfr2));
		NWARN(DEFAULT_ERROR_STRING);
		return;
	}

	//_n=OBJ_COLS(dpfr1);		/* the length of each dot product we will compute */

	if( IS_COMPLEX(dpto) )	SET_OA_ARGSTYPE(oap,COMPLEX_ARGS);
	else			SET_OA_ARGSTYPE(oap,REAL_ARGS);

	/* vdot things it's inputs have the same shape, so if we are taking the inner
	 * product of a column vector with a row vector, we have to transpose one of
	 * the inputs...
	 */

	if( OBJ_ROWS(dpfr1) > 1 )
		SET_OA_SRC1(oap,d_subscript(QSP_ARG  dpfr1,0) );	/* subscript first row */
	else
		SET_OA_SRC1(oap,dpfr1);			/* object is a row */

	if( OBJ_COLS(dpto) > 1 )
		col_dp=c_subscript(QSP_ARG  dpfr2,0);
	else 
		col_dp=dpfr2;

	SET_OA_DEST(oap,mk_subimg(QSP_ARG  dpto,0,0,"target pixel",1,1) );

	//[sizes setDimensionAtIndex : 1 withValue : OBJ_ROWS(col_dp) ];
	SET_DIMENSION(sizes,1,OBJ_ROWS(col_dp));
	SET_DIMENSION(sizes,0,OBJ_COMPS(col_dp));

	SET_OA_SRC2(oap,make_equivalence(QSP_ARG  "_transposed_column",
						col_dp,sizes,OBJ_PREC_PTR(col_dp)) );

	for(i=0;i<OBJ_ROWS(dpto);i++){
		src1_indices[2]=i;
		SET_OBJ_DATA_PTR( OA_SRC1(oap), multiply_indexed_data(dpfr1,src1_indices) );
		for(j=0;j<OBJ_COLS(dpto);j++){
			dst_indices[2]=i;		/* k_th component */
			dst_indices[1]=j;		/* k_th component */
			SET_OBJ_DATA_PTR( OA_DEST(oap), multiply_indexed_data(dpto,dst_indices) );
			src2_indices[1]=j;
			SET_OBJ_DATA_PTR( OA_SRC2(oap), multiply_indexed_data(dpfr2,src2_indices) );
			vdot(QSP_ARG  oap);
		}
	}

	delvec(QSP_ARG  OA_SRC2(oap) );		/* "_transposed_column" */

	if( OA_SRC1(oap) != dpfr1 )
		delvec(QSP_ARG  OA_SRC1(oap) );
	if( col_dp != dpfr2 )
		delvec(QSP_ARG  col_dp);

	delvec(QSP_ARG  OA_DEST(oap) );
}
Ejemplo n.º 10
0
Archivo: size.c Proyecto: E-LLP/QuIP
static int change_size(QSP_ARG_DECL  Data_Obj *dst_dp,Data_Obj *src_dp )
{
	Dimension_Set ef, *enlargement_factor=&ef;
	Dimension_Set rf, *reduction_factor=&rf;
	Vec_Obj_Args oa1, *oap=&oa1;
	Dimension_Set size_ds, n_ds;
	Dimension_Set *size_dsp=(&size_ds), *n_dsp=(&n_ds);
	Data_Obj *src_ss_dp, *dst_ss_dp;
	dimension_t i,j,k,l,m;
	index_t offsets[N_DIMENSIONS]={0,0,0,0,0};
	incr_t dst_incrs[N_DIMENSIONS], src_incrs[N_DIMENSIONS];
	index_t dst_indices[N_DIMENSIONS]={0,0,0,0,0}, src_indices[N_DIMENSIONS]={0,0,0,0,0};

	/* For simplicity, we don't allow size changes to be combined with conversions */

	if( !dp_same_prec(QSP_ARG  dst_dp,src_dp,"change_size") )
		return(-1);

	for(i=0;i<N_DIMENSIONS;i++){
		if( OBJ_TYPE_DIM(dst_dp,i) > OBJ_TYPE_DIM(src_dp,i) ){
			/* enlargement - subsample the destination */
			SET_DIMENSION(enlargement_factor,i,
				floor( OBJ_TYPE_DIM(dst_dp,i) / OBJ_TYPE_DIM(src_dp,i) ) );
			SET_DIMENSION(reduction_factor,i, 0);

			SET_DIMENSION(size_dsp,i, OBJ_TYPE_DIM(src_dp,i) );
			SET_DIMENSION(n_dsp,i, DIMENSION(enlargement_factor,i) );
			dst_incrs[i] = DIMENSION(n_dsp,i);
			src_incrs[i] = 1;
		} else {
			/* reduction - subsample the source */
			SET_DIMENSION(reduction_factor,i,
				ceil( OBJ_TYPE_DIM(src_dp,i) / OBJ_TYPE_DIM(dst_dp,i) ) );
			SET_DIMENSION(enlargement_factor,i, 0 );

			SET_DIMENSION(size_dsp,i, floor( OBJ_TYPE_DIM(src_dp,i) /
				DIMENSION(reduction_factor,i) ) );
			/* We don't need to do this multiple times, just pick one and do it */
			/*SET_DIMENSION(n_dsp,i, DIMENSION(reduction_factor,i) ); */
			SET_DIMENSION(n_dsp,i, 1);
			src_incrs[i] = DIMENSION(reduction_factor,i);
			dst_incrs[i] = 1;
		}
	}
	/* make the subsamples.
	 * the column increment is expressed in columns, etc.
	 */
	dst_ss_dp=make_subsamp(QSP_ARG  "chngsize_dst_obj",dst_dp,size_dsp,offsets,dst_incrs);
	src_ss_dp=make_subsamp(QSP_ARG  "chngsize_src_obj",src_dp,size_dsp,offsets,src_incrs);

	clear_obj_args(oap);
	SET_OA_DEST(oap,dst_ss_dp);
	SET_OA_SRC_OBJ(oap,0, src_ss_dp);
	SET_OA_ARGSTYPE(oap, REAL_ARGS);
	SET_OA_PFDEV(oap,OBJ_PFDEV(dst_dp));

	for(i=0;i<DIMENSION(n_dsp,4);i++){		/* foreach sequence to copy */
		if( dst_incrs[4] > 1 )
			dst_indices[4]=i;
		else	src_indices[4]=i;
		for(j=0;j<DIMENSION(n_dsp,3);j++){	/* foreach frame to copy */
			if( dst_incrs[3] > 1 )
				dst_indices[3]=j;
			else	src_indices[3]=j;
			for(k=0;k<DIMENSION(n_dsp,2);k++){	/* foreach row */
				if( dst_incrs[2] > 1 )
					dst_indices[2]=k;
				else	src_indices[2]=k;
				for(l=0;l<DIMENSION(n_dsp,1);l++){	/* foreach col */
					if( dst_incrs[1] > 1 )
						dst_indices[1]=l;
					else	src_indices[1]=l;
					for(m=0;m<DIMENSION(n_dsp,0);m++){ /* foreach comp */
						if( dst_incrs[0] > 1 )
							dst_indices[0]=m;
						else	src_indices[0]=m;
						/* relocate the appropriate subsample */
						SET_OBJ_DATA_PTR(dst_ss_dp, multiply_indexed_data(dst_dp,dst_indices) );
						SET_OBJ_DATA_PTR(src_ss_dp, multiply_indexed_data(src_dp,src_indices) );

						// This doesn't check for cuda obj...
						//vmov(oap);
						perf_vfunc(QSP_ARG  FVMOV, oap );
					}
				}
			}
		}
	}
	delvec(QSP_ARG  dst_ss_dp);
	delvec(QSP_ARG  src_ss_dp);

	SET_OBJ_FLAG_BITS(dst_dp, DT_ASSIGNED);

	return(0);
}
Ejemplo n.º 11
0
static COMMAND_FUNC( mk_subsample )
{
	const char *obj_name;
	Data_Obj *dp;

	Dimension_Set ds1, *dsp=(&ds1);
	index_t offsets[N_DIMENSIONS];
	long l_offset[N_DIMENSIONS];
	incr_t incrs[N_DIMENSIONS];
	long size[N_DIMENSIONS];
	char pmpt[MAX_PMPT_LEN];
	int i;

	obj_name=NAMEOF("name for subsample object");

	dp=pick_obj(PARENT_PROMPT);

	/* We violate the rule of returning before getting
	 * all arguments, because the fields of dp are needed
	 * to determine what to prompt for!
	 */

	if( dp==NULL ) return;

	for(i=0;i<N_DIMENSIONS;i++){
		/* BUG? should we prompt for all dimensions, instead of just those > 1 ?
		 * If we did, then we could defer the return above...
		 */
		if( OBJ_TYPE_DIM(dp,i) > 1 ){
			if( i < (N_DIMENSIONS-1) )
				// BUG check length
				sprintf(pmpt,"number of %ss per %s",dimension_name[i], dimension_name[i+1]);
			else
				sprintf(pmpt,"number of %ss",dimension_name[i]);

			size[i]=(long) how_many(pmpt);

			sprintf(pmpt,"%s offset",dimension_name[i]);
			l_offset[i] = (long) how_many(pmpt);
			sprintf(pmpt,"%s increment",dimension_name[i]);
			incrs[i] =(incr_t)how_many(pmpt);	// this can be negative...
		} else {
			size[i] = 1;
			l_offset[i]=0;
			incrs[i]=1;
		}
	}
	for(i=0;i<N_DIMENSIONS;i++){
		char offset_descr[LLEN];
		INSIST_POSITIVE_DIM(size[i],dimension_name[i],"mk_subsample");
		sprintf(offset_descr,"%s offset",dimension_name[i]);
		INSIST_NONNEGATIVE(l_offset[i],offset_descr,"mk_subsample");
	}
	for(i=0;i<N_DIMENSIONS;i++){
		SET_DIMENSION(dsp,i,size[i]);
		offsets[i] = (index_t) l_offset[i];
	}

	// make_subsamp checks the increments...

	if( make_subsamp(obj_name,dp,dsp,offsets,incrs) == NULL )
		warn("error making subsamp object");
}