+++ /dev/null
-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]
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()
# 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 =
-/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
-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
----------------------------------------------------------
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
----------------------------------------------------------
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
----------------------------------------------------------
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
----------------------------------------------------------
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
, 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:
// コンストラクタ,デストラクタはデフォルトのものを使う
// 代入演算子,コピーコンストラクタはデフォルトのものを使う
{
using std::swap;
for (size_t i = 0; i < size(); ++i) {
- swap(components_[i], rhs.components_[i]);
+ swap(elements_[i], rhs.elements_[i]);
}
}
//}}}
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型であることは保証されている.
}
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型であることは保証されている.
}
{
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);
}
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型であることは保証されている.
}
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型であることは保証されている.
}
{
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;
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型であることは保証されている.
}
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;
}
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型であることは保証されている.
}
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;
}
*/
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;
}
//}}}
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)
{
}
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;
}
explicit matrix2(const T& arr)
{
for (size_t i = 0; i < size(); ++i) {
- components_[i] = arr[i];
+ elements_[i] = arr[i];
}
}
&m21, &m22, &m23
};
for (size_t i = 0; i < size(); ++i) {
- components_[i] = *table[i];
+ elements_[i] = *table[i];
}
}
matrix2(const matrix2& rhs)
{
for (size_t i = 0; i < size(); ++i) {
- components_[i] = rhs.components_[i];
+ elements_[i] = rhs.elements_[i];
}
}
//}}}
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;
}
explicit matrix3(const T& arr)
{
for (size_t i = 0; i < size(); ++i) {
- components_[i] = arr[i];
+ elements_[i] = arr[i];
}
}
&m31, &m32, &m33, &m34
};
for (size_t i = 0; i < size(); ++i) {
- components_[i] = *table[i];
+ elements_[i] = *table[i];
}
}
matrix3(const matrix3& rhs)
{
for (size_t i = 0; i < size(); ++i) {
- components_[i] = rhs.components_[i];
+ elements_[i] = rhs.elements_[i];
}
}
//}}}
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;
}