1

I was wondering if CUSP library provides a function that creates a matrix with a specific number of columns, rows, and any random values?

I found poisson5pt function but it doesn't return back a matrix with the dimensions I specify!

Thanks in advance

The Hiary
  • 109
  • 1
  • 13
  • `poisson5pt` is for generating a 5 point stencil approximation of the [Poisson equoation](http://en.wikipedia.org/wiki/Poisson%27s_equation) on a regular grid. It has nothing to do with random numbers and the mxn argument is the dimensions of the *computational domain* not the resulting matrix. – talonmies Jul 10 '13 at 09:20
  • I took it from https://github.com/pathscale/cusp-library/blob/master/performance/conversions/test.cu line 107 where it is supposedly used to generate an example – The Hiary Jul 10 '13 at 09:23

1 Answers1

0

In the CUSP matrix gallery you will find random.h which almost does what you want:

template <class MatrixType>
void random(size_t num_rows, size_t num_cols, size_t num_samples, MatrixType& output)

This will produce a matrix of the dimensions you specify with the number of random locations you request filled with 1.

It would be trivial to modify that to use a random value rather than unity, although I don't understand why you would ever want such a matrix. It will not be guaranteed to have any of the properties you probably need in a test matrix if you have plans to use such a matrix in any linear algebra operations.

The Hiary
  • 109
  • 1
  • 13
talonmies
  • 67,081
  • 33
  • 170
  • 244
  • So this function doesn't allow filling the matrix with values other than 1, so is there any other functions that can do that (fill matrix with random values upon creation)?! – The Hiary Jul 10 '13 at 09:44
  • Not that I am aware of, and with good reason, as I mentioned in my answer. I gave you a link to the code. You need to change exactly *one line* to make it do what you want. Just make your own implementation with that one line changed. – talonmies Jul 10 '13 at 09:50