OSDN Git Service

fix problem
authortomohiro yasutomo <o_ggy@users.sourceforge.jp>
Mon, 6 Sep 2010 10:26:02 +0000 (03:26 -0700)
committertomohiro yasutomo <o_ggy@users.sourceforge.jp>
Mon, 6 Sep 2010 10:26:02 +0000 (03:26 -0700)
13 files changed:
bin/numeric
bin/result [deleted file]
lib/libmofmath.a
lib/libmofutil.a
sample/CMakeLists.txt
sample/build_unix/numeric/CMakeFiles/numeric.dir/flags.make
sample/build_unix/numeric/CMakeFiles/numeric.dir/link.txt
src/build_unix/Testing/Temporary/LastTest.log
src/mof/math/basic_matrix.hpp
src/mof/math/matrix2.hpp
src/mof/math/matrix3.hpp
src/mof/math/test/testbin/matrix2_test
src/mof/math/test/testbin/matrix3_test

index 232f877..a78303b 100755 (executable)
Binary files a/bin/numeric and b/bin/numeric differ
diff --git a/bin/result b/bin/result
deleted file mode 100644 (file)
index 3fef0f6..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-100000000 times repeating
-***copy performance test***
-vector2 --- 61140[micro sec]
-raw type2 --- 44058[micro sec]
-vector3 --- 41559[micro sec]
-raw type3 --- 41272[micro sec]
-matrix2 --- 42470[micro sec]
-raw type9 --- 40862[micro sec]
-matrix3 --- 40334[micro sec]
-raw type16 --- 39556[micro sec]
-shared type --- 123380[micro sec]
-***add performance test***
-vector2 + vector2 --- 122974[micro sec]
-vector3 + vector3 --- 123472[micro sec]
-matrix2 + matrix2 --- 626758[micro sec]
-matrix3 + matrix3 --- 957516[micro sec]
-***multiply performance test***
-matrix2 * vector2 --- 1158626[micro sec]
-matrix3 * vector3 --- 1700042[micro sec]
-
-100000000 times repeating
-***copy performance test***
-vector2 --- 62594[micro sec]
-raw type2 --- 40726[micro sec]
-vector3 --- 41518[micro sec]
-raw type3 --- 42889[micro sec]
-matrix2 --- 41901[micro sec]
-raw type9 --- 43194[micro sec]
-matrix3 --- 40890[micro sec]
-raw type16 --- 39739[micro sec]
-shared type --- 126350[micro sec]
-***add performance test***
-vector2 + vector2 --- 123069[micro sec]
-vector3 + vector3 --- 127493[micro sec]
-matrix2 + matrix2 --- 632304[micro sec]
-matrix3 + matrix3 --- 972639[micro sec]
-***multiply performance test***
-matrix2 * vector2 --- 1149971[micro sec]
-matrix3 * vector3 --- 1704253[micro sec]
index c18cc65..47dbea5 100644 (file)
Binary files a/lib/libmofmath.a and b/lib/libmofmath.a differ
index 63ea1d6..3a9add3 100644 (file)
Binary files a/lib/libmofutil.a and b/lib/libmofutil.a differ
index 9df7de1..e0f712a 100644 (file)
@@ -14,7 +14,7 @@ link_directories("${PROJECT_SOURCE_DIR}/../lib")
 if (MSVC)
        set(CMAKE_CXX_FLAGS "/EHsc /nologo /W4")
 elseif (CMAKE_COMPILER_IS_GNUCC)
-       set(CMAKE_CXX_FLAGS " -Wall -O2 -DNDEBUG -std=c++0x")
+       set(CMAKE_CXX_FLAGS " -Wall -O3 -DNDEBUG -std=c++0x")
        #set(CMAKE_CXX_FLAGS "-Wall -g  -std=c++0x")
 endif()
 
index c23b512..ad62032 100644 (file)
@@ -2,7 +2,7 @@
 # Generated by "Unix Makefiles" Generator, CMake Version 2.8
 
 # compile CXX with /usr/bin/c++
-CXX_FLAGS =  -Wall -O2 -DNDEBUG -std=c++0x -I/home/yasutomo/devel/moflib/sample/../src  
+CXX_FLAGS =  -Wall -O3 -DNDEBUG -std=c++0x -I/home/yasutomo/devel/moflib/sample/../src  
 
 CXX_DEFINES = 
 
index 50f91ad..f8cd4eb 100644 (file)
@@ -1 +1 @@
-/usr/bin/c++    -Wall -O2 -DNDEBUG -std=c++0x   CMakeFiles/numeric.dir/main.cpp.o  -o /home/yasutomo/devel/moflib/bin/numeric -rdynamic -L/home/yasutomo/devel/moflib/sample/../lib -lrt -lmofutil -lmofmath -Wl,-rpath,/home/yasutomo/devel/moflib/sample/../lib 
+/usr/bin/c++    -Wall -O3 -DNDEBUG -std=c++0x   CMakeFiles/numeric.dir/main.cpp.o  -o /home/yasutomo/devel/moflib/bin/numeric -rdynamic -L/home/yasutomo/devel/moflib/sample/../lib -lrt -lmofutil -lmofmath -Wl,-rpath,/home/yasutomo/devel/moflib/sample/../lib 
index 23bf51e..44cce8a 100644 (file)
@@ -1,17 +1,17 @@
-Start testing: Sep 05 21:00 PDT
+Start testing: Sep 06 03:01 PDT
 ----------------------------------------------------------
 1/5 Testing: vector2_test
 1/5 Test: vector2_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/vector2_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"vector2_test" start time: Sep 05 21:00 PDT
+"vector2_test" start time: Sep 06 03:01 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
 Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"vector2_test" end time: Sep 05 21:00 PDT
+"vector2_test" end time: Sep 06 03:01 PDT
 "vector2_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -19,14 +19,14 @@ Test Passed.
 2/5 Test: vector3_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/vector3_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"vector3_test" start time: Sep 05 21:00 PDT
+"vector3_test" start time: Sep 06 03:01 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
 Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"vector3_test" end time: Sep 05 21:00 PDT
+"vector3_test" end time: Sep 06 03:01 PDT
 "vector3_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -34,14 +34,14 @@ Test Passed.
 3/5 Test: matrix2_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/matrix2_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"matrix2_test" start time: Sep 05 21:00 PDT
+"matrix2_test" start time: Sep 06 03:01 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
-Test time =   0.01 sec
+Test time =   0.00 sec
 ----------------------------------------------------------
 Test Passed.
-"matrix2_test" end time: Sep 05 21:00 PDT
+"matrix2_test" end time: Sep 06 03:01 PDT
 "matrix2_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -49,14 +49,14 @@ Test Passed.
 4/5 Test: matrix3_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/matrix3_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"matrix3_test" start time: Sep 05 21:00 PDT
+"matrix3_test" start time: Sep 06 03:01 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
 Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"matrix3_test" end time: Sep 05 21:00 PDT
+"matrix3_test" end time: Sep 06 03:01 PDT
 "matrix3_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
@@ -64,15 +64,15 @@ Test Passed.
 5/5 Test: make_matrix_test
 Command: "/home/yasutomo/devel/moflib/src/mof/math/test/testbin/make_matrix_test"
 Directory: /home/yasutomo/devel/moflib/src/build_unix/mof/math
-"make_matrix_test" start time: Sep 05 21:00 PDT
+"make_matrix_test" start time: Sep 06 03:01 PDT
 Output:
 ----------------------------------------------------------
 <end of output>
 Test time =   0.01 sec
 ----------------------------------------------------------
 Test Passed.
-"make_matrix_test" end time: Sep 05 21:00 PDT
+"make_matrix_test" end time: Sep 06 03:01 PDT
 "make_matrix_test" time elapsed: 00:00:00
 ----------------------------------------------------------
 
-End testing: Sep 05 21:00 PDT
+End testing: Sep 06 03:01 PDT
index 4213283..cc3b024 100644 (file)
@@ -29,27 +29,25 @@ namespace math
                , boost::addable2< Derived, float
                , boost::subtractable< Derived 
                , boost::subtractable2< Derived, float
-               , boost::multipliable< Derived
                , boost::multipliable2< Derived, float
                , boost::dividable2< Derived, float
                , boost::equality_comparable< Derived
-               > > > > > > > >
+               > > > > > > >
        {
        protected:
 //{{{ size
                /**
-                * @brief components_のサイズを返す
+                * @brief elements_のサイズを返す
                 */
                size_t size() const
                {
                        return Dim * (Dim + 1);
                }
 //}}}
-               union 
-               {
-                       float components_[Dim * (Dim + 1)];
-                       float elements_[Dim][Dim + 1];
-               };///< 要素の配列(アフィン行列なので,最後の行は省略している)
+               // <実装メモ>elements_は1次元配列として提供している.
+               // 無名共用体を使って2次元配列を用意することもできるが、FPUレジスタの内容を
+               // 毎回スタックと同期しようとするらしく、速度が大幅に落ちてしまう.
+               float elements_[Dim * (Dim + 1)];///< 要素の配列(アフィン行列なので,最後の行は省略している)
        public:
                // コンストラクタ,デストラクタはデフォルトのものを使う
                // 代入演算子,コピーコンストラクタはデフォルトのものを使う
@@ -58,7 +56,7 @@ namespace math
                {
                        using std::swap;
                        for (size_t i = 0; i < size(); ++i) {
-                               swap(components_[i], rhs.components_[i]);
+                               swap(elements_[i], rhs.elements_[i]);
                        }
                }
 //}}}
@@ -66,7 +64,7 @@ namespace math
                Derived& operator+=(const Derived& rhs)
                {
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] += rhs.components_[i];
+                               elements_[i] += rhs.elements_[i];
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
@@ -74,7 +72,7 @@ namespace math
                Derived& operator+=(float rhs) 
                {
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] += rhs;
+                               elements_[i] += rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
@@ -83,7 +81,7 @@ namespace math
                {
                        float tmp[size()];
                        for (size_t i = 0; i < size(); ++i) {
-                               tmp[i] = rhs1 + rhs2.components_[i];
+                               tmp[i] = rhs1 + rhs2.elements_[i];
                        }
                        return Derived(tmp);
                }
@@ -92,7 +90,7 @@ namespace math
                Derived& operator-=(const Derived& rhs)
                {
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] -= rhs.components_[i];
+                               elements_[i] -= rhs.elements_[i];
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
@@ -100,7 +98,7 @@ namespace math
                Derived& operator-=(float rhs)
                {
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] -= rhs;
+                               elements_[i] -= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
@@ -109,12 +107,27 @@ namespace math
                {
                        float tmp[size()];
                        for (size_t i = 0; i < size(); ++i) {
-                               tmp[i] = rhs1 - rhs2.components_[i];
+                               tmp[i] = rhs1 - rhs2.elements_[i];
                        }
                        return Derived(tmp);
                }
 //}}}
 //{{{ operator *=      
+               Derived operator*(const Derived& rhs)
+               {
+                       Derived M;
+                       for (size_t i = 0; i < Dim; ++i) {
+                               for (size_t j = 0; j <= Dim; ++j) {
+                                       float sum = 0;
+                                       for (size_t k = 0; k <= Dim; ++k) {
+                                               sum += at(i, k) * rhs.at(k, j);
+                                       }
+                                       M.elements_[i * (Dim+1) + j] = sum;
+                               }
+                       }
+                       return M;
+               }
+               
                Derived& operator*=(const Derived& rhs)
                {
                        Derived M;
@@ -124,17 +137,18 @@ namespace math
                                        for (size_t k = 0; k <= Dim; ++k) {
                                                sum += at(i, k) * rhs.at(k, j);
                                        }
-                                       M.elements_[i][j] = sum;
+                                       M.elements_[i * (Dim+1) + j] = sum;
                                }
                        }
                        *this = M;
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
 
+
                Derived& operator*=(float rhs) 
                {
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] *= rhs;
+                               elements_[i] *= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
@@ -145,7 +159,7 @@ namespace math
                        for (size_t i = 0; i < Dim; ++i) {
                                float sum = 0;
                                for (size_t k = 0; k <= Dim; ++k) {
-                                       sum += elements_[i][k] * rhs[k];
+                                       sum += elements_[i * (Dim+1) + k] * rhs[k];
                                }
                                arr[i] = sum;
                        }
@@ -156,7 +170,7 @@ namespace math
                Derived& operator/=(float rhs)
                {
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] /= rhs;
+                               elements_[i] /= rhs;
                        }
                        return *reinterpret_cast<Derived*>(this);//thisがDerived型であることは保証されている.
                }
@@ -165,7 +179,7 @@ namespace math
                bool operator==(const Derived& rhs) const
                {
                        for (size_t i = 0; i < size(); ++i) {
-                               if (std::abs(components_[i] - rhs.components_[i]) > MOF_ERROR_THRESHOLD) return false;
+                               if (std::abs(elements_[i] - rhs.elements_[i]) > MOF_ERROR_THRESHOLD) return false;
                        }
                        return true;
                }
@@ -212,8 +226,8 @@ namespace math
                 */
                const float at(size_t i, size_t j) const
                {
-                       if (i < Dim ) return elements_[i][j];
-                       if (j == Dim) return 1;
+                       if (i < Dim ) return elements_[i * (Dim+1) + j];
+                       if (j == Dim) return 1; 
                        else return 0;
                }
 //}}}
@@ -237,10 +251,10 @@ namespace math
        class row_of_matrix : boost::noncopyable
        {
                size_t index_;
-               const float (&elements_)[Dim][Dim+1];
+               const float (&elements_)[Dim * (Dim+1)];
 
        public:
-               row_of_matrix(size_t i, const float (&elements)[Dim][Dim+1])
+               row_of_matrix(size_t i, const float (&elements)[Dim * (Dim+1)])
                        : index_(i), elements_(elements)
                {
                }
@@ -252,7 +266,7 @@ namespace math
 
                float operator[](size_t j) const
                {
-                       if (Dim != index_) return elements_[index_][j];
+                       if (Dim != index_) return elements_[index_ * (Dim+1) + j];
                        else if (Dim == j) return 1;
                        else return 0;
                }
index a460b76..3ddba44 100644 (file)
@@ -31,7 +31,7 @@ namespace math
                explicit matrix2(const T& arr)
                {
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] = arr[i];
+                               elements_[i] = arr[i];
                        }
                }
                
@@ -50,7 +50,7 @@ namespace math
                                        &m21, &m22, &m23
                                };
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] = *table[i];
+                               elements_[i] = *table[i];
                        }
                }
 
@@ -59,7 +59,7 @@ namespace math
        matrix2(const matrix2& rhs)
        {
                for (size_t i = 0; i < size(); ++i) {
-                       components_[i] = rhs.components_[i];
+                       elements_[i] = rhs.elements_[i];
                }
        }
 //}}}
@@ -67,7 +67,7 @@ namespace math
        matrix2& operator = (const matrix2& rhs)
        {
                for (size_t i = 0; i < size(); ++i) {
-                       components_[i] = rhs.components_[i];
+                       elements_[i] = rhs.elements_[i];
                }
                return *this;
        }
index 77e6ade..af56f75 100644 (file)
@@ -31,7 +31,7 @@ namespace math
                explicit matrix3(const T& arr)
                {
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] = arr[i];
+                               elements_[i] = arr[i];
                        }
                }
 
@@ -52,7 +52,7 @@ namespace math
                                        &m31, &m32, &m33, &m34
                                };
                        for (size_t i = 0; i < size(); ++i) {
-                               components_[i] = *table[i];
+                               elements_[i] = *table[i];
                        }
                }
 
@@ -61,7 +61,7 @@ namespace math
        matrix3(const matrix3& rhs)
        {
                for (size_t i = 0; i < size(); ++i) {
-                       components_[i] = rhs.components_[i];
+                       elements_[i] = rhs.elements_[i];
                }
        }
 //}}}
@@ -72,7 +72,7 @@ namespace math
        matrix3& operator = (const matrix3& rhs)
        {
                for (size_t i = 0; i < size(); ++i) {
-                       components_[i] = rhs.components_[i];
+                       elements_[i] = rhs.elements_[i];
                }
                return *this;
        }
index 0bffa2e..ba5c7b3 100755 (executable)
Binary files a/src/mof/math/test/testbin/matrix2_test and b/src/mof/math/test/testbin/matrix2_test differ
index e6f31a0..34feef5 100755 (executable)
Binary files a/src/mof/math/test/testbin/matrix3_test and b/src/mof/math/test/testbin/matrix3_test differ