Beispiel #1
0
inline ValueType spatialaggregate::OcTreeNode< CoordType, ValueType >::getValueInVolume( const spatialaggregate::OcTreePosition< CoordType >& minPosition, const spatialaggregate::OcTreePosition< CoordType >& maxPosition, CoordType minimumSearchVolumeSize ) {

	if( type == OCTREE_LEAF_NODE ) {

		if( inRegion( minPosition, maxPosition ) )
			return value;

		return ValueType(0);

	}
	else {

		if( !overlap( minPosition, maxPosition ) )
			return ValueType(0);

		if( containedInRegion( minPosition, maxPosition ) )
			return value;

		if( (this->maxPosition[0] - this->minPosition[0]) - minimumSearchVolumeSize <= -OCTREE_EPSILON*minimumSearchVolumeSize ) {
			return value;
		}

		ValueType value = ValueType(0);
		for( unsigned int i = 0; i < 8; i++ ) {
			if(!siblings[i])
				continue;
			value += siblings[i]->getValueInVolume( minPosition, maxPosition, minimumSearchVolumeSize );
		}

		return value;

	}

}
Beispiel #2
0
static bool controlExpression(char relOp, expADT expL, expADT expR, environmentADT env){

	valueADT leftV, rightV;

	leftV = Eval(expL, env);
	rightV = Eval(expR, env);

	if(ValueType(leftV) == IntValue && ValueType(rightV) == IntValue ){

		switch(relOp){

		case '<':
		return (GetIntValue(leftV) < GetIntValue(rightV));

		case '>':
			return (GetIntValue(leftV) > GetIntValue(rightV));

		case '=':
			return (GetIntValue(leftV) == GetIntValue(rightV));

		default:
			Error("Reloperator %c is not valid.\n", relOp);
			break;
		}
	}
	else
		Error("\nCompared expressions is not Integers\n");

}
Beispiel #3
0
	void Quaternion::setAsSlerp(Quaternion const& from, Quaternion const& to, Real const t)
	{
		Real64 omega, cosomega, sinomega, scale_from, scale_to;
		Quaternion result(to);

		cosomega = from.x() * to.x() + from.y() * to.y() + from.z() * to.z() + from.w() * to.w();

		if (cosomega < ValueType(0.0))
		{
			cosomega = -cosomega;
			result = -to;
		}

		if((ValueType(1.0) - cosomega) > rengine::epsilon)
		{
			omega = acos(cosomega);
			sinomega = sin(omega);
			scale_from = sin((ValueType(1.0) - t) * omega) / sinomega;
			scale_to = sin(t * omega) / sinomega;
		}
		else // Quaternions are very close, so we can linear interpolate
		{
			scale_from = ValueType(1.0) - t;
			scale_to = t;
		}

		*this = (from * scale_from) + (result * scale_to);
	}
__global__ void kernel_csr_replace_column_vector_offset(const IndexType *row_offset, const IndexType *col,
                                                        const IndexType nrow, const IndexType idx,
                                                        const ValueType *vec, IndexType *offset) {

    IndexType ai = blockIdx.x*blockDim.x+threadIdx.x;
    IndexType aj;
    IndexType add = 1;

    if (ai < nrow) {

        offset[ai+1] = row_offset[ai+1] - row_offset[ai];

        for (aj=row_offset[ai]; aj<row_offset[ai+1]; ++aj) {
            if (col[aj] == idx) {
                add = 0;
                break;
            }
        }

        if (add == 1 && vec[ai] != ValueType(0.0))
            ++offset[ai+1];

        if (add == 0 && vec[ai] == ValueType(0.0))
            --offset[ai+1];

    }

}
Beispiel #5
0
/*
 * SpecialSymbols
 */
bool SpecialSymbols(const char *name, ValueType &out)
{
	     if (strcmp(name, "__PMAS__") == 0) out = ValueType(VERSIONN);
	else if (strcmp(name, "__LINE__") == 0) out = ValueType(file->line_num);
	else if (strcmp(name, "__FILE__") == 0) out = ValueType(file->filename);
	else if (strcmp(name, "__RAMBASE__") == 0) out = ValueType(option_ram_base);
	else return false;
	return true;
}
KOKKOS_INLINE_FUNCTION
void parallel_reduce(const Impl::ThreadVectorRangeBoundariesStruct<iType,Impl::OpenMPTargetExecTeamMember >&
      loop_boundaries, const Lambda & lambda, ValueType& result) {
  result = ValueType();
  for( iType i = loop_boundaries.start; i < loop_boundaries.end; i+=loop_boundaries.increment) {
    ValueType tmp = ValueType();
    lambda(i,tmp);
    result+=tmp;
  }
}
Beispiel #7
0
 inline void extendTo(KeyType x) {
    Int i;
    if(Graph1d<ValueType, KeyType, Int>::N<1)
      {
	Graph1d<ValueType, KeyType, Int>::N=1;
	Graph1d<ValueType, KeyType, Int>::minX=x-0.5*Graph1d<ValueType, KeyType, Int>::delta;
	Graph1d<ValueType, KeyType, Int>::maxX=Graph1d<ValueType, KeyType, Int>::minX+Graph1d<ValueType, KeyType, Int>::delta;
        Graph1d<ValueType, KeyType, Int>::y.resize(Graph1d<ValueType, KeyType, Int>::N);
        if(k>0)
        {
          M.resize(Graph1d<ValueType, KeyType, Int>::N);
          for(int i=0; i<k; i++) m[i].resize(Graph1d<ValueType, KeyType, Int>::N);
        }
      } else
      {
	i=this->idx(x);
	if(i<0)
	  {
            Graph1d<ValueType, KeyType, Int>::y.resize(Graph1d<ValueType, KeyType, Int>::N-i);
            if(k>0)
            {
              M.resize(Graph1d<ValueType, KeyType, Int>::N-i);
              for(int ii=0; ii<k; ii++) m[ii].resize(Graph1d<ValueType, KeyType, Int>::N-i);
            }
	    for(Int j=Graph1d<ValueType, KeyType, Int>::N-1; j>=0; j--)
            {
              Graph1d<ValueType, KeyType, Int>::y[j-i]=Graph1d<ValueType, KeyType, Int>::y[j];
              Graph1d<ValueType, KeyType, Int>::y[j]=ValueType(0);
              if(k>0)
              {
                M[j-i]=M[j];
                M[j]=0;
                for(int ii=0; ii<k; ii++)
                {
                  m[ii][j-i]=m[ii][j];
                  m[ii][j]=ValueType(0);
                }
              }
            }
	    Graph1d<ValueType, KeyType, Int>::N=Graph1d<ValueType, KeyType, Int>::N-i; Graph1d<ValueType, KeyType, Int>::minX+=KeyType(i)*Graph1d<ValueType, KeyType, Int>::delta;
	    i=0;
	  } else if(i>=Graph1d<ValueType, KeyType, Int>::N)
	  {
	    Int n=i-Graph1d<ValueType, KeyType, Int>::N+1;
            Graph1d<ValueType, KeyType, Int>::y.resize(i+1,ValueType(0));
            if(k>0)
            {
              M.resize(i+1,0);
              for(int ii=0; ii<k; ii++) m[ii].resize(i+1,ValueType(0));
            }
	    Graph1d<ValueType, KeyType, Int>::N=i+1;
            Graph1d<ValueType, KeyType, Int>::maxX+=KeyType(n)*Graph1d<ValueType, KeyType, Int>::delta;
	  }
      } }
void MultiColoredSGS<OperatorType, VectorType, ValueType>::SolveD_(void) {

  assert(this->build_ == true);

  for (int i=0; i<this->num_blocks_; ++i) {
    this->x_block_[i]->PointWiseMult(*this->diag_block_[i]);

    // SSOR
    if (this->omega_ != ValueType(1.0))
      this->x_block_[i]->Scale(this->omega_/(ValueType(2.0) - this->omega_));

  }
}
void MultiElimination<OperatorType, VectorType, ValueType>::Solve(const VectorType &rhs,
                                                                  VectorType *x) {
  
  assert(this->build_ == true);

  //  LOG_INFO("Level = " << this->get_level() << " with size=" << this->get_size_diag_block() );


  this->rhs_.CopyFromPermute(rhs,
                             this->permutation_);

  this->x_1_.CopyFrom(this->rhs_, 
                      0,
                      0,
                      this->size_);

  this->rhs_2_.CopyFrom(this->rhs_, 
                      this->size_,
                      0,
                      this->rhs_.get_size() - this->size_);


  // Solve L  
  this->E_.ApplyAdd(this->x_1_, ValueType(-1.0), &this->rhs_2_);


  // Solve R
  this->AA_solver_->Solve(this->rhs_2_,
                          &this->x_2_);


  this->F_.ApplyAdd(this->x_2_, ValueType(-1.0), &this->x_1_);

  this->x_1_.PointWiseMult(this->inv_vec_D_);


  this->x_.CopyFrom(this->x_1_, 
                    0,
                    0,
                    this->size_);

  this->x_.CopyFrom(this->x_2_, 
                    0,
                    this->size_,
                    this->rhs_.get_size() - this->size_);


  x->CopyFromPermuteBackward(this->x_,
                             this->permutation_);

}
void HostMatrixCOO<ValueType>::Apply(const BaseVector<ValueType> &in, BaseVector<ValueType> *out) const {

    assert(in.  get_size() >= 0);
    assert(out->get_size() >= 0);
    assert(in.  get_size() == this->ncol_);
    assert(out->get_size() == this->nrow_);

    const HostVector<ValueType> *cast_in = dynamic_cast<const HostVector<ValueType>*> (&in) ;
    HostVector<ValueType> *cast_out      = dynamic_cast<      HostVector<ValueType>*> (out) ;

    assert(cast_in != NULL);
    assert(cast_out!= NULL);

    _set_omp_backend_threads(this->local_backend_, this->nnz_);

    #pragma omp parallel for



    for (int i=0; i<this->nrow_; ++i) {
        cast_out->vec_[i] = ValueType(0.0);
        if (i == 0) {
            int nthreads = omp_get_num_threads();
            std::cout << "variable nthreads IN COO is " << nthreads << std::endl;
        }
    }

    for (int i=0; i<this->nnz_; ++i)
        cast_out->vec_[this->mat_.row[i] ] += this->mat_.val[i] * cast_in->vec_[ this->mat_.col[i] ];

}
Beispiel #11
0
KOKKOS_INLINE_FUNCTION
void parallel_reduce
  (const Impl::ThreadVectorRangeBoundariesStruct<iType,Impl::TaskExec< Kokkos::Serial > >& loop_boundaries,
   const Lambda & lambda,
   ValueType& initialized_result)
{
  initialized_result = ValueType();
#ifdef KOKKOS_ENABLE_PRAGMA_IVDEP
#pragma ivdep
#endif
  for( iType i = loop_boundaries.start; i < loop_boundaries.end; i+=loop_boundaries.increment) {
    ValueType tmp = ValueType();
    lambda(i,tmp);
    initialized_result+=tmp;
  }
}
Beispiel #12
0
static	void
_DumpItems(
	ValueStruct	*value)
{
	int		i;

	if		(  value  ==  NULL  )	return;
	switch	(ValueType(value)) {
	  case	GL_TYPE_INT:
		printf("int");
		break;
	  case	GL_TYPE_BOOL:
		printf("bool");
		break;
	  case	GL_TYPE_BYTE:
		printf("byte");
		break;
	  case	GL_TYPE_CHAR:
		printf("char(%d)",(int)ValueStringLength(value));
		break;
	  case	GL_TYPE_VARCHAR:
		printf("varchar(%d)",(int)ValueStringLength(value));
		break;
	  case	GL_TYPE_DBCODE:
		printf("dbcode(%d)",(int)ValueStringLength(value));
		break;
	  case	GL_TYPE_NUMBER:
		if		(  ValueFixedSlen(value)  ==  0  ) {
			printf("number(%d)",(int)ValueFixedLength(value));
		} else {
			printf("number(%d,%d)",
				   (int)ValueFixedLength(value),
				   (int)ValueFixedSlen(value));
		}
		break;
	  case	GL_TYPE_TEXT:
		printf("text");
		break;
	  case	GL_TYPE_ARRAY:
		_DumpItems(ValueArrayItem(value,0));
		printf("[%d]",(int)ValueArraySize(value));
		break;
	  case	GL_TYPE_RECORD:
		printf("{\n");
		nTab ++;
		for	( i = 0 ; i < ValueRecordSize(value) ; i ++ ) {
			PutTab(nTab);
			printf("%s\t",ValueRecordName(value,i));
			_DumpItems(ValueRecordItem(value,i));
			printf(";\n");
		}
		nTab --;
		PutTab(nTab);
		printf("}");
		break;
	  default:
		break;
	}
	fflush(stdout);
}
Beispiel #13
0
inline void spatialaggregate::OcTree< CoordType, ValueType >::getValueAndCountInVolume( ValueType& value, unsigned int& count, const spatialaggregate::OcTreePosition< CoordType >& minPosition, const spatialaggregate::OcTreePosition< CoordType >& maxPosition, CoordType minimumSearchVolumeSize ) {

	value = ValueType(0);
	count = 0;
	root->getValueAndCountInVolume( value, count, minPosition, maxPosition, minimumSearchVolumeSize );

}
Beispiel #14
0
__global__ void kernel_reduce(const IndexType n, const ValueType *data, ValueType *out,
                              const IndexType GROUP_SIZE, const IndexType LOCAL_SIZE) {

    IndexType tid = threadIdx.x;

    __shared__ ValueType sdata[BLOCK_SIZE];
    sdata[tid] = ValueType(0.0);

    // get global id
    IndexType gid = GROUP_SIZE * blockIdx.x + tid;

    for (IndexType i = 0; i < LOCAL_SIZE; ++i, gid += BLOCK_SIZE)
      if ( gid < n )
        sdata[tid] += data[gid];

    __syncthreads();

#pragma unroll
    for (IndexType i = BLOCK_SIZE/2; i > 0; i /= 2) {

      if (tid < i)
        sdata[tid] += sdata[tid + i];

      __syncthreads();

    }

    if (tid == 0)
      out[blockIdx.x] = sdata[tid];

}
Beispiel #15
0
T& HashMap<Key, T, Hasher, EqualKey, Alloc>::operator[](const Key& k){
    iterator i = find(k);
    if(i != end() )
        return i->second;
    i = addNode(ValueType(k) );
    return i->second;
  }
Beispiel #16
0
__global__ void kernel_ell_add_spmv(const IndexType num_rows,
                                    const IndexType num_cols,
                                    const IndexType num_cols_per_row,
                                    const IndexType *Acol,
                                    const ValueType *Aval,
                                    const ValueType scalar,
                                    const ValueType *x,
                                    ValueType *y) {

    int row = blockDim.x * blockIdx.x + threadIdx.x;

    if (row < num_rows) {

        ValueType sum = ValueType(0.0);

        for (IndexType n=0; n<num_cols_per_row; ++n) {

            const IndexType ind = ELL_IND(row, n, num_rows, num_cols_per_row);
            const IndexType col = Acol[ind];

            if ((col >= 0) && (col < num_cols))  {

                sum += Aval[ind] * x[col];

            }

        }

        y[row] += scalar*sum;

    }

}
Beispiel #17
0
extern	Bool
ValueToBool(
	ValueStruct	*val)
{
	Bool	ret;

	if		(  val  ==  NULL  ) {
		ret = FALSE;
	} else
	switch	(ValueType(val)) {
	  case	GL_TYPE_CHAR:
	  case	GL_TYPE_VARCHAR:
	  case	GL_TYPE_TEXT:
	  case	GL_TYPE_SYMBOL:
		ret = ( *ValueString(val) == 'T' ) ? TRUE : FALSE;
		break;
	  case	GL_TYPE_NUMBER:
		ret = FixedToInt(&ValueFixed(val)) ? TRUE : FALSE;
		break;
	  case	GL_TYPE_INT:
		ret = ValueInteger(val) ? TRUE : FALSE;
		break;
	  case	GL_TYPE_FLOAT:
		ret = (int)ValueFloat(val) ? TRUE : FALSE;
		break;
	  case	GL_TYPE_BOOL:
		ret = ValueBool(val);
		break;
	  default:
		ret = FALSE;
	}
	return	(ret);
}
Beispiel #18
0
 void Init() {
   if (values_)
     delete[] values_;
   grid_size_ = size_[0] * size_[1] * size_[2];
   values_ = new ValueType[grid_size_];
   for (int i = 0; i < grid_size_; ++i)
     values_[i] = ValueType();
 }
Beispiel #19
0
 virtual MatchResult match(Entry const & anEntry) {
   Operation op;
   if ( op( ValueType().extract(anEntry, theField), theValue  ) ) {
     return Include;
   } else {
     return NoMatch;
   }
 }
void HostVector<ValueType>::Ones(void) {

  _set_omp_backend_threads(this->local_backend_, this->size_);

#pragma omp parallel for
  for (int i=0; i<this->size_; ++i)
    this->vec_[i] = ValueType(1.0);

}
void HostVector<ValueType>::Power(const double power) {

  _set_omp_backend_threads(this->local_backend_, this->size_);

#pragma omp parallel for
  for (int i=0; i<this->size_; ++i)
    this->vec_[i] = pow(this->vec_[i], ValueType(power));

}
bool operator<=(const std::complex<ValueType> &lhs, const std::complex<ValueType> &rhs) {

  if (&lhs == &rhs)
    return true;

  assert(lhs.imag() == rhs.imag() && lhs.imag() == ValueType(0.0));

  return lhs.real() <= rhs.real();

}
Beispiel #23
0
static void
set_value(ValueStruct *value, VALUE obj)
{
    VALUE class_path, str;

    if (NIL_P(obj)) {
        ValueIsNil(value);
    }
    else {
        ValueIsNonNil(value);
        switch (TYPE(obj)) {
        case T_TRUE:
        case T_FALSE:
            SetValueBool(value, RTEST(obj) ? TRUE : FALSE);
            break;
        case T_FIXNUM:
            SetValueInteger(value, FIX2INT(obj));
            break;
        case T_BIGNUM:
            SetValueInteger(value, NUM2INT(obj));
            break;
        case T_FLOAT:
            SetValueFloat(value, RFLOAT(obj)->value);
            break;
        case T_STRING:
            switch (ValueType(value)) {
            case GL_TYPE_BYTE:
            case GL_TYPE_BINARY:
                SetValueBinary(value, RSTRING(obj)->ptr, RSTRING(obj)->len);
                break;
            default:
                SetValueStringWithLength(value,
                                         RSTRING(obj)->ptr,
                                         RSTRING(obj)->len,
                                         codeset);
                break;
            }
            break;
        default:
            class_path = rb_class_path(CLASS_OF(obj));
            if (strcasecmp(StringValuePtr(class_path), "BigDecimal") == 0) {
                str = rb_funcall(obj, rb_intern("to_s"), 1, rb_str_new2("F"));
            } else
            if (strcasecmp(StringValuePtr(class_path), "Time") == 0) {
                str = rb_funcall(obj, rb_intern("strftime"), 1, rb_str_new2("%Y%m%d%H%M%S"));
dbgprintf("strftime [%s]",StringValuePtr(str));
            }
            else {
                str = rb_funcall(obj, rb_intern("to_s"), 0);
            }
            SetValueString(value, StringValuePtr(str), codeset);
            break;
        }
    }
}
Beispiel #24
0
__global__ void kernel_amax(const IndexType n, const ValueType *data, ValueType *out,
                            const IndexType GROUP_SIZE, const IndexType LOCAL_SIZE) {

    IndexType tid = threadIdx.x;

    __shared__ ValueType sdata[BLOCK_SIZE];
    sdata[tid] = ValueType(0);

    // get global id
    IndexType gid = GROUP_SIZE * blockIdx.x + tid;

    for (IndexType i = 0; i < LOCAL_SIZE; ++i, gid += BLOCK_SIZE) {

      if (gid < n) {
        ValueType tmp = data[gid];
        tmp = max(tmp, ValueType(-1.0)*tmp);
        if (tmp > sdata[tid])
          sdata[tid] = tmp;
      }

    }

    __syncthreads();

#pragma unroll
    for (IndexType i = BLOCK_SIZE/2; i > 0; i /= 2) {

      if (tid < i) {
        ValueType tmp = sdata[tid+i];
        tmp = max(tmp, ValueType(-1.0)*tmp);
        if (tmp > sdata[tid])
          sdata[tid] = tmp;
      }

      __syncthreads();

    }

    if (tid == 0)
      out[blockIdx.x] = sdata[tid];

}
Beispiel #25
0
	void Quaternion::setAsRotation(ValueType const angle, ValueType const x, ValueType const y, ValueType const z)
	{
		ValueType vector_length = sqrt(x * x + y * y + z * z);
		if (vector_length < ValueType(epsilon))
		{
			setAsIdentity();
		}
		else
		{
			ValueType half_angle = angle / ValueType(2.0);
			ValueType sin_halfangle = sin(half_angle);

			_v[0] = (x / vector_length) * sin_halfangle;
			_v[1] = (y / vector_length) * sin_halfangle;
			_v[2] = (z / vector_length) * sin_halfangle;
			_v[3] = cos(half_angle);

			//normalize();
		}
	}
Beispiel #26
0
KOKKOS_INLINE_FUNCTION
Tensor2<T>
vol(const Tensor2<T> &tens) {
  using ValueType = typename Tensor2<T>::value_type;
  index_t dim = tens.dim();
  Tensor2<T> ret(dim);
  
  const ValueType theta = (ValueType(1)/dim) * trace(tens);
  
  return theta * identity<T>(dim);
}
Beispiel #27
0
KOKKOS_INLINE_FUNCTION
typename Tensor2<T>::value_type
norm(const Tensor2<T> &tens) {
  using ValueType = typename Tensor2<T>::value_type;
  ValueType ret = ValueType(0);
  for (index_t i = 0; i < tens.arraySize(); ++i) {
    ret += tens(i) * tens(i);
  }
  
  return sqrt(ret);
}
void MultiElimination<OperatorType, VectorType, ValueType>::Clear(void) {

  if (this->build_ == true) {

    this->A_.Clear();
    this->D_.Clear();
    this->C_.Clear();
    this->E_.Clear();
    this->F_.Clear();
    this->AA_.Clear();

    this->A_.ConvertToCSR();
    this->D_.ConvertToCSR();
    this->C_.ConvertToCSR();
    this->E_.ConvertToCSR();
    this->F_.ConvertToCSR();
    this->AA_.ConvertToCSR();


    this->AA_nrow_ = 0;
    this->AA_nnz_  = 0;
    
    this->x_.Clear();
    this->x_1_.Clear();
    this->x_2_.Clear();
    
    this->rhs_.Clear();
    this->rhs_1_.Clear();
    this->rhs_1_.Clear();
    
    this->permutation_.Clear();

    if (this->AA_me_ != NULL)
      delete this->AA_me_;

    if (this->AA_solver_ != NULL)
      this->AA_solver_->Clear();

    this->diag_solver_init_ = false;
    this->level_ = -1;
    this->drop_off_ = ValueType(0.0);
    this->size_ = 0;

    this->AA_me_ = NULL;
    this->AA_solver_ = NULL;

    this->op_mat_format_ = false;
    this->precond_mat_format_ = CSR;

    this->build_ = false ;

  }

}
Beispiel #29
0
 void increment()
 {
   face_handle_t curr_face_handle(m_face_handles[m_lead]);
   vertex_t first = get_first_vertex(curr_face_handle, Time());
   vertex_t second = get_second_vertex(curr_face_handle, Time());
   if (first == m_follow)
     {
       m_follow = m_lead;
       set_edge_to_second_dispatch(curr_face_handle, ValueType(), Time());
       m_lead = second;
     }
   else if (second == m_follow)
     {
       m_follow = m_lead;
       set_edge_to_first_dispatch(curr_face_handle, ValueType(), Time());
       m_lead = first;
     }
   else
     m_lead = m_follow = graph_traits<Graph>::null_vertex();
 }
void MultiColoredSGS<OperatorType, VectorType, ValueType>::SolveL_(void) {

  assert(this->build_ == true);

  for (int i=0; i<this->num_blocks_; ++i){

    for (int j=0; j<i; ++j)
      this->preconditioner_block_[i][j]->ApplyAdd(*this->x_block_[j],
                                                  ValueType(-1.0),
                                                  this->x_block_[i]);

    this->diag_solver_[i]->Solve(*this->x_block_[i],
                                 this->x_block_[i]);

    // SSOR
    if (this->omega_ != ValueType(1.0))
      this->x_block_[i]->Scale(ValueType(1.0)/this->omega_);
  }

}