矩阵乘法码 [英] Matrix multiply code

查看:108
本文介绍了矩阵乘法码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我为编译时已知的任意

维度的Matrix乘法编写的一些代码。我很好奇它是多么实用。对于

实例,通常在编译时知道matricies的维数吗?任何帮助,将不胜感激。希望这段代码对某人有用,或者对某人有用,如果你觉得它有用,请告诉我,或者你有关于如何改进它的建议。


// Public Domain by Christopher Diggins,2005


#include< iostream>

#include< numeric>

#include< valarray>

#include< cassert>

模板<类Value_T,unsigned int Size_N,unsigned int Stride_N> ;

类切片

{

公开:

//构造函数

切片(Value_T * x):p(x){}

// typedef

typedef Value_T value_type;

//只有前向迭代器是提供,

//其他人留给读者练习

struct Slice_forward_iter {

Slice_forward_iter(Value_T * x):p(x ){}

Value_T& operator *(){return * p; }

const Value_T& operator *()const {return * p; }

Value_T& operator ++(){Value_T * tmp = p; p + = Stride_N; return * tmp; }

Value_T& operator ++(int){return *(p + = Stride_N); }

bool运算符==(const Slice_forward_iter& x){return p == x.p; }

bool operator!=(const Slice_forward_iter& x){return p!= x.p; }

Value_T * p;

};

typedef Slice_forward_iter iterator;

typedef const Slice_forward_iter const_iterator;

//公共函数

iterator begin(){return iterator(p); } $ / $
iterator end(){return iterator(p +(Size_N * Stride_N)); }

value_type& operator [](size_t n){return *(p +(n * Stride_N)); }

const value_type& operator [](size_t n)const {return *(p +(n *

Stride_N)); }

static size_t size(){return Size_N; }

static size_t stride(){return Stride_N; }

私人:

//防止默认构造

Slice(){};

Value_T * p;

};


模板<类Value_T,unsigned int Rows_N,unsigned int Cols_N>

class Matrix

{

public:

typedef Slice< Value_T,Cols_N,1> row_type;

typedef Slice< Value_T,Rows_N,Cols_N> col_type;

const row_type row(unsigned int n)const {

assert(n< rows);

return row_type(data +( n * Cols_N));

}

const col_type column(unsigned int n)const {

assert(n< cols);

返回col_type(data + n);

}

row_type operator [](unsigned int n){return row(n); } $ / $
const row_type operator [](unsigned int n)const {return row(n); } $ / $
const static unsigned int rows = Rows_N;

const static unsigned int cols = Cols_N;

typedef Value_T value_type;

private:

可变Value_T数据[Rows_N * Cols_N];

};


模板<类Matrix1,类Matrix2>

struct MatrixMultiplicationType {

typedef Matrix< typename Matrix1 :: value_type,Matrix1 :: rows,Matrix2 :: cols>

type;

};


模板<类Slice1_T,类Slice2_T>

typename Slice1_T :: value_type dot_product(Slice1_T x,Slice2_T y ){

assert(x.size()== y.size());

返回std :: inner_product(x.begin(),x.end( ),y.begin(),typename

Slice1_T :: value_type(0));

}


template< class Matrix1,类Matrix2>

typename MatrixMultiplicationType< Matrix1,Matrix2> :: type

matrix_multiply(const Matrix1& m1,const Matrix2& m2)

{

typename MatrixMultiplicationType< Matrix1,Matrix2> :: type result;

assert(Matrix1 :: cols == Matrix2 :: rows);

for(int I = 0;我<矩阵1 ::行; ++ i)

for(int j = 0; j< Matrix2 :: cols; ++ j)

result [i] [j] = dot_product(m1 .row(i),m2.column(j));

返回结果;

}


模板< typename Matrix_T> ;

void output_matrix(const Matrix_T& x){

for(int i = 0; i< x.rows; ++ i){

for(int j = 0; j< x.cols; ++ j){

std :: cout<< x [i] [j]<< ",";

}

std :: cout<< std :: endl;

}

std :: cout<< std :: endl;

}


void test_matrix(){

Matrix< int,1,2> m1;

m1 [0] [0] = 2;

m1 [0] [1] = 3;

矩阵< int, 2,2> m2;

m2 [0] [0] = 2;

m2 [0] [1] = 0;

m2 [1] [0] = 0;

m2 [1] [1] = 2;

output_matrix(m2);

矩阵< int,1 ,2> m3 = matrix_multiply(m1,m2);

output_matrix(m3);

}


int main(){

test_matrix();

system(" pause");

返回0;

}


-

Christopher Diggins

面向对象的模板库(OOTL)
http://www.ootl.org

Here is some code I wrote for Matrix multiplication for arbitrary
dimensionality known at compile-time. I am curious how practical it is. For
instance, is it common to know the dimensionality of matricies at
compile-time? Any help would be appreciated. Hopefully this code comes in
useful for someone, let me know if you find it useful, or if you have
suggestions on how to improve it.

// Public Domain by Christopher Diggins, 2005

#include <iostream>
#include <numeric>
#include <valarray>
#include <cassert>

template<class Value_T, unsigned int Size_N, unsigned int Stride_N>
class Slice
{
public:
// constructor
Slice(Value_T* x) : p(x) { }
// typedef
typedef Value_T value_type;
// only a forward iterator is provided,
// others are left as an exercise for the reader
struct Slice_forward_iter {
Slice_forward_iter(Value_T* x) : p(x) { }
Value_T& operator*() { return *p; }
const Value_T& operator*() const { return *p; }
Value_T& operator++() { Value_T* tmp = p; p += Stride_N; return *tmp; }
Value_T& operator++(int) { return *(p+=Stride_N); }
bool operator==(const Slice_forward_iter& x) { return p == x.p; }
bool operator!=(const Slice_forward_iter& x) { return p != x.p; }
Value_T* p;
};
typedef Slice_forward_iter iterator;
typedef const Slice_forward_iter const_iterator;
// public functions
iterator begin() { return iterator(p); }
iterator end() { return iterator(p + (Size_N * Stride_N)); }
value_type& operator[](size_t n) { return *(p + (n * Stride_N)); }
const value_type& operator[](size_t n) const { return *(p + (n *
Stride_N)); }
static size_t size() { return Size_N; }
static size_t stride() { return Stride_N; }
private:
// prevent default construction
Slice() { };
Value_T* p;
};

template<class Value_T, unsigned int Rows_N, unsigned int Cols_N>
class Matrix
{
public:
typedef Slice<Value_T, Cols_N, 1> row_type;
typedef Slice<Value_T, Rows_N, Cols_N> col_type;
const row_type row(unsigned int n) const {
assert(n < rows);
return row_type(data + (n * Cols_N));
}
const col_type column(unsigned int n) const {
assert(n < cols);
return col_type(data + n);
}
row_type operator[](unsigned int n) { return row(n); }
const row_type operator[](unsigned int n) const { return row(n); }
const static unsigned int rows = Rows_N;
const static unsigned int cols = Cols_N;
typedef Value_T value_type;
private:
mutable Value_T data[Rows_N * Cols_N];
};

template<class Matrix1, class Matrix2>
struct MatrixMultiplicationType {
typedef Matrix<typename Matrix1::value_type, Matrix1::rows, Matrix2::cols>
type;
};

template<class Slice1_T, class Slice2_T>
typename Slice1_T::value_type dot_product(Slice1_T x, Slice2_T y) {
assert(x.size() == y.size());
return std::inner_product(x.begin(), x.end(), y.begin(), typename
Slice1_T::value_type(0));
}

template<class Matrix1, class Matrix2>
typename MatrixMultiplicationType<Matrix1, Matrix2>::type
matrix_multiply(const Matrix1& m1, const Matrix2& m2)
{
typename MatrixMultiplicationType<Matrix1, Matrix2>::type result;
assert(Matrix1::cols == Matrix2::rows);
for (int i=0; i < Matrix1::rows; ++i)
for (int j=0; j < Matrix2::cols; ++j)
result[i][j] = dot_product(m1.row(i), m2.column(j));
return result;
}

template<typename Matrix_T>
void output_matrix(const Matrix_T& x) {
for (int i=0; i < x.rows; ++i) {
for (int j=0; j < x.cols; ++j) {
std::cout << x[i][j] << ", ";
}
std::cout << std::endl;
}
std::cout << std::endl;
}

void test_matrix() {
Matrix<int, 1, 2> m1;
m1[0][0] = 2;
m1[0][1] = 3;
Matrix<int, 2, 2> m2;
m2[0][0] = 2;
m2[0][1] = 0;
m2[1][0] = 0;
m2[1][1] = 2;
output_matrix(m2);
Matrix<int, 1, 2> m3 = matrix_multiply(m1, m2);
output_matrix(m3);
}

int main() {
test_matrix();
system("pause");
return 0;
}

--
Christopher Diggins
Object Oriented Template Library (OOTL)
http://www.ootl.org

推荐答案

On 2005-05-15,christopher diggins< cd ****** @ videotron.ca>写道:
On 2005-05-15, christopher diggins <cd******@videotron.ca> wrote:
这是我为编译时已知的任意
维度的Matrix乘法编写的一些代码。我很好奇它是多么实用。对于
实例,在编译时知道matricies的维数是否常见?
Here is some code I wrote for Matrix multiplication for arbitrary
dimensionality known at compile-time. I am curious how practical it is. For
instance, is it common to know the dimensionality of matricies at
compile-time?




有一些矩阵已知。这取决于矩阵

模型。如果矩阵模拟某些变换,例如一个三维坐标变换,

或两个已知变量列表之间的线性变换,那么

维度在编译时可能是已知的。

但是如果矩阵是某种数据集(例如:某种类型的集合

的样本或测量值),尺寸可能不会在
$中知道b $ b编译时间。


干杯,

-

Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/

< br>

christopher diggins写道:
christopher diggins wrote:
这是我为编译时已知的任意
维度的Matrix乘法编写的一些代码。我很好奇它是多么实用。对于
实例,在编译时知道matricies的维数是否常见?任何帮助,将不胜感激。希望这段代码对某人有用,如果你觉得它有用,请告诉我,或者你有关于如何改进它的建议。

// Public Domain by Christopher Diggins,2005


除非你声明版权,

你没有权利放弃你的代码

甚至是自己使用。

有关详细信息,请参阅:

http://www.gnu.org/licenses/licenses.html


您可能想要使用copyleft:

http://www.gnu.org/许可证/许可证...... WhatIsCopyleft
#include< iostream>
#include< numeric>
#include< valarray>
#include< cassert> ;

模板< class Value_T,unsigned int Size_N,unsigned int Stride_N>
class Slice
{
public:
//构造函数
Slice(Value_T * x):p(x){}
// typedef
typedef Value_T value_type;
//只提供一个前向迭代器,
//其他人留给读者练习
struct Slice_forward_iter {
Slice_forward_iter(Value_T * x):p(x){}
Value_T& operator *(){return * p; }
const Value_T& operator *()const {return * p; }
Value_T& operator ++(){Value_T * tmp = p; p + = Stride_N; return * tmp; }
Value_T& operator ++(int){return *(p + = Stride_N); }
bool operator ==(const Slice_forward_iter& x){return p == x.p; }
bool operator!=(const Slice_forward_iter& x){return p!= x.p; }
value_T * p;
};
typedef Slice_forward_iter迭代器;
typedef const Slice_forward_iter const_iterator;
//公共函数
iterator begin(){return迭代器(p); } it /> iterator end(){return iterator(p +(Size_N * Stride_N)); }
value_type& operator [](size_t n){return *(p +(n * Stride_N)); }
const value_type& operator [](size_t n)const {return *(p +(n *
Stride_N));静态size_t size(){返回Size_N; }
static size_t stride(){return Stride_N;私有:
//防止默认构造
Slice(){};
Value_T * p;
};

模板< class Value_T,unsigned int Rows_N,unsigned int Cols_N>
class Matrix
{
public:
typedef Slice< Value_T,Cols_N,1> row_type;
typedef Slice< Value_T,Rows_N,Cols_N> col_type;
const row_type row(unsigned int n)const {
assert(n< rows);
return row_type(data +(n * Cols_N));
}
const col_type column(unsigned int n)const {
assert(n< cols);
return col_type(data + n);
}
row_type operator [] (unsigned int n){return row(n); } const /> const row_type operator [](unsigned int n)const {return row(n); const static unsigned int rows = Rows_N;
const static unsigned int cols = Cols_N;
typedef Value_T value_type;
private:
可变的Value_T数据[Rows_N * Cols_N ];
};

模板<类Matrix1,类Matrix2>
结构MatrixMultiplicationType {
typedef矩阵< typename Matrix1 :: value_type,Matrix1 :: rows,Matrix2 :: cols>
type;
};

模板<类Slice1_T,类Slice2_T>
typename Slice1_T :: value_type dot_product(Slice1_T x,Slice2_T y){
assert(x.size()== y.size());
返回std :: inner_product(x.begin(),x.end(),y.begin(),typename
Slice1_T :: value_type(0));
}

模板<类Matrix1,类Matrix2>
typename MatrixMultiplicationType< Matrix1,Matrix2> :: type
matrix_multiply(const Matrix1& m1,const Matrix2& m2)
{
typename MatrixMultiplicationType< Matrix1,Matrix2> :: type result;
assert(Mat rix1 :: cols == Matrix2 :: rows);
for(int i = 0;我<矩阵1 ::行; ++ i)
for(int j = 0; j< Matrix2 :: cols; ++ j)
result [i] [j] = dot_product(m1.row(i),m2。列(j));
返回结果;


模板< typename Matrix_T>
void output_matrix(const Matrix_T& x){
for( int i = 0; i< x.rows; ++ i){
for(int j = 0; j< x.cols; ++ j){
std :: cout< < x [i] [j]<< ",";
}
std :: cout<< std :: endl;
}
std :: cout<< std :: endl;
}

void test_matrix(){
Matrix< int,1,2> m1;
m1 [0] [0] = 2;
m1 [0] [1] = 3;
矩阵< int,2,2> m2;
m2 [0] [0] = 2;
m2 [0] [1] = 0;
m2 [1] [0] = 0;
m2 [ 1] [1] = 2;
output_matrix(m2);
矩阵< int,1,2> m3 = matrix_multiply(m1,m2);
output_matrix(m3);
}
int main(){
test_matrix();
system( 暂停;;
返回0;
}

g ++ -Wall -ansi -pedantic -o main main.cpp
Here is some code I wrote for Matrix multiplication for arbitrary
dimensionality known at compile-time. I am curious how practical it is. For
instance, is it common to know the dimensionality of matricies at
compile-time? Any help would be appreciated. Hopefully this code comes in
useful for someone, let me know if you find it useful, or if you have
suggestions on how to improve it.

// Public Domain by Christopher Diggins, 2005
Unless you claim the copyright,
You have no right to give your code away
or even to use it yourself.
For more details, see:

http://www.gnu.org/licenses/licenses.html

You will probably want to use a copyleft:

http://www.gnu.org/licenses/licenses...WhatIsCopyleft
#include <iostream>
#include <numeric>
#include <valarray>
#include <cassert>

template<class Value_T, unsigned int Size_N, unsigned int Stride_N>
class Slice
{
public:
// constructor
Slice(Value_T* x) : p(x) { }
// typedef
typedef Value_T value_type;
// only a forward iterator is provided,
// others are left as an exercise for the reader
struct Slice_forward_iter {
Slice_forward_iter(Value_T* x) : p(x) { }
Value_T& operator*() { return *p; }
const Value_T& operator*() const { return *p; }
Value_T& operator++() { Value_T* tmp = p; p += Stride_N; return *tmp; }
Value_T& operator++(int) { return *(p+=Stride_N); }
bool operator==(const Slice_forward_iter& x) { return p == x.p; }
bool operator!=(const Slice_forward_iter& x) { return p != x.p; }
Value_T* p;
};
typedef Slice_forward_iter iterator;
typedef const Slice_forward_iter const_iterator;
// public functions
iterator begin() { return iterator(p); }
iterator end() { return iterator(p + (Size_N * Stride_N)); }
value_type& operator[](size_t n) { return *(p + (n * Stride_N)); }
const value_type& operator[](size_t n) const { return *(p + (n *
Stride_N)); }
static size_t size() { return Size_N; }
static size_t stride() { return Stride_N; }
private:
// prevent default construction
Slice() { };
Value_T* p;
};

template<class Value_T, unsigned int Rows_N, unsigned int Cols_N>
class Matrix
{
public:
typedef Slice<Value_T, Cols_N, 1> row_type;
typedef Slice<Value_T, Rows_N, Cols_N> col_type;
const row_type row(unsigned int n) const {
assert(n < rows);
return row_type(data + (n * Cols_N));
}
const col_type column(unsigned int n) const {
assert(n < cols);
return col_type(data + n);
}
row_type operator[](unsigned int n) { return row(n); }
const row_type operator[](unsigned int n) const { return row(n); }
const static unsigned int rows = Rows_N;
const static unsigned int cols = Cols_N;
typedef Value_T value_type;
private:
mutable Value_T data[Rows_N * Cols_N];
};

template<class Matrix1, class Matrix2>
struct MatrixMultiplicationType {
typedef Matrix<typename Matrix1::value_type, Matrix1::rows, Matrix2::cols>
type;
};

template<class Slice1_T, class Slice2_T>
typename Slice1_T::value_type dot_product(Slice1_T x, Slice2_T y) {
assert(x.size() == y.size());
return std::inner_product(x.begin(), x.end(), y.begin(), typename
Slice1_T::value_type(0));
}

template<class Matrix1, class Matrix2>
typename MatrixMultiplicationType<Matrix1, Matrix2>::type
matrix_multiply(const Matrix1& m1, const Matrix2& m2)
{
typename MatrixMultiplicationType<Matrix1, Matrix2>::type result;
assert(Matrix1::cols == Matrix2::rows);
for (int i=0; i < Matrix1::rows; ++i)
for (int j=0; j < Matrix2::cols; ++j)
result[i][j] = dot_product(m1.row(i), m2.column(j));
return result;
}

template<typename Matrix_T>
void output_matrix(const Matrix_T& x) {
for (int i=0; i < x.rows; ++i) {
for (int j=0; j < x.cols; ++j) {
std::cout << x[i][j] << ", ";
}
std::cout << std::endl;
}
std::cout << std::endl;
}

void test_matrix() {
Matrix<int, 1, 2> m1;
m1[0][0] = 2;
m1[0][1] = 3;
Matrix<int, 2, 2> m2;
m2[0][0] = 2;
m2[0][1] = 0;
m2[1][0] = 0;
m2[1][1] = 2;
output_matrix(m2);
Matrix<int, 1, 2> m3 = matrix_multiply(m1, m2);
output_matrix(m3);
}

int main() {
test_matrix();
system("pause");
return 0;
}
g++ -Wall -ansi -pedantic -o main main.cpp



main.cpp:函数`void output_matrix(const Matrix_T&)[with

Matrix_T = Matrix< int,2u,2u>]'':

main.cpp :112:从这里实例化

main.cpp:94:警告:有符号和无符号整数之间的比较

expressionsmain.cpp:112:从这里实例化

main.cpp:95:警告:有符号和无符号整数之间的比较

expressionsmain.cpp:函数`typename

MatrixMultiplicationType< Matrix1,Matrix2> :: type matrix_multiply(const

Matrix1&,const Matrix2&)[with Matrix1 = Matrix< int,1u,2u> ;, Matrix2 =

Matrix< int,2u,2u>] '':

main.cpp:113:从这里实例化

main。 cpp:86:警告:有符号和无符号整数之间的比较

expressionsmain.cpp:113:从这里实例化

main.cpp:87:警告:有符号和无符号之间的比较整数

expressionsmain.cpp:函数`void output_matrix(const Matrix_T&)

[with Matrix_T = Matrix< int,1u,2u>]'':

main.cpp:114:从这里实例化

main.cpp:94:警告:有符号和无符号整数之间的比较

expressionsmain.cpp:114:从这里实例化

main.cpp:95:警告:有符号和无符号整数之间的比较

表达式


显然,你的代码需要大量的工作。

此外,设计仍然很差。

参见面向对象的数字页面

http://www.oonumerics.org/oon/


来了解专家如何做到这一点。


祝你好运。


main.cpp: In function `void output_matrix(const Matrix_T&) [with
Matrix_T = Matrix<int, 2u, 2u>]'':
main.cpp:112: instantiated from here
main.cpp:94: warning: comparison between signed and unsigned integer
expressionsmain.cpp:112: instantiated from here
main.cpp:95: warning: comparison between signed and unsigned integer
expressionsmain.cpp: In function `typename
MatrixMultiplicationType<Matrix1, Matrix2>::type matrix_multiply(const
Matrix1&, const Matrix2&) [with Matrix1 = Matrix<int, 1u, 2u>, Matrix2 =
Matrix<int, 2u, 2u>]'':
main.cpp:113: instantiated from here
main.cpp:86: warning: comparison between signed and unsigned integer
expressionsmain.cpp:113: instantiated from here
main.cpp:87: warning: comparison between signed and unsigned integer
expressionsmain.cpp: In function `void output_matrix(const Matrix_T&)
[with Matrix_T = Matrix<int, 1u, 2u>]'':
main.cpp:114: instantiated from here
main.cpp:94: warning: comparison between signed and unsigned integer
expressionsmain.cpp:114: instantiated from here
main.cpp:95: warning: comparison between signed and unsigned integer
expressions

Evidently, your code needs lots of work.
Also, the design is still very poor.
See The Object-Oriented Numerics Page

http://www.oonumerics.org/oon/

to get an idea about how the experts do this.

Good Luck.


" E. Robert Tisdale <,E ************** @ jpl.nasa.gov>。在留言中写道

news:d6 ********** @ nntp1.jpl.nasa.gov ...
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
news:d6**********@nntp1.jpl.nasa.gov...
christopher diggins写道:
christopher diggins wrote:
这是我为编译时已知的任意
维度的Matrix乘法编写的一些代码。我很好奇它是多么实用。
例如,在编译时知道matricies的维度是否常见?任何帮助,将不胜感激。希望这段代码对某人有用,如果你觉得它有用,请告诉我,或者你有关于如何改进它的建议。

// Public Domain by Christopher Diggins,2005
除非您声明版权,
Here is some code I wrote for Matrix multiplication for arbitrary
dimensionality known at compile-time. I am curious how practical it is.
For instance, is it common to know the dimensionality of matricies at
compile-time? Any help would be appreciated. Hopefully this code comes in
useful for someone, let me know if you find it useful, or if you have
suggestions on how to improve it.

// Public Domain by Christopher Diggins, 2005
Unless you claim the copyright,




在许多国家(包括加拿大和美国),版权并非必须

参见 http://en.wikipedia.org/wiki/Copyrig...yright_notices
http://www.templetons.com/brad/copymyths.html

你没有权利放弃你的代码甚至自己使用。
有关详细信息,请参阅:

http://www.gnu.org/licenses/licenses.html

你可能会想要使用copyleft:

http: //www.gnu.org/licenses/licenses...WhatIsCopyleft

不,谢谢,我更愿意为公共领域贡献一些东西

而不是限制使用。



In many countries (including Canada and the US), copyright doesn''t have to
be claimed to be attributed.
see http://en.wikipedia.org/wiki/Copyrig...yright_notices and
http://www.templetons.com/brad/copymyths.html
You have no right to give your code away
or even to use it yourself.
For more details, see:

http://www.gnu.org/licenses/licenses.html

You will probably want to use a copyleft:

http://www.gnu.org/licenses/licenses...WhatIsCopyleft
No thank you, I would prefer contributing something to the public domain
rather than restricting usage.

g ++ -Wall -ansi -pedantic -o main main.cpp
g++ -Wall -ansi -pedantic -o main main.cpp


main.cpp:在函数中`void output_matrix(const Matrix_T&)[with Matrix_T
= Matrix< int,2u,2u>]'':
main.cpp:112:从这里实例化
main.cpp:94 :警告:有符号和无符号整数之间的比较
expressionsmain.cpp:112:从这里实例化
main.cpp:95:警告:有符号和无符号整数之间的比较
expressionsmain.cpp:在函数中`typename
MatrixMultiplicationType< Matrix1,Matrix2> :: type matrix_multiply(const
Matrix1&,const Matrix2&)[与Ma trix1 = Matrix< int,1u,2u> ;, Matrix2 =
Matrix< int,2u,2u>]'':
main.cpp:113:从这里实例化
main.cpp: 86:警告:有符号和无符号整数之间的比较
expressionsmain.cpp:113:从这里实例化
main.cpp:87:警告:有符号和无符号整数之间的比较
expressionsmain.cpp:In function`void output_matrix(const Matrix_T&)
[with Matrix_T = Matrix< int,1u,2u>]'':
main.cpp:114:从这里实例化
main.cpp: 94:警告:有符号和无符号整数之间的比较
expressionsmain.cpp:114:从这里实例化
main.cpp:95:警告:有符号和无符号整数之间的比较
表达式

很明显,你的代码需要大量的工作。


main.cpp: In function `void output_matrix(const Matrix_T&) [with Matrix_T
= Matrix<int, 2u, 2u>]'':
main.cpp:112: instantiated from here
main.cpp:94: warning: comparison between signed and unsigned integer
expressionsmain.cpp:112: instantiated from here
main.cpp:95: warning: comparison between signed and unsigned integer
expressionsmain.cpp: In function `typename
MatrixMultiplicationType<Matrix1, Matrix2>::type matrix_multiply(const
Matrix1&, const Matrix2&) [with Matrix1 = Matrix<int, 1u, 2u>, Matrix2 =
Matrix<int, 2u, 2u>]'':
main.cpp:113: instantiated from here
main.cpp:86: warning: comparison between signed and unsigned integer
expressionsmain.cpp:113: instantiated from here
main.cpp:87: warning: comparison between signed and unsigned integer
expressionsmain.cpp: In function `void output_matrix(const Matrix_T&)
[with Matrix_T = Matrix<int, 1u, 2u>]'':
main.cpp:114: instantiated from here
main.cpp:94: warning: comparison between signed and unsigned integer
expressionsmain.cpp:114: instantiated from here
main.cpp:95: warning: comparison between signed and unsigned integer
expressions

Evidently, your code needs lots of work.




仅仅因为我忽略了签名和未签名之间的一些比较

整数警告?我不怀疑我的代码有错误并且需要工作,但是来自GCC的b / b $ b迂腐警告并不表明实际需要工作的地方。我知道你确实为我提供的东西要多得多;-)

此外,设计仍然很差。


你能更具体一点吗?我很欣赏批评,但我需要一些东西

更有形。

参见面向对象的数字页面

http://www.oonumerics.org/oon/

获得一个想法关于专家如何做到这一点。


谢谢,我仔细查看了几个库,我的原始

问题仍然存在。

祝你好运。



Simply because I overlooked a few comparison between signed and unsigned
integers warnings? I don''t doubt my code has errors and needs work, but the
pedantic warnings from GCC do not indicate where work is actually needed. I
do know that you do have much more to offer me than that ;-)
Also, the design is still very poor.
Could you be more specific? I do appreciate criticism, but I need something
more tangible.
See The Object-Oriented Numerics Page

http://www.oonumerics.org/oon/

to get an idea about how the experts do this.
Thank you, I have looked closely at several libraries, and my original
questions still stand.
Good Luck.




谢谢。


- Christopher Diggins



Thank you.

- Christopher Diggins


这篇关于矩阵乘法码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆