Skip to content

Commit

Permalink
Make WhereNode work in the light of gaps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemens Marschner committed Apr 6, 2016
1 parent 36c4be3 commit 8d5488d
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Source/ComputationNetworkLib/ReshapingNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,24 @@ template <class ElemType>
outMBLayout->InitAsPackedSequences(SequenceLengthVector(sequences, indexSequences), /*temp*/m_placementBuffer, /*temp*/m_rowAllocationsBuffer);
// copy to output
vector<ElemType> buf(outMBLayout->GetNumCols(), numeric_limits<ElemType>::quiet_NaN()); // STL cannot easily avoid initializing, so we might as well init with NaN for gaps
for (size_t i = 0; i < sequences.size(); i++)
for (size_t i = 0, j = 0; i < sequences.size();)
{
let& seq = outMBLayout->GetAllSequences()[i];
if (seq.seqId == GAP_SEQUENCE_ID) // gaps will keep the NaN
if (sequences[i].seqId == GAP_SEQUENCE_ID) // gaps will keep the NaN
{
++i;
continue;
}
let& seq = outMBLayout->GetAllSequences()[j];
if (seq.seqId == GAP_SEQUENCE_ID) // When would we see this?
{
++j;
continue;
}
let& indexSequence = indexSequences[i];
for (size_t t = 0; t < seq.GetNumTimeSteps(); t++)
buf[outMBLayout->GetColumnIndex(seq, t)] = (ElemType)indexSequence[t];
/*
BUGBUG: a debug assert when doing this:
TakeRight (N, x) = BS.Sequences._Take (FutureValue, N, x)
Last(x) = TakeRight(1, x)
*/
++i;
++j;
}
// the result will be kept in CPUDEVICE, since most likely we will access it again in PackedIndexNode
Value().TransferToDeviceIfNotThere(CPUDEVICE, /*isBeingMoved=*/ true, /*emptyTransfer=*/ true, /*updatePreferredDevice=*/ true);
Expand Down

0 comments on commit 8d5488d

Please sign in to comment.