Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
wendelin
Commits
83c69678
Commit
83c69678
authored
Nov 17, 2024
by
Levin Zimmermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Demonstrate how resizing needs less disk space than creating orphans
parents
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
164 additions
and
0 deletions
+164
-0
t_zbigarray_resize.py
t_zbigarray_resize.py
+80
-0
t_zbigarray_set_none.py
t_zbigarray_set_none.py
+84
-0
No files found.
t_zbigarray_resize.py
0 → 100644
View file @
83c69678
import
os
import
sys
from
golang
import
defer
,
func
import
numpy
as
np
import
transaction
import
ZODB
,
ZODB
.
FileStorage
from
wendelin.bigarray.array_zodb
import
ZBigArray
storage_path
=
"tzbigarray.fs"
try
:
os
.
remove
(
storage_path
)
except
:
pass
@
func
def
root
(
func
):
storage
=
ZODB
.
FileStorage
.
FileStorage
(
storage_path
,
pack_gc
=
False
)
db
=
ZODB
.
DB
(
storage
)
connection
=
db
.
open
()
root
=
connection
.
root
defer
(
connection
.
close
)
defer
(
db
.
close
)
defer
(
storage
.
close
)
func
(
root
,
storage
,
db
)
def
t
(
root
,
storage
,
db
):
def
_
(
msg
):
print
(
msg
+
'
\
n
'
)
#print("array: %s" % str(arr[:]))
print
(
"
\
t
shape: %s"
%
str
(
arr
.
shape
))
print
(
"
\
t
storage length: %s"
%
len
(
storage
))
print
(
"
\
t
storage size: %s"
%
_getstoragesize
())
print
(
'
\
n
'
)
arr
=
root
.
zbigarray
=
ZBigArray
(
shape
=
[
0
,
2
],
dtype
=
int
)
transaction
.
commit
()
_
(
"Create new ZBigArray"
)
_append_zblk
(
arr
)
_
(
"Append ~one ZBlk to ZBigAray"
)
db
.
pack
()
_
(
"Pack database (1)"
)
arr
.
resize
((
0
,
2
))
transaction
.
commit
()
_
(
"Resize array (set length to 0)"
)
_append_zblk
(
arr
)
_
(
"Add new data again to array (to have same size as before)"
)
db
.
pack
()
_
(
"Pack database (2)"
)
_append_zblk
(
arr
)
_
(
"Add more new data"
)
db
.
pack
()
_
(
"Pack database (3)"
)
def
_append_zblk
(
arr
,
size
=
2
):
elements
=
200000
# roughly the size of 1xZBlk0
arr
.
append
([[
0
for
_
in
range
(
size
)]
for
_
in
range
(
int
(
elements
/
size
))])
transaction
.
commit
()
def
_getstoragesize
():
return
os
.
path
.
getsize
(
storage_path
)
if
__name__
==
"__main__"
:
root
(
t
)
t_zbigarray_set_none.py
0 → 100644
View file @
83c69678
import
os
import
sys
from
golang
import
defer
,
func
import
numpy
as
np
import
transaction
import
ZODB
,
ZODB
.
FileStorage
from
wendelin.bigarray.array_zodb
import
ZBigArray
storage_path
=
"tzbigarray.fs"
try
:
os
.
remove
(
storage_path
)
except
:
pass
@
func
def
root
(
func
):
storage
=
ZODB
.
FileStorage
.
FileStorage
(
storage_path
,
pack_gc
=
False
)
db
=
ZODB
.
DB
(
storage
)
connection
=
db
.
open
()
root
=
connection
.
root
defer
(
connection
.
close
)
defer
(
db
.
close
)
defer
(
storage
.
close
)
func
(
root
,
storage
,
db
)
def
t
(
root
,
storage
,
db
):
def
_
(
msg
):
print
(
msg
+
'
\
n
'
)
#print("array: %s" % str(arr[:]))
print
(
"
\
t
shape: %s"
%
str
(
arr
.
shape
))
print
(
"
\
t
storage length: %s"
%
len
(
storage
))
print
(
"
\
t
storage size: %s"
%
_getstoragesize
())
print
(
'
\
n
'
)
arr
=
root
.
zbigarray
=
ZBigArray
(
shape
=
[
0
,
2
],
dtype
=
int
)
transaction
.
commit
()
_
(
"Create new ZBigArray (1)"
)
_append_zblk
(
arr
)
_
(
"Append ~one ZBlk to ZBigAray"
)
db
.
pack
()
_
(
"Pack database (1)"
)
root
.
zbigarray
=
None
transaction
.
commit
()
_
(
"De-refer initial ZBigArray"
)
arr
=
root
.
zbigarray
=
ZBigArray
(
shape
=
[
0
,
2
],
dtype
=
int
)
transaction
.
commit
()
_
(
"Create new ZBigArray (2)"
)
_append_zblk
(
arr
)
_
(
"Add new data to newly created array"
)
db
.
pack
()
_
(
"Pack database (2)"
)
_append_zblk
(
arr
)
_
(
"Add more new data"
)
db
.
pack
()
_
(
"Pack database (3)"
)
def
_append_zblk
(
arr
,
size
=
2
):
elements
=
200000
# roughly the size of 1xZBlk0
arr
.
append
([[
0
for
_
in
range
(
size
)]
for
_
in
range
(
int
(
elements
/
size
))])
transaction
.
commit
()
def
_getstoragesize
():
return
os
.
path
.
getsize
(
storage_path
)
if
__name__
==
"__main__"
:
root
(
t
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment