TEST_F( TArrayTest, resizeTest ) { TArray<float> arrayInstance; EXPECT_EQ( 0, arrayInstance.size() ); arrayInstance.resize( 5 ); EXPECT_EQ( 5, arrayInstance.size() ); }
bool tick_main(void) { if (! gThreadManager.isThreadRunning()) { return false; } jmp_buf hayatJmpBuf; if (setjmp(hayatJmpBuf) == 0) { hmd_halt_jmpbuf = & hayatJmpBuf; gThreadManager.exec1tick(); hyu32 n = updateFuncArr.size(); for (hyu32 i = 0; i < n; ++i) updateFuncArr[i](); n = drawFuncArr.size(); for (hyu32 i = 0; i < n; ++i) drawFuncArr[i](); GC::incremental(); } else { #ifdef HMD_ALLOW_CPP_EXCEPTION throw "error on hayat script execution"; #else HMD_FATAL_ERROR(M_M("error on hayat script execution")); #endif } return true; }
void Frame::init(TArray<PassData*> &newPasses) { if (newPasses.isEmpty()) { return; } for (ui32 i = 0; i < newPasses.size(); ++i) { m_newPasses.add(newPasses[i]); } m_uniforBuffers = new UniformBuffer[newPasses.size()]; }
TEST_F( TArrayTest, removeItTest) { TArray<float> arrayInstance; arrayInstance.add( 1.0f ); EXPECT_EQ( 1, arrayInstance.size() ); TArray<float>::Iterator it = arrayInstance.find( 1.0f ); EXPECT_NE( arrayInstance.end(), it ); arrayInstance.remove( it ); EXPECT_EQ( 0, arrayInstance.size() ); }
TEST_F( TArrayTest, addItemsTest ) { TArray<float> arrayInstance; arrayInstance.add( 0.0f ); float data[2] = { 0, 1 }; arrayInstance.add( data, 2 ); EXPECT_EQ( 3, arrayInstance.size() ); EXPECT_EQ( 0.0f, arrayInstance[ 0 ] ); EXPECT_EQ( 0.0f, arrayInstance[ 1 ] ); EXPECT_EQ( 1.0f, arrayInstance[ 2 ] ); arrayInstance.add( nullptr, 0 ); EXPECT_EQ( 3, arrayInstance.size() ); }
TEST_F( TArrayTest, ContainerClearTest ) { TArray<float*> arrayInstance; ContainerClear( arrayInstance ); EXPECT_TRUE( arrayInstance.isEmpty() ); arrayInstance.add( new float( 0.0f ) ); arrayInstance.add( new float( 1.0f ) ); arrayInstance.add( new float( 2.0f ) ); EXPECT_EQ( arrayInstance.size(), 3U ); ContainerClear( arrayInstance ); EXPECT_EQ( arrayInstance.size(), 0U ); EXPECT_TRUE( arrayInstance.isEmpty() ); }
void test_replace(void) { TArray<int> arr; arr.initialize(10); for (int i = 0; i < 10; ++i) arr.add(i * 10); CPPUNIT_ASSERT_EQUAL(30, arr.replace(3, -10)); CPPUNIT_ASSERT_EQUAL(50, arr.replace(5, -10)); CPPUNIT_ASSERT_EQUAL(80, arr.replace(8, 800)); CPPUNIT_ASSERT_EQUAL(-10, arr.replace(5, 10)); CPPUNIT_ASSERT_EQUAL(-10, arr.replace(3, 10)); CPPUNIT_ASSERT_EQUAL(800, arr.replace(8, 10)); CPPUNIT_ASSERT_EQUAL((hyu32)10, arr.size()); arr.deleteVal(10); CPPUNIT_ASSERT_EQUAL((hyu32)6, arr.size()); }
void test_insert_remove(void) { TArray<int> arr; arr.initialize(2); CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size()); HMD_ASSERT_HALT(arr.insert(1)); arr.insert(0) = 10; CPPUNIT_ASSERT_EQUAL((hyu32)1, arr.size()); CPPUNIT_ASSERT_EQUAL(10, arr[0]); arr.insert(0) = 20; CPPUNIT_ASSERT_EQUAL((hyu32)2, arr.size()); CPPUNIT_ASSERT_EQUAL(20, arr[0]); CPPUNIT_ASSERT_EQUAL(10, arr[1]); arr.insert(1) = 30; CPPUNIT_ASSERT_EQUAL((hyu32)3, arr.size()); CPPUNIT_ASSERT_EQUAL(20, arr[0]); CPPUNIT_ASSERT_EQUAL(30, arr[1]); CPPUNIT_ASSERT_EQUAL(10, arr[2]); arr.insert(3) = 40; CPPUNIT_ASSERT_EQUAL((hyu32)4, arr.size()); CPPUNIT_ASSERT_EQUAL(20, arr[0]); CPPUNIT_ASSERT_EQUAL(30, arr[1]); CPPUNIT_ASSERT_EQUAL(10, arr[2]); CPPUNIT_ASSERT_EQUAL(40, arr[3]); arr.insert(-1) = 50; CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size()); CPPUNIT_ASSERT_EQUAL(20, arr[0]); CPPUNIT_ASSERT_EQUAL(30, arr[1]); CPPUNIT_ASSERT_EQUAL(10, arr[2]); CPPUNIT_ASSERT_EQUAL(50, arr[3]); CPPUNIT_ASSERT_EQUAL(40, arr[4]); arr.remove(2); CPPUNIT_ASSERT_EQUAL((hyu32)4, arr.size()); CPPUNIT_ASSERT_EQUAL(20, arr[0]); CPPUNIT_ASSERT_EQUAL(30, arr[1]); CPPUNIT_ASSERT_EQUAL(50, arr[2]); CPPUNIT_ASSERT_EQUAL(40, arr[3]); arr.remove(-3); CPPUNIT_ASSERT_EQUAL((hyu32)3, arr.size()); CPPUNIT_ASSERT_EQUAL(20, arr[0]); CPPUNIT_ASSERT_EQUAL(50, arr[1]); CPPUNIT_ASSERT_EQUAL(40, arr[2]); HMD_ASSERT_HALT(arr.remove(3)); HMD_ASSERT_HALT(arr.remove(-4)); int* p = arr.nthAddr(3); int* q = arr.addSpaces(2); CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size()); CPPUNIT_ASSERT_EQUAL(p, q); }
TEST_F( TArrayTest, removeBackTest) { TArray<float> arrayInstance; createArray( ArrayData, ArraySize, arrayInstance ); arrayInstance.removeBack(); EXPECT_EQ( 3, arrayInstance.size() ); EXPECT_EQ( 2.0f, arrayInstance[ 2 ] ); }
TEST(TEST_FUNC, SortArrayWithTwoSameElements) { TArray arr {1, 1}; EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAre(1, 1)); TEST_FUNC(arr.data(), arr.size()); EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAre(1, 1)); }
TEST(TEST_FUNC, SortArrayWithTwoDistinctElements) { TArray arr {2, 1}; EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAre(2, 1)); TEST_FUNC(arr.data(), arr.size()); EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAre(1, 2)); }
TEST_F( TArrayTest, addTest) { TArray<float> arrayInstance; arrayInstance.add( 0.0f ); arrayInstance.add( 1.0f ); EXPECT_EQ( 2, arrayInstance.size() ); EXPECT_EQ( 0.0f, arrayInstance[ 0 ] ); EXPECT_EQ( 1.0f, arrayInstance[ 1 ] ); }
TEST(TEST_FUNC, SortArrayWithElevenElements) { int source [] {15, 13, 11, 2, 7, 1, 18, 8, 10, 5, 4}; const size_t size = sizeof(source) / sizeof(int); TArray arr {source, source + size}; EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAreArray({15, 13, 11, 2, 7, 1, 18, 8, 10, 5, 4})); TEST_FUNC(arr.data(), arr.size()); EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAreArray({1, 2, 4, 5, 7, 8, 10, 11, 13, 15, 18})); }
TEST_F( TArrayTest, resize_with_init_Test ) { TArray<float> arrayInstance; EXPECT_EQ( 0, arrayInstance.capacity() ); arrayInstance.resize( 10, 1.0f ); EXPECT_EQ( 10, arrayInstance.size() ); for ( size_t i = 0; i < 10; i++ ) { EXPECT_FLOAT_EQ( 1.0f, arrayInstance[ i ] ); } }
TEST_F( TArrayTest, iterateTest ) { TArray<float> arrayInstance; createArray( ArrayData, ArraySize, arrayInstance ); size_t i( 0 ); for( TArray<float>::Iterator it = arrayInstance.begin( ); it != arrayInstance.end( ); ++it ) { ++i; } EXPECT_EQ( i, arrayInstance.size() ); }
TEST(TEST_FUNC, SortArrayWithTenElements) { int source [] {8, 10, 11, 3, 6, 9, 5, 2, 17, 1}; const size_t size = sizeof(source) / sizeof(int); TArray arr {source, source + size}; EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAreArray({8, 10, 11, 3, 6, 9, 5, 2, 17, 1})); TEST_FUNC(arr.data(), arr.size()); EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAreArray({1, 2, 3, 5, 6, 8, 9, 10, 11, 17})); }
TEST(TEST_FUNC, SortArrayWithNineElements) { int source [] {19, 8, 18, 1, 16, 17, 12, 14, 9}; const size_t size = sizeof(source) / sizeof(int); TArray arr {source, source + size}; EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAreArray({19, 8, 18, 1, 16, 17, 12, 14, 9})); TEST_FUNC(arr.data(), arr.size()); EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAreArray({1, 8, 9, 12, 14, 16, 17, 18, 19})); }
TEST(TEST_FUNC, SortArrayWithSixElements) { int source [] {4, 2, 5, 1, 7, 3}; const size_t size = sizeof(source) / sizeof(int); TArray arr {source, source + size}; EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAre(4, 2, 5, 1, 7, 3)); TEST_FUNC(arr.data(), arr.size()); EXPECT_FALSE(arr.empty()); EXPECT_THAT(arr, ElementsAre(1, 2, 3, 4, 5, 7)); }
void term_main(void) { hyu32 n = termFuncArr.size(); for (hyu32 i = 0; i < n; ++i) termFuncArr[i](); finalizeAll(); finalizeDebug(); loadPathArr.finalize(); updateFuncArr.finalize(); drawFuncArr.finalize(); termFuncArr.finalize(); for (hyu32 i = dllHandleArr.size(); i > 0; ) { AfxFreeLibrary(dllHandleArr[--i]); } dllHandleArr.finalize(); HMD_FREE(mainMem); HMD_FREE(debugMem); }
void test_deleteVal(void) { TArray<int> arr; arr.initialize(10); for (int i = 0; i < 10; ++i) arr.add(i * 10); arr[3] = 80; arr[6] = 80; CPPUNIT_ASSERT_EQUAL((hyu32)10, arr.size()); arr.deleteVal(20); CPPUNIT_ASSERT_EQUAL((hyu32)9, arr.size()); arr.deleteVal(80); CPPUNIT_ASSERT_EQUAL((hyu32)6, arr.size()); CPPUNIT_ASSERT_EQUAL(0, arr[0]); CPPUNIT_ASSERT_EQUAL(10, arr[1]); CPPUNIT_ASSERT_EQUAL(40, arr[2]); CPPUNIT_ASSERT_EQUAL(50, arr[3]); CPPUNIT_ASSERT_EQUAL(70, arr[4]); CPPUNIT_ASSERT_EQUAL(90, arr[5]); }
TEST_F( TArrayTest, findTest ) { TArray<float> arrayInstance; arrayInstance.add( 0.0f ); arrayInstance.add( 1.0f ); arrayInstance.add( 2.0f ); arrayInstance.add( 3.0f ); EXPECT_EQ( 4, arrayInstance.size() ); TArray<float>::Iterator it = arrayInstance.find( 1.0f ); EXPECT_NE( it, arrayInstance.end() ); EXPECT_EQ( *it, 1.0f ); }
// ロードパスを追加する void addLoadPath(const char* path) { //printf("addLoadPath(%s)\n", path); hyu32 n = loadPathArr.size(); if (n == 0) { loadPathArr.add(NULL); n = 1; } hyu32 len = HMD_STRLEN(path); char* apath = gMemPool->allocT<char>(len+1); HMD_STRNCPY(apath, path, len+1); loadPathArr[n-1] = apath; // end mark に上書き loadPathArr.add(NULL); // 新しい end mark HMD_LOADPATH = loadPathArr.top(); // n=0;for(const char** p = HMD_LOADPATH; *p != NULL; ++p)HMD_PRINTF("path %d:'%s'\n",n++,*p); }
TEST_F( TArrayTest, removeTest) { TArray<float> arrayInstance; createArray( ArrayData, ArraySize, arrayInstance ); std::stringstream stream; static const size_t Size = 3; arrayInstance.remove( 1 ); EXPECT_EQ( Size, arrayInstance.size() ); float expectedResult[ Size ] = { 0.0f, 2.0f, 3.0f }; bool equal = true; for ( size_t i=0; i<Size; ++i ) { if ( arrayInstance[ i ] != expectedResult[ i ] ) { stream << "error in index " << i << std::endl; equal = false; break; } } EXPECT_TRUE( equal ) << stream.str(); }
void Context::fwriteDebugInfo(FILE* fp, hyu32 offs) { TArray<const char*> paths; m_fwriteDebugInfo(fp, paths, offs); // SourceInfo終了マーク hyu8 buf[4]; memset(buf, 0, 4); fwrite(buf, sizeof(hyu32), 1, fp); // パス情報書き出し hyu32 n = paths.size(); Endian::pack<hyu16>(buf, (hyu16)n); fwrite(buf, sizeof(hyu16), 1, fp); for (hyu32 i = 0; i < n; i++) { const char* p = paths[i]; fwrite(p, 1, HMD_STRLEN(p)+1, fp); } }
ui32 Tokenizer::tokenize( const String& str, TArray<String>& tokens, const String& delimiters ) { // Skip delimiters at beginning. String::size_type lastPos = str.find_first_not_of( delimiters, 0 ); // find first "non-delimiter". String::size_type pos = str.find_first_of( delimiters, lastPos ); while( String::npos != pos || String::npos != lastPos ) { // Found a token, add it to the vector. String tmp = str.substr( lastPos, pos - lastPos ); if ( !tmp.empty() && ' ' != tmp[ 0 ] ) { tokens.add( tmp ); } // Skip delimiters. Note the "not_of" lastPos = str.find_first_not_of( delimiters, pos ); // Find next "non-delimiter" pos = str.find_first_of( delimiters, lastPos ); } return static_cast<ui32>( tokens.size() ); }
int main() { // test 1 Tensor<double> T(2,2,2); T.fill(0.0); T(1,0,1) = -0.5; T.at(1,1,0) = 0.5; cout << "printing T: size = " << T.size() << " objsize = " << sizeof(T) << endl; for(double x : T) cout << x << endl; // test 2 typedef Tensor<float, CblasRowMajor, varray<float>> MyTensor; MyTensor::shape_type shape = { 4, 4 }; MyTensor Q(shape); Q.fill(2.0); MyTensor::shape_type index = { 1, 2 }; Q(index) = -0.5; ++index[0]; Q.at(index) = 0.5; cout << "printing Q: size = " << Q.size() << " objsize = " << sizeof(Q) << endl; for(double x : Q) cout << x << endl; Q = T; cout << "printing Q (=T): size = " << Q.size() << " objsize = " << sizeof(Q) << endl; for(double x : Q) cout << x << endl; // test 3 Tensor<double> S(2,2,2); S.fill(1.0); axpy(0.5, T, S); cout << "printing S: size = " << S.size() << " objsize = " << sizeof(S) << endl; for(double x : S) cout << x << endl; Tensor<double> U; axpy(0.5, S, U); cout << "printing U: size = " << U.size() << " objsize = " << sizeof(U) << endl; for(double x : U) cout << x << endl; // test 4 Tensor<double> V(0, 0); gemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 1.0, T, S, 1.0, V); cout << "printing V: size = " << V.size() << " objsize = " << sizeof(V) << endl; for(double x : V) cout << x << endl; // test 5 cout << boolalpha; cout << "is_tensor<Tensor<double>> = " << is_tensor<Tensor<double>>::value << endl; cout << "is_tensor<Tensor<Tensor<double>>> = " << is_tensor<Tensor<Tensor<double>>>::value << endl; cout << "is_tensor<vector<double>> = " << is_tensor<vector<double>>::value << endl; // test 6 Tensor<Tensor<double>> A(4,4); A.fill(Tensor<double>(0,0)); A(0,0) = Tensor<double>(2,2); A(1,1) = Tensor<double>(2,2); A(2,2) = Tensor<double>(2,2); A(3,3) = Tensor<double>(2,2); Tensor<Tensor<double>> B(4,4); B.fill(Tensor<double>(0,0)); B(0,0) = Tensor<double>(2,2); B(1,1) = Tensor<double>(2,2); B(2,2) = Tensor<double>(2,2); B(3,3) = Tensor<double>(2,2); Tensor<Tensor<double>> C(4,4); C.fill(Tensor<double>(0,0)); // rank info is required to determine contraction ranks at gemm gemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 1.0, A, B, 1.0, C); // test 7 Tensor<double> a(4,4); a.fill(1.0); // gemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 1.0, A, a, 1.0, C); // this will give a compile-time error, since gemm for "tensor of tensor" and "tensor" is not supported // test 8 TArray<double,3> t(2,2,2); t.fill(0.0); t(1,0,1) = -0.5; t.at(1,1,0) = 0.5; cout << "printing t: size = " << t.size() << " objsize = " << sizeof(t) << endl; for(double x : t) cout << x << endl; TArray<double,3> s(S); cout << "printing s: size = " << s.size() << " objsize = " << sizeof(s) << endl; for(double x : s) cout << x << endl; TArray<double,2> v; gemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 1.0, t, s, 1.0, v); cout << "printing v: size = " << v.size() << " objsize = " << sizeof(v) << endl; for(double x : v) cout << x << endl; TArray<double,3,CblasRowMajor,std::set<double>> u; cout << "dot(a, a) = " << dot(a, a) << endl; return 0; }
void Context::writeByteCodes(TArray<hyu8>* out) { TArray<hyu8> classInitializer; m_bytecode.write(&classInitializer); TArray< TArray<hyu8>* > binaries; TArray< TArray<hyu8>* > needDeleteBin; //innerClassSyms = @innerClasses.keys.sort TArray<SymbolID_t>& innerClassSyms = m_innerClasses.keys(); hyu16 flags = 0; if (classInfo()->isPrimitive()) flags |= 0x0001; hyu32 numInnerClass = innerClassSyms.size(); HMD_ASSERT(numInnerClass < 65536); TArray<SymbolID_t>& methodSyms = m_classInfo->m_methods.keys(); TArray<ClassInfo::m_SigCode_t>& methodSigCodes = m_classInfo->m_methods.values(); hyu32 numMethod = methodSyms.size(); HMD_ASSERT(numMethod < 65536); hyu32 numClosure = m_classInfo->numClosure(); HMD_ASSERT(numClosure < 65536); packOut<hyu16>(out,flags); // フラグ hyu16 packOut<hyu16>(out,(hyu16)numMethod); // メソッド数 hyu16 packOut<hyu16>(out,(hyu16)numInnerClass); // インナークラス数 hyu16 packOut<hyu16>(out,m_classInfo->numSuper()); // スーパークラス数 hyu16 packOut<hyu16>(out,m_classInfo->numClassVar()); // クラス変数数 hyu16 packOut<hyu16>(out,m_classInfo->numMembVar()); // メンバ変数数 hyu16 packOut<hyu16>(out,m_classInfo->numConstVar()); // 定数数 hyu16 packOut<hyu16>(out,m_classInfo->numDefaultVal()); // デフォルト値数 packOut<hyu16>(out,(hyu16)numClosure); // クロージャ数 hyu16 packOut<hyu16>(out,0xf9f9); // 未使用 for (hyu32 i = 0; i < numMethod; i++) packOut<SymbolID_t>(out,methodSyms[i]); // メソッドシンボル for (hyu32 i = 0; i < numInnerClass; i++) packOut<SymbolID_t>(out,innerClassSyms[i]); // クラス名シンボル m_classInfo->writeClassVarSyms(out); // クラス変数シンボル m_classInfo->writeMembVarSyms(out); // メンバ変数シンボル m_classInfo->writeConstVarSyms(out); // 定数シンボル out->align(4, 0xfb); hyu32 pos = classInitializer.size(); for (hyu32 i = 0; i < numMethod; i++) { packOut<hyu32>(out, pos); // メソッドオフセット Bytecode* bc = methodSigCodes[i].pBytecode; TArray<hyu8>* bin = new TArray<hyu8>(128); needDeleteBin.add(bin); bc->setOffset(pos); bc->write(bin); binaries.add(bin); pos += bin->size(); HMD_DEBUG_ASSERT((pos & 3) == 0); } for (hyu32 i = 0; i < numClosure; i++) { packOut<hyu32>(out, pos); // クロージャオフセット Bytecode* bc = m_classInfo->m_closures[i]; TArray<hyu8>* bin = new TArray<hyu8>(128); needDeleteBin.add(bin); bc->setOffset(pos); bc->write(bin); binaries.add(bin); pos += bin->size(); HMD_DEBUG_ASSERT((pos & 3) == 0); } for (hyu32 i = 0; i < numInnerClass; i++) { packOut<hyu32>(out, pos); // クラスオフセット Context* inner = m_innerClasses[innerClassSyms[i]]; TArray<hyu8>* bin = new TArray<hyu8>(128); needDeleteBin.add(bin); inner->bytecode().setOffset(pos); inner->writeByteCodes(bin); bin->align(4, 0xfa); binaries.add(bin); pos += bin->size(); } packOut<hyu32>(out, pos); // インナークラスバイトコードの終了位置オフセット m_classInfo->writeSuperLinks(out); // スーパークラス m_classInfo->writeUsingPaths(out); // usingパス情報 //printf("classInitializer addr=%x\n",out->size()); m_bytecode.setOffset(m_bytecode.getOffset() + out->size()); out->add(classInitializer); hyu32 n = binaries.size(); for (hyu32 i = 0; i < n; i++) { out->add(*binaries[i]); } n = needDeleteBin.size(); for (hyu32 i = 0; i < n; i++) { delete needDeleteBin[i]; } #ifdef EXPERIMENT_SYMBOL_DUMP m_classInfo->printSyms(); #endif }
void GIFFManager::load_file(const TArray<char> & data) { GP<ByteStream> str=ByteStream::create((const char *)data, data.size()); load_file(str); }
void FBasisSetLibraryImpl::ImportMolproLib(std::string const &FileName, std::ostream *pxout) { // how this files look: // Note: Lines with * are comments. // He s STO-3G STO3G : 3 1 1.3 // STO-3G // 6.3624214 1.158923 0.31364979 0.15432897 0.53532814 0.44463454 // Li s STO-3G STO3G : 6 2 1.3 4.6 // STO-3G // 16.119575 2.9362007 0.7946505 0.6362897 0.1478601 0.0480887 0.15432897 // 0.53532814 0.44463454 -0.09996723 0.39951283 0.70011547 // Li p STO-3G STO3G : 3 1 1.3 // STO-3G // 0.6362897 0.1478601 0.0480887 0.15591627 0.60768372 0.39195739 // B s cc-pVDZ VDZ : 9 3 1.9 1.9 9.9 // cc-pVDZ // 4570 685.9 156.5 44.47 14.48 5.131 1.898 0.3329 0.1043 0.000696 // 0.005353 0.027134 0.10138 0.272055 0.448403 0.290123 0.014322 -0.003486 // -0.000139 -0.001097 -0.005444 -0.021916 -0.059751 -0.138732 -0.131482 // 0.539526 0.580774 1 // interpretation: First Line: // ElementName OrbitalType N*[AlternativeNameI] : // #PrimOrbitals #OrbitalsTheyAreContractedTo N*[ContractFrom.ContractTo] // Any string, usually reference to be cited for the basis set // M*[PrimitiveOrbitalExponents] L*[PrimitiveOrbitalCoefficients] // for each contraction contraction length coefficients are supplied. // and data sets like this are also seen: // H P 6-311G2P : 2 0 // G92 6-311G polarization // .15000000D+01 .37500000D+00 // H P 6-311G3P : 3 0 // G92 6-311G polarization // .30000000D+01 .75000000D+00 .18750000D+00 // H S 6-31G** 6-31G* 6-31G : 4 1 1.3 // G92 6-31G** // .18731137D+02 .28253944D+01 .64012169D+00 .16127776D+00 .33494604D-01 // .23472695D+00 .81375733D+00 // all/some primitive orbitals are probably left uncontracted. Therefore no // contraction coefficients are supplied for these (only exponents). // Also I originally tought that the names of the basis set after the first // one were alternative Names of the set (like cc-pVDZ = VDZ). This is // however not how it works, at least not in all cases: It seems that names // which are supplied actually mean that the currently described elements // have to be inserted into the basis sets of ALL names provided, which // may or may not be identical basis sets (for example, for the s and p // orbitals of the 931G basis set, also the starred names are listed, which // means that these basis sets share these orbitals, altough in general they // are different). // so.. let's begin the mess. // read the entire file into a stringstream object (we need to modify it). TArray<char> pFileContent; if (!LoadFileIntoMemory(pFileContent, FileName)) throw std::runtime_error( "FBasisSetLibraryImpl: Failed to open file '"+FileName+"' for basis library import." ); // okay, now this is very bad. This FORTRAN stuff (sometimes) denotes // exponents in scientific notation not as "23423e-3" but as "23423D-03". We // do a lame attempt to convert that. This might break in some situations. // FIXME: correct this somehow. for (uint i = 0; i < pFileContent.size() - 2; ++i) { if (pFileContent[i]=='D' && (pFileContent[i+1]=='+' || pFileContent[i+1]=='-') && pFileContent[i+2]=='0') pFileContent[i] = 'E'; } FBasisNameSet AllBasisNames; std::stringstream str(&pFileContent[0], std::stringstream::in); // ^- NOTE: "in" means from stream, into local data, not // into stream (file naming convention) try { while(str.good()) { // clear exception mask, now stream will not throw() when something // unexpected happens. str.exceptions(std::ios::goodbit); std::string s; std::getline( str, s ); if (s.size() == 0 || s[0] == '*' || s[0] == '!') // empty or comment line, throw it away and go on with the next continue; if (!str.good()) // eof, bad etc. break; str.exceptions(std::ios::failbit); // ^- when something fails, throw an exception. this will happen // if the actual file format does not match the one I had in mind // when coding this. // expected format: ElementName[w]OrbitalType[w]AlternativeNames[w] : // using namespace std; // cout << "** read line: '" << s << "'" << endl; std::stringstream line(s, std::stringstream::in); line.exceptions(std::ios::badbit | std::ios::failbit); std::string Element, Type; line >> Element >> Type; if ( Type.size() != 1 ) throw std::runtime_error( "Parsing error, cannot interpret orbital type '" + Type + "'" ); int AngMom; std::vector<std::pair<int,int> > Cos; std::vector<double> Exps; char cAngMom = ::tolower(Type[0]); for (AngMom = 0; AngMom < 9; ++ AngMom) if (cAngMom == "spdfghikl"[AngMom]) break; if (AngMom == 9) throw std::runtime_error((format("Failed to understand angular momentum '%s'.") % cAngMom).str()); // std::cout << "Element " << Element << " Type " << Type << std::endl; FStringList BasisNames; // all names of basis sets in which the // current entry is to be inserted. for (line >> s; s != ":"; line >> s) { // std::cout << "Alternative Name:" << s << std::endl; BasisNames.push_back( tolower(stripwhitespace(s)) ); AllBasisNames.insert(stripwhitespace(s)); } // expected format: #prim orbitals #contractions (#contr.)*[a.b] // denoting indices of begin and end of a contraction with the // following exponents/contraction coefficients. int nExp, nCo, nCoeff(0), // total number of contraction coefficients to read (in all contractions). nHighestExpInCo(0); // 1-based index. line >> nExp >> nCo; // std::cout << "#Prim " << nExp << " #Co " << nCo << std::endl; Cos.reserve(nCo); for (int i = 0; i < nCo; ++ i){ std::pair<int,int> iCo; char Dot; line >> iCo.first >> Dot >> iCo.second; iCo.first -= 1; // convert to 0-based [begin,end). if (Dot != '.') throw std::runtime_error("GTO-Contraction read format error."); // std::cout << " Co: #" << iCo.first << "-#" << iCo.second << std::endl; if (iCo.second <= iCo.first || iCo.second > nExp) throw std::runtime_error("GTO-Contraction logical error."); nCoeff += iCo.second - iCo.first; nHighestExpInCo = std::max(nHighestExpInCo, iCo.second); Cos.push_back(iCo); } std::string EntryComment; do{ // read name, maybe skip comments. getline(str, EntryComment); } while (EntryComment.size() != 0 && EntryComment[0] == '*'); // cout << "Entry Comment: " << EntryComment << endl; // now read exponents and contraction coefficients; // (this will break if comments are present in between) Exps.resize(nExp); std::vector<double> Coeffs(nCoeff, 0); for ( int i = 0; i < nExp; ++ i ){ str >> Exps[i]; // cout << "Exp: " << Exps.back() << endl; } // read in contraction coefficients. if ( nCo != 0 ) for ( int i = 0; i < nCoeff; ++ i ){ double Coeff; str >> Coeff; // cout << "Coeff: " << Coeff << endl; Coeffs[i] = Coeff; } // copy over the contraction coefficients to the contractions. std::vector<double> CoMatrix(Exps.size() * nCo, 0.); int iCoeff = 0; for ( int i = 0; i < nCo; ++ i ){ for (int j = Cos[i].first; j != Cos[i].second; ++ j) CoMatrix[j + i*Exps.size()] = Coeffs[iCoeff + j - Cos[i].first]; iCoeff += (Cos[i].second - Cos[i].first); } // in some files some primitive orbitals are left uncontracted. // but these are not stored as 1-GTO contractions but the // coefficients for these are just not present in the file. // Make 1-GTO contractions for them. int nAdditionalCo = nExp - nHighestExpInCo; if (0 != nAdditionalCo) { // generate 1-GTO-each contractions manually. int nCoExplicit = nCo; nCo += nAdditionalCo; CoMatrix.resize(Exps.size() * nCo, 0.); int iStart = nHighestExpInCo; // ^- 0 based index, the rhs one is 1-based. for ( int i = 0; i < nAdditionalCo; ++ i ) { int iCo = i + nCoExplicit; CoMatrix[(i + iStart) + Exps.size() * iCo] = 1.; } } // import all names of the basis function FStringList::const_iterator itName; _for_each(itName, BasisNames) m_BasisNames.insert(*itName); // make the actual basis function and link it to all the names. FAtomShellPtr pBfn(new FAtomShell(AngMom, &Exps[0], Exps.size(), &CoMatrix[0], CoMatrix.size()/Exps.size())); int iElement = ElementNumberFromName(Element); _for_each(itName, BasisNames) m_BasisFns.insert( FBasisFnMap::value_type(MakeKey(*itName, iElement), pBfn) ); // chew the EOL marker if present, leave loop otherwise. str.exceptions(std::ios::goodbit); str.ignore(0xbad, '\n'); }; } catch (std::ios_base::failure &e){ // this is not exactly something i would usually // call "error handling" but i really hate this string- // fiddling stuff and we can't really do anything better // about it anyway. std::cerr << "PARSER EXCEPTION:" << e.what() << std::endl; throw std::runtime_error( "Parsing of LIBMOL file FAILED because the actual syntax did not match the expected one. Last entry successfully processed: "); } catch (std::exception &e){ std::cerr << "Exception during LibmolFile parsing: " << e.what() << std::endl; throw; }; // if provided, write some imporant looking comments about what // we loaded to the standard output. if (pxout) { std::ostream &xout = *pxout; std::size_t iDirSep = FileName.rfind('/'); if ( iDirSep == std::string::npos ) iDirSep = 0; else iDirSep += 1; xout << format(" LOADED %-25s") % FileName.substr(iDirSep); if ( 1 ) { xout << "["; FBasisNameSet::const_iterator itSet; uint nLen = 0; _for_each(itSet, AllBasisNames) { if ( nLen >= 40 ) { xout << ",..."; break; } if (itSet != AllBasisNames.begin()) xout << ", "; xout << *itSet; nLen += itSet->size(); } xout << "]"; } xout << std::endl; }
void test_array(void) { int dat[10] = { 100, 110, 120, -130, 140, -15000, 16000, 1700, 18, 19000 }; TArray<int> arr; arr.initialize(0); CPPUNIT_ASSERT_EQUAL((int*)NULL, arr.m_contents); CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size()); CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.m_capacity); arr.initialize(2); CPPUNIT_ASSERT(arr.m_contents != NULL); CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size()); CPPUNIT_ASSERT_EQUAL((hyu32)2, arr.m_capacity); arr.add(dat, 5); CPPUNIT_ASSERT_EQUAL((hyu32)5, arr.size()); CPPUNIT_ASSERT_EQUAL(100, arr[0]); CPPUNIT_ASSERT_EQUAL(140, arr[4]); arr.fill(7); CPPUNIT_ASSERT_EQUAL(7, arr[0]); CPPUNIT_ASSERT_EQUAL(7, arr[4]); CPPUNIT_ASSERT(arr.checkIndex(100)); CPPUNIT_ASSERT(arr.checkIndex(-5)); CPPUNIT_ASSERT(! arr.checkIndex(-6)); arr[2] = 222; CPPUNIT_ASSERT_EQUAL(222, *(arr.nthAddr(2))); arr.subst(20, 202020, -1); CPPUNIT_ASSERT_EQUAL((hyu32)21, arr.size()); CPPUNIT_ASSERT_EQUAL(-1, arr[5]); CPPUNIT_ASSERT_EQUAL(-1, arr[19]); CPPUNIT_ASSERT_EQUAL(202020, arr[20]); arr.add(&dat[5], 5); arr.add(123); arr.add(456); CPPUNIT_ASSERT_EQUAL((hyu32)28, arr.size()); CPPUNIT_ASSERT_EQUAL(-15000, arr[21]); CPPUNIT_ASSERT_EQUAL(19000, arr[25]); CPPUNIT_ASSERT_EQUAL(123, arr[26]); CPPUNIT_ASSERT_EQUAL(456, arr[27]); int x = 222; CPPUNIT_ASSERT_EQUAL(2, arr.issue(x)); x = 202020; CPPUNIT_ASSERT_EQUAL(20, arr.issue(x)); x = 123; CPPUNIT_ASSERT_EQUAL(26, arr.issue(x)); CPPUNIT_ASSERT_EQUAL((hyu32)28, arr.size()); x = 98765; CPPUNIT_ASSERT_EQUAL(28, arr.issue(x)); CPPUNIT_ASSERT_EQUAL(98765, arr[28]); arr.clear(); CPPUNIT_ASSERT_EQUAL((hyu32)0, arr.size()); hyu32 capa = arr.m_capacity; arr.reserve(capa); CPPUNIT_ASSERT(capa != arr.m_capacity); }