00001 // $Id$ 00002 00003 /*********************************************************************** 00004 Moses - factored phrase-based language decoder 00005 Copyright (C) 2006 University of Edinburgh 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 ***********************************************************************/ 00021 00022 #ifndef moses_SquareMatrix_h 00023 #define moses_SquareMatrix_h 00024 00025 #include <iostream> 00026 #include "TypeDef.h" 00027 #include "Util.h" 00028 #include "WordsBitmap.h" 00029 00030 namespace Moses 00031 { 00032 00034 class SquareMatrix 00035 { 00036 friend std::ostream& operator<<(std::ostream &out, const SquareMatrix &matrix); 00037 protected: 00038 const size_t m_size; 00039 float *m_array; 00041 SquareMatrix(); // not implemented 00042 SquareMatrix(const SquareMatrix ©); // not implemented 00043 00044 public: 00045 SquareMatrix(size_t size) 00046 :m_size(size) { 00047 m_array = (float*) malloc(sizeof(float) * size * size); 00048 } 00049 ~SquareMatrix() { 00050 free(m_array); 00051 } 00053 inline size_t GetSize() const { 00054 return m_size; 00055 } 00057 inline float GetScore(size_t startPos, size_t endPos) const { 00058 return m_array[startPos * m_size + endPos]; 00059 } 00061 inline void SetScore(size_t startPos, size_t endPos, float value) { 00062 m_array[startPos * m_size + endPos] = value; 00063 } 00064 float CalcFutureScore( WordsBitmap const& ) const; 00065 float CalcFutureScore( WordsBitmap const&, size_t startPos, size_t endPos ) const; 00066 00067 TO_STRING(); 00068 }; 00069 00070 inline std::ostream& operator<<(std::ostream &out, const SquareMatrix &matrix) 00071 { 00072 for (size_t endPos = 0 ; endPos < matrix.GetSize() ; endPos++) { 00073 for (size_t startPos = 0 ; startPos < matrix.GetSize() ; startPos++) 00074 out << matrix.GetScore(startPos, endPos) << " "; 00075 out << std::endl; 00076 } 00077 00078 return out; 00079 } 00080 00081 } 00082 #endif
1.5.9