コード例 #1
0
ファイル: scan_dim.hpp プロジェクト: FilipeMaia/arrayfire
    static Kernel get_scan_dim_kernels(int kerIdx, int dim, bool isFinalPass, uint threads_y)
    {
        std::string ref_name =
            std::string("scan_") +
            std::to_string(dim) +
            std::string("_") +
            std::to_string(isFinalPass) +
            std::string("_") +
            std::string(dtype_traits<Ti>::getName()) +
            std::string("_") +
            std::string(dtype_traits<To>::getName()) +
            std::string("_") +
            std::to_string(op) +
            std::string("_") +
            std::to_string(threads_y) +
            std::string("_") +
            std::to_string(int(inclusive_scan));

        int device = getActiveDeviceId();

        kc_entry_t entry = kernelCache(device, ref_name);

        if (entry.prog==0 && entry.ker==0) {
            Binary<To, op> scan;
            ToNumStr<To> toNumStr;

            std::ostringstream options;
            options << " -D To=" << dtype_traits<To>::getName()
                    << " -D Ti=" << dtype_traits<Ti>::getName()
                    << " -D T=To"
                    << " -D dim=" << dim
                    << " -D DIMY=" << threads_y
                    << " -D THREADS_X=" << THREADS_X
                    << " -D init=" << toNumStr(scan.init())
                    << " -D " << binOpName<op>()
                    << " -D CPLX=" << af::iscplx<Ti>()
                    << " -D isFinalPass="******" -D inclusive_scan=" << inclusive_scan;
            if (std::is_same<Ti, double>::value ||
                std::is_same<Ti, cdouble>::value) {
                options << " -D USE_DOUBLE";
            }

            const char *ker_strs[] = {ops_cl, scan_dim_cl};
            const int   ker_lens[] = {ops_cl_len, scan_dim_cl_len};
            cl::Program prog;
            buildProgram(prog, 2, ker_strs, ker_lens, options.str());

            entry.prog = new Program(prog);
            entry.ker = new Kernel[2];

            entry.ker[0] = Kernel(*entry.prog, "scan_dim_kernel");
            entry.ker[1] = Kernel(*entry.prog, "bcast_dim_kernel");


            addKernelToCache(device, ref_name, entry);
        }

        return entry.ker[kerIdx];
    }
コード例 #2
0
ファイル: Binary.cpp プロジェクト: kd0kfo/libdnstd
 Binary Binary::operator +(const Binary& B)
 {
   Binary sum(i+B.getInt());
   if(B.getBitSize() > sum.bitSize)
     sum.setBitSize(B.getBitSize());
   return sum;
 }
LLVMSymbolizer::BinaryPair
LLVMSymbolizer::getOrCreateBinary(const std::string &Path) {
  BinaryMapTy::iterator I = BinaryForPath.find(Path);
  if (I != BinaryForPath.end())
    return I->second;
  Binary *Bin = 0;
  Binary *DbgBin = 0;
  OwningPtr<Binary> ParsedBinary;
  OwningPtr<Binary> ParsedDbgBinary;
  if (!error(createBinary(Path, ParsedBinary))) {
    // Check if it's a universal binary.
    Bin = ParsedBinary.take();
    ParsedBinariesAndObjects.push_back(Bin);
    if (Bin->isMachO() || Bin->isMachOUniversalBinary()) {
      // On Darwin we may find DWARF in separate object file in
      // resource directory.
      const std::string &ResourcePath =
          getDarwinDWARFResourceForPath(Path);
      bool ResourceFileExists = false;
      if (!sys::fs::exists(ResourcePath, ResourceFileExists) &&
          ResourceFileExists &&
          !error(createBinary(ResourcePath, ParsedDbgBinary))) {
        DbgBin = ParsedDbgBinary.take();
        ParsedBinariesAndObjects.push_back(DbgBin);
      }
    }
  }
  if (DbgBin == 0)
    DbgBin = Bin;
  BinaryPair Res = std::make_pair(Bin, DbgBin);
  BinaryForPath[Path] = Res;
  return Res;
}
コード例 #4
0
/*
Step 1: Let zi := xi for i =1,2, ...,n (i.e., z is a copy of the
		primary parent x).
Step 2: Let zi := (1 - zi) with a probability PBF when xi = yi
		where PBF is a prespecified bit-flip probability.
Note:	Random primary parent selection
*/
bool BinaryCrsNonGeometric::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
{
	Binary* p1 = (Binary*) (gen1.get());
	Binary* p2 = (Binary*) (gen2.get());
	Binary* ch = (Binary*) (child.get());
	
	double PBF = 0.5; //prespecified bit-flip probability

	//Step 1
	for (uint dimension = 0; dimension < p1->variables.size(); dimension++) {
		switch (state_->getRandomizer()->getRandomInteger(0, 1)) {
			case 0: for (uint i = 0; i < p1->getNumBits(); i++) {
						ch->variables[dimension][i] = p1->variables[dimension][i];
					}
					break;
			case 1: for (uint i = 0; i < p2->getNumBits(); i++) {
						ch->variables[dimension][i] = p2->variables[dimension][i];
					}
		}
		//Step 2
		for(uint i = 0; i < p1->getNumBits(); i++) {
			if (p1->variables[dimension][i] == p2->variables[dimension][i]) {
				double changeProbability = state_->getRandomizer()->getRandomDouble();
				if (changeProbability > PBF)
					ch->variables[dimension][i] =  ch->variables[dimension][i]  ? false:true;				
			}
		}
	}

	// update integer and real domain representation
	ch->update();

	return true;
}
コード例 #5
0
ファイル: Binary.cpp プロジェクト: kd0kfo/libdnstd
 Binary Binary::operator -(const Binary& B)
 {
   Binary diff(i-B.i);
   if(B.getBitSize() > diff.bitSize)
     diff.setBitSize(B.getBitSize());
   return diff;
 }
コード例 #6
0
ファイル: kernel_builder.hpp プロジェクト: bambang/vsipl
void build_kernel(Binary<expr::op::Sub, L, R> e, Kernel<T>& k)
{
  Kernel_builder<L, T>::apply(e.arg1(), k);
  Kernel<T> k2(k);
  Kernel_builder<R, T>::apply(e.arg2(), k2);
  k -= k2;
}
コード例 #7
0
ファイル: reduce.cpp プロジェクト: PierreBizouard/arrayfire
    To reduce_all(const Array<Ti> &in)
    {
        Transform<Ti, To, op> transform;
        Binary<To, op> reduce;

        To out = reduce.init();

        // Decrement dimension of select dimension
        af::dim4 dims = in.dims();
        af::dim4 strides = in.strides();
        const Ti *inPtr = in.get();

        for(dim_t l = 0; l < dims[3]; l++) {
            dim_t off3 = l * strides[3];

            for(dim_t k = 0; k < dims[2]; k++) {
                dim_t off2 = k * strides[2];

                for(dim_t j = 0; j < dims[1]; j++) {
                    dim_t off1 = j * strides[1];

                    for(dim_t i = 0; i < dims[0]; i++) {
                        dim_t idx = i + off1 + off2 + off3;

                        To val = transform(inPtr[idx]);
                        out = reduce(val, out);
                    }
                }
            }
        }

        return out;
    }
コード例 #8
0
ファイル: BINTREE_.CPP プロジェクト: Dirker27/DataStructures
void main()
{
	randomize();

	Binary b;
	b.execute();
}
コード例 #9
0
ファイル: Sponge.cpp プロジェクト: daniel0076/sha3
void SpongeConstruction(string inputString, int outputLen)
{
	// Transform the input string into binary bits
	BinaryTransfer( inputString ) ;

	// Padding using Multirate
	vector< Binary > Message = Padding( inputString ) ;

	//Initialize the state variable
	Binary stateVar ;


	// Absorbing phase
	for(auto & block: Message){
		block<<=CAPACITY;
		//XOR with statevar
		stateVar^=block;
		stateVar=internalFun(stateVar);
	}
	// Squeezing phase
	string hashVal ; // The final output value
	if(outputLen <BITRATE){
		hashVal=stateVar.to_string().substr(0,outputLen);
	}else{
		hashVal+=stateVar.to_string().substr(0,BITRATE);
		while(hashVal.length() < outputLen){
			stateVar=internalFun(stateVar);
			hashVal+=stateVar.to_string().substr(0,BITRATE);
		}
	}


	// Print the hash value to the stdout
	PrintHex( hashVal.substr(0, outputLen) ) ;
}
コード例 #10
0
ファイル: Binary.cpp プロジェクト: kd0kfo/libdnstd
 Binary Binary::operator |(const Binary& B)
 {
   Binary _or(i | B.getInt());
   if(B.getBitSize() > _or.bitSize)
     _or.setBitSize(B.getBitSize());
   return _or;
 }
コード例 #11
0
ファイル: Binary.cpp プロジェクト: kd0kfo/libdnstd
 Binary Binary::operator &(const Binary& B)
 {
   Binary _and(i & B.getInt());
   if(B.getBitSize() > _and.bitSize)
     _and.setBitSize(B.getBitSize());
   return _and;
 }
コード例 #12
0
ファイル: kernel_builder.hpp プロジェクト: bambang/vsipl
void build_kernel(Binary<expr::op::Mult, Binary<O, L, R>, S> e,
                  Kernel<T>& k)
{
  Kernel<T> k1(k);
  Kernel_builder<Binary<O, L, R>, T>::apply(e.arg1(), k1);
  k1 *= T(e.arg2());
  k += k1;
}
コード例 #13
0
ファイル: kernel_builder.hpp プロジェクト: bambang/vsipl
void build_kernel(Binary<expr::op::Div, Call<B, I, J>, S> e,
                  Kernel<T>& k)
{
  Kernel<T> k1(k);
  Kernel_builder<Call<B, I, J>, T>::apply(e.arg1(), k1);
  k1 /= T(e.arg2());
  k += k1;
}
コード例 #14
0
void DataObserverAdapter::_Update(const Binary& arMeas, size_t aIndex)
{
	JNIEnv* pEnv = GetEnv();

	jboolean value = arMeas.GetValue();
	jbyte quality = arMeas.GetQuality();
	jlong timestamp = arMeas.GetTime();
	jlong index = aIndex;

	pEnv->CallVoidMethod(mProxy, mUpdateBinaryInput, value, quality, timestamp, index);
}
コード例 #15
0
ファイル: ZDT5.cpp プロジェクト: Juanjdurillo/jMetalCpp
double ZDT5::evalG(Solution * solution) {
  double res = 0.0;
  Binary * variable ;

  for (int i = 1; i < numberOfVariables_; i++) {
  	variable = (Binary *)(solution->getDecisionVariables()[i]) ;
    res += evalV(variable->cardinality());
  }

  return res;
}
コード例 #16
0
Status BinCommon::rd_value(CommandInitiator* thread, Binary& value)
{
  uint size;
  Status status = rd_value(thread, size);
  if (status == OK) {
    if (size > 0) { // protect from unrealistic size?
      value.reserve(size);
      status = rd_bytes(thread, size, (char*) value.data());
    }
  }
  return status;
}
コード例 #17
0
ファイル: Binary.cpp プロジェクト: Respublica/mysqlwrap
bool operator==(const Binary &left, const Binary &right) {
	unsigned char* leftBuffer = left.Buffer();
	unsigned char* rightBuffer = right.Buffer();
	size_t leftLen = left.BufferLength();
	size_t rightLen = right.BufferLength();

	if (leftLen != rightLen) return false;

	for (size_t i = 0; i < leftLen; i++) {
		if (leftBuffer[i] != rightBuffer[i]) return false;
	}
	return true;
}
コード例 #18
0
ファイル: scan_dim.hpp プロジェクト: klemmster/arrayfire
static Kernel* get_scan_dim_kernels(int kerIdx)
{
    try {
        static std::once_flag compileFlags[DeviceManager::MAX_DEVICES];
        static std::map<int, Program*> scanProgs;
        static std::map<int, Kernel*>  scanKerns;
        static std::map<int, Kernel*>  bcastKerns;

        int device= getActiveDeviceId();

        std::call_once(compileFlags[device], [device] () {

            Binary<To, op> scan;
            ToNum<To> toNum;

            std::ostringstream options;
            options << " -D To=" << dtype_traits<To>::getName()
                    << " -D Ti=" << dtype_traits<Ti>::getName()
                    << " -D T=To"
                    << " -D dim=" << dim
                    << " -D DIMY=" << threads_y
                    << " -D THREADS_X=" << THREADS_X
                    << " -D init=" << toNum(scan.init())
                    << " -D " << binOpName<op>()
                    << " -D CPLX=" << af::iscplx<Ti>()
                    << " -D isFinalPass="******" -D USE_DOUBLE";
            }

            const char *ker_strs[] = {ops_cl, scan_dim_cl};
            const int   ker_lens[] = {ops_cl_len, scan_dim_cl_len};
            cl::Program prog;
            buildProgram(prog, 2, ker_strs, ker_lens, options.str());
            scanProgs[device] = new Program(prog);

            scanKerns[device] = new Kernel(*scanProgs[device],  "scan_dim_kernel");
            bcastKerns[device] = new Kernel(*scanProgs[device],  "bcast_dim_kernel");

        });

        return (kerIdx == 0) ? scanKerns[device] : bcastKerns[device];
    } catch (cl::Error err) {
        CL_TO_AF_ERROR(err);
        throw;
    }
}
コード例 #19
0
ファイル: Binary.cpp プロジェクト: kd0kfo/libdnstd
  Binary Binary::toBinary(Binary::value_type i)
  {
    Binary b;
    if(i == 0)
      return b;
    b.i = i;
    b.bString = "";
    while(i > 0)
      {
	int modI = i % 2;
	b.bString = (modI) ? "1"+b.str() :"0"+b.str();
	i >>= 1;
      }
    b.setBitSize(b.bString.size());
    return b;
  }
コード例 #20
0
LLVMSymbolizer::BinaryPair
LLVMSymbolizer::getOrCreateBinary(const std::string &Path) {
  BinaryMapTy::iterator I = BinaryForPath.find(Path);
  if (I != BinaryForPath.end())
    return I->second;
  Binary *Bin = nullptr;
  Binary *DbgBin = nullptr;
  ErrorOr<Binary *> BinaryOrErr = createBinary(Path);
  if (!error(BinaryOrErr.getError())) {
    std::unique_ptr<Binary> ParsedBinary(BinaryOrErr.get());
    // Check if it's a universal binary.
    Bin = ParsedBinary.get();
    ParsedBinariesAndObjects.push_back(std::move(ParsedBinary));
    if (Bin->isMachO() || Bin->isMachOUniversalBinary()) {
      // On Darwin we may find DWARF in separate object file in
      // resource directory.
      const std::string &ResourcePath =
          getDarwinDWARFResourceForPath(Path);
      BinaryOrErr = createBinary(ResourcePath);
      error_code EC = BinaryOrErr.getError();
      if (EC != std::errc::no_such_file_or_directory && !error(EC)) {
        DbgBin = BinaryOrErr.get();
        ParsedBinariesAndObjects.push_back(std::unique_ptr<Binary>(DbgBin));
      }
    }
    // Try to locate the debug binary using .gnu_debuglink section.
    if (!DbgBin) {
      std::string DebuglinkName;
      uint32_t CRCHash;
      std::string DebugBinaryPath;
      if (getGNUDebuglinkContents(Bin, DebuglinkName, CRCHash) &&
          findDebugBinary(Path, DebuglinkName, CRCHash, DebugBinaryPath)) {
        BinaryOrErr = createBinary(DebugBinaryPath);
        if (!error(BinaryOrErr.getError())) {
          DbgBin = BinaryOrErr.get();
          ParsedBinariesAndObjects.push_back(std::unique_ptr<Binary>(DbgBin));
        }
      }
    }
  }
  if (!DbgBin)
    DbgBin = Bin;
  BinaryPair Res = std::make_pair(Bin, DbgBin);
  BinaryForPath[Path] = Res;
  return Res;
}
コード例 #21
0
ファイル: Symbolize.cpp プロジェクト: afesteves/llvm
ErrorOr<ObjectFile *>
LLVMSymbolizer::getOrCreateObject(const std::string &Path,
                                  const std::string &ArchName) {
  const auto &I = BinaryForPath.find(Path);
  Binary *Bin = nullptr;
  if (I == BinaryForPath.end()) {
    Expected<OwningBinary<Binary>> BinOrErr = createBinary(Path);
    if (!BinOrErr) {
      auto EC = errorToErrorCode(BinOrErr.takeError());
      BinaryForPath.insert(std::make_pair(Path, EC));
      return EC;
    }
    Bin = BinOrErr->getBinary();
    BinaryForPath.insert(std::make_pair(Path, std::move(BinOrErr.get())));
  } else if (auto EC = I->second.getError()) {
    return EC;
  } else {
    Bin = I->second->getBinary();
  }

  assert(Bin != nullptr);

  if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(Bin)) {
    const auto &I = ObjectForUBPathAndArch.find(std::make_pair(Path, ArchName));
    if (I != ObjectForUBPathAndArch.end()) {
      if (auto EC = I->second.getError())
        return EC;
      return I->second->get();
    }
    ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
        UB->getObjectForArch(ArchName);
    if (auto EC = ObjOrErr.getError()) {
      ObjectForUBPathAndArch.insert(
          std::make_pair(std::make_pair(Path, ArchName), EC));
      return EC;
    }
    ObjectFile *Res = ObjOrErr->get();
    ObjectForUBPathAndArch.insert(std::make_pair(std::make_pair(Path, ArchName),
                                                 std::move(ObjOrErr.get())));
    return Res;
  }
  if (Bin->isObject()) {
    return cast<ObjectFile>(Bin);
  }
  return object_error::arch_not_found;
}
コード例 #22
0
ファイル: Binary.cpp プロジェクト: kd0kfo/libdnstd
 Binary Binary::operator ^(const Binary& B)
 {
   Binary::value_type tempInt = i & B.i;
   Binary _xor(tempInt);
   if(B.bitSize > _xor.bitSize)
     _xor.bitSize = B.getBitSize();
   return _xor;
 }
コード例 #23
0
ファイル: ZDT5.cpp プロジェクト: Juanjdurillo/jMetalCpp
/**
 * Evaluates a solution
 * @param solution The solution to evaluate
 */
void ZDT5::evaluate(Solution *solution) {
  Binary * variable ;
  int    counter  ;

  variable = (Binary *)(solution->getDecisionVariables()[0]) ;

  fx_[0]        = 1 + variable->cardinality();

  double g    = evalG(solution)  ;
  double h    = evalH(fx_[0],g)  ;
  fx_[1]        = h * g          ;

  solution->setObjective(0,fx_[0]);
  solution->setObjective(1,fx_[1]);


} // evaluate
コード例 #24
0
ファイル: Database.cpp プロジェクト: prakashnsm/dnp3-1
void Database::_Update(const Binary& arPoint, size_t aIndex)
{
	if(UpdateValue<Binary>(mBinaryVec, arPoint, aIndex)) {
		LOG_BLOCK(LEV_DEBUG, "Binary Change: " << arPoint.ToString() << " Index: " << aIndex);
		BinaryInfo& v = mBinaryVec[aIndex];
		if(mpEventBuffer) mpEventBuffer->Update(v.mValue, v.mClass, aIndex);
	}
}
コード例 #25
0
void GroundTruth::on_pushButton_clicked()
{
    QString filename = QFileDialog::getOpenFileName(
                this,
                tr("Open File"),
                "/home/soumyadeep/work/stampVarOwnData/soumya/non_overlapped/",
                "All Files (*.*)" );
    string imagepath;
    imagepath = filename.toUtf8().constData();
    src = imread(imagepath,1);


    cvtColor(src, src_gray, CV_BGR2GRAY);

    //IITkgp_functions::statistical_analysis stat;
    //stat.DrawHistogram(src_gray);


    IITkgp_functions::folder folderobj;

    imagename = imagepath.c_str();
    substring = folderobj.input_image_name_cut(imagepath.c_str());
    folderobj.makedir(substring);

    /*
    char *name;
    name = (char *) malloc ( 2001 * sizeof(char));
      if(name == NULL)
      {
        printf("Memory can not be allocated\n");
        exit(0);
      }
      name = folderobj.CreateNameIntoFolder(substring,"gray.png");
      imwrite(name,src_gray);
      */

      namedWindow( "Src Image", CV_WINDOW_KEEPRATIO );
      imshow("Src Image",src);


      Binary BSelecWin;
      BSelecWin.setModal(true);
      BSelecWin.exec();
      //waitKey(0);
}
コード例 #26
0
 Binary operator-(const Binary& other)
 {
     int maxSize = 0;
     if(strlen(this->binaryNum) > strlen(other.binaryNum))
         maxSize = strlen(this->binaryNum);
     else
         maxSize = strlen(other.binaryNum);
     Binary result = new char[maxSize + 2];
     assert(result!=NULL);
     if(this->getBinaryNum().fromBinary() > other.getBinaryNum().fromBinary())
     {
         int tmp = this->getBinaryNum().fromBinary() - other.getBinaryNum().fromBinary();
         strcpy(result.binaryNum, toBinary(tmp));
         return result.binaryNum;
     }
     else
         return 0;
 }
コード例 #27
0
ファイル: scan.cpp プロジェクト: EmergentOrder/arrayfire
        void operator()(To *out, const dim4 ostrides, const dim4 odims,
                        const Ti *in , const dim4 istrides, const dim4 idims,
                        const int dim)
        {

            dim_type istride = istrides[dim];
            dim_type ostride = ostrides[dim];

            Transform<Ti, To, op> transform;
            // FIXME: Change the name to something better
            Binary<To, op> scan;

            To out_val = scan.init();
            for (dim_type i = 0; i < idims[dim]; i++) {
                To in_val = transform(in[i * istride]);
                out_val = scan(in_val, out_val);
                out[i * ostride] = out_val;
            }
        }
コード例 #28
0
	/*
	 *  Checking if the input Binary is particular Array2D.
	 *  Particular Array2D is a Binary data that starts with 512 byte data of
	 * all value that is 0xff.
	 *  Notice: Particular Array2D's size is not 512 byte. I misunderstood it.
	 *  http://twitter.com/rgssws4m told me about this case.
	 */
		bool Array2D::isInvalidArray2D(Binary const& b)
		{
			static unsigned const PARTICULAR_DATA_SIZE = 512;
		// check the data size
			if( b.size() < PARTICULAR_DATA_SIZE ) return false;
		// check the data inside Binary
			for(unsigned i = 0; i < PARTICULAR_DATA_SIZE; i++) if(b[i] != 0xff) return false;

			debug::Tracer::printBinary(b, clog);
		// return true if it is particular Array2D
			return true;
		}
コード例 #29
0
ファイル: Statement.cpp プロジェクト: Respublica/mysqlwrap
Nullable<Binary> Statement::GetBinaryDataInRow(unsigned int column) {
	Nullable<Binary> result;

	if (column >= _resultParams.size()) {
		throw DatabaseException("Error in Statement::GetDataInRow", 0, "----", "column out of range");
	}

	if (_resultBind[column].buffer_type != MYSQL_TYPE_BLOB) {
		throw DatabaseException("Error in Statement::GetDataInRow", 0, "----", "column not of correct type");
	}

	if (! (*(_resultParams[column]->IsNull()))) {
		if (mysql_stmt_fetch_column(_stmt, &(_resultBind[column]), column, 0) != 0) {
			throw DatabaseException(_stmt, "Error in GetDataInRow(Binary)");
		}	
		Binary fromdb;
		fromdb.AssignDataToBuffer((unsigned char *)_resultParams[column]->Buffer(), *(_resultParams[column]->BufferLength()));
		result = fromdb;
	}

	return result;
}
コード例 #30
0
ファイル: TTPCrossover.cpp プロジェクト: julesy89/ttp-cpp
Binary *crossBinary(double probability, Binary *bins1, Binary *bins2) {


    if (PseudoRandom::randDouble() < probability) {
        //1. Compute the total number of bits
        int totalNumberOfBits = bins1->getNumberOfBits();

        //2. Calculate the point to make the crossover
        int crossoverPoint = PseudoRandom::randInt(0, totalNumberOfBits - 1);

        //3. Compute the variable containing the crossoverPoint bit
        Binary *offspring = new Binary(totalNumberOfBits);
        for (int i = 0; i < crossoverPoint; ++i) {
            offspring->setIth(i, bins1->getIth(i));
        }
        for (int i = crossoverPoint; i < bins1->getNumberOfBits(); ++i) {
            offspring->setIth(i, bins2->getIth(i));
        }
        return offspring;
    }
    return bins1;

}