Skip to content

Commit

Permalink
Normalize files with mixed line endings (to DOS LE)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahilleb-msft committed Nov 17, 2015
1 parent a2f3932 commit 403cc42
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 157 deletions.
4 changes: 2 additions & 2 deletions Common/Include/ScriptableObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Microsoft { namespace MSR { namespace ScriptableObjects {
// - C++ primitives like 'double' -> wrap in a Wrapper first then in a BoxOf, e.g. Number = BoxOf<Wrapped<double>>

struct Object { virtual ~Object() { } };


// indicates that the object has a name should be set from the expression path

struct HasName { virtual void SetName(const wstring & name) = 0; };
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace Microsoft { namespace MSR { namespace ScriptableObjects {
// TODO: unify with ComputationNodeBase
// -----------------------------------------------------------------------

class ComputationNodeObject : public Object { }; // a base class for all nodes (that has no template parameter)
class ComputationNodeObject : public Object { }; // a base class for all nodes (that has no template parameter)

// -----------------------------------------------------------------------
// HasToString -- trait to indicate an object can print their content
Expand Down
176 changes: 88 additions & 88 deletions Common/Include/Sequences.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,97 +567,97 @@ namespace Microsoft { namespace MSR { namespace CNTK {
// -----------------------------------------------------------------------

template<class ElemType>
static inline Matrix<ElemType> DataSliceWithMBLayout(Matrix<ElemType> & data,
const FrameRange & frameRange/*select frame or entire batch*/,
const MBLayoutPtr & pMBLayout/*the MB layout of 'data'*/)
{
// MBLayout of data and of FrameRange must be identical pointers,
// or in case of broadcasting, respective parent pointers.
// MBLayouts that are identical in content but not object identity (pointer) are not admissible.
// For those cases, use a ReconcileMBLayout node.
if (frameRange.m_pMBLayout != pMBLayout)
{
// if broadcast allowed then it is allowed to broadcast from an outer-loop value
// Currently, the only 'outer' loop we have is to have no layout.
if (frameRange.m_broadcastAllowed && !pMBLayout && data.GetNumCols() == 1)
return data.AsReference();
if (frameRange.m_pMBLayout && pMBLayout && *frameRange.m_pMBLayout == *pMBLayout)
LogicError("DataSlice: frameRange's MBLayout inconsistent with matrix. They are compatible though--are you missing a ReconcileMBLayout operation?");
else
LogicError("DataSlice: frameRange's MBLayout inconsistent with matrix");
}
// if FrameRange refers to whole minibatch (map mode)
// or if we don't even have a layout
// then return the whole matrix
// but as a reference (e.g. it cannot be resized)
if (!pMBLayout || frameRange.IsAllFrames())
{
if (frameRange.seqIndex == SIZE_MAX)
return data.AsReference();
else
{
if (!pMBLayout)
LogicError("DataSlice: Attempting to retrieve a parallel sequence from data without layout.");
#if 1
else
LogicError("DataSlice: To retrieve a parallel sequence, implement Matrix::RowSlice() first!");
#else
// get a reshaped view that stacks all sequences into T long vectors
auto mat = data.ColumnSlice(0, data.GetNumCols());
mat.Resize(data.GetNumRows() * pMBLayout->GetNumParallelSequences(), data.GetNumRows() / pMBLayout->GetNumParallelSequences());
return mat; // .RowSlice(frameRange.seqIndex * data.GetNumRows());
// TODO: Why does RowSlice() not exist? Seems simple. Is there a hidden assumption of contiguous memory?#endif
#endif
}
}
// FrameRange refers to a time slice -> return that
else
{
size_t numParallelSequences = pMBLayout->GetNumParallelSequences();
size_t startColumn = frameRange.t() * numParallelSequences;
if (frameRange.seqIndex == SIZE_MAX)
return data.ColumnSlice(startColumn, numParallelSequences);
else
return data.ColumnSlice(startColumn + frameRange.seqIndex, 1);
}
}
static inline Matrix<ElemType> DataSliceWithMBLayout(Matrix<ElemType> & data,
const FrameRange & frameRange/*select frame or entire batch*/,
const MBLayoutPtr & pMBLayout/*the MB layout of 'data'*/)
{
// MBLayout of data and of FrameRange must be identical pointers,
// or in case of broadcasting, respective parent pointers.
// MBLayouts that are identical in content but not object identity (pointer) are not admissible.
// For those cases, use a ReconcileMBLayout node.
if (frameRange.m_pMBLayout != pMBLayout)
{
// if broadcast allowed then it is allowed to broadcast from an outer-loop value
// Currently, the only 'outer' loop we have is to have no layout.
if (frameRange.m_broadcastAllowed && !pMBLayout && data.GetNumCols() == 1)
return data.AsReference();
if (frameRange.m_pMBLayout && pMBLayout && *frameRange.m_pMBLayout == *pMBLayout)
LogicError("DataSlice: frameRange's MBLayout inconsistent with matrix. They are compatible though--are you missing a ReconcileMBLayout operation?");
else
LogicError("DataSlice: frameRange's MBLayout inconsistent with matrix");
}
// if FrameRange refers to whole minibatch (map mode)
// or if we don't even have a layout
// then return the whole matrix
// but as a reference (e.g. it cannot be resized)
if (!pMBLayout || frameRange.IsAllFrames())
{
if (frameRange.seqIndex == SIZE_MAX)
return data.AsReference();
else
{
if (!pMBLayout)
LogicError("DataSlice: Attempting to retrieve a parallel sequence from data without layout.");
#if 1
else
LogicError("DataSlice: To retrieve a parallel sequence, implement Matrix::RowSlice() first!");
#else
// get a reshaped view that stacks all sequences into T long vectors
auto mat = data.ColumnSlice(0, data.GetNumCols());
mat.Resize(data.GetNumRows() * pMBLayout->GetNumParallelSequences(), data.GetNumRows() / pMBLayout->GetNumParallelSequences());
return mat; // .RowSlice(frameRange.seqIndex * data.GetNumRows());
// TODO: Why does RowSlice() not exist? Seems simple. Is there a hidden assumption of contiguous memory?#endif
#endif
}
}
// FrameRange refers to a time slice -> return that
else
{
size_t numParallelSequences = pMBLayout->GetNumParallelSequences();
size_t startColumn = frameRange.t() * numParallelSequences;
if (frameRange.seqIndex == SIZE_MAX)
return data.ColumnSlice(startColumn, numParallelSequences);
else
return data.ColumnSlice(startColumn + frameRange.seqIndex, 1);
}
}

// -----------------------------------------------------------------------
// MaskMissingColumnsTo() -- function to set gaps to zero or NaN
// -----------------------------------------------------------------------

// This sets MB columns to 0 (or any 'val') that have the NoLabel or NoFeature flag set.
// Such situation happens when packing multiple sequences for parallel processing--there will be some gaps, which are flagged by these flags.
// Nodes that operate in 'map' style (input(j) -> output(j) independently) can ignore this; it will be garbage-in-garbage-out.
// However, nodes that 'reduce' minibatches (e.g. computing the sum of all frames across all sequences) must deal with the garbage.
// This function sets those to 0, assuming that now they can be reduced without affecting the result.
// This function can operate on the whole range or on a selected single frame and/or a single sequence.
// It is indirectly guarded by the m_maskMissingColumnsToZero flag, which, if false, will install a layout with IsAllNone() to be true. TODO: we better always install the same layout, and instead test m_maskMissingColumnsToZero here.
// Note that existing 'reduce' style operations--the criterion nodes and gradient computation--already call this. --BUGBUG: They can't, wrong layout!
// Warning: The layout used here must match the matrix. E.g. don't pass a child's matrix from a criterion node (use Inputs(x)->MaskMissing{Values,Gradient}ColumnsToZero() instead.
template<class ElemType>
static inline bool MaskMissingColumnsTo(Matrix<ElemType>& matrixToBeMasked, const MBLayoutPtr & pMBLayout, const FrameRange & frameRange, ElemType val)
{
bool foundLabelOrFeatureMissing = false; // return value: set to true if either nolabel or feature missing is processed

if (pMBLayout && !pMBLayout->IsAllNone()) // TODO: This should check whether there are any gaps.
{
size_t nT = pMBLayout->GetNumTimeSteps();
size_t nS = pMBLayout->GetNumParallelSequences();

if (matrixToBeMasked.GetNumCols() != nT * nS)
LogicError("MaskMissingColumnsToZero: pMBLayout->m_minibatchPackingFlags should have one element for each timestep of all streams. Check feature reader. ");

shared_ptr<Matrix<char>> columnsValidityMask = pMBLayout->GetColumnsValidityMask(frameRange, matrixToBeMasked.GetDeviceId());
if (columnsValidityMask != nullptr)
{
auto matrixSliceToMask = DataSliceWithMBLayout(matrixToBeMasked, frameRange, pMBLayout);
foundLabelOrFeatureMissing = true;
matrixSliceToMask.MaskColumnsValue(*columnsValidityMask, val);
}
}

return foundLabelOrFeatureMissing;
}

// This sets MB columns to 0 (or any 'val') that have the NoLabel or NoFeature flag set.
// Such situation happens when packing multiple sequences for parallel processing--there will be some gaps, which are flagged by these flags.
// Nodes that operate in 'map' style (input(j) -> output(j) independently) can ignore this; it will be garbage-in-garbage-out.
// However, nodes that 'reduce' minibatches (e.g. computing the sum of all frames across all sequences) must deal with the garbage.
// This function sets those to 0, assuming that now they can be reduced without affecting the result.
// This function can operate on the whole range or on a selected single frame and/or a single sequence.
// It is indirectly guarded by the m_maskMissingColumnsToZero flag, which, if false, will install a layout with IsAllNone() to be true. TODO: we better always install the same layout, and instead test m_maskMissingColumnsToZero here.
// Note that existing 'reduce' style operations--the criterion nodes and gradient computation--already call this. --BUGBUG: They can't, wrong layout!
// Warning: The layout used here must match the matrix. E.g. don't pass a child's matrix from a criterion node (use Inputs(x)->MaskMissing{Values,Gradient}ColumnsToZero() instead.
template<class ElemType>
static inline bool MaskMissingColumnsTo(Matrix<ElemType>& matrixToBeMasked, const MBLayoutPtr & pMBLayout, const FrameRange & frameRange, ElemType val)
{
bool foundLabelOrFeatureMissing = false; // return value: set to true if either nolabel or feature missing is processed

if (pMBLayout && !pMBLayout->IsAllNone()) // TODO: This should check whether there are any gaps.
{
size_t nT = pMBLayout->GetNumTimeSteps();
size_t nS = pMBLayout->GetNumParallelSequences();

if (matrixToBeMasked.GetNumCols() != nT * nS)
LogicError("MaskMissingColumnsToZero: pMBLayout->m_minibatchPackingFlags should have one element for each timestep of all streams. Check feature reader. ");

shared_ptr<Matrix<char>> columnsValidityMask = pMBLayout->GetColumnsValidityMask(frameRange, matrixToBeMasked.GetDeviceId());
if (columnsValidityMask != nullptr)
{
auto matrixSliceToMask = DataSliceWithMBLayout(matrixToBeMasked, frameRange, pMBLayout);
foundLabelOrFeatureMissing = true;
matrixSliceToMask.MaskColumnsValue(*columnsValidityMask, val);
}
}

return foundLabelOrFeatureMissing;
}

}}}
2 changes: 1 addition & 1 deletion DataReader/DSSMReader/DSSMReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DSSMReader : public IDataReader<ElemType>
bool m_partialMinibatch; // a partial minibatch is allowed
LabelKind m_labelType; // labels are categories, create mapping table
msra::dbn::randomordering m_randomordering; // randomizing class
MBLayoutPtr m_pMBLayout;
MBLayoutPtr m_pMBLayout;

std::wstring m_labelsName;
std::wstring m_featuresName;
Expand Down
2 changes: 1 addition & 1 deletion DataReader/LibSVMBinaryReader/LibSVMBinaryReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class LibSVMBinaryReader : public IDataReader<ElemType>
bool m_partialMinibatch; // a partial minibatch is allowed
LabelKind m_labelType; // labels are categories, create mapping table
msra::dbn::randomordering m_randomordering; // randomizing class
MBLayoutPtr m_pMBLayout;
MBLayoutPtr m_pMBLayout;

std::wstring m_labelsName;
std::wstring m_labelsCategoryName;
Expand Down
10 changes: 5 additions & 5 deletions MachineLearning/CNTKComputationNetworkLib/InputAndParamNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace Microsoft { namespace MSR { namespace CNTK {
fstream >> rows >> cols;

SetDims(rows, cols);
LoadFunctionValues(fstream);
LoadFunctionValues(fstream);

m_imageLayout = ImageLayoutWHC(1, rows, 1);
}
Expand Down Expand Up @@ -350,8 +350,8 @@ namespace Microsoft { namespace MSR { namespace CNTK {
Inputs(1)->FunctionValues().TransferFromDeviceToDevice(input0DeviceId, input1DeviceId);
}

virtual void /*ComputationNode::*/ComputeInputPartial(const size_t inputIndex, const FrameRange & frameRange) override
{
virtual void /*ComputationNode::*/ComputeInputPartial(const size_t inputIndex, const FrameRange & frameRange) override
{
if (frameRange.IsAllFrames()) { ComputeInputPartialMap(inputIndex); return; } // TODO: remove these one by one
if (inputIndex > 1)
InvalidArgument("LookupTable operation only takes two inputs.");
Expand Down Expand Up @@ -573,8 +573,8 @@ namespace Microsoft { namespace MSR { namespace CNTK {
Matrix<ElemType>::ScaleAndAdd(1.0, GradientValues(), Inputs(inputIndex)->GradientValues());
}

virtual void /*ComputationNode::*/ComputeInputPartial(const size_t inputIndex, const FrameRange & frameRange) override
{
virtual void /*ComputationNode::*/ComputeInputPartial(const size_t inputIndex, const FrameRange & frameRange) override
{
if (frameRange.IsAllFrames()) { ComputeInputPartialMap(inputIndex); return; } // TODO: remove these one by one
assert(m_functionValues->GetNumRows() == GradientValues().GetNumRows()); // original used m_functionValues->GetNumRows() for loop dimension
assert(m_pMBLayout);
Expand Down
40 changes: 20 additions & 20 deletions MachineLearning/CNTKSGDLib/DataReaderHelpers.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// DataReaderHelper.h -- helper functions that understand both DataReader and ComputationNetwork

#pragma once

#include "Basics.h"
#include "DataReader.h"
#include "ComputationNetwork.h"
#include "MPIWrapper.h"
#include <string>
#include <map>

#include "Basics.h"
#include "DataReader.h"
#include "ComputationNetwork.h"
#include "MPIWrapper.h"
#include <string>
#include <map>
#include "TrainingCriterionNodes.h"

namespace Microsoft { namespace MSR { namespace CNTK {

/*static*/ struct DataReaderHelpers
{
// -------------------------------------------------------------------
namespace Microsoft { namespace MSR { namespace CNTK {

/*static*/ struct DataReaderHelpers
{
// -------------------------------------------------------------------
// DecimateMinibatch - decimate minibatch for parallelization
// -------------------------------------------------------------------
// -------------------------------------------------------------------

// We sub-sample the parallel utterances.
template<class ElemType>
Expand Down Expand Up @@ -96,15 +96,15 @@ namespace Microsoft { namespace MSR { namespace CNTK {
pNewMBLayout->Set(id, t, pMBLayout->Get(id + sent_start, t));
pMBLayout->MoveFrom(pNewMBLayout); // update layout in-place
}

// -------------------------------------------------------------------

// -------------------------------------------------------------------
// GetMinibatchIntoNetwork() -- get one minibatch from Reader (this->trainSetDataReader) into Network (this->net)
// Returns false if end of epoch has been reached.
// If not, then actualMBSize is set. Note that 0 is a valid value to be returned for actualMBSize, caller must handle that correctly.
// -------------------------------------------------------------------
// -------------------------------------------------------------------

// Note: Later, a function like this will become part of the reader interface.
// TODO: callers of this often do ComputationNetwork::UpdateEvalTimeStamps(featureNodes) and also for labels; we should eliminate the need for this.
// TODO: callers of this often do ComputationNetwork::UpdateEvalTimeStamps(featureNodes) and also for labels; we should eliminate the need for this.
template<class ElemType>
static bool GetMinibatchIntoNetwork(IDataReader<ElemType>& trainSetDataReader,
ComputationNetwork& net,
Expand Down Expand Up @@ -188,6 +188,6 @@ namespace Microsoft { namespace MSR { namespace CNTK {

return true;
}
};

}}}
};

}}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// F. Seide, V-hansu

#define _CRT_SECURE_NO_WARNINGS // "secure" CRT not available on all platforms --add this at the top of all CPP files that give "function or variable may be unsafe" warnings

#define _CRT_SECURE_NO_WARNINGS // "secure" CRT not available on all platforms --add this at the top of all CPP files that give "function or variable may be unsafe" warnings

#include "BestGpu.h" // for CPUONLY
#include "latticearchive.h" // we implement parts of class lattice
#include "simple_checked_arrays.h"
Expand Down Expand Up @@ -865,4 +865,4 @@ namespace msra { namespace lattices {
emulatemmierrorsignal (thisedgealignments.getalignmentsbuffer(), thisedgealignments.getalignoffsets(), edges, nodes, logpps, errorsignal);
}
}
};};
};};
4 changes: 2 additions & 2 deletions Math/Math/CPUMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ namespace Microsoft { namespace MSR { namespace CNTK {
static void ElementWisePower (ElemType alpha, const CPUMatrix<ElemType>& a, CPUMatrix<ElemType>& c);

static bool AreEqual(const CPUMatrix<ElemType>& a, const CPUMatrix<ElemType>& b, const ElemType threshold = 1e-8);

static void TensorShuffleScaleAndAdd(ElemType keepWeight, const CPUMatrix<ElemType>& a, size_t D, size_t S, size_t M, size_t K, size_t T, ElemType scaleFactor, const CPUMatrix<ElemType>& b, CPUMatrix<ElemType>& c);

static void TensorShuffleScaleAndAdd(ElemType keepWeight, const CPUMatrix<ElemType>& a, size_t D, size_t S, size_t M, size_t K, size_t T, ElemType scaleFactor, const CPUMatrix<ElemType>& b, CPUMatrix<ElemType>& c);

static CPUMatrix<ElemType> Ones(const size_t rows, const size_t cols);
static CPUMatrix<ElemType> Zeros(const size_t rows, const size_t cols);
Expand Down
Loading

0 comments on commit 403cc42

Please sign in to comment.