Skip to content

Commit

Permalink
added another overload to convert ConfigValuePtr to ConfigArray&, whi…
Browse files Browse the repository at this point in the history
…ch fixes a bug in reading out an array
  • Loading branch information
frankseide committed Nov 22, 2015
1 parent 5ab06be commit 2e2de8e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Common/Include/ScriptableObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ namespace Microsoft { namespace MSR { namespace ScriptableObjects {
// - ConfigLambdas (default values of named arguments)

struct IConfigRecord;
class ConfigArray;

// TODO: separate this out from BrainScript to an interface that still does type casts--possible?
class ConfigValuePtr : public shared_ptr<Object>
Expand Down Expand Up @@ -248,6 +249,7 @@ namespace Microsoft { namespace MSR { namespace ScriptableObjects {
// Linux gcc barfs on this ^^ for 'us = (double)((wstring)arg).size();' due to some ambiguity error (while it works fine with Visual Studio).
// If you encounter this, instead say 'us = (double)((const wstring&)arg).size();' with a &. Don't forget the const (I have seen broken typecasts without).
operator const IConfigRecord &() const { return AsRef<IConfigRecord>(); }
operator const ConfigArray &() const { return AsRef<ConfigArray>(); }
operator double() const { return AsRef<Double>(); }
operator float() const { return (float) AsRef<Double>(); }
operator bool() const { return AsRef<Bool>(); }
Expand Down
6 changes: 3 additions & 3 deletions MachineLearning/CNTK/CNTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ void DoEvalBeamSearch(const ConfigParameters& config, IDataReader<ElemType>& rea
eval.BeamSearch(&reader, testDataWriter, evalNodeNamesVector, outputNodeNamesVector, mbSize[0], beamWidth, epochSize);
}

// TODO: per discussion with Dong Yu, Guoguo Chen, and Yu Zhang, this function can be removed.
template <typename ElemType>
void DoSequenceTrain(const ConfigParameters& config)
{
Expand Down Expand Up @@ -1774,13 +1775,12 @@ int wmainWithBS(int argc, wchar_t* argv[]) // called from wmain which is a wra

// MAIN LOOP that executes the actions
auto actionsVal = config[L"actions"];
// Note: weird behavior. If 'actions' is a single value (rather than an array) then it will have been resolved already. That means, it has already completed the action.
// Note: weird behavior. If 'actions' is a scalar value (rather than an array) then it will have been resolved already after the above call. That means, it has already completed its action!
// Not pretty, but a direct consequence of the lazy evaluation. The only good solution would be to have a syntax for arrays including length 0 and 1.
// Since this in the end behaves indistinguishable from the array loop below, we will keep it for now.
if (actionsVal.Is<ScriptableObjects::ConfigArray>())
{
const ScriptableObjects::ConfigArray & actions = actionsVal.AsRef<ScriptableObjects::ConfigArray>();
// Note: We must use AsRef<>() here. Just assigning (using the auto-typecast) will make a copy, which will ^^ not work since the elements are not yet resolved.
const ScriptableObjects::ConfigArray & actions = actionsVal;
for (int i = actions.GetIndexRange().first; i <= actions.GetIndexRange().second; i++)
{
actions.At(i, [](const wstring &){}); // this will evaluate and thus execute the action
Expand Down
1 change: 1 addition & 0 deletions MachineLearning/CNTKSGDLib/SGD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
TrainOrAdaptModel(startEpoch, net, refNet, refNode, trainSetDataReader, validationSetDataReader);
}

// TODO: per discussion with Dong Yu, Guoguo Chen, and Yu Zhang, this function can be removed.
template<class ElemType>
void SGD<ElemType>::SequenceTrain(IComputationNetBuilder<ElemType>* netBuilder, wstring origModelFileName,
IDataReader<ElemType>* trainSetDataReader, IDataReader<ElemType>* validationSetDataReader,
Expand Down

0 comments on commit 2e2de8e

Please sign in to comment.