Skip to content

Commit b77ad0c

Browse files
committed
---
yaml --- r: 146378 b: refs/heads/try2 c: 9ec4c18 h: refs/heads/master v: v3
1 parent 231000d commit b77ad0c

File tree

11 files changed

+250
-37
lines changed

11 files changed

+250
-37
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e9605dc0c9322da9adae5f70099010b5e4a83c92
8+
refs/heads/try2: 9ec4c1851afc15320922259c0c381cdbc9409f17
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/Makefile.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,6 @@ ifneq ($(findstring clean,$(MAKECMDGOALS)),)
677677
endif
678678

679679
ifneq ($(findstring install,$(MAKECMDGOALS)),)
680-
ifdef DESTDIR
681-
CFG_INFO := $(info cfg: setting CFG_PREFIX via DESTDIR, $(DESTDIR)/$(CFG_PREFIX))
682-
CFG_PREFIX:=$(DESTDIR)/$(CFG_PREFIX)
683-
export CFG_PREFIX
684-
endif
685-
686680
CFG_INFO := $(info cfg: including install rules)
687681
include $(CFG_SRC_DIR)mk/install.mk
688682
endif

branches/try2/configure

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,14 @@ then
463463
# extract the first 2 version fields, ignore everything else
464464
sed 's/pandoc \([0-9]*\)\.\([0-9]*\).*/\1 \2/')
465465

466+
MIN_PV_MAJOR="1"
467+
MIN_PV_MINOR="9"
466468
# these patterns are shell globs, *not* regexps
467469
PV_MAJOR=${PV_MAJOR_MINOR% *}
468470
PV_MINOR=${PV_MAJOR_MINOR#* }
469-
if [ "$PV_MAJOR" -lt "1" ] || [ "$PV_MINOR" -lt "8" ]
471+
if [ "$PV_MAJOR" -lt "$MIN_PV_MAJOR" ] || [ "$PV_MINOR" -lt "$MIN_PV_MINOR" ]
470472
then
471-
step_msg "pandoc $PV_MAJOR.$PV_MINOR is too old. disabling"
473+
step_msg "pandoc $PV_MAJOR.$PV_MINOR is too old. Need at least $MIN_PV_MAJOR.$MIN_PV_MINOR. Disabling"
472474
BAD_PANDOC=1
473475
fi
474476
fi

branches/try2/mk/install.mk

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@
1818
# $(2) is the destination directory
1919
# $(3) is the filename/libname-glob
2020
ifdef VERBOSE
21-
INSTALL = install -m755 $(1)/$(3) $(2)/$(3)
21+
INSTALL = install -m755 $(1)/$(3) $(DESTDIR)$(2)/$(3)
2222
else
23-
INSTALL = $(Q)$(call E, install: $(2)/$(3)) && install -m755 $(1)/$(3) $(2)/$(3)
23+
INSTALL = $(Q)$(call E, install: $(DESTDIR)$(2)/$(3)) && install -m755 $(1)/$(3) $(DESTDIR)$(2)/$(3)
2424
endif
2525

2626
# For MK_INSTALL_DIR
2727
# $(1) is the directory to create
28-
MK_INSTALL_DIR = (umask 022 && mkdir -p $(1))
28+
MK_INSTALL_DIR = (umask 022 && mkdir -p $(DESTDIR)$(1))
2929

3030
# For INSTALL_LIB,
3131
# Target-specific $(LIB_SOURCE_DIR) is the source directory
3232
# Target-specific $(LIB_DESTIN_DIR) is the destination directory
3333
# $(1) is the filename/libname-glob
3434
ifdef VERBOSE
35-
DO_INSTALL_LIB = install -m644 `ls -drt1 $(LIB_SOURCE_DIR)/$(1) | tail -1` $(LIB_DESTIN_DIR)/
35+
DO_INSTALL_LIB = install -m644 `ls -drt1 $(LIB_SOURCE_DIR)/$(1) | tail -1` $(DESTDIR)$(LIB_DESTIN_DIR)/
3636
else
37-
DO_INSTALL_LIB = $(Q)$(call E, install_lib: $(LIB_DESTIN_DIR)/$(1)) && \
38-
install -m644 `ls -drt1 $(LIB_SOURCE_DIR)/$(1) | tail -1` $(LIB_DESTIN_DIR)/
37+
DO_INSTALL_LIB = $(Q)$(call E, install_lib: $(DESTDIR)$(LIB_DESTIN_DIR)/$(1)) && \
38+
install -m644 `ls -drt1 $(LIB_SOURCE_DIR)/$(1) | tail -1` $(DESTDIR)$(LIB_DESTIN_DIR)/
3939
endif
4040

4141
# Target-specific $(LIB_SOURCE_DIR) is the source directory
@@ -152,9 +152,9 @@ install-host: $(CSREQ$(ISTAGE)_T_$(CFG_BUILD_)_H_$(CFG_BUILD_))
152152
$(Q)$(call INSTALL_LIB,$(LIBRUSTDOC_GLOB_$(CFG_BUILD)))
153153
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUNTIME_$(CFG_BUILD)))
154154
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUSTLLVM_$(CFG_BUILD)))
155-
$(Q)$(call INSTALL,$(S)/man, $(CFG_MANDIR)/man1,rustc.1)
156-
$(Q)$(call INSTALL,$(S)/man, $(CFG_MANDIR)/man1,rustdoc.1)
157-
$(Q)$(call INSTALL,$(S)/man, $(CFG_MANDIR)/man1,rustpkg.1)
155+
$(Q)$(call INSTALL,$(S)/man,$(CFG_MANDIR)/man1,rustc.1)
156+
$(Q)$(call INSTALL,$(S)/man,$(CFG_MANDIR)/man1,rustdoc.1)
157+
$(Q)$(call INSTALL,$(S)/man,$(CFG_MANDIR)/man1,rustpkg.1)
158158

159159
install-targets: $(INSTALL_TARGET_RULES)
160160

branches/try2/src/librustc/rustc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ pub fn monitor(f: ~fn(@diagnostic::Emitter)) {
338338
let ch = SharedChan::new(ch);
339339
let ch_capture = ch.clone();
340340
let mut task_builder = task::task();
341+
task_builder.name("rustc");
341342
task_builder.supervised();
342343

343344
// XXX: Hacks on hacks. If the env is trying to override the stack size

branches/try2/src/libstd/char.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn is_digit_radix(c: char, radix: uint) -> bool {
187187
#[inline]
188188
pub fn to_digit(c: char, radix: uint) -> Option<uint> {
189189
if radix > 36 {
190-
fail!("to_digit: radix {} is to high (maximum 36)", radix);
190+
fail!("to_digit: radix {} is too high (maximum 36)", radix);
191191
}
192192
let val = match c {
193193
'0' .. '9' => c as uint - ('0' as uint),
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! The Gamma distribution.
12+
13+
use rand::Rng;
14+
use super::{IndependentSample, Sample, StandardNormal, Exp};
15+
use num;
16+
17+
/// The Gamma distribution `Gamma(shape, scale)` distribution.
18+
///
19+
/// The density function of this distribution is
20+
///
21+
/// ```
22+
/// f(x) = x^(k - 1) * exp(-x / θ) / (Γ(k) * θ^k)
23+
/// ```
24+
///
25+
/// where `Γ` is the Gamma function, `k` is the shape and `θ` is the
26+
/// scale and both `k` and `θ` are strictly positive.
27+
///
28+
/// The algorithm used is that described by Marsaglia & Tsang 2000[1],
29+
/// falling back to directly sampling from an Exponential for `shape
30+
/// == 1`, and using the boosting technique described in [1] for
31+
/// `shape < 1`.
32+
///
33+
/// # Example
34+
///
35+
/// ```rust
36+
/// use std::rand;
37+
/// use std::rand::distributions::{IndependentSample, Gamma};
38+
///
39+
/// fn main() {
40+
/// let gamma = Gamma::new(2.0, 5.0);
41+
/// let v = gamma.ind_sample(rand::task_rng());
42+
/// println!("{} is from a Gamma(2, 5) distribution", v);
43+
/// }
44+
/// ```
45+
///
46+
/// [1]: George Marsaglia and Wai Wan Tsang. 2000. "A Simple Method
47+
/// for Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3
48+
/// (September 2000),
49+
/// 363-372. DOI:[10.1145/358407.358414](http://doi.acm.org/10.1145/358407.358414)
50+
pub enum Gamma {
51+
priv Large(GammaLargeShape),
52+
priv One(Exp),
53+
priv Small(GammaSmallShape)
54+
}
55+
56+
// These two helpers could be made public, but saving the
57+
// match-on-Gamma-enum branch from using them directly (e.g. if one
58+
// knows that the shape is always > 1) doesn't appear to be much
59+
// faster.
60+
61+
/// Gamma distribution where the shape parameter is less than 1.
62+
///
63+
/// Note, samples from this require a compulsory floating-point `pow`
64+
/// call, which makes it significantly slower than sampling from a
65+
/// gamma distribution where the shape parameter is greater than or
66+
/// equal to 1.
67+
///
68+
/// See `Gamma` for sampling from a Gamma distribution with general
69+
/// shape parameters.
70+
struct GammaSmallShape {
71+
inv_shape: f64,
72+
large_shape: GammaLargeShape
73+
}
74+
75+
/// Gamma distribution where the shape parameter is larger than 1.
76+
///
77+
/// See `Gamma` for sampling from a Gamma distribution with general
78+
/// shape parameters.
79+
struct GammaLargeShape {
80+
shape: f64,
81+
scale: f64,
82+
c: f64,
83+
d: f64
84+
}
85+
86+
impl Gamma {
87+
/// Construct an object representing the `Gamma(shape, scale)`
88+
/// distribution.
89+
///
90+
/// Fails if `shape <= 0` or `scale <= 0`.
91+
pub fn new(shape: f64, scale: f64) -> Gamma {
92+
assert!(shape > 0.0, "Gamma::new called with shape <= 0");
93+
assert!(scale > 0.0, "Gamma::new called with scale <= 0");
94+
95+
match shape {
96+
1.0 => One(Exp::new(1.0 / scale)),
97+
0.0 .. 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
98+
_ => Large(GammaLargeShape::new_raw(shape, scale))
99+
}
100+
}
101+
}
102+
103+
impl GammaSmallShape {
104+
fn new_raw(shape: f64, scale: f64) -> GammaSmallShape {
105+
GammaSmallShape {
106+
inv_shape: 1. / shape,
107+
large_shape: GammaLargeShape::new_raw(shape + 1.0, scale)
108+
}
109+
}
110+
}
111+
112+
impl GammaLargeShape {
113+
fn new_raw(shape: f64, scale: f64) -> GammaLargeShape {
114+
let d = shape - 1. / 3.;
115+
GammaLargeShape {
116+
shape: shape,
117+
scale: scale,
118+
c: 1. / num::sqrt(9. * d),
119+
d: d
120+
}
121+
}
122+
}
123+
124+
impl Sample<f64> for Gamma {
125+
fn sample<R: Rng>(&mut self, rng: &mut R) -> f64 { self.ind_sample(rng) }
126+
}
127+
impl Sample<f64> for GammaSmallShape {
128+
fn sample<R: Rng>(&mut self, rng: &mut R) -> f64 { self.ind_sample(rng) }
129+
}
130+
impl Sample<f64> for GammaLargeShape {
131+
fn sample<R: Rng>(&mut self, rng: &mut R) -> f64 { self.ind_sample(rng) }
132+
}
133+
134+
impl IndependentSample<f64> for Gamma {
135+
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
136+
match *self {
137+
Small(ref g) => g.ind_sample(rng),
138+
One(ref g) => g.ind_sample(rng),
139+
Large(ref g) => g.ind_sample(rng),
140+
}
141+
}
142+
}
143+
impl IndependentSample<f64> for GammaSmallShape {
144+
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
145+
// Need (0, 1) here.
146+
let mut u = rng.gen::<f64>();
147+
while u == 0. {
148+
u = rng.gen();
149+
}
150+
151+
self.large_shape.ind_sample(rng) * num::pow(u, self.inv_shape)
152+
}
153+
}
154+
impl IndependentSample<f64> for GammaLargeShape {
155+
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
156+
loop {
157+
let x = *rng.gen::<StandardNormal>();
158+
let v_cbrt = 1.0 + self.c * x;
159+
if v_cbrt <= 0.0 { // a^3 <= 0 iff a <= 0
160+
continue
161+
}
162+
163+
let v = v_cbrt * v_cbrt * v_cbrt;
164+
// Need (0, 1) here, not [0, 1). This would be faster if
165+
// we were generating an f64 in (0, 1) directly.
166+
let mut u = rng.gen::<f64>();
167+
while u == 0.0 {
168+
u = rng.gen();
169+
}
170+
171+
let x_sqr = x * x;
172+
if u < 1.0 - 0.0331 * x_sqr * x_sqr ||
173+
num::ln(u) < 0.5 * x_sqr + self.d * (1.0 - v + num::ln(v)) {
174+
return self.d * v * self.scale
175+
}
176+
}
177+
}
178+
}
179+
180+
#[cfg(test)]
181+
mod bench {
182+
use super::*;
183+
use mem::size_of;
184+
use rand::distributions::IndependentSample;
185+
use rand::{StdRng, RAND_BENCH_N};
186+
use extra::test::BenchHarness;
187+
use iter::range;
188+
use option::{Some, None};
189+
190+
191+
#[bench]
192+
fn bench_gamma_large_shape(bh: &mut BenchHarness) {
193+
let gamma = Gamma::new(10., 1.0);
194+
let mut rng = StdRng::new();
195+
196+
do bh.iter {
197+
for _ in range(0, RAND_BENCH_N) {
198+
gamma.ind_sample(&mut rng);
199+
}
200+
}
201+
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
202+
}
203+
204+
#[bench]
205+
fn bench_gamma_small_shape(bh: &mut BenchHarness) {
206+
let gamma = Gamma::new(0.1, 1.0);
207+
let mut rng = StdRng::new();
208+
209+
do bh.iter {
210+
for _ in range(0, RAND_BENCH_N) {
211+
gamma.ind_sample(&mut rng);
212+
}
213+
}
214+
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
215+
}
216+
}

branches/try2/src/libstd/rand/distributions.rs renamed to branches/try2/src/libstd/rand/distributions/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ use rand::{Rng,Rand};
2727
use clone::Clone;
2828

2929
pub use self::range::Range;
30+
pub use self::gamma::Gamma;
3031

3132
pub mod range;
33+
pub mod gamma;
3234

3335
/// Types that can be used to create a random instance of `Support`.
3436
pub trait Sample<Support> {
@@ -554,36 +556,34 @@ mod tests {
554556
#[cfg(test)]
555557
mod bench {
556558
use extra::test::BenchHarness;
557-
use rand::*;
559+
use rand::{XorShiftRng, RAND_BENCH_N};
558560
use super::*;
559561
use iter::range;
560562
use option::{Some, None};
561563
use mem::size_of;
562564

563-
static N: u64 = 100;
564-
565565
#[bench]
566566
fn rand_normal(bh: &mut BenchHarness) {
567567
let mut rng = XorShiftRng::new();
568568
let mut normal = Normal::new(-2.71828, 3.14159);
569569

570570
do bh.iter {
571-
for _ in range(0, N) {
571+
for _ in range(0, RAND_BENCH_N) {
572572
normal.sample(&mut rng);
573573
}
574574
}
575-
bh.bytes = size_of::<f64>() as u64 * N;
575+
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
576576
}
577577
#[bench]
578578
fn rand_exp(bh: &mut BenchHarness) {
579579
let mut rng = XorShiftRng::new();
580580
let mut exp = Exp::new(2.71828 * 3.14159);
581581

582582
do bh.iter {
583-
for _ in range(0, N) {
583+
for _ in range(0, RAND_BENCH_N) {
584584
exp.sample(&mut rng);
585585
}
586586
}
587-
bh.bytes = size_of::<f64>() as u64 * N;
587+
bh.bytes = size_of::<f64>() as u64 * RAND_BENCH_N;
588588
}
589589
}

0 commit comments

Comments
 (0)