当前位置: 首页>>代码示例>>C++>>正文


C++ NDArray类代码示例

本文整理汇总了C++中NDArray的典型用法代码示例。如果您正苦于以下问题:C++ NDArray类的具体用法?C++ NDArray怎么用?C++ NDArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NDArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateState_

inline void RMSPropOptimizer::Update(int index, NDArray weight, NDArray grad) {
  if (n_.count(index) == 0) {
    CreateState_(index, weight);
  }

  params_["lr"] = std::to_string(GetLR_(index));
  params_["wd"] = std::to_string(GetWD_(index));
  UpdateCount_(index);
  auto keys = GetParamKeys_();
  auto values = GetParamValues_();
  CHECK_EQ(keys.size(), values.size());

  NDArrayHandle inputs[5];
  inputs[0] = weight.GetHandle();
  inputs[1] = grad.GetHandle();
  inputs[2] = n_[index]->GetHandle();
  inputs[3] = g_[index]->GetHandle();
  inputs[4] = delta_[index]->GetHandle();

  int num_outputs = 1;
  NDArrayHandle output = weight.GetHandle();
  NDArrayHandle *outputs = &output;

  MXImperativeInvoke(alex_update_handle_, 5, inputs,
      &num_outputs, &outputs,
      keys.size(), keys.data(), values.data());
}
开发者ID:GrassSunFlower,项目名称:mxnet,代码行数:27,代码来源:optimizer.hpp

示例2: dpiRatio

/**
 * @param pos A point in Qt screen coordinates from, for example, a mouse click
 * @return A QPointF defining the position in data coordinates
 */
QPointF FigureCanvasQt::toDataCoords(QPoint pos) const {
  // There is no isolated method for doing the transform on matplotlib's
  // classes. The functionality is bound up inside other methods
  // so we are forced to duplicate the behaviour here.
  // The following code is derived form what happens in
  // matplotlib.backends.backend_qt5.FigureCanvasQT &
  // matplotlib.backend_bases.LocationEvent where we transform first to
  // matplotlib's coordinate system, (0,0) is bottom left,
  // and then to the data coordinates
  const int dpiRatio(devicePixelRatio());
  const double xPosPhysical = pos.x() * dpiRatio;
  GlobalInterpreterLock lock;
  // Y=0 is at the bottom
  double height = PyFloat_AsDouble(
      Python::Object(m_figure.pyobj().attr("bbox").attr("height")).ptr());
  const double yPosPhysical =
      ((height / devicePixelRatio()) - pos.y()) * dpiRatio;
  // Transform to data coordinates
  QPointF dataCoords;
  try {
    auto invTransform = gca().pyobj().attr("transData").attr("inverted")();
    NDArray transformed = invTransform.attr("transform_point")(
        Python::NewRef(Py_BuildValue("(ff)", xPosPhysical, yPosPhysical)));
    auto rawData = reinterpret_cast<double *>(transformed.get_data());
    dataCoords =
        QPointF(static_cast<qreal>(rawData[0]), static_cast<qreal>(rawData[1]));
  } catch (Python::ErrorAlreadySet &) {
    PyErr_Clear();
    // an exception indicates no transform possible. Matplotlib sets this as
    // an empty data coordinate so we will do the same
  }
  return dataCoords;
}
开发者ID:mantidproject,项目名称:mantid,代码行数:37,代码来源:FigureCanvasQt.cpp

示例3: getAddress

/** This method copies an NDArray object from the asynNDArrayDriver to an NDArray pointer passed in by the caller.
  * The destination NDArray address is passed by the caller in the genericPointer argument. The caller
  * must allocate the memory for the array, and pass the size in NDArray->dataSize.
  * The method will limit the amount of data copied to the actual array size or the
  * input dataSize, whichever is smaller.
  * \param[in] pasynUser Used to obtain the addr for the NDArray to be copied from, and for asynTrace output.
  * \param[out] genericPointer Pointer to an NDArray. The NDArray must have been previously allocated by the caller.
  * The NDArray from the asynNDArrayDriver will be copied into the NDArray pointed to by genericPointer.
  */
asynStatus asynNDArrayDriver::readGenericPointer(asynUser *pasynUser, void *genericPointer)
{
    NDArray *pArray = (NDArray *)genericPointer;
    NDArray *myArray;
    NDArrayInfo_t arrayInfo;
    int addr;
    asynStatus status = asynSuccess;
    const char* functionName = "readNDArray";

    status = getAddress(pasynUser, &addr); if (status != asynSuccess) return(status);
    this->lock();
    myArray = this->pArrays[addr];
    if (!myArray) {
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
                    "%s:%s: error, no valid array available, pData=%p",
                    driverName, functionName, pArray->pData);
        status = asynError;
    } else {
        this->pNDArrayPool->copy(myArray, pArray, 0);
        myArray->getInfo(&arrayInfo);
        if (arrayInfo.totalBytes > pArray->dataSize) arrayInfo.totalBytes = pArray->dataSize;
        memcpy(pArray->pData, myArray->pData, arrayInfo.totalBytes);
        pasynUser->timestamp = myArray->epicsTS;
    }
    if (!status)
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
              "%s:%s: error, maxBytes=%lu, data=%p\n",
              driverName, functionName, (unsigned long)arrayInfo.totalBytes, pArray->pData);
    this->unlock();
    return status;
}
开发者ID:waynelewis,项目名称:ADCore,代码行数:40,代码来源:asynNDArrayDriver.cpp

示例4: NDArray

inline void SGDOptimizer::CreateState_(int index, NDArray weight) {
  if (params_.count("momentum") == 0) {
    states_[index] = nullptr;
  } else {
    states_[index] = new NDArray(weight.GetShape(), weight.GetContext());
    *states_[index] = 0;
  }
}
开发者ID:GrassSunFlower,项目名称:mxnet,代码行数:8,代码来源:optimizer.hpp

示例5: main

int main() {
	int retcode = 0;
	cout << "XMAP buffer parser!" << endl; // prints !!!Hello World!!!

	unsigned short *testfilebuf = NULL;
	unsigned int testfilelen = 1024*1024;
	testfilebuf = (unsigned short*)calloc(testfilelen, sizeof(unsigned short));
	retcode = load_dataset_txt("/home/up45/sandbox/data1.txt", testfilebuf, testfilelen);
	printf("retcode: %d\n", retcode);
	for (int i=0; i<10; i++) printf("%6d  0x%04X\n", testfilebuf[i], testfilebuf[i]);


	XmapBuffer buf;
	printf("Parsing data1.txt....\n");
	buf.parse(testfilebuf, testfilelen);
	free(testfilebuf);
	//buf.report(4);

	//return 0;


	printf("Parsing testbuf1....\n");
	buf.parse(testbuf1, sizeof(testbuf1)/2);
	printf("Parsing testbuf2...\n");
	buf.parse(testbuf2, sizeof(testbuf2)/2);

	buf.report(2);

	printf("Getting pixelmap reference\n");
	XmapBuffer::PixelMap_t& pm = buf.pixels();

	printf("pixel0 report:\n");
	pm[0].report(2);

	printf("Testing copy\n");
	unsigned short dest[3] = {0,0,0};
	XmapChannelData *xcd = pm[0].channels()[0];
	Spectrum* sp;
	sp = dynamic_cast<Spectrum*> (xcd);
	sp->report(2);
	sp->copy_data(dest, 3);
	printf("dest: %d %d %d\n", dest[0], dest[1], dest[2]);

	printf("Testing copy to NDArray\n");
	NDArray ndarr;
	ndarr.dataSize = 500;
	ndarr.dataType = NDUInt16;
	ndarr.ndims = 2;
	ndarr.initDimension(ndarr.dims+0, (int)pm[0].num_channels());
	ndarr.initDimension(ndarr.dims+1, pm[0].data_size());
	ndarr.pData = calloc(ndarr.dataSize, sizeof(char));

	pm[0].copy_data( &ndarr );
	ndarr.report(stdout, 11);

	return 0;
}
开发者ID:dls-controls,项目名称:dxp,代码行数:57,代码来源:test_xmap_buffer.cpp

示例6: getStringParam

void mar345::getImageData()
{
    char fullFileName[MAX_FILENAME_LEN];
    size_t dims[2];
    int itemp;
    int imageCounter;
    NDArray *pImage;
    char statusMessage[MAX_MESSAGE_SIZE];
    char errorBuffer[MAX_MESSAGE_SIZE];
    FILE *input;
    const char *functionName = "getImageData";

    /* Inquire about the image dimensions */
    getStringParam(NDFullFileName, MAX_FILENAME_LEN, fullFileName);
    getIntegerParam(NDArraySizeX, &itemp); dims[0] = itemp;
    getIntegerParam(NDArraySizeY, &itemp); dims[1] = itemp;
    getIntegerParam(NDArrayCounter, &imageCounter);
    pImage = this->pNDArrayPool->alloc(2, dims, NDUInt16, 0, NULL);

    epicsSnprintf(statusMessage, sizeof(statusMessage), "Reading mar345 file %s", fullFileName);
    setStringParam(ADStatusMessage, statusMessage);
    callParamCallbacks();
    input = fopen(fullFileName, "rb");
    if (input == NULL) {
        (void) strerror_r(errno, errorBuffer, sizeof(errorBuffer));
        asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
            "%s%s: unable to open input file %s, error=%s\n",
            driverName, functionName, fullFileName, errorBuffer);
        return;
    }
    get_pck(input, (epicsInt16 *)pImage->pData);
    fclose(input);

    /* Put the frame number and time stamp into the buffer */
    pImage->uniqueId = imageCounter;
    pImage->timeStamp = this->acqStartTime.secPastEpoch + this->acqStartTime.nsec / 1.e9;

    /* Get any attributes that have been defined for this driver */        
    this->getAttributes(pImage->pAttributeList);

    /* Call the NDArray callback */
    /* Must release the lock here, or we can get into a deadlock, because we can
     * block on the plugin lock, and the plugin can be calling us */
    this->unlock();
    asynPrint(this->pasynUserSelf, ASYN_TRACE_FLOW, 
         "%s:%s: calling NDArray callback\n", driverName, functionName);
    doCallbacksGenericPointer(pImage, NDArrayData, 0);
    this->lock();

    /* Free the image buffer */
    pImage->release();
}
开发者ID:NSLS-II-CSX,项目名称:xf23id1-ioc1,代码行数:52,代码来源:mar345.cpp

示例7: x

void Householder<T>::evalHHmatrixData(const NDArray<T>& x, NDArray<T>& tail, T& coeff, T& normX) {

	// input validation
	if(!x.isVector() && !x.isScalar())
		throw "ops::helpers::Householder::evalHHmatrixData method: input array must be vector or scalar!";

	if(!x.isScalar() && x.lengthOf() != tail.lengthOf() + 1)
		throw "ops::helpers::Householder::evalHHmatrixData method: input tail vector must have length less than unity compared to input x vector!";

	normX = x.template reduceNumber<simdOps::Norm2<T>>();	
	const T min = DataTypeUtils::min<T>();	
		
	if(normX*normX - x(0)*x(0) <= min) {

		normX = x(0);
		coeff = (T)0.;		
		tail = (T)0.;		
	}
	else {
		
		if(x(0) >= (T)0.)
			normX = -normX;									// choose opposite sign to lessen roundoff error
		
		T u0 = x(0) - normX;
		coeff = -u0 / normX;				

		if(x.isRowVector())
			tail.assign(x({{}, {1, -1}}) / u0);		
		else
			tail.assign(x({{1, -1}, {}}) / u0);		
	}		
}
开发者ID:smarthi,项目名称:libnd4j,代码行数:32,代码来源:householder.cpp

示例8: NDArray

NDArrayTyped<T>::NDArrayTyped(const NDArray &other, T* dptr)
    : NDArray(other)
//    , m_data((T*)other.m_data_ch)
{
    if (!dptr) {
        m_data = (T*)other.data();
    } else {
        m_data = dptr;
        m_data_ch = (char*)m_data;
        m_data_ptr = new ArrayData(m_data_ch, other.size()*sizeof(T));
        m_type = TypeMap<T>::type;
        m_typesize = typesize(m_type);
    }
}
开发者ID:kitizz,项目名称:nutmeg,代码行数:14,代码来源:ndarray.cpp

示例9: Update

void Optimizer::Update(int index, NDArray weight, NDArray grad) {
  if (!init_) {
    std::vector<const char *> param_keys;
    std::vector<const char *> param_values;
    for (const auto &k_v : params_) {
      param_keys.push_back(k_v.first.c_str());
      param_values.push_back(k_v.second.c_str());
    }
    MXOptimizerCreateOptimizer(creator_, params_.size(), param_keys.data(),
                               param_values.data(), &handle_);
    init_ = true;
  }
  MXOptimizerUpdate(handle_, index, weight.GetHandle(), grad.GetHandle(),
      learning_rate_, weight_decay_);
}
开发者ID:AI42,项目名称:MXNet.cpp,代码行数:15,代码来源:optimizer.hpp

示例10: freeCaptureBuffer

void NDPluginFile::freeCaptureBuffer(int numCapture)
{
    int i;
    NDArray *pArray;
    
    if (!this->pCapture) return;
    /* Free the capture buffer */
    for (i=0; i<numCapture; i++) {
        pArray = this->pCapture[i];
        if (!pArray) break;
        pArray->release();
    }
    free(this->pCapture);
    this->pCapture = NULL;
}
开发者ID:jlmuir,项目名称:ADCore,代码行数:15,代码来源:NDPluginFile.cpp

示例11: GetMeanImg

 void GetMeanImg() {
   mean_img = NDArray(Shape(1, 3, 224, 224), global_ctx, false);
   mean_img.SyncCopyFromCPU(
       NDArray::LoadToMap("./model/mean_224.nd")["mean_img"].GetData(),
       1 * 3 * 224 * 224);
   NDArray::WaitAll();
 }
开发者ID:LynetteXing1991,项目名称:MXNet.cpp,代码行数:7,代码来源:feature_extract.cpp

示例12: wrap

/**
 * Converts an Octave numeric NDArray into a double R array.
 *
 * Currently only 3D arrays are supported.
 */
inline SEXP wrap(const NDArray& x){

	int nd = x.ndims();
	VERBOSE_LOG("(%iD-NDArray)", nd);
	if( nd > 3 ){
		std::ostringstream err;
		err << "<NDArray> - Could not convert NDArray[" << x.ndims() << "]: only up to 3 dimensions are supported";
		WRAP_ERROR(err.str().c_str());

	}else if( nd == 2 ){// safe-guard in case of a 2D-NDArray (i.e. a Matrix object)
		VERBOSE_LOG(" = ");
		return wrap(x.as_matrix()) ;
	}

	// copy values from the outer to inner dimensions
	int n = x.dim1();
	int p = x.dim2();
	int q = x.dim3();
	VERBOSE_LOG("[%i x %i x %i]", n, p, q);
	Rcpp::NumericVector res( Rcpp::Dimension(n, p, q) );
	Rcpp::NumericVector::iterator z = res.begin();
	for(int k=0; k<q; k++){
		for(int j=0; j<p; j++){
			for(int i=0; i<n; i++){
				*z = x.elem(i,j,k);
				z++;
			}
		}
	}
	return res;
}
开发者ID:renozao,项目名称:RcppOctave,代码行数:36,代码来源:conversion.cpp

示例13: ResizeInput

NDArray ResizeInput(NDArray data, const Shape new_shape) {
  NDArray pic = data.Reshape(Shape(0, 1, 28, 28));
  NDArray output;
  Operator("_contrib_BilinearResize2D")
    .SetParam("height", new_shape[2])
    .SetParam("width", new_shape[3])
    (pic).Invoke(output);
  return output;
}
开发者ID:eric-haibin-lin,项目名称:mxnet,代码行数:9,代码来源:lenet_with_mxdataiter.cpp

示例14: w

NDArray<T> Householder<T>::evalHHmatrix(const NDArray<T>& x) {

	// input validation
	if(!x.isVector() && !x.isScalar())
		throw "ops::helpers::Householder::evalHHmatrix method: input array must be vector or scalar!";

	NDArray<T> w((int)x.lengthOf(), 1,  x.ordering(), x.getWorkspace());							// column-vector
	NDArray<T> wT(1, (int)x.lengthOf(), x.ordering(), x.getWorkspace());							// row-vector (transposed w)	

	T coeff;
	T normX = x.template reduceNumber<simdOps::Norm2<T>>();	
	const T min = DataTypeUtils::min<T>();
	
	if(normX*normX - x(0)*x(0) <= min) {

		normX = x(0); 
		coeff = (T)0.;		
		w = (T)0.;
		
	} 	
	else {
		
		if(x(0) >= (T)0.)
			normX = -normX;									// choose opposite sign to lessen roundoff error
		
		T u0 = x(0) - normX;
		coeff = -u0 / normX;				
		w.assign(x / u0);		
	}
	
	w(0) = (T)1.;
	wT.assign(&w);
	
	NDArray<T> identity((int)x.lengthOf(), (int)x.lengthOf(), x.ordering(), x.getWorkspace());					 
	identity.setIdentity();																			// identity matrix	

	return identity - mmul(w, wT) * coeff;	

}
开发者ID:smarthi,项目名称:libnd4j,代码行数:39,代码来源:householder.cpp

示例15: getIntegerParam

void NDPluginFile::doNDArrayCallbacks(NDArray *pArray)
{
  int arrayCallbacks = 0;
  static const char *functionName = "doNDArrayCallbacks";

  getIntegerParam(NDArrayCallbacks, &arrayCallbacks);
  if (arrayCallbacks == 1) {
    NDArray *pArrayOut = this->pNDArrayPool->copy(pArray, NULL, 1);
    if (pArrayOut != NULL) {
      this->getAttributes(pArrayOut->pAttributeList);
      this->unlock();
      doCallbacksGenericPointer(pArrayOut, NDArrayData, 0);
      this->lock();
      pArrayOut->release();
    }
    else {
      asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, 
        "%s: Couldn't allocate output array. Callbacks failed.\n", 
        functionName);
    }
  }
}
开发者ID:argonnexraydetector,项目名称:ADCore,代码行数:22,代码来源:NDPluginFile.cpp


注:本文中的NDArray类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。