Ejemplo n.º 1
0
def test_matrix_gb_type():
    v = Matrix.from_type(bool, 10)
    assert v.gb_type == lib.GrB_BOOL
    v = Matrix.from_type(int, 10)
    assert v.gb_type == lib.GrB_INT64
    v = Matrix.from_type(float, 10)
    assert v.gb_type == lib.GrB_FP64
Ejemplo n.º 2
0
def test_matrix_create_from_type():
    m = Matrix.from_type(int)
    assert m.nrows == 0
    assert m.ncols == 0
    assert m.nvals == 0
    m = Matrix.from_type(int, 10, 10)
    assert m.nrows == 10
    assert m.ncols == 10
    assert m.nvals == 0
Ejemplo n.º 3
0
def generate_bias():
    for i in range(nneurons):
        bias = Matrix.from_type(lib.GrB_FP32, nneurons, nneurons)
        for i in range(nneurons):
            bias[i, i] = 0.3
        bias.nvals  # causes async completion
        yield bias
Ejemplo n.º 4
0
def test_matrix_assign():

    m = Matrix.from_lists(list(range(3)), list(range(3)), list(range(3)))
    assert m.nvals == 3

    m[2] = Vector.from_list(list(repeat(6, 3)))
    assert m.nvals == 5
    assert m == Matrix.from_lists([0, 1, 2, 2, 2], [0, 1, 0, 1, 2],
                                  [0, 1, 6, 6, 6], 3, 3)

    m = Matrix.from_lists(list(range(3)), list(range(3)), list(range(3)))
    assert m.nvals == 3

    m[2, :] = Vector.from_list(list(repeat(6, 3)))
    assert m.nvals == 5
    assert m == Matrix.from_lists([0, 1, 2, 2, 2], [0, 1, 0, 1, 2],
                                  [0, 1, 6, 6, 6], 3, 3)

    m = Matrix.from_lists(list(range(3)), list(range(3)), list(range(3)))

    assert m.nvals == 3
    m[:, 2] = Vector.from_list(list(repeat(6, 3)))
    assert m.nvals == 5
    assert m == Matrix.from_lists([0, 1, 0, 1, 2], [0, 1, 2, 2, 2],
                                  [0, 1, 6, 6, 6], 3, 3)

    m = Matrix.from_type(int, 3, 3)
    assert m.nvals == 0
    n = Matrix.from_lists([0, 1, 2], [0, 1, 2], [0, 1, 2])
    m[:, :] = n
    assert m == n
Ejemplo n.º 5
0
def test_matrix_get_set_element():
    m = Matrix.from_type(int, 10, 10)
    m[3, 3] = 3
    assert m.nrows == 10
    assert m.ncols == 10
    assert m.nvals == 1
    assert m[3, 3] == 3
Ejemplo n.º 6
0
def test_matrix_create_dup():
    m = Matrix.from_type(int, 10, 10)
    m[3, 3] = 3
    n = Matrix.dup(m)
    assert n.nrows == 10
    assert n.ncols == 10
    assert n.nvals == 1
    assert n[3, 3] == 3
Ejemplo n.º 7
0
def test_matrix_reduce_float():
    v = Matrix.from_type(float, 10, 10)
    r = v.reduce_float()
    assert type(r) is float
    assert r == 0.0
    v[3, 3] = 3.3
    v[4, 4] = 4.4
    assert v.reduce_float() == 7.7
Ejemplo n.º 8
0
def test_matrix_reduce_int():
    v = Matrix.from_type(int, 10, 10)
    r = v.reduce_int()
    assert type(r) is int
    assert r == 0
    v[3, 3] = 3
    v[4, 4] = 4
    assert v.reduce_int() == 7
Ejemplo n.º 9
0
def generate_bias(neurons, nlayers):
    result = []
    for i in range(nlayers):
        bias = Matrix.from_type(lib.GrB_FP32, neurons, neurons)
        for i in range(neurons):
            bias[i,i] = BIAS[neurons]
        bias.nvals # causes async completion
        result.append(bias)
    return result
Ejemplo n.º 10
0
    def __init__(self, configuration=None, identifier=None, weight_type=bool):
        super(Memory, self).__init__(configuration)
        self.identifier = identifier

        self._weight_type = weight_type
        self._max_index = 16
        self._node_count = 0

        self._node_id = {}  # {node -> id}
        self._id_node = {}  # {id -> node}
        self._edge_graph = defaultdict(lambda: Matrix.from_type(
            self._weight_type, self._max_index, self._max_index))
Ejemplo n.º 11
0
def dnn(W, Bias, Y0):
    Y = Matrix.from_type(Y0.gb_type, nfeatures, nneurons)

    for layer, (w, b) in enumerate(zip(W, Bias)):
        with plus_times_fp32:
            print('Y @= w')
            (Y0 if layer == 0 else Y).mxm(w, out=Y)
        with plus_plus_fp32:
            print('Y @= b')
            Y @= b
        Y.select(lib.GxB_GT_ZERO, out=Y)
        Y.apply(lib.LAGraph_YMAX_FP32, out=Y)
    return Y
Ejemplo n.º 12
0
    def __init__(self, weight_type=bool):
        self._weight_type = weight_type
        self._max_index = 16
        self._node_count = 0

        self._node_id = {}  # {node -> id}
        self._id_node = {}  # {id -> node}
        self._edge_graph = defaultdict(
            lambda: Matrix.from_type(
                self._weight_type,
                self._max_index,
                self._max_index)
        )
Ejemplo n.º 13
0
def test_matrix_reduce_bool():
    v = Matrix.from_type(bool, 10, 10)
    assert not v.reduce_bool()
    v[3, 3] = True
    assert v.reduce_bool()