473,583 Members | 3,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Matrix multiply code

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_i ter {
Slice_forward_i ter(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==(cons t Slice_forward_i ter& x) { return p == x.p; }
bool operator!=(cons t Slice_forward_i ter& x) { return p != x.p; }
Value_T* p;
};
typedef Slice_forward_i ter iterator;
typedef const Slice_forward_i ter 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 MatrixMultiplic ationType {
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(Sli ce1_T x, Slice2_T y) {
assert(x.size() == y.size());
return std::inner_prod uct(x.begin(), x.end(), y.begin(), typename
Slice1_T::value _type(0));
}

template<class Matrix1, class Matrix2>
typename MatrixMultiplic ationType<Matri x1, Matrix2>::type
matrix_multiply (const Matrix1& m1, const Matrix2& m2)
{
typename MatrixMultiplic ationType<Matri x1, 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<typena me Matrix_T>
void output_matrix(c onst 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(m 2);
Matrix<int, 1, 2> m3 = matrix_multiply (m1, m2);
output_matrix(m 3);
}

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

--
Christopher Diggins
Object Oriented Template Library (OOTL)
http://www.ootl.org
Jul 23 '05 #1
15 13255
On 2005-05-15, christopher diggins <cd******@video tron.ca> wrote:
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?


There are some matrices where this is known. It depends on what the matrix
models. If the matrix models some transform, e.g. a 3d coordinate transform,
or a linear transform between two known lists of variables, then the
dimensions may well be known at compile time.

But if the matrix is a data set of some sort (example: some sort of collection
of samples or measurements), the dimensions probably will not be known at
compile time.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #2
christopher diggins wrote:
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_i ter {
Slice_forward_i ter(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==(cons t Slice_forward_i ter& x) { return p == x.p; }
bool operator!=(cons t Slice_forward_i ter& x) { return p != x.p; }
Value_T* p;
};
typedef Slice_forward_i ter iterator;
typedef const Slice_forward_i ter 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 MatrixMultiplic ationType {
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(Sli ce1_T x, Slice2_T y) {
assert(x.size() == y.size());
return std::inner_prod uct(x.begin(), x.end(), y.begin(), typename
Slice1_T::value _type(0));
}

template<class Matrix1, class Matrix2>
typename MatrixMultiplic ationType<Matri x1, Matrix2>::type
matrix_multiply (const Matrix1& m1, const Matrix2& m2)
{
typename MatrixMultiplic ationType<Matri x1, 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<typena me Matrix_T>
void output_matrix(c onst 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(m 2);
Matrix<int, 1, 2> m3 = matrix_multiply (m1, m2);
output_matrix(m 3);
}

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

main.cpp: In function `void output_matrix(c onst 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
MatrixMultiplic ationType<Matri x1, 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(c onst 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.
Jul 23 '05 #3
"E. Robert Tisdale" <E.************ **@jpl.nasa.gov > wrote in message
news:d6******** **@nntp1.jpl.na sa.gov...
christopher diggins wrote:
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,


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

main.cpp: In function `void output_matrix(c onst 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
MatrixMultiplic ationType<Matri x1, 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(c onst 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.


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.


Thank you.

- Christopher Diggins
Jul 23 '05 #4
christopher diggins wrote:
E. Robert Tisdale wrote:
christopher diggins wrote:

Here is some code I wrote for Matrix multiplication for arbitrary
dimensionali ty 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
suggestion s on how to improve it.

// Public Domain by Christopher Diggins, 2005


Unless you claim the copyright,

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


main.cpp: In function `void output_matrix(c onst Matrix_T&) [with Matrix_T
= Matrix<int, 2u, 2u>]':
main.cpp:11 2: instantiated from here
main.cpp:94 : warning: comparison between signed and unsigned integer
expressionsma in.cpp:112: instantiated from here
main.cpp:95 : warning: comparison between signed and unsigned integer
expressionsma in.cpp: In function `typename
MatrixMultipl icationType<Mat rix1, Matrix2>::type matrix_multiply (const
Matrix1&, const Matrix2&) [with Matrix1 = Matrix<int, 1u, 2u>, Matrix2 =
Matrix<int, 2u, 2u>]':
main.cpp:11 3: instantiated from here
main.cpp:86 : warning: comparison between signed and unsigned integer
expressionsma in.cpp:113: instantiated from here
main.cpp:87 : warning: comparison between signed and unsigned integer
expressionsma in.cpp: In function `void output_matrix(c onst Matrix_T&)
[with Matrix_T = Matrix<int, 1u, 2u>]':
main.cpp:11 4: instantiated from here
main.cpp:94 : warning: comparison between signed and unsigned integer
expressionsma in.cpp:114: instantiated from here
main.cpp:95 : warning: comparison between signed and unsigned integer
expressions

Evidently, your code needs lots of work.

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.

Thank you.

- Christopher Diggins


Take a look at the blitz++ Tiny Vector Matrix library

http://www.oonumerics.org/blitz/

You can also look at the Array classes in
The C++ Scalar, Vector, Matrix and Tensor class Library

http://www.netwood.net/~edwin/svmtl/

I also have an old recursive template definitions
for Matrix classes that you can get from

ftp.cs.ucla.edu/pub/Tensor.tar.Z

All of these things exist
mainly to help answer the questions that you have asked.

Strictly speaking, your questions are off-topic in this forum
but probably dead on in the object oriented numerics mailing list

http://www.oonumerics.org/mailman/li....cgi/oon-list/

Try there. I don't think that you'll be disappointed.
Jul 23 '05 #5
> 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.


I was curious how an "expert" implementation compares, so I compared my code
to boost::ublas. Preliminary tests show that my implementation runs over
twice as fast, and I haven't done any profiling or optimizing whatsoever.
This makes sense, because the compiler can optimize the indexing using
constants rather than doing variable lookups. This still leaves my original
question: How practical is it? And do people often no matrix dimensions at
compile time?

For those interested here is my first attempt at benchmarking.:

#include <boost/progress.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

// ... see previous post ...

using namespace boost::numeric: :ublas;

template<class Number, unsigned int M, unsigned int R, unsigned int N,
unsigned int I>
void compare_naive_a nd_ublas()
{
Matrix<Number, M, N> result1;
matrix<Number> result2;
{
std::cout << "about to run Naive test " << std::endl;
Matrix<Number, M, R> m1;
Matrix<Number, R, N> m2;
int n = 0;
for (unsigned i = 0; i < M; ++i)
for (unsigned j = 0; j < R; ++j)
m1[i][j] = ++n;
n = 0;
for (unsigned i = 0; i < R; ++i)
for (unsigned j = 0; j < N; ++j)
m2[i][j] = ++n;
boost::progress _timer t;
for (int i=0; i < I; i++) {
result1 = matrix_multiply (m1, m2);
}
std::cout << "naive time elapsed " << t.elapsed() << std::endl;
}
{
std::cout << "about to run uBlas test " << std::endl;
matrix<Number> m1(M, R);
matrix<Number> m2(R, N);
int n = 0;
for (unsigned i = 0; i < M; ++i)
for (unsigned j = 0; j < R; ++j)
m1(i, j) = ++n;
n = 0;
for (unsigned i = 0; i < R; ++i)
for (unsigned j = 0; j < N; ++j)
m2(i, j) = ++n;
boost::progress _timer t;
for (int i=0; i < I; i++) {
result2 = prod(m1, m2);
}
std::cout << "boost time elapsed " << t.elapsed() << std::endl;
}
for (unsigned i = 0; i < M; ++i)
for (unsigned j = 0; j < N; ++j)
assert(result1[i][j] == result2(i, j));
}

int main() {
compare_naive_a nd_ublas<int,17 ,23,31,1000>();
system("pause") ;
return 0;
}


Jul 23 '05 #6
"christophe r diggins" <cd******@video tron.ca> wrote in message
news:bJ******** **************@ weber.videotron .net...
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.


I should be saying rows and columns, not dimensionality.

Christopher Diggins
Jul 23 '05 #7
> Take a look at the blitz++ Tiny Vector Matrix library

http://www.oonumerics.org/blitz/
This only works for very small matricies, my method works for very
arbitrarily large matricies.
You can also look at the Array classes in
The C++ Scalar, Vector, Matrix and Tensor class Library

http://www.netwood.net/~edwin/svmtl/
I don't see how this code tracks the rows and columns at compile-time.
I also have an old recursive template definitions
for Matrix classes that you can get from

ftp.cs.ucla.edu/pub/Tensor.tar.Z
I can't open it.
All of these things exist
mainly to help answer the questions that you have asked.

Strictly speaking, your questions are off-topic in this forum
but probably dead on in the object oriented numerics mailing list
Okay let me rephrase it. I have presented a way to do very fast matrix
multiplication in C++ by representing the rows and columns as template
parameters. I use some simple template metaprogramming to compute the type
of the result of the matrix multiplication. The core of the technique is:

template&lt;cla ss Matrix1, class Matrix2>
struct MatrixMultiplic ationType {
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(Sli ce1_T x, Slice2_T y) {
assert(x.size() == y.size());
return std::inner_prod uct(x.begin(), x.end(), y.begin(), typename
Slice1_T::value _type(0));
}

template<class Matrix1, class Matrix2>
typename MatrixMultiplic ationType<Matri x1, Matrix2>::type
matrix_multiply (const Matrix1& m1, const Matrix2& m2)
{
typename MatrixMultiplic ationType<Matri x1, 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;
}

My question is: am I duplicating prior work and does anyone find this
interesting?
http://www.oonumerics.org/mailman/li....cgi/oon-list/

Try there. I don't think that you'll be disappointed.


Thanks.

--
Christopher Diggins
Object Oriented Template Library (OOTL)
http://www.ootl.org
Jul 23 '05 #8
christopher diggins wrote:
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.


You might want to look into Strassen's algorithm for matrix
multiplication which is asymptotically faster than the conventional
(row.column) approach.
Jul 23 '05 #9

"christophe r diggins" <cd******@video tron.ca> wrote in message news:bJ******** **************@ weber.videotron .net...
Here is some code I wrote for Matrix multiplication for arbitrary
dimensionality known at compile-time. I am curious how practical it is. For

---------

BTW if I may interfere - now mostly they do it in assembly language to
boost the performance. I'd like to see some bench comparisons for
normal C++ algorithms because I'd say there's not much difference.

UF

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3315
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for my particular application. One of the advantages is that the _compiler_ can force inner matrix dimensions used in multiplication to agree. A...
4
4789
by: Yudan Yi | last post by:
I have a problem to copy (assign) a matrix to another matrix. Curreny, I know copy the number using loops, while it will take some time, I wonder if there have faster method. The following code explain my situation detailed. double ** matrixa, **matrixb; int nrow = 10, mcol = 10; matrixa = initmatrix(nrow, mcol); // allocate memory a...
3
12887
by: robix | last post by:
Hi again. I'm now asking your help because of a smal problem i'm getting with my multiplication matrix code. I'll try to give you as many details as possible. My matrix structure: typedef struct { int col; /* number of colowns */ int lin; /* number of lines*/
7
12048
by: sangeetha | last post by:
Hi, i need to transpose a nx1 matrix to 1xn matrix inorder to multiply with nxn matrix in c language ... can anyone help in this coding ..the nx1 matrix is pi the data type is double *pi..this is used through out the program ..now i need this transpose for further calculations.... Kindly help as soon as possible.....if this is not possible...
14
4933
by: amitnanda | last post by:
Hi Guys, I have a matrix multiplication program in C that multiplies two matrices. When their size is 3*3 or 800*800, the program runs fine. But above that size, I get a "segmentation fault". I need this huge size as part of my assignment.
7
7573
by: VijaKhara | last post by:
Hi all, Is there any method which can implememt the matrix multiplication faster than using the formula as we often do by hand? I am writing the following code and my matrice: one is 3x40000 and the other one 40000x3. the program runs too slow: /*multiply two matrice: xyz_trans * xyz , the output is w 3x3*/
0
2802
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it...
18
2456
by: Hypnotik | last post by:
Hello everyone. I'm writing a program which uses a class called matrix. I have written all of the different functions, constructor, etc. When I run the program I receive "Constructor", which I placed in the constructor, and then the program crashes. I have no clue where my problem is. The matrix is for size 2x2 up to 10x10, and it must be...
3
3875
by: crazygrey | last post by:
Hello, I'm a newbie to C++ so excuse me if my question was trivial but it is important to me. I'm implementing a simple code to find the forward kinematics of a robot: #include "stdafx.h" #include<iostream> #include<iomanip> #include<fstream> #include"math.h"
0
7821
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8190
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1152
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.