Skip to content

Commit 1f0c310

Browse files
committed
Initial commit.
0 parents  commit 1f0c310

File tree

8 files changed

+679
-0
lines changed

8 files changed

+679
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.bak
2+
/build
3+
*.egg-info
4+
*.pyc
5+
/dist
6+
/easy-install.pth
7+
/site.py
8+
sparsevectors*.egg
9+
sparsevectors*.so

README.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
========
2+
sparsevectors
3+
========
4+
5+
A library that provides the SparseVector object which is defaultdict(float) with
6+
the following properties and methods:
7+
8+
- getting a non-existing element always returns 0.0
9+
- method dot(other) returns the dot-product between this SparseVector and another
10+
- method iaddc(other[,weight]) adds to each element in this SparseVector the
11+
corresponding element of the other SparseVector, multiplied by weight, if given.
12+
If the result is 0.0, then the element in the current SparseVector is removed
13+
14+
15+
Authors
16+
-------
17+
18+
This code is based on the cpython defaultdict code (see https://github.com/python/cpython)
19+
and is inspired by Liang Huang's (http://web.engr.oregonstate.edu/~huanlian) hvector
20+
library (http://web.engr.oregonstate.edu/~huanlian/software/hvector-1.0.tar.bz).
21+
Any errors are mine though.
22+
23+
Status
24+
------
25+
26+
This is still an early version and may contain bugs, memory leaks.
27+
Any help to make it better or in finding and squashing bugs is welcome.
28+
29+
Installation
30+
------------
31+
32+
TBD
33+
34+
35+
License
36+
-------
37+
38+
Licensed under the terms of the `CPython License`_. See attached file LICENSE.txt.
39+
40+
41+
.. _CPython License: https://github.com/python/cpython/blob/master/LICENSE
42+

__init__.py

Whitespace-only changes.

examples.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
3+
from sparsevectors import SparseVector
4+
5+
print("create d")
6+
d = SparseVector()
7+
8+
print("d=",d)
9+
print("set el 1 to 2.2")
10+
d[1] = 2.2
11+
print("done")
12+
print("d[1]=",d[1])
13+
print("Nonexistent: d[100]=",d[100])
14+
print("d=",d,"d[1]=",d[1],"d[2]=",d[2],"d[100]=",d[100])
15+
print("len(d)=",len(d))
16+
17+
dcopy = SparseVector(d)
18+
print("Copy of d, dcopy=",dcopy)
19+
print("set d[1] to 5.5")
20+
d[1]=5.5
21+
#d[2]="asas"
22+
print("d=",d,"dcopy=",dcopy)
23+
24+
print("create e")
25+
e = SparseVector()
26+
print("set el 1 to 2.0")
27+
e[1] = 2.0
28+
#e[3] = "aaaa"
29+
print("e=",e)
30+
print("calculating dot")
31+
r1 = d.dot(e)
32+
print("dot=",r1)
33+
34+
print("incrementing d by 2 * e")
35+
d.iaddc(e,2.0)
36+
37+
print("d=",d,"dcopy=",dcopy,"e=",e)
38+
39+
#print("Testing type errors")
40+
#s1 = SparseVector({1: "sasas"})
41+
#d.iaddc(s1,2.0)

setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
from setuptools import setup
3+
# from distutils.core import setup
4+
from distutils.extension import Extension
5+
6+
here = os.path.abspath(os.path.dirname(__file__))
7+
def read(fname):
8+
return open(os.path.join(here, fname)).read()
9+
readme = read('README.rst')
10+
11+
12+
setup(name = "sparsevectors",
13+
version = "1.0",
14+
description="Simple Sparse vector type based on defaultdict(float).",
15+
long_description=readme,
16+
author="Johann Petrak",
17+
author_email="[email protected]",
18+
url="https://todo.org/todo",
19+
ext_modules = [Extension("sparsevectors", ["src/_sparsevectorsmodule.c"])],
20+
tests_require = ['nose'],
21+
test_suite = 'nose.collector',
22+
classifiers=[
23+
'Development Status LL 4 - Beta',
24+
'License :: OSI Approved :: Apache 2 License',
25+
'Programming Language :: Python',
26+
'Programming Language :: C',
27+
],
28+
)

sparsevector.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
def __bootstrap__():
3+
global __bootstrap__, __loader__, __file__
4+
import sys, pkg_resources, imp
5+
__file__ = pkg_resources.resource_filename(__name__,'sparsevectors.cpython-35m-x86_64-linux-gnu.so')
6+
__loader__ = None; del __bootstrap__, __loader__
7+
imp.load_dynamic(__name__,__file__)
8+
os.environ['PYTHON_EGG_CACHE'] = '~/'
9+
__bootstrap__()

0 commit comments

Comments
 (0)