-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from joksas/develop
merge v1.0.1
- Loading branch information
Showing
5 changed files
with
236 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import badcrossbar.computing as computing | ||
import numpy as np | ||
from scipy.sparse import lil_matrix | ||
from collections import namedtuple | ||
import copy | ||
import pytest | ||
|
||
Interconnect = namedtuple('Interconnect', ['word_line', 'bit_line']) | ||
|
||
applied_voltages_list = [ | ||
np.array([ | ||
[5]]), | ||
np.array([ | ||
[5, 10, -4]]), | ||
np.array([ | ||
[5], | ||
[7]]), | ||
np.array([ | ||
[7, 11, 13], | ||
[-2, 0, 5]])] | ||
|
||
resistances_list = [ | ||
np.ones((1,1)), | ||
np.ones((1,1)), | ||
np.array([[10, 20], [30, 40]]), | ||
np.ones((2,2))] | ||
|
||
r_i_list = [ | ||
Interconnect(0.5, 0), | ||
Interconnect(0.5, 0.25), | ||
Interconnect(0, 0.25), | ||
Interconnect(0.5, 0.25)] | ||
|
||
# i | ||
i_expected = [ | ||
np.array([ | ||
[10]]), | ||
np.array([ | ||
[10, 20, -8], | ||
[0, 0, 0]]), | ||
np.array([ | ||
[5/10], | ||
[5/20], | ||
[7/30], | ||
[7/40]]), | ||
np.array([ | ||
[14, 22, 26], | ||
[0, 0, 0], | ||
[-4, 0, 10], | ||
[0, 0, 0], | ||
[0, 0, 0], | ||
[0, 0, 0], | ||
[0, 0, 0], | ||
[0, 0, 0]])] | ||
|
||
i_inputs = [i for i in zip( | ||
applied_voltages_list, resistances_list, r_i_list, i_expected)] | ||
|
||
|
||
@pytest.mark.parametrize('applied_voltages,resistances,r_i,expected', i_inputs) | ||
def test_i(applied_voltages, resistances, r_i, expected): | ||
"""Tests `badcrossbar.computing.fill.i()`. | ||
""" | ||
i_matrix = computing.fill.i(applied_voltages, resistances, r_i) | ||
np.testing.assert_array_almost_equal(i_matrix, expected) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import badcrossbar.computing as computing | ||
import numpy as np | ||
from scipy.sparse import lil_matrix | ||
from collections import namedtuple | ||
import copy | ||
import pytest | ||
|
||
Interconnect = namedtuple('Interconnect', ['word_line', 'bit_line']) | ||
r_i = Interconnect(0.5, 0.25) | ||
|
||
conductances_list = [ | ||
np.array([[100], [0]]), | ||
np.array([[20, 50]]), | ||
np.array([[42]]), | ||
np.array([[0, 20], [30, 0]])] | ||
|
||
g_matrices = [ | ||
lil_matrix((4, 4)), | ||
lil_matrix((4, 4)), | ||
lil_matrix((2, 2)), | ||
lil_matrix((8, 8))] | ||
|
||
# word_line_nodes | ||
word_line_nodes_expected = [ | ||
np.array([ | ||
[102, 0, -100, 0], | ||
[0, 2, 0, 0], | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0]]), | ||
np.array([ | ||
[24, -2, -20, 0], | ||
[-2, 52, 0, -50], | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0]]), | ||
np.array([ | ||
[44, -42], | ||
[0, 0]]), | ||
np.array([ | ||
[4, -2, 0, 0, 0, 0, 0, 0], | ||
[-2, 22, 0, 0, 0, -20, 0, 0], | ||
[0, 0, 34, -2, 0, 0, -30, 0], | ||
[0, 0, -2, 2, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 0]])] | ||
|
||
word_line_nodes_inputs = [i for i in zip( | ||
conductances_list, g_matrices, word_line_nodes_expected)] | ||
|
||
# bit_line_nodes | ||
bit_line_nodes_expected = [ | ||
np.array([ | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0], | ||
[-100, 0, 104, -4], | ||
[0, 0, -4, 8]]), | ||
np.array([ | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0], | ||
[-20, 0, 24, 0], | ||
[0, -50, 0, 54]]), | ||
np.array([ | ||
[0, 0], | ||
[-42, 46]]), | ||
np.array([ | ||
[0, 0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 4, 0, -4, 0], | ||
[0, -20, 0, 0, 0, 24, 0, -4], | ||
[0, 0, -30, 0, -4, 0, 38, 0], | ||
[0, 0, 0, 0, 0, -4, 0, 8]])] | ||
|
||
bit_line_nodes_inputs = [i for i in zip( | ||
conductances_list, g_matrices, bit_line_nodes_expected)] | ||
|
||
@pytest.mark.parametrize('conductances,g_matrix,expected', word_line_nodes_inputs) | ||
def test_word_line_nodes(conductances, g_matrix, expected): | ||
"""Tests `badcrossbar.computing.kcl.word_line_nodes()`. | ||
""" | ||
filled_g_matrix = computing.kcl.word_line_nodes( | ||
copy.deepcopy(g_matrix), conductances, r_i).toarray() | ||
np.testing.assert_array_almost_equal(filled_g_matrix, expected) | ||
|
||
|
||
@pytest.mark.parametrize('conductances,g_matrix,expected', bit_line_nodes_inputs) | ||
def test_bit_line_nodes(conductances, g_matrix, expected): | ||
"""Tests `badcrossbar.computing.kcl.bit_line_nodes()`. | ||
""" | ||
filled_g_matrix = computing.kcl.bit_line_nodes( | ||
copy.deepcopy(g_matrix), conductances, r_i).toarray() | ||
np.testing.assert_array_almost_equal(filled_g_matrix, expected) | ||
|