void minHeap::update(int index) { int parent = (index-1)/2; if((index != 0) && h[index].info->load < h[parent].info->load) { swap(parent,index); update(parent); } int c1 = 2*index+1; int c2 = 2*index+2; if(c2<numElements()){ int smaller = least(index,c1,c2); if(smaller != index){ swap(smaller,index); update(smaller); return; } } if(c1<numElements() && h[c1].info->load < h[index].info->load) { swap(c1,index); update(c1); return; } }
JNIEXPORT void JNICALL Java_org_adaptinet_sdk_fastcache_DataArray_fromDataItemArray(JNIEnv *env, jobject _this, jobjectArray a) { try { DATAARRAY * pda = getDataArray(env, _this); DATATYPE dt; DataArrayGetDatatype(pda, &dt); unsigned long len = env->GetArrayLength(a); if(len > numElements(pda)) { len = numElements(pda); } if(dt==DT_DATAITEM) { for(unsigned long i=0;i<len;i++) { jobject var = env->GetObjectArrayElement(a, i); DATAITEM * di = getDataItem(env, var); unsigned long x = i; if(di) DataArrayPutElement(pda,&x,di); } } else { ThrowFastCacheException(env, "dataarray cannot be assigned from dataItem", -1); } } catch(JNIException & ex) { JNIException::lastError = ex.getErrorCode(); } }
JNIEXPORT void JNICALL Java_org_adaptinet_sdk_fastcache_DataArray_setDataItems(JNIEnv *env, jobject _this, jlong idx, jint nelem, jobjectArray ja, jint ja_start) { try { DATAARRAY * pda = getDataArray(env, _this); DATATYPE dt; DataArrayGetDatatype(pda, &dt); unsigned long len = env->GetArrayLength(ja); if(len > numElements(pda)) { len = numElements(pda); } if(dt==DT_DATAITEM) { DATAITEM di; DataItemInit(&di); for(unsigned long i=ja_start,j=idx;i<ja_start+nelem;i++,j++) { jobject var = env->GetObjectArrayElement(ja, i); DATAITEM *di = getDataItem(env, var); unsigned long x = j; DataArrayPutElement(pda,&x,di); } } else { ThrowFastCacheException(env, "dataarray type is not dataItem", -1); } } catch(...) { ThrowFastCacheException(env, "dataarray error setting dataItem", -1); } }
LocationID *convertListToArray(List l, int *numLocation) { // Sets the number of elements to "numLocation" *numLocation = numElements(l); // Allocated memory for array LocationID *array = malloc(sizeof(LocationID)*numElements(l)); //increment variables int i; NodePointer curr; // ensures that both i is less than numLocation // i.e. not overflowing the array by some random accident // and curr is not null // i.e not accessing a null pointer by some random accident // just to be safe (Y) for (i = 0, curr = l->first; i < *numLocation && curr != NULL; i++, curr = curr->next) { array[i] = curr->item; } return array; }
Attribute *Attribute::copy() { Attribute *nattr = new Attribute( numComponents(), elementComponentSize() ); nattr->m_data.resize( numElements() * numComponents()*elementComponentSize() ); msys_memcpy( nattr->m_data.m_data, m_data.m_data, numElements() * numComponents()*elementComponentSize() ); nattr->m_numElements = numElements(); return nattr; }
JNIEXPORT void JNICALL Java_org_adaptinet_sdk_fastcache_DataArray_fromStringArray(JNIEnv *env, jobject _this, jobjectArray a) { try { DATAARRAY * pda = getDataArray(env, _this); DATATYPE dt; DataArrayGetDatatype(pda, &dt); unsigned long len = env->GetArrayLength(a); if(len > numElements(pda)) { len = numElements(pda); } if(dt==DT_DATAITEM) { DATAITEM di; DataItemInit(&di); di.dt = DT_SSTR; for(unsigned long i=0;i<len;i++) { jstring s = (jstring)env->GetObjectArrayElement(a, i); const char *str = env->GetStringUTFChars(s, 0); SString bs = SafeString(str); di.dt = DT_SSTR; di.psstringVal = &bs; unsigned long x = i; if(DataArrayPutElement(pda,&x,&di)==RET_ERROR) { ThrowFastCacheException(env, "dataarray index past end of array", 0); } env->ReleaseStringUTFChars(s, str); DataItemClear(&di); } } else if(dt==DT_SSTR) { for(unsigned long i=0;i<len;i++) { jstring s = (jstring)env->GetObjectArrayElement(a, i); const char *str = env->GetStringUTFChars(s, 0); SString bs = SafeString(str); unsigned long x = i; if(DataArrayPutElement(pda,&x,&bs)==RET_ERROR) ThrowFastCacheException(env, "dataarray index past end of array", 0); env->ReleaseStringUTFChars(s, str); } } else { ThrowFastCacheException(env, "dataarray cannot be assigned from string\n", 0); } } catch(JNIException & ex) { JNIException::lastError = ex.getErrorCode(); } }
void DeepImage::subtractDeepImage(const DeepImage & other) { int originalNumElems = numElements(); addDeepImage(other); // Invert the alpha values of all the added samples // to indicate that they should be subtracted when rendering each pixel. std::vector<DeepDataType> & alphaValues = mChannelData.at(ALPHA); for (int i = originalNumElems; i < numElements(); ++i) { alphaValues[i] = -1.f * alphaValues[i]; } }
void minHeap::update(InfoRecord *x) { // find index // TODO: OPTIMIZE it! int index; for (index=0; index<numElements(); index++) if (x == h[index].info) break; if (index == numElements()) { CmiAbort("minHeap: update a non-existent element!\n"); } update(index); }
int numElements(Heap h) { int num = 1; // add the number of children if any, by recursion if(h.right != nullptr){ num = 1 + numElements(*h.left) + numElements(*h.right); } else if(h.left != nullptr){ num = 1 + numElements(*h.left); } return num; }
JNIEXPORT void JNICALL Java_org_adaptinet_sdk_fastcache_DataArray_fromShortArray(JNIEnv *env, jobject _this, jshortArray a) { try { DATAARRAY * pda = getDataArray(env, _this); DATATYPE dt; DataArrayGetDatatype(pda, &dt); unsigned long len = env->GetArrayLength(a); if(len > numElements(pda)) { len = numElements(pda); } jshort *iarr = env->GetShortArrayElements(a, 0); if(dt==DT_DATAITEM) { DATAITEM di; DataItemInit(&di); di.dt = DT_I2; for(unsigned long i=0;i<len;i++) { di.iVal = iarr[i]; unsigned long x = i; if(DataArrayPutElement(pda,&x,&di)==RET_ERROR) { ThrowFastCacheException(env, "dataarray index past end of array", 0); return; } } } else if(dt==DT_I2) { void *pData; DataArrayAccessData(pda, &pData); memcpy(pData, iarr, len*sizeof(short)); DataArrayUnaccessData(pda); } else { ThrowFastCacheException(env, "dataarray cannot be assigned from short", -1); return; } env->ReleaseShortArrayElements(a, iarr, 0); } catch(JNIException & ex) { JNIException::lastError = ex.getErrorCode(); } }
JNIEXPORT void JNICALL Java_org_adaptinet_sdk_fastcache_DataArray_fromBooleanArray(JNIEnv *env, jobject _this, jbooleanArray a) { try { DATAARRAY * pda = getDataArray(env, _this); DATATYPE dt; DataArrayGetDatatype(pda, &dt); unsigned long len = env->GetArrayLength(a); if(len > numElements(pda)) { len = numElements(pda); } jboolean *iarr = env->GetBooleanArrayElements(a, 0); if(dt==DT_DATAITEM) { DATAITEM di; DataItemInit(&di); di.dt = DT_BOOL; for(unsigned long i=0;i<len;i++) { di.bVal = iarr[i] ? 1 : 0; unsigned long x = i; DataArrayPutElement(pda,&x,&di); } } else if(dt==DT_BOOL) { bool di; for(unsigned long i=0;i<len;i++) { di = iarr[i] ? 1 : 0; unsigned long x = i; DataArrayPutElement(pda,&x,&di); } } else { ThrowFastCacheException(env, "dataarray cannot be assigned from boolean", -1); } env->ReleaseBooleanArrayElements(a, iarr, 0); } catch(JNIException & ex) { JNIException::lastError = ex.getErrorCode(); } }
DynamicDataBuffer::DynamicDataBuffer( ID3D11Device* pDevice, int nElements, int elementSizeBytes, DXGI_FORMAT format, ID3D11Buffer* pBuffer ) : m_nElements( nElements ), m_elementSizeBytes( elementSizeBytes ), m_format( format ), m_pBuffer( pBuffer ) { D3D11_SHADER_RESOURCE_VIEW_DESC desc; ZeroMemory( &desc, sizeof( desc ) ); desc.Format = format; desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; D3D11_BUFFER_SRV bsrv; bsrv.ElementOffset = 0; bsrv.ElementWidth = numElements(); desc.Buffer = bsrv; // TODO: this can fail HRESULT hr = pDevice->CreateShaderResourceView( m_pBuffer, &desc, &m_pSRV ); // TODO: want something other than immediate context? pDevice->GetImmediateContext( &m_pContext ); }
MutualCoherenceFunction(int64_t cols, int64_t rows) : mCols(cols), mRows(rows), mData(Memory::alignedNew<Complex>(numElements()), Memory::alignedDelete) { assert((cols > 0) && (rows > 0)); init(); }
JNIEXPORT void JNICALL Java_org_adaptinet_sdk_fastcache_DataArray_setBooleans(JNIEnv *env, jobject _this, jlong idx, jint nelem, jbooleanArray ja, jint ja_start) { try { DATAARRAY * pda = getDataArray(env, _this); DATATYPE dt; DataArrayGetDatatype(pda, &dt); unsigned long len = env->GetArrayLength(ja); if(len > numElements(pda)) { len = numElements(pda); } jboolean *iarr = env->GetBooleanArrayElements(ja, 0); if(dt==DT_DATAITEM) { DATAITEM di; DataItemInit(&di); di.dt = DT_BOOL; for(unsigned long i=ja_start,j=idx;i<ja_start+nelem;i++,j++) { di.boolVal = iarr[i]==JNI_TRUE ? true : false; unsigned long x = j; DataArrayPutElement(pda,&x,&di); } } else if(dt==DT_BOOL) { bool di; for(unsigned long i=ja_start,j=idx;i<ja_start+nelem;i++,j++) { di = iarr[i]==JNI_TRUE ? true : false; unsigned long x = j; DataArrayPutElement(pda,&x,&di); } } else { ThrowFastCacheException(env, "dataarray type mismatch", -1); return; } env->ReleaseBooleanArrayElements(ja, iarr, 0); } catch(...) { ThrowFastCacheException(env, "dataarray error setting dataItem", -1); } }
//! @brief Returns distributed force moments (one for each element) expressed in local coordinates. const XC::Matrix &XC::Beam2dUniformLoad::getLocalMoments(void) const { static Matrix retval; const size_t sz= numElements(); retval= Matrix(sz,1); for(size_t i=0; i<sz; i++) retval(i,0)= 0.0; return retval; }
void Project::SetVisibleDomain(Domain *newDomain) { if (newDomain) { visibleDomain = newDomain; if (glPanel) glPanel->SetActiveDomainNew(visibleDomain); Fort14 *currFort14 = visibleDomain->GetFort14(); if (currFort14) { emit numElements(currFort14->GetNumElements()); emit numNodes(currFort14->GetNumNodes()); } emit undoAvailable(visibleDomain->UndoAvailable()); emit redoAvailable(visibleDomain->RedoAvailable()); if (displayOptions && displayOptions->isVisible()) { displayOptions->SetActiveDomain(visibleDomain); displayOptions->update(); } if (projectTree) { if (visibleDomain == fullDomain) projectTree->setCurrentItem(projectTree->findItems("Full Domain", Qt::MatchExactly | Qt::MatchRecursive).first()); else { SubDomain *targetDomain = DetermineSubdomain(visibleDomain); if (targetDomain) { QString name = targetDomain->GetDomainName(); projectTree->setCurrentItem(projectTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive).first()); } } } if (editSubdomainList) { if (visibleDomain == fullDomain) editSubdomainList->clearSelection(); else { SubDomain *targetDomain = DetermineSubdomain(visibleDomain); if (targetDomain) { QString name = targetDomain->GetDomainName(); editSubdomainList->setCurrentItem(editSubdomainList->findItems(name, Qt::MatchExactly | Qt::MatchRecursive).first()); } } } } }
string *printLinear(Heap h) { int length = numElements(h); string *heapsString = new string[length]; Heap *nodes = *returnAllHeaps(h); for(int i = 0; i< length; i++){ heapsString[i] = nodes[i].name; } return heapsString; }
JNIEXPORT void JNICALL Java_org_adaptinet_sdk_fastcache_DataArray_setStrings(JNIEnv *env, jobject _this, jlong idx, jint nelem, jobjectArray ja, jint ja_start) { DATAARRAY * pda = getDataArray(env, _this); DATATYPE dt; DataArrayGetDatatype(pda, &dt); unsigned long len = env->GetArrayLength(ja); if(len > numElements(pda)) { len = numElements(pda); } if(dt==DT_DATAITEM) { DATAITEM di; DataItemInit(&di); for(long i=ja_start,j=idx;i<ja_start+nelem;i++,j++) { jstring s = (jstring)env->GetObjectArrayElement(ja, i); const char *str = env->GetStringUTFChars(s, 0); di.dt = DT_SSTR; di.sstringVal = SafeString(str); unsigned long x = j; DataArrayPutElement(pda,&x,&di); DataItemClear(&di); } } else if(dt==DT_SSTR) { for(long i=ja_start,j=idx;i<ja_start+nelem;i++,j++) { jstring s = (jstring)env->GetObjectArrayElement(ja, i); const char *str = env->GetStringUTFChars(s, 0); unsigned long x = j; DataArrayPutElement(pda,&x,SafeString(str)); } } else { ThrowFastCacheException(env, "dataarray cannot set strings", 0); return; } }
void Attribute::bindAsAttribute( int index ) { // activate and specify pointer to vertex array // should be done only when attribute has been updated oglBindBuffer(GL_ARRAY_BUFFER, m_bufferId); oglBufferData(GL_ARRAY_BUFFER, numComponents()*elementComponentSize()*numElements(), getRawPointer(), GL_STATIC_DRAW); oglBindBuffer(GL_ARRAY_BUFFER, m_bufferId); oglEnableVertexAttribArray(index); oglVertexAttribPointer(index, numComponents(), elementComponentType(), false, 0, 0); }
//! @brief Returns distributed force vectors (one for each element) expressed in local coordinates. const XC::Matrix &XC::Beam2dUniformLoad::getLocalForces(void) const { static Matrix retval; const size_t sz= numElements(); retval= Matrix(sz,2); for(size_t i=0; i<sz; i++) { retval(i,0)= WAxial(); retval(i,1)= WTrans(); } return retval; }
void Attribute::bindAsUniform( int index ) { switch( numComponents() ) { case 1: if( m_internalComponentType == GL_FLOAT ) { //printf("setting uniform tmp: %f at uniform location %i\n", *((float *)getRawPointer()), index ); glUniform1fv( index, numElements(), (float *)getRawPointer()); } else if( m_internalComponentType == GL_INT ) { glUniform1iv( index, numElements(), (int*)getRawPointer()); }else if( m_internalComponentType == SAMPLER ) { int *texIds = (int*)getRawPointer(); int textureUnits[32]; int num = numElements(); for( int i=0;i<num;++i ) { glActiveTexture(GL_TEXTURE0+g_nextTextureUnit); glBindTexture(m_textureTarget, *texIds); textureUnits[i] = g_nextTextureUnit; ++texIds; ++g_nextTextureUnit; } glUniform1iv( index, num, textureUnits); } break; case 2: if( m_internalComponentType == GL_FLOAT ) glUniform2fv( index, numElements(), (float *)getRawPointer()); break; case 3: if( m_internalComponentType == GL_FLOAT ) glUniform3fv( index, numElements(), (float *)getRawPointer()); break; case 4: if( m_internalComponentType == GL_FLOAT ) glUniform4fv( index, numElements(), (float *)getRawPointer()); break; case 9: glUniformMatrix3fv( index, numElements(), false, (float *)getRawPointer() ); break; case 16: glUniformMatrix4fv( index, numElements(), false, (float *)getRawPointer() ); break; }; }
void Attribute::bindAsUniform( int index ) { switch( numComponents() ) { case 1: if( elementComponentType() == GL_FLOAT ) { //printf("setting uniform tmp: %f at uniform location %i\n", *((float *)getRawPointer()), index ); oglUniform1fv( index, numElements(), (float *)getRawPointer()); } else if( elementComponentType() == GL_INT ) { oglUniform1iv( index, numElements(), (int*)getRawPointer()); }else if( elementComponentType() == ATTR_TYPE_SAMPLER ) { // get gl textureid unsigned int t = (unsigned int) (*(int*)getRawPointer()); // bind texture to given texture unit (index) oglActiveTexture(GL_TEXTURE0+index); glBindTexture(GL_TEXTURE_2D, t); // now set the sampler uniform to point to the textureunit int tt = index; // for now texture unit == unfiform location // this will be bad with higher number of uniforms in shader // need more clever texture unit management oglUniform1iv( index, 1, &tt); } break; case 2: if( elementComponentType() == GL_FLOAT ) oglUniform2fv( index, numElements(), (float *)getRawPointer()); break; case 3: if( elementComponentType() == GL_FLOAT ) oglUniform3fv( index, numElements(), (float *)getRawPointer()); break; case 4: if( elementComponentType() == GL_FLOAT ) oglUniform4fv( index, numElements(), (float *)getRawPointer()); break; case 9: oglUniformMatrix3fv( index, numElements(), false, (float *)getRawPointer() ); break; case 16: oglUniformMatrix4fv( index, numElements(), false, (float *)getRawPointer() ); break; }; }
void Attribute::bindAsAttribute( int index ) { if(m_isDirty && m_numElements) { // activate and specify pointer to vertex array // should be done only when attribute has been updated glBindBuffer(GL_ARRAY_BUFFER, m_bufferId); glBufferData(GL_ARRAY_BUFFER, numComponents()*elementComponentSize()*numElements(), getRawPointer(), GL_STATIC_DRAW); m_isDirty = false; } glBindBuffer(GL_ARRAY_BUFFER, m_bufferId); glEnableVertexAttribArray(index); if( m_internalComponentType == GL_FLOAT ) glVertexAttribPointer(index, numComponents(), m_internalComponentType, false, 0, 0); else glVertexAttribIPointer(index, numComponents(), m_internalComponentType, 0, 0); }
int main(int argc, char *argv[]) { FILE *fp; char buffer[BUFSIZ]; SET *odd; int words; /* Check usage and open the file. */ if (argc != 2) { fprintf(stderr, "usage: %s file1\n", argv[0]); exit(EXIT_FAILURE); } if ((fp = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "%s: cannot open %s\n", argv[0], argv[1]); exit(EXIT_FAILURE); } /* Insert or delete words to compute their parity. */ words = 0; odd = createSet(MAX_SIZE); while (fscanf(fp, "%s", buffer) == 1) { words ++; if (hasElement(odd, buffer)) removeElement(odd, buffer); else addElement(odd, buffer); } printf("%d total words\n", words); printf("%d words occur an odd number of times\n", numElements(odd)); fclose(fp); destroySet(odd); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { FILE *fp; char buffer[MAX_WORD_LENGTH]; SET *sets[MAX_WORD_LENGTH]; int i; /* Check usage and open the file. */ if (argc != 2) { fprintf(stderr, "usage: %s file1 [file2]\n", argv[0]); exit(EXIT_FAILURE); } if ((fp = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "%s: cannot open %s\n", argv[0], argv[1]); exit(EXIT_FAILURE); } /* Insert all words into the set of the appropriate length. */ for (i = 0; i < MAX_WORD_LENGTH; i ++) sets[i] = createSet(MAX_UNIQUE); while (fscanf(fp, "%s", buffer) == 1) addElement(sets[strlen(buffer) - 1], buffer); fclose(fp); /* Display the counts for each word length. */ for (i = 0; i < MAX_DISPLAYED; i ++) { printf("%5d distinct words ", numElements(sets[i])); printf("of length %d\n", i + 1); } exit(EXIT_SUCCESS); }
void ompi_send_f08_desc_f(CFI_cdesc_t *desc, MPI_Fint *count, MPI_Fint *datatype, MPI_Fint *dest, MPI_Fint *tag, MPI_Fint *comm, MPI_Fint *ierr) { size_t num_bytes = 0; if (isContiguous(desc)) { //printf("ompi_send_f08_desc_f: buf is contiguous\n"); ompi_send_f(desc->base_addr, count, datatype, dest, tag, comm, ierr); } else { size_t cont_size = desc->elem_len * numElements(desc); void * cont_buf = malloc(cont_size); //assert(cont_buf); num_bytes = (char*) copyToContiguous(desc, cont_buf, 0, desc->rank) - (char*) cont_buf; //printf("ompi_send_f08_desc_f: buf not contiguous, # elements==%ld, sending %ld bytes\n", numElements(desc), num_bytes); ompi_send_f(cont_buf, count, datatype, dest, tag, comm, ierr); free(cont_buf); } }
bool HashTable<D>::add(const D & data) { // add the entry to the table int index = hash(data); if (! table[index].empty() ) { // this is just a performance check // cerr << "Warning: collision" << endl; } itemsByNumber.add(data); if ( searchList( table[index], data ) != -1 ) { return false; } table[ index ].push_back( Node(data, numElements() )); numberOfElements++; return true; }
void DeepImage::addDeepImage(const DeepImage & other) { // Verify the input image has the correct channels. for (auto & channelName : mChannelNamesInOrder) { if (other.mChannelNamesInOrder.end() == std::find(other.mChannelNamesInOrder.begin(), other.mChannelNamesInOrder.end(), channelName)) { std::cerr << "This deep image has a channel " << channelName << " that doesn't exist in the other image" << std::endl; return; } } // Verify that the input image has the correct size. if (mWidth != other.mWidth || mHeight != other.mHeight) { std::cerr << "The image sizes doesn't match up." << std::endl; return; } // Update the index vectors int originalNumElems = numElements(); for (int i = 0; i < mWidth * mHeight; ++i) { std::vector<int> & indexVector = mIndexData[i]; const std::vector<int> & otherIndexVector = other.mIndexData[i]; indexVector.reserve(indexVector.size() + otherIndexVector.size()); for (int otherIndex : otherIndexVector) { indexVector.push_back(originalNumElems + otherIndex); // - 1); } } // Append the channel vectors for (auto & channelData : mChannelData) { std::vector<DeepDataType> & channelVector = channelData.second; const std::vector<DeepDataType> & otherChannelVector = other.mChannelData.at(channelData.first); // First expand the channel to be able to hold all the new data. channelVector.reserve(channelVector.size() + otherChannelVector.size()); // Then copy the data from other to this channel. std::copy(otherChannelVector.begin(), otherChannelVector.end(), std::back_inserter(channelVector)); } }
string printPretty(Heap h) { int numNodes = numElements(h); int numLines = 1; Heap *node = *returnAllHeaps(h); // find the height of the heap Heap *leftHeap = new Heap; leftHeap = h.left; while(leftHeap != nullptr){ numLines++; leftHeap = leftHeap->left; } // get the node in order from left to right (in order) std::vector<Heap> heapInorder; inorder(&h, heapInorder); // initialize the char[] with blank spaces char pretty[lengthOfContent(h)*numLines+numLines]; for (int i = 0; i< lengthOfContent(h)*numLines+numLines; i++){ pretty[i] = ' '; } // add line changes for(int i = 1; i < numLines; i++){ pretty[i*lengthOfContent(h)+i-1] = '\n'; } // add terminator pretty[lengthOfContent(h)*numLines+numLines -1] = '\0'; // find where the node belongs and place it int nodeStart; for(int i = 0; i< numNodes; i++){ nodeStart = 0; // find out where it belongs horizontally for(int j = 0; j< i; j++){ nodeStart = nodeStart + heapInorder.at(j).name.length(); } // find out on which line the node belongs bool lineFound = false; int k = 0; int line; while(!lineFound){ if(node[k].name == heapInorder.at(i).name){ line = (int) log2((double)(k+1)); lineFound = true; } else{ k++; } } // place the node where it belongs for(int z = 0; z< heapInorder.at(i).name.length(); z++){ pretty[line*(lengthOfContent(h)+1)+nodeStart+z] = heapInorder.at(i).name.at(z); } } string str(pretty); return str; }
void testCMarginBuffer() { const int64_t cols = 23; const int64_t rows = 54; const int64_t numPixels = cols * rows; const int64_t numElements = (cols + 2 * margin) * (rows + 2 * margin); CMarginBuffer2D<margin> buffer1(cols, rows); EXPECT_EQ(cols, buffer1.cols()); EXPECT_EQ(rows, buffer1.rows()); EXPECT_EQ(numPixels, buffer1.numPixels()); EXPECT_EQ(numElements, buffer1.numElements()); // generate test data generateTestData(buffer1); // check the data in the buffer for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)), static_cast<Real>(x)), buffer1.pixel(x, y)); } } // create a compatible buffer auto buffer2 = buffer1.createCompatibleBuffer(); EXPECT_EQ(cols, buffer1.cols()); EXPECT_EQ(rows, buffer2.rows()); EXPECT_EQ(numPixels, buffer2.numPixels()); EXPECT_EQ(numElements, buffer2.numElements()); EXPECT_TRUE(buffer1.compatible(buffer2)); EXPECT_TRUE(buffer2.compatible(buffer1)); // copy the data in the new buffer buffer2.assign(buffer1); // clear the first buffer const Complex clearValue(42.0, -8.0); buffer1.setValue(clearValue); // check the data in the first buffer for (int64_t y = 0; y < rows; ++y) for (int64_t x = 0; x < cols; ++x) EXPECT_EQ(clearValue, buffer1.pixel(x, y)); // check the data in the second buffer for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)), static_cast<Real>(x)), buffer2.pixel(x, y)); } } // test addAssign buffer1.setValue(Complex(1.0, -1.0)); generateTestData(buffer2); buffer1 += buffer2; for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + R(1.0), static_cast<Real>(x) - R(1.0)), buffer1.pixel(x, y)); } } // test multiplyAssign(CMarginBuffer) buffer1.setValue(Complex(1.0, -1.0)); generateTestData(buffer2); buffer1 *= buffer2; for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + static_cast<Real>(x), -std::sin(static_cast<Real>(y)) + static_cast<Real>(x)), buffer1.pixel(x, y)); } } // test multiplyAssign(Complex) generateTestData(buffer1); buffer1 *= Complex(1.0, -1.0); for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + static_cast<Real>(x), -std::sin(static_cast<Real>(y)) + static_cast<Real>(x)), buffer1.pixel(x, y)); } } // test multiplyAssign(Real) generateTestData(buffer1); buffer1 *= 5.0; for (int64_t y = 0; y < rows; ++y) { for (int64_t x = 0; x < cols; ++x) { EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) * R(5.0), static_cast<Real>(x) * R(5.0)), buffer1.pixel(x, y)); } } // create a third buffer const Complex initialValue(-49.0, 7.0); CMarginBuffer2D<margin> buffer3(cols + 1, rows, initialValue); EXPECT_FALSE(buffer3.compatible(buffer1)); EXPECT_FALSE(buffer1.compatible(buffer3)); for (int64_t y = 0; y < rows; ++y) for (int64_t x = 0; x < cols; ++x) EXPECT_EQ(initialValue, buffer3.pixel(x, y)); std::mt19937 generator; std::uniform_real_distribution<Real> distribution(0.0, Math::twoPi); for (int64_t y = 0; y < rows; ++y) for (int64_t x = 0; x < cols + 1; ++x) buffer3.pixel(x, y) = fromArg(distribution(generator)); EXPECT_EQ(buffer3.numPixels(), buffer3.absSqrReduce()); // todo: test multiplyAssign // todo: test info }