changed MakeRuntimeObject() to return a shared_ptr<Object> instead of shared_ptr<C>

This commit is contained in:
Frank Seide 2015-08-28 23:32:59 -07:00
Родитель 5e9296bc9d
Коммит 262de81085
3 изменённых файлов: 11 добавлений и 9 удалений

Просмотреть файл

@ -368,7 +368,7 @@ namespace Microsoft { namespace MSR { namespace CNTK { namespace BS {
} }
// factory function for ComputationNodes // factory function for ComputationNodes
template<> template<>
shared_ptr<ComputationNode> MakeRuntimeObject<ComputationNode>(const IConfigRecordPtr configp) shared_ptr<Object> MakeRuntimeObject<ComputationNode>(const IConfigRecordPtr configp)
{ {
let & config = *configp; let & config = *configp;
let classIdParam = config[L"class"]; let classIdParam = config[L"class"];
@ -412,7 +412,7 @@ namespace Microsoft { namespace MSR { namespace CNTK { namespace BS {
// The difference to the above is that the children are not resolved immediately but later during network connection. // The difference to the above is that the children are not resolved immediately but later during network connection.
// This takes the record as a shared_ptr so that we can keep it inside a lambda. // This takes the record as a shared_ptr so that we can keep it inside a lambda.
template<> template<>
shared_ptr<RecurrentComputationNode> MakeRuntimeObject<RecurrentComputationNode>(const IConfigRecordPtr configp) shared_ptr<Object> MakeRuntimeObject<RecurrentComputationNode>(const IConfigRecordPtr configp)
{ {
let & config = *configp; let & config = *configp;
let classIdParam = config[L"class"]; let classIdParam = config[L"class"];
@ -544,12 +544,12 @@ namespace Microsoft { namespace MSR { namespace CNTK { namespace BS {
{ {
return MakeRuntimeObject<C>(config); return MakeRuntimeObject<C>(config);
}; };
rtInfo.IsConfigRecord = is_base_of<IConfigRecord, C>::value; rtInfo.isConfigRecord = is_base_of<IConfigRecord, C>::value;
return rtInfo; return rtInfo;
} }
// note: don't forget to duplicate the above when we move this out // note: don't forget to duplicate the above when we move this out
#if 0 #if 1
// get information about configurable runtime types // get information about configurable runtime types
const ConfigurableRuntimeType * FindExternalRuntimeTypeInfo(const wstring & typeId) const ConfigurableRuntimeType * FindExternalRuntimeTypeInfo(const wstring & typeId)
{ {
@ -897,6 +897,8 @@ namespace Microsoft { namespace MSR { namespace CNTK { namespace BS {
else if (e->op == L"^") return MakePrimitiveConfigValuePtr(left ^ right, e->location, exprPath); else if (e->op == L"^") return MakePrimitiveConfigValuePtr(left ^ right, e->location, exprPath);
else return CompOp<bool>(e, left, right, exprPath); else return CompOp<bool>(e, left, right, exprPath);
}; };
// NodeOps handle the magic CNTK types, that is, infix operations between ComputeNode objects.
// TODO: rename to MagicOps
static ConfigValuePtr NodeOp(ExpressionPtr e, ConfigValuePtr leftVal, ConfigValuePtr rightVal, const wstring & exprPath) static ConfigValuePtr NodeOp(ExpressionPtr e, ConfigValuePtr leftVal, ConfigValuePtr rightVal, const wstring & exprPath)
{ {
if (rightVal.Is<Double>()) // ComputeNode * scalar if (rightVal.Is<Double>()) // ComputeNode * scalar
@ -943,7 +945,7 @@ namespace Microsoft { namespace MSR { namespace CNTK { namespace BS {
// This lists all infix operators with lambdas for evaluating them. // This lists all infix operators with lambdas for evaluating them.
static map<wstring, InfixOps> infixOps = static map<wstring, InfixOps> infixOps =
{ {
// NumbersOp StringsOp BoolOp ComputeNodeOp DictOp // NumbersOp StringsOp BoolOp ComputeNodeOp DictOp TODO: this comment is incomplete
{ L"*", InfixOps(NumOp, BadOp, BadOp, NodeOp, NodeOp, NodeOp, BadOp) }, { L"*", InfixOps(NumOp, BadOp, BadOp, NodeOp, NodeOp, NodeOp, BadOp) },
{ L"/", InfixOps(NumOp, BadOp, BadOp, BadOp, BadOp, BadOp, BadOp) }, { L"/", InfixOps(NumOp, BadOp, BadOp, BadOp, BadOp, BadOp, BadOp) },
{ L".*", InfixOps(BadOp, BadOp, BadOp, NodeOp, BadOp, BadOp, BadOp) }, { L".*", InfixOps(BadOp, BadOp, BadOp, NodeOp, BadOp, BadOp, BadOp) },
@ -1019,7 +1021,7 @@ namespace Microsoft { namespace MSR { namespace CNTK { namespace BS {
Fail(L"unknown runtime type " + e->id, e->location); Fail(L"unknown runtime type " + e->id, e->location);
// form the config record // form the config record
let dictExpr = e->args[0]; let dictExpr = e->args[0];
let argsExprPath = rtInfo->IsConfigRecord ? L"" : exprPath; // reset expr-name path if object exposes a dictionary let argsExprPath = rtInfo->isConfigRecord ? L"" : exprPath; // reset expr-name path if object exposes a dictionary
let value = ConfigValuePtr(rtInfo->construct(ConfigRecordFromDictExpression(dictExpr, scope, argsExprPath)), e->location, exprPath); // this constructs it let value = ConfigValuePtr(rtInfo->construct(ConfigRecordFromDictExpression(dictExpr, scope, argsExprPath)), e->location, exprPath); // this constructs it
// if object has a name, we set it // if object has a name, we set it
let valueWithName = dynamic_cast<HasName*>(value.get()); let valueWithName = dynamic_cast<HasName*>(value.get());

Просмотреть файл

@ -271,7 +271,7 @@ namespace Microsoft{ namespace MSR { namespace CNTK { namespace BS {
// create a runtime object from its type --general case // create a runtime object from its type --general case
// There can be specializations of this that instantiate objects that do not take ConfigRecords or involve mapping like ComputationNode. // There can be specializations of this that instantiate objects that do not take ConfigRecords or involve mapping like ComputationNode.
template<typename C> template<typename C>
shared_ptr<C> MakeRuntimeObject(const IConfigRecordPtr config) shared_ptr<Object> MakeRuntimeObject(const IConfigRecordPtr config)
{ {
return make_shared<C>(config); return make_shared<C>(config);
} }

Просмотреть файл

@ -90,7 +90,7 @@ namespace Microsoft { namespace MSR { namespace CNTK { namespace BS { // or BS::
// - a bool saying whether T derives from IConfigRecord // - a bool saying whether T derives from IConfigRecord
struct ConfigurableRuntimeType struct ConfigurableRuntimeType
{ {
bool IsConfigRecord; // exposes IConfigRecord --in this case the expression name is computed differently, namely relative to this item bool isConfigRecord; // exposes IConfigRecord --in this case the expression name is computed differently, namely relative to this item
function<shared_ptr<Object>(const IConfigRecordPtr)> construct; // lambda to construct an object of this class function<shared_ptr<Object>(const IConfigRecordPtr)> construct; // lambda to construct an object of this class
}; };