comparison deep/stacked_dae/utils.py @ 167:1f5937e9e530

More moves - transformations into data_generation, added "deep" folder
author Dumitru Erhan <dumitru.erhan@gmail.com>
date Fri, 26 Feb 2010 14:15:38 -0500
parents scripts/stacked_dae/utils.py@7d8366fb90bf
children 3632e6258642
comparison
equal deleted inserted replaced
166:17ae5a1a4dd1 167:1f5937e9e530
1 #!/usr/bin/python
2
3 from jobman import DD
4
5 # from pylearn codebase
6 def update_locals(obj, dct):
7 if 'self' in dct:
8 del dct['self']
9 obj.__dict__.update(dct)
10
11 def produit_croise_jobs(val_dict):
12 job_list = [DD()]
13 all_keys = val_dict.keys()
14
15 for key in all_keys:
16 possible_values = val_dict[key]
17 new_job_list = []
18 for val in possible_values:
19 for job in job_list:
20 to_insert = job.copy()
21 to_insert.update({key: val})
22 new_job_list.append(to_insert)
23 job_list = new_job_list
24
25 return job_list
26
27 def test_produit_croise_jobs():
28 vals = {'a': [1,2], 'b': [3,4,5]}
29 print produit_croise_jobs(vals)
30
31
32 # taken from http://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python
33 """Simple module for getting amount of memory used by a specified user's
34 processes on a UNIX system.
35 It uses UNIX ps utility to get the memory usage for a specified username and
36 pipe it to awk for summing up per application memory usage and return the total.
37 Python's Popen() from subprocess module is used for spawning ps and awk.
38
39 """
40
41 import subprocess
42
43 class MemoryMonitor(object):
44
45 def __init__(self, username):
46 """Create new MemoryMonitor instance."""
47 self.username = username
48
49 def usage(self):
50 """Return int containing memory used by user's processes."""
51 self.process = subprocess.Popen("ps -u %s -o rss | awk '{sum+=$1} END {print sum}'" % self.username,
52 shell=True,
53 stdout=subprocess.PIPE,
54 )
55 self.stdout_list = self.process.communicate()[0].split('\n')
56 return int(self.stdout_list[0])
57