rethinking things, added DEVOUR tests

This commit is contained in:
Skye Terran 2021-08-25 16:25:25 -07:00
parent 81fc8a8579
commit 826a070a4f
2 changed files with 141 additions and 0 deletions

29
python/DEVOURTest.json Normal file
View File

@ -0,0 +1,29 @@
{
"shape": [
[
"0",
"1"
],
[
"0",
"1"
],
[
"0",
"2"
],
[
"0",
"2"
],
[
"0",
"1"
]
],
"memory": [
"float",
1.0,
3.0
]
}

112
python/ORCTest.ipynb Normal file
View File

@ -0,0 +1,112 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"## DEVOUR Virtual Data Structure\r\n",
"Dynamic: The structure of the output DEVOUR graph is dynamically generated from raw input data\r\n",
"\r\n",
"Explicit: Every node in a DEVOUR graph is explicitly typed and namespaced for reliability and interoperability between programs\r\n",
"\r\n",
"Virtual: DEVOUR graphs contain their own serialized virtual memory space\r\n",
"\r\n",
"Ordered: A DEVOUR graph's virtual memory is structured as an ordered list for performance\r\n",
"\r\n",
"Unique: A DEVOUR graph contains only one instance of a given \"real\" value, mapped into its virtual memory\r\n",
"\r\n",
"Relational: A DEVOUR graph's virtual memory is referenced via indexed pointers within its data structure"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 37,
"source": [
"class DevourObject:\r\n",
" def __init__(self, type, value):\r\n",
" self.type = type\r\n",
" self.value = value\r\n",
"\r\n",
"class DevourGraph:\r\n",
" def __init__(self):\r\n",
" self.graph = []\r\n",
"\r\n",
" # adds a new object to the graph\r\n",
" def add(self, type, value):\r\n",
" self.graph.append(DevourObject(type, value))\r\n",
"\r\n",
" # exports the graph as a single dictionary object\r\n",
" def serialize(self):\r\n",
" shape = []\r\n",
" memory = []\r\n",
"\r\n",
" # serialize DevourObject instances\r\n",
" for object in self.graph:\r\n",
" # redirect the type name to virtual memory\r\n",
" if object.type not in memory:\r\n",
" memory.append(object.type)\r\n",
" type_pointer = hex(len(memory) - 1)[2:]\r\n",
" else:\r\n",
" type_pointer = hex(memory.index(object.type))[2:]\r\n",
" \r\n",
" # redirect object to virtual memory\r\n",
" if object.value not in memory:\r\n",
" memory.append(object.value)\r\n",
" value_pointer = hex(len(memory) - 1)[2:]\r\n",
" else:\r\n",
" value_pointer = hex(memory.index(object.value))[2:]\r\n",
"\r\n",
" # add a redirector to shape\r\n",
" shape.append((type_pointer, value_pointer))\r\n",
"\r\n",
" return {\"shape\": shape, \"memory\": memory}"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 39,
"source": [
"# test\r\n",
"graph = DevourGraph()\r\n",
"graph.add(\"float\", 1.0)\r\n",
"graph.add(\"float\", 1.0)\r\n",
"graph.add(\"float\", 3.0)\r\n",
"graph.add(\"float\", 3.0)\r\n",
"graph.add(\"float\", 1.0)\r\n",
"\r\n",
"# write to disk\r\n",
"import json\r\n",
"with open(\"DEVOURTest.json\", \"w\") as outfile:\r\n",
" json.dump(graph.serialize(), outfile, indent = 4)"
],
"outputs": [],
"metadata": {}
}
],
"metadata": {
"orig_nbformat": 4,
"language_info": {
"name": "python",
"version": "3.7.8",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.8 64-bit"
},
"interpreter": {
"hash": "57baa5815c940fdaff4d14510622de9616cae602444507ba5d0b6727c008cbd6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}