From 97dca787a7a85dd43f4f69e1e6b3626cedef3871 Mon Sep 17 00:00:00 2001 From: Javier Luraschi Date: Mon, 2 Feb 2015 16:57:24 -0800 Subject: [PATCH 1/2] Implement () operator for CPUSparseMatrix in CSC format --- Math/Math/CPUSparseMatrix.cpp | 3 ++- Math/Math/CPUSparseMatrix.h | 39 ++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Math/Math/CPUSparseMatrix.cpp b/Math/Math/CPUSparseMatrix.cpp index a09cabd10..e4f3f1d63 100644 --- a/Math/Math/CPUSparseMatrix.cpp +++ b/Math/Math/CPUSparseMatrix.cpp @@ -125,6 +125,7 @@ namespace Microsoft { namespace MSR { namespace CNTK { throw std::logic_error("CPUSparseMatrix: unsupported sparse matrix format"); } m_format = format; + m_default = defaultElem(); ZeroInit(); } @@ -541,7 +542,7 @@ namespace Microsoft { namespace MSR { namespace CNTK { bool result = true; -//#pragma omp parallel for + #pragma omp parallel for foreach_coord(i, j, a) { if (abs(a(i, j) - b(i, j)) > threshold) diff --git a/Math/Math/CPUSparseMatrix.h b/Math/Math/CPUSparseMatrix.h index b415f9995..56831159a 100644 --- a/Math/Math/CPUSparseMatrix.h +++ b/Math/Math/CPUSparseMatrix.h @@ -92,18 +92,39 @@ namespace Microsoft { namespace MSR { namespace CNTK { void Resize(const size_t numRows, const size_t numCols, size_t numNZElemToReserve = 0, const bool growOnly = true, const bool keepExistingValues = true); void Reset(); - inline ElemType& operator() (const size_t row, const size_t col) + inline ElemType defaultElem() { - row; - col; - NOT_IMPLEMENTED; + ElemType default; + memset(&default, 0, sizeof(ElemType)); + return default; } - inline const ElemType& operator() (const size_t row, const size_t col) const + const ElemType& operator() (const size_t row, const size_t col) const { - row; - col; - NOT_IMPLEMENTED; + if (col >= m_numCols || row >= m_numRows) + { + throw std::runtime_error("Position outside matrix dimensions"); + } + + if (m_format == MatrixFormat::matrixFormatSparseCSC) + { + size_t start = m_compIndex[col]; + size_t end = m_compIndex[col + 1]; + for (size_t p = start; p < end; p++) + { + size_t i = m_unCompIndex[p]; + if (i == row) + { + return m_pArray[p]; + } + } + + return m_default; + } + else + { + NOT_IMPLEMENTED; + } } public: @@ -158,6 +179,8 @@ namespace Microsoft { namespace MSR { namespace CNTK { size_t m_blockSize; //block size size_t *m_blockIds; //block ids + + ElemType m_default; }; typedef CPUSparseMatrix CPUSingleSparseMatrix; From e469db0ae294c92d393daabf2eab3610958d0345 Mon Sep 17 00:00:00 2001 From: kaisheny Date: Mon, 2 Feb 2015 20:19:10 -0800 Subject: [PATCH 2/2] Remove restriction of using one utterance per minibatch in simple evaluator. --- MachineLearning/cn/SimpleEvaluator.h | 1 - 1 file changed, 1 deletion(-) diff --git a/MachineLearning/cn/SimpleEvaluator.h b/MachineLearning/cn/SimpleEvaluator.h index 6c53a09b9..4dda0ab99 100644 --- a/MachineLearning/cn/SimpleEvaluator.h +++ b/MachineLearning/cn/SimpleEvaluator.h @@ -102,7 +102,6 @@ namespace Microsoft { namespace MSR { namespace CNTK { evalResultsLastMBs.push_back((ElemType)0); dataReader.StartMinibatchLoop(mbSize, 0, testSize); - dataReader.SetNbrSlicesEachRecurrentIter(1); for (int i=0; i