概要
std::array<type> の行列版.column-major.任意型の固定長行列型を生成する.
Table 1. namespace sstd{ template <typename T> class mat; }
Table 1. namespace sstd{ template <typename T> class mat; }
| プロトタイプ宣言 | 動作説明 |
|---|---|
| template <typename T> void copy (class sstd::mat<T>& lhs, class sstd::mat<T>& rhs); | copy rhs to lhs |
| template <typename T> void move (class sstd::mat<T>& lhs, class sstd::mat<T>& rhs); | move rhs to lhs |
| template <typename T> void swap(class sstd::mat<T>& lhs, class sstd::mat<T>& rhs); | sawp rhs and lhs |
| template <typename T> void zeros(class sstd::mat<T>& Mat); | |
| template <typename T> class sstd::mat<T> Tr(class sstd::mat<T>& rhs); | transpose rhs |
| template <typename T> void Tr_myself(class sstd::mat<T>& rhs); | transpose rhs(myself) |
| template <typename T> class sstd::mat<T>* copyRect(class sstd::mat<T>*& pMat, uint rowStart, uint rowEnd, uint colStart, uint colEnd); | |
| void print(class sstd::mat <char>& Mat); | |
| void print(class sstd::mat <uchar>& Mat); | |
| void print(class sstd::mat <int>& Mat); | |
| void print(class sstd::mat <uint>& Mat); | |
| void print(class sstd::mat <float>& Mat); | |
| void print(class sstd::mat<double>& Mat); |
使用例
#include <sstd/sstd.hpp> int main(){ printf("■ Init sstd::mat<type>\n"); printf("\n"); sstd::mat<double> Matd(5, 3); printf("RowNum: %d\n", Matd.rows()); printf("ColNum: %d\n", Matd.cols()); printf("Length: %d\n", Matd.len()); printf("Indication of column major\n"); uint i=0; for(uint q=0; q<Matd.cols(); q++){ for(uint p=0; p<Matd.rows(); p++){ Matd(p, q) = i; i++; } } sstd::print(Matd); printf("\n"); //=== i=0; for(uint q=0; q<Matd.len(); q++){ Matd[i] = i; i++; } sstd::print(Matd); printf("\n"); //=== sstd::mat<double>* pMatd = new sstd::mat<double>(5, 3); printf("RowNum: %d\n", pMatd->rows()); printf("ColNum: %d\n", pMatd->cols()); printf("Length: %d\n", pMatd->len()); printf("Indication of column major\n"); i=0; for(uint q=0; q<pMatd->cols(); q++){ for(uint p=0; p<pMatd->rows(); p++){ (*pMatd)(p, q) = i; i++; } } sstd::print(*pMatd); printf("\n"); delete pMatd; //=== printf("■ copy\n");printf("\n"); sstd::mat<double> Matd_copy = Matd; Matd_copy = Matd; // "sstd::copy(Matd_copy, Matd);" is called. sstd::print(Matd_copy); printf("\n"); //=== printf("■ copy row\n");printf("\n"); sstd::mat<double> Matd_rowCopy(5, 3); sstd::zeros(Matd_rowCopy); Matd_rowCopy(1, ':') = Matd(1, ':'); sstd::print(Matd_rowCopy); printf("\n"); printf("■ copy col\n");printf("\n"); sstd::mat<double> Matd_colCopy(5, 3); sstd::zeros(Matd_colCopy); Matd_colCopy(':', 2) = Matd(':', 2); sstd::print(Matd_colCopy); printf("\n"); //=== sstd::printn(Matd_colCopy); printf("\n"); sstd::printn_all(Matd_colCopy); printf("\n"); }
実行結果
$ ./exe.exe ■ Init sstd::mat<type> RowNum: 5 ColNum: 3 Length: 15 Indication of column major 0.000000 5.000000 10.000000 1.000000 6.000000 11.000000 2.000000 7.000000 12.000000 3.000000 8.000000 13.000000 4.000000 9.000000 14.000000 0.000000 5.000000 10.000000 1.000000 6.000000 11.000000 2.000000 7.000000 12.000000 3.000000 8.000000 13.000000 4.000000 9.000000 14.000000 RowNum: 5 ColNum: 3 Length: 15 Indication of column major 0.000000 5.000000 10.000000 1.000000 6.000000 11.000000 2.000000 7.000000 12.000000 3.000000 8.000000 13.000000 4.000000 9.000000 14.000000 ■ copy 0.000000 5.000000 10.000000 1.000000 6.000000 11.000000 2.000000 7.000000 12.000000 3.000000 8.000000 13.000000 4.000000 9.000000 14.000000 ■ copy row 0.000000 0.000000 0.000000 1.000000 6.000000 11.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 ■ copy col 0.000000 0.000000 10.000000 0.000000 0.000000 11.000000 0.000000 0.000000 12.000000 0.000000 0.000000 13.000000 0.000000 0.000000 14.000000 Matd_colCopy = 0.000000 0.000000 10.000000 0.000000 0.000000 11.000000 0.000000 0.000000 12.000000 0.000000 0.000000 13.000000 0.000000 0.000000 14.000000 TEST_mat(738): Matd_colCopy = 0.000000 0.000000 10.000000 0.000000 0.000000 11.000000 0.000000 0.000000 12.000000 0.000000 0.000000 13.000000 0.000000 0.000000 14.000000
実装
0 件のコメント:
コメントを投稿