{"action":"created","comment":{"url":"https://api.github.com/repos/opesci/devito/pulls/comments/70683559","id":70683559,"diff_hunk":"@@ -1,29 +1,102 @@\n import numpy as np\n from sympy import IndexedBase\n from tools import aligned\n-\n+import os\n+from signal import *\n+import sys\n \n __all__ = ['DenseData', 'TimeData', 'PointData']\n \n \n class DenseData(IndexedBase):\n-    def __init__(self, name, shape, dtype):\n+\n+    def __init__(self, name, shape, dtype, disk_path=None):\n         self.name = name\n         self.dtype = dtype\n         self.pointer = None\n         self.initializer = None\n+        self.disk_path = disk_path\n         super(DenseData, self).__init__(name)\n \n     def __new__(cls, *args, **kwargs):\n         return IndexedBase.__new__(cls, args[0], shape=args[1])\n \n+    # this is the default directory where memmap files will be created\n+    _default_disk_path = None\n+    # holds the string name of all memmap file created\n+    _memmap_file_list = []\n+    # default exit code used on interrupt and kill\n+    _default_exit_code = 0\n+\n+    # functions for managing memmap files\n+    # call this method to specify where you want memmap file to be created\n+    @staticmethod\n+    def set_default_disk_path(disk_path):\n+        \"\"\"call this method to specify default directory to create memmap file\"\"\"\n+        if not os.path.exists(disk_path):\n+            os.makedirs(disk_path)\n+        DenseData._default_disk_path = disk_path\n+        print(\"default disk path set to: \" + DenseData._default_disk_path)\n+\n+    @staticmethod\n+    def get_memmap_file_list():\n+        \"\"\"returns the list of string path to all memmap file created\"\"\"\n+        return DenseData._memmap_file_list\n+\n+    # used for clean memmap file on normal exit\n+    @staticmethod\n+    def remove_memmap_file():\n+        \"\"\"call this method at the end of script to clean up generated memmpa file\"\"\"\n+        for f in DenseData._memmap_file_list:\n+            try:\n+                os.remove(f)\n+            except OSError:\n+                print(\"error removing \" + f + \" skipping\")\n+                pass\n+\n+    # used for clean memmap file on signal, internal method\n+    @staticmethod\n+    def _remove_memmap_file_on_signal(*args):\n+        DenseData.remove_memmap_file()\n+        sys.exit(DenseData._default_exit_code)\n+\n+    # to register clean up method for chosen signals\n+    @staticmethod\n+    def register_remove_memmap_file_signal():\n+        \"\"\"call this method to make sure memmap files are removed on interrupt or kill\"\"\"\n+        for sig in (SIGABRT, SIGINT, SIGSEGV, SIGTERM):\n+            signal(sig, DenseData._remove_memmap_file_on_signal)\n+    # end of functions for managing memmap files\n+\n+    # This function allocate memmory for this data. if either _defualt_disk_path or\n+    # self.disk_path is not None, a numpy memmap is used, if not a numpy ndarray is used.\n+    # Warning: this function assume that seld.name is unique\n+    def _allocate_memory(self):\n+        \"\"\"allocate memmory for this data. if either _defualt_disk_path or self.disk_path is not None,\n+           a numpy memmap is used, if not a numpy ndarray is used.\"\"\"\n+        if DenseData._default_disk_path is None and self.disk_path is None:\n+            # not disk_path use ndarray\n+            self.pointer = aligned(np.zeros(self.shape, self.dtype, order='C'), alignment=64)\n+            return\n+        elif self.disk_path is None:\n+            # using defualt disk_path\n+            self.disk_path = DenseData._default_disk_path\n+        elif not os.path.exists(self.disk_path):\n+            # create disk path\n+            os.makedirs(self.disk_path)\n+        # allocate memory\n+        f = self.disk_path + \"/data_\" + self.name\n+        self.pointer = aligned(np.memmap(filename=f, dtype=self.dtype, mode='w+', shape=tuple(self.shape), order='C'), alignment=64)","path":"devito/interfaces.py","position":89,"original_position":91,"commit_id":"1cfff86cf92de32ace3d93fb46f9681168c81056","original_commit_id":"a2b2f995c9df0e42eea88441bbde7220ac97cb44","user":{"login":"navjotk","id":679809,"avatar_url":"https://avatars.githubusercontent.com/u/679809?v=3","gravatar_id":"","url":"https://api.github.com/users/navjotk","html_url":"https://github.com/navjotk","followers_url":"https://api.github.com/users/navjotk/followers","following_url":"https://api.github.com/users/navjotk/following{/other_user}","gists_url":"https://api.github.com/users/navjotk/gists{/gist_id}","starred_url":"https://api.github.com/users/navjotk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/navjotk/subscriptions","organizations_url":"https://api.github.com/users/navjotk/orgs","repos_url":"https://api.github.com/users/navjotk/repos","events_url":"https://api.github.com/users/navjotk/events{/privacy}","received_events_url":"https://api.github.com/users/navjotk/received_events","type":"User","site_admin":false},"body":"It is still there. Can you make sure that the two lines do the same thing? Since the function `aligned` was written with `ndarray` in mind. ","created_at":"2016-07-13T18:37:35Z","updated_at":"2016-07-13T18:37:35Z","html_url":"https://github.com/opesci/devito/pull/36#discussion_r70683559","pull_request_url":"https://api.github.com/repos/opesci/devito/pulls/36","_links":{"self":{"href":"https://api.github.com/repos/opesci/devito/pulls/comments/70683559"},"html":{"href":"https://github.com/opesci/devito/pull/36#discussion_r70683559"},"pull_request":{"href":"https://api.github.com/repos/opesci/devito/pulls/36"}}},"pull_request":{"url":"https://api.github.com/repos/opesci/devito/pulls/36","id":76981571,"html_url":"https://github.com/opesci/devito/pull/36","diff_url":"https://github.com/opesci/devito/pull/36.diff","patch_url":"https://github.com/opesci/devito/pull/36.patch","issue_url":"https://api.github.com/repos/opesci/devito/issues/36","number":36,"state":"open","locked":false,"title":"Memmap","user":{"login":"pp1336","id":19698704,"avatar_url":"https://avatars.githubusercontent.com/u/19698704?v=3","gravatar_id":"","url":"https://api.github.com/users/pp1336","html_url":"https://github.com/pp1336","followers_url":"https://api.github.com/users/pp1336/followers","following_url":"https://api.github.com/users/pp1336/following{/other_user}","gists_url":"https://api.github.com/users/pp1336/gists{/gist_id}","starred_url":"https://api.github.com/users/pp1336/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pp1336/subscriptions","organizations_url":"https://api.github.com/users/pp1336/orgs","repos_url":"https://api.github.com/users/pp1336/repos","events_url":"https://api.github.com/users/pp1336/events{/privacy}","received_events_url":"https://api.github.com/users/pp1336/received_events","type":"User","site_admin":false},"body":"Implementing memmap spills to disk","created_at":"2016-07-11T16:16:00Z","updated_at":"2016-07-13T18:37:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e6c3b3d2a8ad69eb15e627d20971f4c8b863b310","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/opesci/devito/pulls/36/commits","review_comments_url":"https://api.github.com/repos/opesci/devito/pulls/36/comments","review_comment_url":"https://api.github.com/repos/opesci/devito/pulls/comments{/number}","comments_url":"https://api.github.com/repos/opesci/devito/issues/36/comments","statuses_url":"https://api.github.com/repos/opesci/devito/statuses/1cfff86cf92de32ace3d93fb46f9681168c81056","head":{"label":"opesci:memmap","ref":"memmap","sha":"1cfff86cf92de32ace3d93fb46f9681168c81056","user":{"login":"opesci","id":10018551,"avatar_url":"https://avatars.githubusercontent.com/u/10018551?v=3","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"repo":{"id":54585666,"name":"devito","full_name":"opesci/devito","owner":{"login":"opesci","id":10018551,"avatar_url":"https://avatars.githubusercontent.com/u/10018551?v=3","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opesci/devito","description":"Code generation for the inversion workflow","fork":false,"url":"https://api.github.com/repos/opesci/devito","forks_url":"https://api.github.com/repos/opesci/devito/forks","keys_url":"https://api.github.com/repos/opesci/devito/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opesci/devito/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opesci/devito/teams","hooks_url":"https://api.github.com/repos/opesci/devito/hooks","issue_events_url":"https://api.github.com/repos/opesci/devito/issues/events{/number}","events_url":"https://api.github.com/repos/opesci/devito/events","assignees_url":"https://api.github.com/repos/opesci/devito/assignees{/user}","branches_url":"https://api.github.com/repos/opesci/devito/branches{/branch}","tags_url":"https://api.github.com/repos/opesci/devito/tags","blobs_url":"https://api.github.com/repos/opesci/devito/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opesci/devito/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opesci/devito/git/refs{/sha}","trees_url":"https://api.github.com/repos/opesci/devito/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opesci/devito/statuses/{sha}","languages_url":"https://api.github.com/repos/opesci/devito/languages","stargazers_url":"https://api.github.com/repos/opesci/devito/stargazers","contributors_url":"https://api.github.com/repos/opesci/devito/contributors","subscribers_url":"https://api.github.com/repos/opesci/devito/subscribers","subscription_url":"https://api.github.com/repos/opesci/devito/subscription","commits_url":"https://api.github.com/repos/opesci/devito/commits{/sha}","git_commits_url":"https://api.github.com/repos/opesci/devito/git/commits{/sha}","comments_url":"https://api.github.com/repos/opesci/devito/comments{/number}","issue_comment_url":"https://api.github.com/repos/opesci/devito/issues/comments{/number}","contents_url":"https://api.github.com/repos/opesci/devito/contents/{+path}","compare_url":"https://api.github.com/repos/opesci/devito/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opesci/devito/merges","archive_url":"https://api.github.com/repos/opesci/devito/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opesci/devito/downloads","issues_url":"https://api.github.com/repos/opesci/devito/issues{/number}","pulls_url":"https://api.github.com/repos/opesci/devito/pulls{/number}","milestones_url":"https://api.github.com/repos/opesci/devito/milestones{/number}","notifications_url":"https://api.github.com/repos/opesci/devito/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opesci/devito/labels{/name}","releases_url":"https://api.github.com/repos/opesci/devito/releases{/id}","deployments_url":"https://api.github.com/repos/opesci/devito/deployments","created_at":"2016-03-23T18:59:49Z","updated_at":"2016-04-22T12:11:36Z","pushed_at":"2016-07-13T17:40:51Z","git_url":"git://github.com/opesci/devito.git","ssh_url":"git@github.com:opesci/devito.git","clone_url":"https://github.com/opesci/devito.git","svn_url":"https://github.com/opesci/devito","homepage":null,"size":379,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":12,"forks":0,"open_issues":12,"watchers":0,"default_branch":"master"}},"base":{"label":"opesci:master","ref":"master","sha":"af221e8cdb8e1b25a81c8cfc36615d442a4352bd","user":{"login":"opesci","id":10018551,"avatar_url":"https://avatars.githubusercontent.com/u/10018551?v=3","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"repo":{"id":54585666,"name":"devito","full_name":"opesci/devito","owner":{"login":"opesci","id":10018551,"avatar_url":"https://avatars.githubusercontent.com/u/10018551?v=3","gravatar_id":"","url":"https://api.github.com/users/opesci","html_url":"https://github.com/opesci","followers_url":"https://api.github.com/users/opesci/followers","following_url":"https://api.github.com/users/opesci/following{/other_user}","gists_url":"https://api.github.com/users/opesci/gists{/gist_id}","starred_url":"https://api.github.com/users/opesci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opesci/subscriptions","organizations_url":"https://api.github.com/users/opesci/orgs","repos_url":"https://api.github.com/users/opesci/repos","events_url":"https://api.github.com/users/opesci/events{/privacy}","received_events_url":"https://api.github.com/users/opesci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opesci/devito","description":"Code generation for the inversion workflow","fork":false,"url":"https://api.github.com/repos/opesci/devito","forks_url":"https://api.github.com/repos/opesci/devito/forks","keys_url":"https://api.github.com/repos/opesci/devito/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opesci/devito/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opesci/devito/teams","hooks_url":"https://api.github.com/repos/opesci/devito/hooks","issue_events_url":"https://api.github.com/repos/opesci/devito/issues/events{/number}","events_url":"https://api.github.com/repos/opesci/devito/events","assignees_url":"https://api.github.com/repos/opesci/devito/assignees{/user}","branches_url":"https://api.github.com/repos/opesci/devito/branches{/branch}","tags_url":"https://api.github.com/repos/opesci/devito/tags","blobs_url":"https://api.github.com/repos/opesci/devito/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opesci/devito/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opesci/devito/git/refs{/sha}","trees_url":"https://api.github.com/repos/opesci/devito/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opesci/devito/statuses/{sha}","languages_url":"https://api.github.com/repos/opesci/devito/languages","stargazers_url":"https://api.github.com/repos/opesci/devito/stargazers","contributors_url":"https://api.github.com/repos/opesci/devito/contributors","subscribers_url":"https://api.github.com/repos/opesci/devito/subscribers","subscription_url":"https://api.github.com/repos/opesci/devito/subscription","commits_url":"https://api.github.com/repos/opesci/devito/commits{/sha}","git_commits_url":"https://api.github.com/repos/opesci/devito/git/commits{/sha}","comments_url":"https://api.github.com/repos/opesci/devito/comments{/number}","issue_comment_url":"https://api.github.com/repos/opesci/devito/issues/comments{/number}","contents_url":"https://api.github.com/repos/opesci/devito/contents/{+path}","compare_url":"https://api.github.com/repos/opesci/devito/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opesci/devito/merges","archive_url":"https://api.github.com/repos/opesci/devito/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opesci/devito/downloads","issues_url":"https://api.github.com/repos/opesci/devito/issues{/number}","pulls_url":"https://api.github.com/repos/opesci/devito/pulls{/number}","milestones_url":"https://api.github.com/repos/opesci/devito/milestones{/number}","notifications_url":"https://api.github.com/repos/opesci/devito/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opesci/devito/labels{/name}","releases_url":"https://api.github.com/repos/opesci/devito/releases{/id}","deployments_url":"https://api.github.com/repos/opesci/devito/deployments","created_at":"2016-03-23T18:59:49Z","updated_at":"2016-04-22T12:11:36Z","pushed_at":"2016-07-13T17:40:51Z","git_url":"git://github.com/opesci/devito.git","ssh_url":"git@github.com:opesci/devito.git","clone_url":"https://github.com/opesci/devito.git","svn_url":"https://github.com/opesci/devito","homepage":null,"size":379,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":12,"forks":0,"open_issues":12,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/opesci/devito/pulls/36"},"html":{"href":"https://github.com/opesci/devito/pull/36"},"issue":{"href":"https://api.github.com/repos/opesci/devito/issues/36"},"comments":{"href":"https://api.github.com/repos/opesci/devito/issues/36/comments"},"review_comments":{"href":"https://api.github.com/repos/opesci/devito/pulls/36/comments"},"review_comment":{"href":"https://api.github.com/repos/opesci/devito/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/opesci/devito/pulls/36/commits"},"statuses":{"href":"https://api.github.com/repos/opesci/devito/statuses/1cfff86cf92de32ace3d93fb46f9681168c81056"}}}}
{"actor":{"display_login":"navjotk"}}