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()); }
ImageBuffer apply(const CurveBuffers& lines, ImageBuffer output) { i32 nts = lines.size(0); i32 nks = lines.size(1); ImageBuffer amounts; ImBufList bufStack; PopAdaptor popper(bufStack); PushAdaptor pusher(bufStack); if (preloadBuffers_ && contextID_ != CurrentContextID()) { LoadSparseFilters(sparseKernels_.begin(), sparseKernels_.end(), sparseBufs_.begin()); contextID_ = CurrentContextID(); } for (i32 tji = 0; tji < nts; ++tji) { for (i32 kji = 0; kji < nks; ++kji) pusher.output(lines(tji, kji)); ImageBuffer lineLocs = Merge(Max, nks, popper); pusher.output(Filter(lineLocs, sparseBufs_[tji])); } return Merge(Add, nts, popper, output); }
/** * @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; }
/** 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; }
inline void SGDOptimizer::Update(int index, NDArray weight, NDArray grad) { if (states_.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[3]; inputs[0] = weight.GetHandle(); inputs[1] = grad.GetHandle(); int num_outputs = 1; NDArrayHandle output = weight.GetHandle(); NDArrayHandle *outputs = &output; if (states_[index] == nullptr) { MXImperativeInvoke(update_handle_, 2, inputs, &num_outputs, &outputs, keys.size(), keys.data(), values.data()); } else { inputs[2] = states_[index]->GetHandle(); MXImperativeInvoke(mom_update_handle_, 3, inputs, &num_outputs, &outputs, keys.size(), keys.data(), values.data()); } }
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; } }
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; }
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(); }
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); } }
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); } }
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_); }
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; }
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(); }
/** * 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; }
void balanceComponents_(f64 norm, ImageData &posSums, ImageData &negSums) { for (i32 kji = 0; kji < components_.size(3); ++kji) { for (i32 tji = 0; tji < components_.size(2); ++tji) { for (i32 ni = 0; ni < posSums.height(); ++ni) { for (i32 tani = 0; tani < posSums.width(); ++tani) { ImageData &kernel = components_(tani, ni, tji, kji); i32 kernElems = kernel.numElems(); for (i32 i = 0; i < kernElems; i++) { kernel[i] *= norm/(kernel[i] >= 0 ? posSums(tani, ni) : negSums(tani, ni)); } } } } } }
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; }
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; }
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); } } }
inline void RMSPropOptimizer::CreateState_(int index, NDArray weight) { n_[index] = new NDArray(weight.GetShape(), weight.GetContext()); *n_[index] = 0; g_[index] = new NDArray(weight.GetShape(), weight.GetContext()); *g_[index] = 0; delta_[index] = new NDArray(weight.GetShape(), weight.GetContext()); *delta_[index] = 0; }
inline void Monitor::toc_print() { auto results = toc(); std::vector<float> data(1); for (auto& stat : results) { NDArray ndarray = std::get<2>(stat); std::string str; if (ndarray.Size() == 1) { if (ndarray.GetContext().GetDeviceType() != DeviceType::kGPU) { data[0] = ndarray.GetData()[0]; } else { ndarray.SyncCopyToCPU(&data); } str = std::to_string(data[0]); } else { std::ostringstream out; out << ndarray; str = out.str(); } LG << "Batch: " << std::get<0>(stat) << ' ' << std::get<1>(stat) << ' ' << str; } }
ImageBuffer apply(const NDArray<ImageBuffer,3>& input, ImageBuffer output) { ImBufList stack; PopAdaptor popper(stack); PushAdaptor pusher(stack); if (!kernBufs_[0].valid()) LoadSparseFilters(kernels_.begin(), kernels_.end(), kernBufs_.begin()); i32 nto = params_.numOrientations; i32 ncs = params_.numCurvatures; NDIndex<3> srcIndx; for (i32 tji = 0; tji < nto; ++tji) { srcIndx[0] = tji; for (i32 ktji = 0; ktji < ncs; ++ktji) { srcIndx[1] = ktji; for (i32 knji = 0; knji < ncs; ++knji) { srcIndx[2] = knji; pusher.output(Filter(input[srcIndx], kernBufs_[srcIndx])); } } pusher.output(Merge(Add, ncs*ncs, popper)); } Merge(Add, nto, popper, output); if (params_.minSupport != 0 || params_.maxSupport != 1) { Rescale(output, params_.minSupport, params_.maxSupport, 0, 1, false, output); } return output; }
static void FindStationFromNode( Digraph& dg, Digraph::Node u, EdgeArray& es, bool reverse = false ) { NDArray nds; if( reverse ) { DFS_Helper3( dg, u, nds ); } else { DFS_Helper2( dg, u, nds ); } std::sort( nds.begin(), nds.end(), SortNodeDist() ); for( int i = 0; i < nds.size(); i++ ) { if( i < MAX_PATH_LENGTH ) { bool ret = true; DPath p; if( reverse ) { ret = DFS_Helper( dg, nds[i].u, u, p ); } else { ret = DFS_Helper( dg, u, nds[i].u, p ); } if( !ret ) continue; for( DPath::ArcIt e( p ); e != INVALID; ++e ) { if( !es.contains( e ) ) es.append( e ); } } } }
FlowSupportOp(f64 ti, f64 kti, f64 kni, RelaxFlowOpParams ¶ms) : params_(params), kernels_(params.numOrientations, params.numCurvatures, params.numCurvatures), kernBufs_(params.numOrientations, params.numCurvatures, params.numCurvatures), ti_(ti), kti_(kti), kni_(kni) { for (i32 i = 0; i < kernels_.numElems(); i++) kernels_[i] = ImageData(params.kernelSize, params.kernelSize); }
inline void AdamOptimizer::Update(int index, NDArray weight, NDArray grad) { if (mean_.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()); float lr = std::stof(params_["lr"]); float wd = std::stof(params_["wd"]); float b1 = std::stof(params_["beta1"]); float b2 = std::stof(params_["beta2"]); float t = count_[index]; float coef1 = 1.0f - std::pow(b1, t); float coef2 = 1.0f - std::pow(b2, t); lr *= std::sqrt(coef2) / coef1; NDArrayHandle inputs[4]; inputs[0] = weight.GetHandle(); inputs[1] = grad.GetHandle(); int num_outputs = 1; NDArrayHandle output = weight.GetHandle(); NDArrayHandle *outputs = &output; inputs[2] = mean_[index]->GetHandle(); inputs[3] = var_[index]->GetHandle(); MXImperativeInvoke(update_handle_, 4, inputs, &num_outputs, &outputs, keys.size(), keys.data(), values.data()); }
static void DFS_Helper2( Digraph& dg, Digraph::Node u, NDArray& nds ) { NodeArray ns; Dfs<Digraph> aDfs( dg ); aDfs.run( u ); for( Digraph::NodeIt n( dg ); n != INVALID; ++n ) { if( aDfs.reached( n ) ) { NodeDist nd; nd.u = n; nd.dist = aDfs.dist( n ); nds.push_back( nd ); } } }
void Extract(NDArray data) { /*Normalize the pictures*/ data.Slice(0, 1) -= mean_img; data.Slice(1, 2) -= mean_img; args_map["data"] = data; /*bind the excutor*/ executor = net.SimpleBind(global_ctx, args_map, map<string, NDArray>(), map<string, OpReqType>(), aux_map); executor->Forward(false); /*print out the features*/ auto array = executor->outputs[0].Copy(Context(kCPU, 0)); NDArray::WaitAll(); for (int i = 0; i < 1024; ++i) { cout << array.At(0, i) << ","; } cout << endl; }
void Householder<T>::mulLeft(NDArray<T>& matrix, const NDArray<T>& tail, const T coeff) { // if(matrix.rankOf() != 2) // throw "ops::helpers::Householder::mulLeft method: input array must be 2D matrix !"; if(matrix.sizeAt(0) == 1) matrix *= (T)1. - coeff; else if(coeff != (T)0.) { NDArray<T>* bottomPart = matrix.subarray({{1, matrix.sizeAt(0)}, {}}); NDArray<T> bottomPartCopy = *bottomPart; if(tail.isColumnVector()) { NDArray<T> column = tail; NDArray<T>* row = tail.transpose(); NDArray<T> resultingRow = mmul(*row, bottomPartCopy); NDArray<T>* fistRow = matrix.subarray({{0,1}, {}}); resultingRow += *fistRow; *fistRow -= resultingRow * coeff; *bottomPart -= mmul(column, resultingRow) * coeff; delete row; delete fistRow; } else { NDArray<T> row = tail; NDArray<T>* column = tail.transpose(); NDArray<T> resultingRow = mmul(row, bottomPartCopy); NDArray<T>* fistRow = matrix.subarray({{0,1}, {}}); resultingRow += *fistRow; *fistRow -= resultingRow * coeff; *bottomPart -= mmul(*column, resultingRow) * coeff; delete column; delete fistRow; } delete bottomPart; } }
static void DFS_Helper3( Digraph& dg, Digraph::Node u, NDArray& nds ) { typedef ReverseDigraph<Digraph> RDigraph; RDigraph rdg( dg ); Dfs<RDigraph> aDfs( rdg ); aDfs.run( u ); for( Digraph::NodeIt n( dg ); n != INVALID; ++n ) { if( aDfs.reached( n ) ) { NodeDist nd; nd.u = n; nd.dist = aDfs.dist( n ); nds.push_back( nd ); } } }
void Householder<T>::mulRight(NDArray<T>& matrix, const NDArray<T>& tail, const T coeff) { // if(matrix.rankOf() != 2) // throw "ops::helpers::Householder::mulRight method: input array must be 2D matrix !"; if(matrix.sizeAt(1) == 1) matrix *= (T)1. - coeff; else if(coeff != (T)0.) { NDArray<T>* rightPart = matrix.subarray({{}, {1, matrix.sizeAt(1)}}); NDArray<T> rightPartCopy = *rightPart; NDArray<T>* fistCol = matrix.subarray({{},{0,1}}); if(tail.isColumnVector()) { NDArray<T> column = tail; NDArray<T>* row = tail.transpose(); NDArray<T> resultingCol = mmul(rightPartCopy, column); resultingCol += *fistCol; *fistCol -= resultingCol * coeff; *rightPart -= mmul(resultingCol, *row) * coeff; delete row; } else { NDArray<T> row = tail; NDArray<T>* column = tail.transpose(); NDArray<T> resultingCol = mmul(rightPartCopy, *column); resultingCol += *fistCol; *fistCol -= resultingCol * coeff; *rightPart -= mmul(resultingCol, row) * coeff; delete column; } delete rightPart; delete fistCol; } }
void util_fill_ndarr_dims(NDArray &ndarr, unsigned long int *sizes, int ndims) { log4cxx::LoggerPtr log( log4cxx::Logger::getLogger("main") ); static short counter = 3; int i=0; ndarr.ndims = ndims; int num_elements = 1; for (i=0; i<ndims; i++) { // Note: the NDArray dimensions are reverse order in relation to // the HDF5 dataset dimensionality. sigh.... ndarr.initDimension(&(ndarr.dims[ndims-i-1]), sizes[i]); num_elements *= sizes[i]; } ndarr.pData = calloc(num_elements, sizeof(short)); LOG4CXX_TRACE(log, "Filling array with dummy data..."); for (i=0; i<num_elements; i++) { *((short*)ndarr.pData + i) = i; } short *ptrdata = (short*)ndarr.pData; ptrdata[0] = counter++; ptrdata[1] = counter++; LOG4CXX_TRACE(log, "Done filling array!"); }