changeset 1304:ca7e4829f6a0

Merged
author Olivier Delalleau <delallea@iro>
date Fri, 01 Oct 2010 14:56:54 -0400
parents b5673b32e8ec (current diff) 1a3090eca2ec (diff)
children b60a9b6eee68
files doc/v2_planning/coding_style.txt
diffstat 2 files changed, 34 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/doc/v2_planning/coding_style.txt	Fri Oct 01 14:56:01 2010 -0400
+++ b/doc/v2_planning/coding_style.txt	Fri Oct 01 14:56:54 2010 -0400
@@ -245,34 +245,45 @@
 Ideas (DE):
 
    * Most major Python projects suggest following PEP-257:
-http://www.python.org/dev/peps/pep-0257/, which contains conventions on
-writing docstrings (what they should contain, not the specific markup) for
-Python. These are very general conventions, however,.
+     http://www.python.org/dev/peps/pep-0257/, which contains conventions on
+     writing docstrings (what they should contain, not the specific markup)
+     for Python. These are very general conventions, however,.
    
    * Numpy, in particular, has a very nice page on how to document things if
-contributing: http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines
-(it's mostly about documentation, not coding style, despite the page name). 
+     contributing: http://projects.scipy.org/numpy/wiki/CodingStyleGuidelines
+     (it's mostly about documentation, not coding style, despite the page
+     name). 
   
-   * A pretty good example from numpy, with relevant comments: 
-http://github.com/numpy/numpy/blob/master/doc/example.py 
+   * A pretty good example from numpy, with relevant comments:
+     http://github.com/numpy/numpy/blob/master/doc/example.py 
   
    * A real-life example (record arrays) from numpy:
-http://github.com/numpy/numpy/blob/master/numpy/core/records.py
+     http://github.com/numpy/numpy/blob/master/numpy/core/records.py
  
    * The recommendations are quite sane and common-sense, we should follow them.
-  
-   * Make sure that what we write is compatible with tools like sphinx's autodoc
-extension: http://sphinx.pocoo.org/ext/autodoc.html#module-sphinx.ext.autodoc (which we
-will most probably use to generate semi-automatic pretty docs)
+ 
+   * numpy's way of doing things is a bit different from the way we currently
+     document Theano: they don't use param/type/rtype, for instance, but nice
+     readable section titles. I personally find their approach better-looking
+     and they do have a sphinx extension that would allow us to have the same
+     style
+     (http://github.com/numpy/numpy/blob/master/doc/sphinxext/numpydoc.py).
+     The disadvantage of taking this approach is that Theano and Pylearn will
+     be documented slightly differently
+
+   * Make sure that what we write is compatible with tools like sphinx's
+     autodoc extension:
+     http://sphinx.pocoo.org/ext/autodoc.html#module-sphinx.ext.autodoc (which
+     we will most probably use to generate semi-automatic pretty docs)
   
    * Nice cheat-sheet for docutils:
-   http://docutils.sourceforge.net/docs/user/rst/quickref.html
+     http://docutils.sourceforge.net/docs/user/rst/quickref.html
   
    * http://docs.python.org/release/2.5.2/lib/module-doctest.html -
-   in-documentation unit-testing: we should perhaps encourage people to write
-such things where warranted (where there are interesting usage examples).
-notetests can automatically run those, so no configuration overhead is
-necessary.
+     in-documentation unit-testing: we should perhaps encourage people to
+     write such things where warranted (where there are interesting usage
+     examples).  notetests can automatically run those, so no configuration
+     overhead is necessary.
 
 Compatibility with various Python versions
 ------------------------------------------
--- a/pylearn/formulas/noise.py	Fri Oct 01 14:56:01 2010 -0400
+++ b/pylearn/formulas/noise.py	Fri Oct 01 14:56:54 2010 -0400
@@ -37,8 +37,7 @@
             size = inp.shape,
             n = 1,
             p =  1 - noise_lvl,
-            dtype=theano.config.floatX) 
-    # QUESTION: should the dtype not default to the input dtype?
+            dtype=inp.dtype)
     return mask * input
 
 
@@ -51,8 +50,9 @@
     :type noise_lvl: tuple(float,float)
     :param noise_lvl: The %% of noise for the salt and pepper. Between 0 (no noise) and 1.
     """
-    return theano_rng.binomial( size = inp.shape, n = 1, p =  1 - noise_lvl[0], dtype=theano.config.floatX) * inp \
-                        + (inp==0) * theano_rng.binomial( size = inp.shape, n = 1, p =  noise_lvl[1], dtype=theano.config.floatX)
+    assert inp.dtype in ['float32','float64']
+    return theano_rng.binomial( size = inp.shape, n = 1, p =  1 - noise_lvl[0], dtype=inp.dtype) * inp \
+                        + (inp==0) * theano_rng.binomial( size = inp.shape, n = 1, p =  noise_lvl[1], dtype=inp.dtype)
 
 @tags.tags('noise','gauss','gaussian')
 def gaussian_noise(theano_rng,inp,noise_lvl):
@@ -63,4 +63,5 @@
     :type noise_lvl: float
     :param noise_lvl: The standard deviation of the gaussian.
     """
-    return theano_rng.normal( size = inp.shape, std = noise_lvl, dtype=theano.config.floatX) + inp
+    assert inp.dtype in ['float32','float64']
+    return theano_rng.normal( size = inp.shape, std = noise_lvl, dtype=inp.dtype) + inp