Ejemplo n.º 1
0
  // grabs c
  CArrayIndexIndexed( BaseGDL* c, bool strictArrSubs_ = false)
  : strictArrSubs( strictArrSubs_)
  , ix( NULL), ixDim( NULL)
  , rawData( c)
  {
    assert( rawData != NULL);
    
    if( rawData->Rank() == 0) // type ONE
    {
      rawData->Scalar2RangeT(sInit);
      s = sInit; // in case of assoc NIter is not called
      isScalar = true;
      return;
    }

    // type INDEXED
    isScalar = false;;
    
    ixDim = &rawData->Dim();

    assert( rawData->Type() != GDL_UNDEF);
    DType dType = rawData->Type();
    int typeCheck = DTypeOrder[ dType];
    if( typeCheck >= 100)
      throw GDLException(-1, NULL,"Type not allowed as subscript.",true,false);

    if( strictArrSubs)
      ix = new (ixBuf) AllIxIndicesStrictT( rawData);
    else
      ix = new (ixBuf) AllIxIndicesT( rawData);
  }
Ejemplo n.º 2
0
Archivo: fftw.cpp Proyecto: cenit/GDL
  T* fftw_template(EnvT* e, BaseGDL* p0,
		   SizeT nEl, SizeT dbl, SizeT overwrite, double direct, bool recenter) {
    int dim[MAXRANK];

    T* res;
    BaseGDL* data;
    Guard<BaseGDL> guard_data;

    // if recenter and inverse (direct > 0) we will work on a "de-centered" p0 variant.
    // and of course not center the result.

    if (recenter && direct == 1)
    {
      DLong centerIx[ MAXRANK];
      for (int i = 0; i < p0->Rank(); ++i) centerIx[i] = (p0->Dim(i)%2==1)?((p0->Dim(i))/2)+1:((p0->Dim(i))/2);
      data = p0->CShift(centerIx);
      recenter = false;
      guard_data.Reset(data);
    } else data = p0;

    if (overwrite == 0)
      res = new T(data->Dim(), BaseGDL::ZERO);
    else
    {
      res = (T*) p0; //we overwrite the real p0.
      if (e->GlobalPar(0)) e->SetPtrToReturnValue(&e->GetPar(0));
    }

    for (SizeT i = 0; i < data->Rank(); ++i)
    {
      dim[i] = (int) data->Dim(data->Rank() - i - 1);
    }

    DComplexDblGDL* p0C = static_cast<DComplexDblGDL*> (data);
    DComplexGDL* p0CF = static_cast<DComplexGDL*> (data);

    if (data->Type() == GDL_COMPLEXDBL)
    {
      double *dptr;
      dptr = (double*) &(*res)[0];

      fftw_plan p;
      fftw_complex *in, *out;
      in = (fftw_complex *) &(*p0C)[0];
      out = (fftw_complex *) & dptr[0];

      p = fftw_plan_dft((int) data->Rank(), dim, in, out, (int) direct, FFTW_ESTIMATE);

      fftw_execute(p);

      if (direct == -1)
      {
        //        TRACEOMP(__FILE__, __LINE__)
#pragma omp parallel if (nEl >= CpuTPOOL_MIN_ELTS && (CpuTPOOL_MAX_ELTS == 0 || CpuTPOOL_MAX_ELTS <= nEl))
        {
#pragma omp for
          for (OMPInt i = 0; i < nEl; ++i)
          {
            out[i][0] /= nEl;
            out[i][1] /= nEl;
          }
        }
      }

      // 02 06 2010
      //cout << "fftw dest" << endl ;
      fftw_destroy_plan(p); // 1 

    } else if (data->Type() == GDL_COMPLEX)
    {
      float *dptrf;
      dptrf = (float*) &(*res)[0];

      fftwf_plan p_f;
      fftwf_complex *in_f, *out_f;
      in_f = (fftwf_complex *) &(*p0CF)[0];
      out_f = (fftwf_complex *) & dptrf[0];

      p_f = fftwf_plan_dft((int) data->Rank(), dim, in_f, out_f, (int) direct, FFTW_ESTIMATE);

      fftwf_execute(p_f);

      if (direct == -1)
      {
        //        TRACEOMP(__FILE__, __LINE__)
#pragma omp parallel if (nEl >= CpuTPOOL_MIN_ELTS && (CpuTPOOL_MAX_ELTS == 0 || CpuTPOOL_MAX_ELTS <= nEl))
        {
#pragma omp for
          for (OMPInt i = 0; i < nEl; ++i)
          {
            out_f[i][0] /= nEl;
            out_f[i][1] /= nEl;
          }
        }
      }

      // 02 06 2010
      //cout << "fftwF dest" << endl ;
      fftwf_destroy_plan(p_f); // 2

    }
    if (recenter)
    {
      Guard<BaseGDL> guard_res(res);
      DLong centerIx[ MAXRANK];
      for (int i = 0; i < data->Rank(); ++i) centerIx[i] = (p0->Dim(i))/2;
      return (T*) res->CShift(centerIx);
    } else return res;
  }
Ejemplo n.º 3
0
  void print_os( ostream* os, EnvT* e, int parOffset, SizeT width)
  {
    // FORMAT keyword
    if( e->GetKW( 0) != NULL)
      {
	DString fmtString;
	e->AssureScalarKW<DStringGDL>( 0, fmtString);

	if( fmtString != "")
	{
	  try {
	  RefFMTNode fmtAST = GetFMTAST( fmtString);
#ifdef GDL_DEBUG
	  antlr::print_tree pt;
	  cout << "Format parser output:" << endl;
	  pt.pr_tree(static_cast<antlr::RefAST>(fmtAST));
	  cout << "Format Parser end." << endl;
#endif

	  // formatted output ignores WIDTH
	  FMTOut Formatter( fmtAST, os, e, parOffset); 
	  return;
	  }
	  catch( antlr::ANTLRException& ex)
	  {
	    e->Throw( ex.getMessage());
	  }
	}
      }
    //else // default-format output
      {
	int nParam = e->NParam();

	if( nParam == parOffset) 
	  {
	    (*os) << endl;
	    return;
	  }
      
	BaseGDL* par;
	bool lastParScalar = false;
	BaseGDL* parOffsetPar = e->GetPar( parOffset);
        bool anyArrayBefore = false;
	if( parOffsetPar != NULL)
	  anyArrayBefore = parOffsetPar->Rank() > 0;

	SizeT actPos = 0;
	for( SizeT i=parOffset; i<nParam; i++)
	  {
	    if( i > parOffset) lastParScalar = /*par->Type() == GDL_STRING &&*/ par->Scalar();
	    par=e->GetPar( i);
	    if( par == NULL) // allowed here: NullGDL::GetSingleInstance())
	      e->Throw("Variable is undefined: "+e->GetParString( i));
            if (lastParScalar && anyArrayBefore && par->Rank() != 0) (*os) << endl; // e.g. print,[1],1,[1] 
            anyArrayBefore |= par->Rank() != 0;
	    par->ToStream( *os, width, &actPos);
// debug	  
// 		(*os) << flush;
	  }
        bool singleNullChar = (par->Type() == GDL_STRING &&
				!lastParScalar &&
				(nParam-parOffset)>1 &&
			       (*static_cast<DStringGDL*>(par))[0] == "");
// 	}
	if( (par->Dim().Rank() == 0  && !singleNullChar) || par->Type() == GDL_STRUCT)
	{
		(*os) << endl;
	}
      }
  }