예제 #1
0
def test_is_equal(arg, other, expected):
    """
    Verify that comparison of arrays evaluates correctly
    """
    my_arr = Array(arg[0], *arg[1])
    other_arr = Array(other[0], *other[1])
    assert my_arr.is_equal(other_arr).flatten == expected
예제 #2
0
    def run(self):
        start = time.time()
        self.environment.set_total_intensity(0)
        self.environment.set_blue_intensity(0)
        array = Array()
        water = Array()
        wheel = {}
        array.randomize()
        t = 0
        while t < 350:
            if t < 7:
                wheel[t] = Array()
                array.calculate_next(self.environment, water, wheel[t % 7], t)
            else:
                array.calculate_next(self.environment, water, wheel[(t - 6) % 7], t)
            paint_array(array, str(t))
            self.record_data(t, array)

            if t == 20:
                self.environment.set_total_intensity(800)
            #if t == 200:
             #   self.environment.set_blue_intensity(5)

            t += 1
        end = time.time()
        runtime = end - start
        print("This simulation took " + str(round(runtime / 60)) + " minutes.")
예제 #3
0
    def test_eq_1D_false(self):
        # Tests that two 1D arrays that are of different shape returns false
        array1 = Array((3, ), 1, 2, 3)
        array2 = Array((2, ), 1, 2)

        assert array1 != array2
        assert array1 != "string"
예제 #4
0
    def test_add_1D_array(self):
        array1 = Array((3, ), 1, 2, 3)
        array2 = Array((3, ), 2, 3, 4)
        result = array1 + array2

        assert result[0] == 3
        assert result[1] == 5
        assert result[2] == 7
예제 #5
0
    def test_is_equal_int(self):
        # Tests one 1D array with integers and a integer as parameter
        array1 = Array((3, ), 1, 2, 3)
        number = 2
        result = array1.is_equal(number)
        expected = Array((3, ), False, True, False)

        assert result == expected
예제 #6
0
    def test_is_equal_array(self):
        # Tests two 1D arrays with integers
        array1 = Array((3, ), 1, 2, 3)
        array2 = Array((3, ), 1, 5, -3)
        result = array1.is_equal(array2)
        expected = Array((3, ), True, False, False)

        assert result == expected
예제 #7
0
    def test_is_equal_2d_array(self):
        # Tests two 2D arrays with integers
        array1 = Array((2, 3), 1, 2, 3, 4, 5, 6)
        array2 = Array((2, 3), 2, 3, 3, 5, 6, 6)
        result = array1.is_equal(array2)
        expected = Array((2, 3), False, False, True, False, False, True)

        assert result == expected
예제 #8
0
def test__eq__(arg, other, expected):
    """
    Verify that comparison of arrays evaluates correctly
    """
    my_arr = Array(arg[0], *arg[1])
    other_arr = Array(other[0], *other[1])
    bool = (my_arr == other_arr)
    assert bool == expected
예제 #9
0
    def test_sub_2D_array(self):
        array1 = Array((2, 3), 1, 2, 3, 4, 5, 6)
        array2 = Array((2, 3), 2, 3, 4, 5, 6, 4)
        result = array1 - array2

        assert result[0][0] == -1
        assert result[1][1] == -1
        assert result[1][2] == 2
예제 #10
0
    def test_mul_1D_array(self):
        array1 = Array((3, ), 1, 2, 3)
        array2 = Array((3, ), 2, 3, 4)
        result = array1 * array2

        assert result[0] == 2
        assert result[1] == 6
        assert result[2] == 12
예제 #11
0
    def test_mul_2D_array(self):
        array1 = Array((2, 3), 1, 2, 3, 4, 5, 6)
        array2 = Array((2, 3), 2, 3, 4, 5, 6, 4)
        result = array1 * array2

        assert result[0][0] == 2
        assert result[1][1] == 30
        assert result[1][2] == 24
예제 #12
0
    def test_sub_1D_array(self):
        array1 = Array((3, ), 1, 2, 3)
        array2 = Array((3, ), 2, 3, 4)
        result = array2 - array1

        assert result[0] == 1
        assert result[1] == 1
        assert result[2] == 1
예제 #13
0
    def test_add_2D_array(self):
        array1 = Array((3, 3), 1, 2, 3, 4, 5, 6, 7, 8, 9)
        array2 = Array((3, 3), 2, 3, 4, 5, 6, 7, 8, 9, 10)
        result = array1 + array2

        assert result[0][0] == 3
        assert result[1][2] == 13
        assert result[2][2] == 19
예제 #14
0
    def test_eq_2D_array(self):
        # Tests that two 2D arrays that are of same shape and contains the same int values returns true
        # and that two 2D arrays that are of the same shape, but contains different values return false
        array1 = Array((2, 3), 1, 2, 3, 4, 5, 6)
        array2 = Array((2, 3), 1, 2, 3, 4, 5, 6)
        array3 = Array((2, 3), 2, 3, 4, 5, 6, 4)

        assert array1 == array2
        assert array1 != array3
예제 #15
0
    def test_is_equal_incorrect(self):
        # Tests that a ValueError is raised when called on one 1D array with
        # another array of different shape and the wrong data type
        array1 = Array((3, ), 1, 2, 3)
        array2 = Array((2, ), 2, 3)

        with pytest.raises(ValueError):
            array1.is_equal(array2)
            array1.is_equal("string")
예제 #16
0
    def __init__(self, sourceCollection=None):
        if sourceCollection:
            self._array = Array(len(sourceCollection))

            index = 0
            for item in sourceCollection:
                self._array[index] = item
                index += 1
        else:
            self._array = Array(0)
예제 #17
0
 def __init__(self, arr=None, capacity=None):
     if isinstance(arr, Array):
         self._data = arr
         for i in range(self._parent(arr.get_size() - 1), -1, -1):
             self._sift_down(i)
         return
     if not capacity:
         self._data = Array()
     else:
         self._data = Array(capacity=capacity)
예제 #18
0
    def test_min_element_correct(self):
        array1 = Array((3, ), -1.0, 2.4, 1.0)
        array2 = Array((3, ), -1, 2, 1)
        array3 = Array((2, ), True, False)
        result1 = array1.min_element()
        result2 = array2.min_element()
        result3 = array3.min_element()

        assert result1 == -1.0
        assert result2 == -1
        assert result3 == False
예제 #19
0
 def __init__(self, capacity):
     # data 表示为元素的数组
     self._data = Array(capacity=capacity)
     # index[i] 数组表示为对堆中第i的位置上的元素
     self._index = Array(capacity=capacity)
     # reversed[i] 为i的在索引堆位置是index逆运算
     self._reversed = Array(capacity=capacity)
     for i in range(capacity):
         self._reversed.add(i, -1)
     self.capacity = capacity
     self.count = 0
예제 #20
0
def test__sub__(arg, other, expected):
    """
    Verify that subtracting from array element-wise returns what it's supposed to
    """
    if isinstance(other, (int, float)):
        other_ = other
    else:
        other_ = Array(arg[0], *other)
    my_arr = Array(arg[0], *arg[1])
    new_arr = my_arr - other_
    assert new_arr.flatten == expected
예제 #21
0
def test__radd__(arg, other, expected):
    """
    Verify that adding to array element-wise returns what it's supposed to
    """
    if isinstance(other, (int, float)):
        other_ = other
    else:
        other_ = Array(arg[0], *other)
    my_arr = Array(arg[0], *arg[1])
    new_arr = other_ + my_arr
    assert new_arr.flatten == expected
    def __init__(self, arr=None):

        if arr is None:
            self.__data = Array()
        elif isinstance(arr, int):
            self.__data = Array(arr)
        else:
            # 如果 arr 不为空,使用 heapify 操作将 arr 整理成堆
            self.__data = Array(arr)
            i = (self.get_size() - 2) // 2
            while i >= 0:
                self.__sift_down(i)
                i -= 1
예제 #23
0
def load_pgm():
    files = os.listdir(root + '/pgm/')
    num_file = len(files)

    # size of PGM is 32
    size = 32
    # Input Data to be stored
    X = [Array(size**2, 1, False) for i in range(num_file)]
    for i in range(num_file):
        # Open one of files in the pgm directory
        f = open('pgm/' + str(i + 1) + '.pgm', 'r')
        # List of data in the text
        data = f.read().split("\n")
        # initialize with Zeros
        rows = [0] * size**2
        idx = 0
        for line in data:
            row = line.split(" ")
            if (len(row) == size):
                temp = [item[0] / 255 for item in zip(list(map(float, row)))]
                rows[size * idx:(idx + 1) * size] = [
                    item[0] / 255 for item in zip(list(map(float, row)))
                ]
                idx += 1

        X[i].rows = rows

    # Teaching Data to be stored
    f_t = open('labels.txt')
    data = f_t.read().split("\n")
    T = list(map(float, data))
    f.close()

    return X, T
예제 #24
0
def test_variance(arg, np_arg):
    """
    Verify that variance of array values is correct
    """
    my_arr = Array(arg[0], *arg[1])
    np_arr = np.array(np_arg)
    assert my_arr.variance() == pytest.approx(np.var(np_arr))
예제 #25
0
def test_mean(arg, np_arg):
    """
    Verify that mean of array values is correct
    """
    my_arr = Array(arg[0], *arg[1])
    np_arr = np.array(np_arg)
    assert my_arr.mean() == pytest.approx(np.mean(np_arr))
예제 #26
0
    def __init__(self, source_collection=None):
        self._items = Array(ArraySet.DEFAULT_CAPACITY)
        AbstractSet.__init__(self, source_collection)

        if source_collection is not None:
            for element in source_collection:
                self.add(element)
예제 #27
0
    def test_mul_1D_float(self):
        array1 = Array((3, ), 1.0, 2.0, 3.0)
        result = array1 * 2.0

        assert result[0] == 2.0
        assert result[1] == 4.0
        assert result[2] == 6.0
예제 #28
0
def softmax(x):
    ret = Array(x.m, x.n, False)
    exps = [math.exp(item[0]) for item in zip(x.rows)]
    sums = sum(exps)
    ret.rows = [item[0] / sums for item in zip(exps)]

    return ret
예제 #29
0
파일: LUT3D.py 프로젝트: alexfry/aces-dev
    def setArray(self, dimension, values):
        dimensions = dimension
        dimensions.append(3)

        integers = bitDepthIsInteger(self.getAttribute('outBitDepth'))

        self._array = Array(dimensions, values, integers)
        self.addElement(self._array)
예제 #30
0
 def setMatrix(self, dimensions, values, floatEncoding='string'):
     integers = bitDepthIsInteger(self.getAttribute('outBitDepth'))
     values = Array(dimensions,
                    values,
                    integers,
                    floatEncoding=floatEncoding)
     self._array = values
     self.addElement(values)