~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/python/ga4py/gain/random.pyx

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2012-02-09 20:02:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209200241-jgk03qfsphal4ug2
Tags: 6.1-1
* New upstream release.

[ Michael Banck ]
* debian/patches/02_makefile_flags.patch: Updated.
* debian/patches/02_makefile_flags.patch: Use internal blas and lapack code.
* debian/patches/02_makefile_flags.patch: Define GCC4 for LINUX and LINUX64
  (Closes: #632611 and LP: #791308).
* debian/control (Build-Depends): Added openssh-client.
* debian/rules (USE_SCALAPACK, SCALAPACK): Removed variables (Closes:
  #654658).
* debian/rules (LIBDIR, USE_MPIF4, ARMCI_NETWORK): New variables.
* debian/TODO: New file.
* debian/control (Build-Depends): Removed libblas-dev, liblapack-dev and
  libscalapack-mpi-dev.
* debian/patches/04_show_testsuite_diff_output.patch: New patch, shows the
  diff output for failed tests.
* debian/patches/series: Adjusted.
* debian/testsuite: Optionally run all tests if "all" is passed as option.
* debian/rules: Run debian/testsuite with "all" if DEB_BUILD_OPTIONS
  contains "checkall".

[ Daniel Leidert ]
* debian/control: Used wrap-and-sort. Added Vcs-Svn and Vcs-Browser fields.
  (Priority): Moved to extra according to policy section 2.5.
  (Standards-Version): Bumped to 3.9.2.
  (Description): Fixed a typo.
* debian/watch: Added.
* debian/patches/03_hurd-i386_define_path_max.patch: Added.
  - Define MAX_PATH if not defines to fix FTBFS on hurd.
* debian/patches/series: Adjusted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from core import asarray
 
2
from core import ndarray
 
3
from core import me
 
4
 
 
5
from mpi4py import MPI
 
6
 
 
7
import numpy as np
 
8
 
 
9
def random_sample(size=None):
 
10
    """random_sample(size=None)
 
11
 
 
12
        Return random floats in the half-open interval [0.0, 1.0).
 
13
 
 
14
        Results are from the "continuous uniform" distribution over the
 
15
        stated interval.  To sample :math:`Unif[a, b), b > a` multiply
 
16
        the output of `random_sample` by `(b-a)` and add `a`::
 
17
 
 
18
          (b - a) * random_sample() + a
 
19
 
 
20
        Parameters
 
21
        ----------
 
22
        size : int or tuple of ints, optional
 
23
            Defines the shape of the returned array of random floats. If None
 
24
            (the default), returns a single float.
 
25
 
 
26
        Returns
 
27
        -------
 
28
        out : float or ndarray of floats
 
29
            Array of random floats of shape `size` (unless ``size=None``, in which
 
30
            case a single float is returned).
 
31
 
 
32
        Examples
 
33
        --------
 
34
        >>> np.random.random_sample()
 
35
        0.47108547995356098
 
36
        >>> type(np.random.random_sample())
 
37
        <type 'float'>
 
38
        >>> np.random.random_sample((5,))
 
39
        array([ 0.30220482,  0.86820401,  0.1654503 ,  0.11659149,  0.54323428])
 
40
 
 
41
        Three-by-two array of random numbers from [-5, 0):
 
42
 
 
43
        >>> 5 * np.random.random_sample((3, 2)) - 5
 
44
        array([[-3.99149989, -0.52338984],
 
45
               [-2.99091858, -0.79479508],
 
46
               [-1.23204345, -1.75224494]])
 
47
 
 
48
    """
 
49
    # this was my first implementation
 
50
    # but each process does a lot of unnecessary work
 
51
    #a = np.random.random_sample(size)
 
52
    #if size is None:
 
53
    #    return a
 
54
    #else:
 
55
    #    return asarray(a)
 
56
    a = None
 
57
    if size is None:
 
58
        a = np.random.random_sample(size)
 
59
        a = MPI.COMM_WORLD.bcast(a, 0)
 
60
    else:
 
61
        a = ndarray(size, dtype=float)
 
62
        buf = a.access()
 
63
        if buf is not None:
 
64
            buf[:] = np.random.random_sample(buf.shape)
 
65
        a.release_update()
 
66
    return a
 
67
 
 
68
def seed(seed=None):
 
69
    """seed(seed=None)
 
70
 
 
71
        Seed the generator.
 
72
 
 
73
        This method is called when `RandomState` is initialized. It can be
 
74
        called again to re-seed the generator. For details, see `RandomState`.
 
75
 
 
76
        Parameters
 
77
        ----------
 
78
        seed : int or array_like, optional
 
79
            Seed for `RandomState`.
 
80
 
 
81
        See Also
 
82
        --------
 
83
        RandomState
 
84
 
 
85
    """
 
86
    #np.random.seed(seed)
 
87
    if seed is None:
 
88
        np.random.seed()
 
89
    elif isinstance(seed,int):
 
90
        np.random.seed(seed+me())
 
91
    else:
 
92
        a = np.asarray(seed)
 
93
        a += me()
 
94
        np.random.seed(a)