Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
[IO] Refactor, make it more consistent with CXXNet IO
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen committed Sep 25, 2015
1 parent bad86cb commit 0e02bd7
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 386 deletions.
55 changes: 9 additions & 46 deletions include/mxnet/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class IIterator : public dmlc::DataIter<DType> {
/*! \brief store the name of each data, it could be used for making NDArrays */
std::vector<std::string> data_names;
/*! \brief set data name to each attribute of data */
inline void SetDataName(const std::string data_name){
inline void SetDataName(const std::string data_name) {
data_names.push_back(data_name);
}
}; // class IIterator
Expand Down Expand Up @@ -67,7 +67,7 @@ struct DataBatch {
}; // struct DataBatch

/*! \brief typedef the factory function of data iterator */
typedef IIterator<DataBatch> *(*DataIteratorFactory)();
typedef std::function<IIterator<DataBatch> *()> DataIteratorFactory;
/*!
* \brief Registry entry for DataIterator factory functions.
*/
Expand All @@ -83,51 +83,14 @@ struct DataIteratorReg
*
* \code
* // example of registering a mnist iterator
* REGISTER_IO_ITERATOR(MNIST, MNISTIterator)
* .describe("Mnist data iterator");
*
* \endcode
*/
#define MXNET_REGISTER_IO_ITER(name, DataIteratorType) \
static ::mxnet::IIterator<DataBatch>* __create__ ## DataIteratorType ## __() { \
return new DataIteratorType; \
} \
DMLC_REGISTRY_REGISTER(::mxnet::DataIteratorReg, DataIteratorReg, name) \
.set_body(__create__ ## DataIteratorType ## __)
/*!
* \brief Macro to register chained Iterators
*
* \code
* // example of registering a imagerec iterator
* MXNET_REGISTER_IO_CHAINED_ITERATOR(ImageRec, ImageRecordIter, BatchIter)
* .describe("batched image record data iterator");
*
* REGISTER_IO_ITE(MNISTIter)
* .describe("Mnist data iterator")
* .set_body([]() {
* return new PrefetcherIter(new MNISTIter());
* });
* \endcode
*/
#define MXNET_REGISTER_IO_CHAINED_ITER(name, ChainedDataIterType, HoldingDataIterType) \
static ::mxnet::IIterator<DataBatch>* __create__ ## ChainedDataIterType ## __() { \
return new HoldingDataIterType(new ChainedDataIterType); \
} \
DMLC_REGISTRY_REGISTER(::mxnet::DataIteratorReg, DataIteratorReg, name) \
.set_body(__create__ ## ChainedDataIterType ## __)
/*!
* \brief Macro to register three chained Iterators
*
* \code
* // example of registering a imagerec iterator
* MXNET_REGISTER_IO_CHAINED_ITERATOR(ImageRecordIter,
* ImageRecordIter, ImageRecBatchLoader, Prefetcher)
* .describe("batched image record data iterator");
*
* \endcode
*/
#define MXNET_REGISTER_IO_THREE_CHAINED_ITER(\
name, FirstIterType, SecondIterType, ThirdIterType) \
static ::mxnet::IIterator<DataBatch>* __create__ ## ThirdIterType ## __() { \
return new FirstIterType(new SecondIterType(new ThirdIterType)); \
} \
DMLC_REGISTRY_REGISTER(::mxnet::DataIteratorReg, DataIteratorReg, name) \
.set_body(__create__ ## ThirdIterType ## __)

#define MXNET_REGISTER_IO_ITER(name) \
DMLC_REGISTRY_REGISTER(::mxnet::DataIteratorReg, DataIteratorReg, name)
} // namespace mxnet
#endif // MXNET_IO_H_
5 changes: 0 additions & 5 deletions src/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ inline int GetNumThreadPerGPU() {
* \brief Random Engine
*/
typedef std::mt19937 RANDOM_ENGINE;
// Get a double float, prnd is the pointer to a Random Engine
#define NextDouble(prnd) std::generate_canonical<float, 10>(*prnd)
// Get a random int in [0, range)
#define NextUInt32(range, prnd) static_cast<uint32_t> \
(floor(std::generate_canonical<float, 10>(*prnd) * range))

/*!
* \brief Helper functions.
Expand Down
Loading

0 comments on commit 0e02bd7

Please sign in to comment.