设为首页 加入收藏

TOP

Caffe源码中各种依赖库的作用及简单使用(五)
2015-11-10 13:45:44 来源: 作者: 【 】 浏览:30
Tags:Caffe 源码 各种 依赖 作用 简单 使用
)))
? ?break;
? printf("key: %p %.*s, data: %p %.*s\n",
? ?key.mv_data, (int)key.mv_size, (char *)key.mv_data,
? ?data.mv_data, (int)data.mv_size, (char *)data.mv_data);
?}
?mdb_cursor_close(cur2);
?E(mdb_txn_commit(txn));


?printf("Restarting cursor outside txn\n");
?E(mdb_txn_begin(env, NULL, 0, &txn));
?E(mdb_cursor_open(txn, dbi, &cursor));
?for (op = MDB_FIRST, i = 0; i <= 32; op = MDB_NEXT, i++) {
? if (RES(MDB_NOTFOUND, mdb_cursor_get(cursor, &key, &data, op)))
? ?break;
? printf("key: %p %.*s, data: %p %.*s\n",
? ?key.mv_data, (int)key.mv_size, (char *)key.mv_data,
? ?data.mv_data, (int)data.mv_size, (char *)data.mv_data);
?}
?mdb_cursor_close(cursor);
?mdb_txn_abort(txn);


?mdb_dbi_close(env, dbi);
?mdb_env_close(env);


?return 0;
}


void ListMsg(const lm::helloworld& msg) {
?std::cout << msg.id() << std::endl;
?std::cout << msg.str() << std::endl;
}


int test_ProtoBuf()
{
?//http://www.ibm.com/developerworks/cn/linux/l-cn-gpb/
?//http://blog.163.com/jiang_tao_2010/blog/static/12112689020114305013458/
?//http://www.cnblogs.com/dkblog/archive/2012/03/27/2419010.html
?// 1-->首先编写一个ml.helloworld.proto文件,内容如下:
?/*
?syntax = "proto2";
?package lm;


?message helloworld
?{
? required int32? ? id = 1;? // ID
? required string? ? str = 2;? // str
? optional int32? ? opt = 3;? //optional field
?}
?*/


?// 2-->利用protoc.exe生成ml.helloworld.pb.h和ml.hellowrold.ph.cc


?// 3-->Writer,将把一个结构化数据写入磁盘,以便其他人来读取
?/*lm::helloworld msg1;
?msg1.set_id(101);
?msg1.set_str("hello");


?// Write the new address book back to disk.
?std::fstream output("./log", std::ios::out | std::ios::trunc | std::ios::binary);
?if (!msg1.SerializeToOstream(&output)) {
? std::cerr << "Failed to write msg." << std::endl;
? return -1;
?}*/


?// 4-->Reader,读取结构化数据,log文件
?lm::helloworld msg2;
?
?std::fstream input("./log", std::ios::in | std::ios::binary);
?if (!msg2.ParseFromIstream(&input)) {
? std::cerr << "Failed to parse address book." << std::endl;
? return -1;
?}


?ListMsg(msg2);


?return 0;
}


#define H5FILE_NAME? "E:/tmp/HDF5/SDS.h5"
#define DATASETNAME? "IntArray"
#define NX? ?5 /* dataset dimensions */
#define NY? ?6
#define RANK? ?2


int test_HDF5_write_HDF5_Data()
{
?hid_t? ? ? file, dataset;? ? ? ? /* file and dataset handles */
?hid_t? ? ? datatype, dataspace;? /* handles */
?hsize_t? ? dimsf[2];? ? ? ? ? ? ? /* dataset dimensions */
?herr_t? ? ? status;
?int? ? ? ? data[NX][NY];? ? ? ? ? /* data to write */
?int? ? ? ? i, j;


?//Data? and output buffer initialization.
?for (j = 0; j < NX; j++)
? for (i = 0; i < NY; i++)
? ?data[j][i] = i + j + 100;//changed
?/*
?* 0 1 2 3 4 5
?* 1 2 3 4 5 6
?* 2 3 4 5 6 7
?* 3 4 5 6 7 8
?* 4 5 6 7 8 9
?*/


?/*
?* Create a new file using H5F_ACC_TRUNC access,
?* default file creation properties, and default file
?* access properties.
?*/
?file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);


?/*
?* Describe the size of the array and create the data space for fixed
?* size dataset.
?*/
?dimsf[0] = NX;
?dimsf[1] = NY;
?dataspace = H5Screate_simple(RANK, dimsf, NULL);


?/*
?* Define datatype for the data in the file.
?* We will store little endian INT numbers.
?*/
?datatype = H5Tcopy(H5T_NATIVE_INT);
?status = H5Tset_order(datatype, H5T_ORDER_LE);


?/*
?* Create a new dataset within the file using defined dataspace and
?* datatype and default dataset creation properties.
?*/
?dataset = H5Dcreate2(file, DATASETNAME, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);


?//Write the data to the dataset using default transfer properties.
?status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);


?//Close/release resources.
?H5Sclose(dataspace);
?H5Tclose(data

首页 上一页 2 3 4 5 6 下一页 尾页 5/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇AngularJS 的异步服务测试与Mocki.. 下一篇Linux下多线程编程互斥锁和条件变..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: