~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

Viewing changes to CXSparse_newfiles/MATLAB/CSparse/cs_randperm_mex.c

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "cs_mex.h"
 
2
/* cs_randperm: random permutation.  p=cs_randperm(n,0) is 1:n,
 
3
 * p=cs_randperm(n,-1) is n:-1:1.  p = cs_randperm (n,seed) is a random
 
4
 * permutation using the given seed (where seed is not 0 or -1).
 
5
 * seed defaults to 1.  A single seed always gives a repeatable permutation.
 
6
 * Use p = cs_randperm(n,rand) to get a permutation that varies with each use.
 
7
 */
 
8
void mexFunction
 
9
(
 
10
    int nargout,
 
11
    mxArray *pargout [ ],
 
12
    int nargin,
 
13
    const mxArray *pargin [ ]
 
14
)
 
15
{
 
16
    double seed ;
 
17
    CS_INT iseed, n, *p ;
 
18
    if (nargout > 1 || nargin < 1 || nargin > 2)
 
19
    {
 
20
        mexErrMsgTxt ("Usage: p = cs_randperm(n,seed)") ;
 
21
    }
 
22
    seed = (nargin > 1) ? mxGetScalar (pargin [1]) : 1 ;
 
23
    iseed = (seed > 0 && seed < 1) ? (seed * RAND_MAX) : seed ;
 
24
    n = mxGetScalar (pargin [0]) ;
 
25
    n = CS_MAX (n, 0) ;
 
26
    p = cs_dl_randperm (n, iseed) ;
 
27
    pargout [0] = cs_dl_mex_put_int (p, n, 1, 1) ;          /* return p */
 
28
}