https://github.com/Microsoft/CNTK
Raw File
Tip revision: cfec3659da4784a5d2299d82ee505d17e4b75d09 authored by Wayne Xiong on 23 August 2016, 18:00:30 UTC
Merge remote-tracking branch 'origin/jdroppo/cudnn-rnn-lstm' into weixi/lfmmi-2-lstm
Tip revision: cfec365
ConfigUtil.h
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
//

#pragma once

#include <string>
#include <vector>
#include "Config.h"

namespace Microsoft { namespace MSR { namespace CNTK {

// Helper function to get sections that contains specified parameter.
inline std::vector<std::string> TryGetSectionsWithParameter(const ConfigParameters& config, const std::string& parameterName)
{
    std::vector<std::string> sectionNames;
    for (const std::pair<std::string, ConfigParameters>& section : config)
    {
        if (section.second.ExistsCurrent(parameterName))
        {
            sectionNames.push_back(section.first);
        }
    }

    return sectionNames;
}

// Helper function to get sections that contains specified parameter. Throws if the parameter does not exist.
inline std::vector<std::string> GetSectionsWithParameter(const std::string& reader, const ConfigParameters& config, const std::string& parameterName)
{
    auto result = TryGetSectionsWithParameter(config, parameterName);
    if (result.empty())
    {
        RuntimeError("%s requires %s parameter.", reader.c_str(), parameterName.c_str());
    }
    return result;
}

}}}
back to top