2016-02-19 18:38:42 +03:00
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
|
|
|
|
//
|
|
|
|
// DataReader.cpp : Defines the exported functions for the DLL application.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "Basics.h"
|
|
|
|
|
|
|
|
#define DATAREADER_EXPORTS
|
|
|
|
#include "DataReader.h"
|
|
|
|
#include "Config.h"
|
|
|
|
#include "ReaderShim.h"
|
|
|
|
#include "HTKMLFReader.h"
|
|
|
|
#include "HeapMemoryProvider.h"
|
2016-04-01 13:38:53 +03:00
|
|
|
#include "HTKDataDeserializer.h"
|
|
|
|
#include "MLFDataDeserializer.h"
|
2016-06-03 18:03:05 +03:00
|
|
|
#include "StringUtil.h"
|
2016-02-19 18:38:42 +03:00
|
|
|
|
|
|
|
namespace Microsoft { namespace MSR { namespace CNTK {
|
|
|
|
|
|
|
|
// Factory methods for the reader.
|
|
|
|
// TODO: Must be removed when SGD is moved to an untyped matrix.
|
|
|
|
auto factory = [](const ConfigParameters& parameters) -> ReaderPtr
|
|
|
|
{
|
2016-09-06 21:05:13 +03:00
|
|
|
return std::make_shared<HTKMLFReader>(parameters);
|
2016-02-19 18:38:42 +03:00
|
|
|
};
|
|
|
|
|
2016-03-01 06:27:52 +03:00
|
|
|
extern "C" DATAREADER_API void GetReaderF(IDataReader** preader)
|
2016-02-19 18:38:42 +03:00
|
|
|
{
|
|
|
|
*preader = new ReaderShim<float>(factory);
|
|
|
|
}
|
|
|
|
|
2016-03-01 06:27:52 +03:00
|
|
|
extern "C" DATAREADER_API void GetReaderD(IDataReader** preader)
|
2016-02-19 18:38:42 +03:00
|
|
|
{
|
|
|
|
*preader = new ReaderShim<double>(factory);
|
|
|
|
}
|
|
|
|
|
2016-04-01 13:38:53 +03:00
|
|
|
// TODO: Not safe from the ABI perspective. Will be uglified to make the interface ABI.
|
2016-04-15 13:36:08 +03:00
|
|
|
extern "C" DATAREADER_API bool CreateDeserializer(IDataDeserializer** deserializer, const std::wstring& type, const ConfigParameters& deserializerConfig, CorpusDescriptorPtr corpus, bool primary)
|
2016-04-01 13:38:53 +03:00
|
|
|
{
|
2016-06-06 16:23:39 +03:00
|
|
|
if (type == L"HTKFeatureDeserializer")
|
2016-04-01 13:38:53 +03:00
|
|
|
{
|
2016-04-15 13:36:08 +03:00
|
|
|
*deserializer = new HTKDataDeserializer(corpus, deserializerConfig, primary);
|
2016-04-01 13:38:53 +03:00
|
|
|
}
|
2016-06-06 16:23:39 +03:00
|
|
|
else if (type == L"HTKMLFDeserializer")
|
2016-04-01 13:38:53 +03:00
|
|
|
{
|
2016-04-15 13:36:08 +03:00
|
|
|
*deserializer = new MLFDataDeserializer(corpus, deserializerConfig, primary);
|
2016-04-01 13:38:53 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Unknown type.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deserializer created.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-19 18:38:42 +03:00
|
|
|
}}}
|