def eval(self): pnl = Matrix() market_query = self.market[0] pnl.extend([market.price.day_ahead for market in market_query]) pnl = pnl[1:]-pnl[0:-1] self.pnl = pnl #* self.price
def eval(self): pnl = Matrix() market_query = self.market[0] pnl.extend([market.price.day_ahead for market in market_query]) pnl = pnl[1:] - pnl[0:-1] self.pnl = pnl #* self.price
def readFromCSV(self, filePath, dimension): csvPreprocessor = CSVPreprocessor() csvPreprocessor.readCSV(filePath) matrix = csvPreprocessor.csvToMatrix() if matrix.getNumberOfRows( ) != dimension + 1 or matrix.getNumberOfColumns() != dimension * 2 + 1: return False else: self._randomRotationMatrix = Matrix( matrix.getRawMatrix()[:dimension, :dimension]) self._randomTranslationMatrix = Matrix( matrix.getRawMatrix()[:, dimension:]) return True
def test(): data = [ [0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1], [0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1], [0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1], [1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1], [0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1] ] fn = '/home/cjgrady/test.qtree' mtx = Matrix(data=data) cmpMtx = QuadtreeCompressedMatrix() cmpMtx.compress(mtx) cmpMtx.writeFile(fn) print cmpMtx.data
def decompress(self): lArray = [] for count, val in self.data: lArray.extend(count*[val]) data = [lArray[i:i+self.xSize] for i in xrange(0, self.xSize*self.ySize, self.xSize)] mtx = Matrix(data=data, xSize=self.xSize, ySize=self.ySize) return mtx
def test(): data = [ [0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1], [0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1], [0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1], [1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1], [0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1] ] fn = '/home/cjgrady/test.qtree' mtx = Matrix(data=data) cmpMtx = STreeCompressedMatrix() cmpMtx.compress(mtx) cmpMtx.writeFile(fn) #print cmpMtx.data #mtx2 = cmpMtx.decompress() mtx2 = STreeCompressedMatrix() mtx2.readFile(fn) mtx3 = mtx2.decompress() for row in mtx3.data: print row print cmpMtx.getValue(1, 0)
def convertAscToMatrix(asciiFn, threshold=1): # Assume ncols, nrows, then 3 other metadata lines before data f = open(asciiFn, 'r') lines = f.readlines() f.close() xSize = int(lines[0].split('ncols')[1].strip()) ySize = int(lines[1].split('nrows')[1].strip()) # 2 - xll # 3 - yll # 4 - cell size # 5 - no data NODATA_VALUE = -1 #NODATA_VALUE = int(lines[5].split('NODATA_value')[1].strip()) data = [] for line in lines[5:]: row = [] vals = line.split(' ') for j in vals: if len(j) > 0: i = float(j) if i < 1.0: i = i * 100 i = int(i) #for i in [int(j) for j in line.split(' ')]: if i >= threshold and i != NODATA_VALUE: row.append(1) else: row.append(0) data.append(row) mtx = Matrix(data=data, xSize=xSize, ySize=ySize) return mtx
def test(): data = [ [0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1], [0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1], [0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1], [1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1], [0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1] ] mtx = Matrix(data=data) cmpMtx = NormalRLECompressedMatrix() cmpMtx.compress(mtx) mtx2 = cmpMtx.decompress() cmpMtx.writeFile('/home/cjgrady/cjTestRLE.bin') mtx3 = NormalRLECompressedMatrix() mtx3.readFile('/home/cjgrady/cjTestRLE.bin')
def read(self, label): self._fhandle = open(self._file_name, "r") matrix_list = list() for row in self._fhandle: row = row.strip() if row.startswith('#'): continue columns = list() cols = row.split() for column in cols: column = int(column) columns.append(column) matrix_list.append(columns) self._fhandle.close() matrix = Matrix(label) matrix.create(matrix_list) return matrix
def main(): matrices_sizes = [[4,4], [4,4], [4,4], [4,4], [4,4], [4,4], [4,4]] matrix_obj = Matrix(matrices_sizes) personal_print(matrix_obj.all_matrices) print(matrix_obj.get_determinants()) personal_print(matrix_obj.get_the_transposed_matrix()) personal_print(matrix_obj.get_multiplication_result(10)) personal_print(matrix_obj.get_multiplication_result()) personal_print(matrix_obj.get_inverse_matrix())
def decompress(self): lArray = [] for count, val in self.data: lArray.extend(count * [val]) data = [] for y in xrange(self.ySize): row = [] for x in xrange(self.xSize): row.append(lArray[pointToHilbert(x, y, self.order)]) data.append(row) mtx = Matrix(data=data, xSize=self.xSize, ySize=self.ySize) return mtx
def test(): data = [[0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1], [0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1], [0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1], [1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1], [0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1]] fn = '/home/cjgrady/test.qtree' mtx = Matrix(data=data) cmpMtx = QuadtreeHilbertCompressedMatrix(rleThreshold=2) cmpMtx.compress(mtx) cmpMtx.writeFile(fn) #print cmpMtx.data #mtx2 = cmpMtx.decompress() #for row in mtx2.data: # print row mtx2 = QuadtreeHilbertCompressedMatrix() mtx2.readFile(fn) print mtx2.data # mtx2.readFile(fn) mtx3 = mtx2.decompress() for row in mtx3.data: print row m = [] for y in xrange(cmpMtx.ySize): r = [] for x in xrange(cmpMtx.xSize): r.append(cmpMtx.getValue(x, y)) m.append(r) for r in m: print r
def test(): data = [[0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1], [0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0], [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1], [0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1], [0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1], [1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1], [1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1], [0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1], [1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1]] mtx = Matrix(data=data) cmpMtx = HilbertRLECompressedMatrix() cmpMtx.compress(mtx) #print cmpMtx.data mtx2 = cmpMtx.decompress() for row in mtx2.data: print row
def test_matrix_initialization(matrix_input, expected_exception): if expected_exception is None: assert Matrix(matrix_input).matrix == matrix_input else: with pytest.raises(expected_exception): Matrix(matrix_input)
def main(): fname_read_a = input("Enter input file name: ") if len(fname_read_a) < 1: fname_read_a = "files/input/input_a.txt" fname_read_b = input("Enter input file name: ") if len(fname_read_b) < 1: fname_read_b = "files/input/input_b.txt" fname_write = input("Enter output file name: ") if len(fname_write) < 1: fname_write = "files/output/output.txt" matrix_file_reader_1 = MatrixFileReader(fname_read_a) matrix_file_reader_2 = MatrixFileReader(fname_read_b) label_a = "A" matrix_a = matrix_file_reader_1.read(label_a) label_b = "B" matrix_b = matrix_file_reader_2.read(label_b) matrix_checker = MatrixChecker() try: matrix_checker.test_sizes(matrix_a, matrix_b) except ValueError as e: print(e) exit(1) matrix_multiplication = MatrixMultiplication() matrix_a_arr = matrix_a._matrix matrix_b_arr = matrix_b._matrix start = time.time() matrix_c_arr = matrix_multiplication.square_matrix_multiply( matrix_a_arr, matrix_b_arr) end = time.time() runtime_c = end - start start = time.time() matrix_cr_arr = matrix_multiplication.square_matrix_multiply( matrix_a_arr, matrix_b_arr) end = time.time() runtime_cr = end - start start = time.time() matrix_crs_arr = matrix_multiplication.square_matrix_multiply_recursive_strassen( matrix_a_arr, matrix_b_arr) end = time.time() runtime_crs = end - start matrix_c = Matrix("Classical approach") matrix_c._matrix = matrix_c_arr matrix_cr = Matrix("Recursive approach") matrix_cr._matrix = matrix_cr_arr matrix_crs = Matrix("Recursive Strassen\'s algorithm") matrix_crs._matrix = matrix_crs_arr output_str_a = "Input matrix \"{_matrix_label}\":\n{_matrix}\n".format( _matrix_label=matrix_a._label, _matrix=str(matrix_a)) output_str_b = "Input matrix \"{_matrix_label}\":\n{_matrix}\n".format( _matrix_label=matrix_b._label, _matrix=str(matrix_b)) output_str_c = "Output matrix \"{_matrix_label}\":\n{_matrix}\nRuntime:\n{_runtime}\n".format( _matrix_label=matrix_c._label, _matrix=str(matrix_c), _runtime=runtime_c) output_str_cr = "Output matrix \"{_matrix_label}\":\n{_matrix}\nRuntime:\n{_runtime}\n".format( _matrix_label=matrix_cr._label, _matrix=str(matrix_cr), _runtime=runtime_cr) output_str_crs = "Output matrix \"{_matrix_label}\":\n{_matrix}\nRuntime:\n{_runtime}\n".format( _matrix_label=matrix_crs._label, _matrix=str(matrix_crs), _runtime=runtime_crs) output_file_writer = OutputFileWriter(fname_write) output_file_writer.write(output_str_a) output_file_writer.write("\n") output_file_writer.write(output_str_b) output_file_writer.write("\n") output_file_writer.write(output_str_c) output_file_writer.write("\n") output_file_writer.write(output_str_cr) output_file_writer.write("\n") output_file_writer.write(output_str_crs) output_file_writer.write("\n") output_file_writer.close() print("") print(output_str_a) print(output_str_b) print(output_str_c) print(output_str_cr) print(output_str_crs) print("") output_str = "Please, see the output results in the file \"{_path_to_file}\"".format( _path_to_file=fname_write) print(output_str)
""" @summary: Module containing script to convert binary rasters to compressed rasters via normal run length encoding """ import os from matrix.matrix import Matrix from rle.normal import NormalRLECompressedMatrix inDir = '/data/geo716/final project/data/bins' outDir = '/data/geo716/final project/data/rles' for i in xrange(1000): #i = 0 print i binFn = os.path.join(inDir, '%s.bin' % i) rleFn = os.path.join(outDir, '%s.rle' % i) mtx = Matrix() mtx.readFile(binFn) mtx2 = NormalRLECompressedMatrix() mtx2.compress(mtx) mtx2.writeFile(rleFn)
values.append(row) with open(OUT_CSV, 'w') as csvOutFile: writer = csv.writer(csvOutFile) headerRow = [ 'Id', 'Projection Id', 'Occurrence Set Id', 'Scenario Id', 'Algorithm Code', 'Number of Presences', 'Morans I', 'Variance', 'ASCII Size', 'Tiff Size', 'Binary Size', 'RLE Size', 'Hilbert Size', 'Quadtree Size', 'S-Tree Size', 'Combo 6 Size', 'Combo 8 Size', 'Combo 10 Size' ] writer.writerow(headerRow) for idStr, prjId, occId, scnId, algoCode, tiffSize in values[1:]: print idStr id = int(idStr) mtx = Matrix() mtx.readFile(getFileName('bins', id, 'bin')) numPres, variance = getNumPresencesAndVariance(mtx.data) mI = calculateMoransI(mtx.data) asciiSize = getFileSize(getFileName('ascs', id, 'asc')) tiffSize = tiffSize binSize = getFileSize(getFileName('bins', id, 'bin')) rleSize = getFileSize(getFileName('rles', id, 'rle')) hilbertSize = getFileSize(getFileName('hilberts', id, 'hilb')) qTreeSize = getFileSize(getFileName('qtrees', id, 'qtree')) sTreeSize = getFileSize(getFileName('strees', id, 'stree')) combo6Size = getFileSize(getFileName('combos6', id, 'combo6')) combo8Size = getFileSize(getFileName('combos8', id, 'combo8')) combo10Size = getFileSize(getFileName('combos10', id, 'combo10')) row = [id, prjId, occId, scnId, algoCode, numPres, mI, variance,
def diagonal(self): m = Matrix() return self.assertEquals(m.diagonal([1, 2, 3, 4, 5, 6, 7, 8, 9]), 25)
def csvToMatrix(self): self._matrix = Matrix(array(self._dataCSV.values)) self._nameOfColumns = self._dataCSV.columns return self._matrix
values.append(row) with open(OUT_CSV, 'w') as csvOutFile: writer = csv.writer(csvOutFile) headerRow = [ 'Id', 'Projection Id', 'Occurrence Set Id', 'Scenario Id', 'Algorithm Code', 'Number of Presences', 'Morans I', 'Variance', 'ASCII Size', 'Tiff Size', 'Binary Size', 'RLE Size', 'Hilbert Size', 'Quadtree Size', 'S-Tree Size', 'Combo 6 Size', 'Combo 8 Size', 'Combo 10 Size' ] writer.writerow(headerRow) for idStr, prjId, occId, scnId, algoCode, tiffSize in values[1:]: print idStr id = int(idStr) mtx = Matrix() mtx.readFile(getFileName('bins', id, 'bin')) numPres, variance = getNumPresencesAndVariance(mtx.data) mI = calculateMoransI(mtx.data) asciiSize = getFileSize(getFileName('ascs', id, 'asc')) tiffSize = tiffSize binSize = getFileSize(getFileName('bins', id, 'bin')) rleSize = getFileSize(getFileName('rles', id, 'rle')) hilbertSize = getFileSize(getFileName('hilberts', id, 'hilb')) qTreeSize = getFileSize(getFileName('qtrees', id, 'qtree')) sTreeSize = getFileSize(getFileName('strees', id, 'stree')) combo6Size = getFileSize(getFileName('combos6', id, 'combo6')) combo8Size = getFileSize(getFileName('combos8', id, 'combo8')) combo10Size = getFileSize(getFileName('combos10', id, 'combo10')) row = [
""" import csv import os from matrix.matrix import Matrix inDir = '/data/geo716/final project/data/bins' inCsvFn = '/data/geo716/final project/data/projectionsNew.csv' outCsvFn = '/data/geo716/final project/data/projections2.csv' with open(inCsvFn) as csvIn: with open(outCsvFn, 'w') as csvOut: reader = csv.reader(csvIn) writer = csv.writer(csvOut) headers = reader.next() headers.append('Number of presence') all = [] all.append(headers) i = 0 for row in reader: fn = os.path.join(inDir, '%s.bin' % i) mtx = Matrix() mtx.readFile(fn) row.append(sum([sum(r) for r in mtx.data])) all.append(row) i += 1 writer.writerows(all)
def decompress(self): data = quadtreeDecompress(self.data, self.xSize) mtx = Matrix(data=data, xSize=self.xSize, ySize=self.ySize) return mtx
@summary: Get the number of presences in a layer """ import csv import os from matrix.matrix import Matrix inDir = '/data/geo716/final project/data/bins' inCsvFn = '/data/geo716/final project/data/projectionsNew.csv' outCsvFn = '/data/geo716/final project/data/projections2.csv' with open(inCsvFn) as csvIn: with open(outCsvFn, 'w') as csvOut: reader = csv.reader(csvIn) writer = csv.writer(csvOut) headers = reader.next() headers.append('Number of presence') all = [] all.append(headers) i = 0 for row in reader: fn = os.path.join(inDir, '%s.bin' % i) mtx = Matrix() mtx.readFile(fn) row.append(sum([sum(r) for r in mtx.data])) all.append(row) i += 1 writer.writerows(all)
def perturbDataset(self): self._perturbedDataset = Matrix(self._transformer.fit_transform(self._dataset.getRawMatrix()))
def test_ones(input_length, expected_result): if expected_result is TypeError or expected_result is ValueError: with pytest.raises(expected_result): Matrix.ones(input_length) else: assert Matrix.ones(input_length) == expected_result
def generate(originalDimension, k, epsilon): transformer = GaussianRandomProjection(n_components=k, eps=epsilon) return Matrix(transformer._make_random_matrix(k, originalDimension))
def test_is_valid_matrix(test_input, expected_exception): if expected_exception is None: Matrix.is_valid_matrix(test_input) else: with pytest.raises(expected_exception): Matrix.is_valid_matrix(test_input)
""" @summary: Module containing script to convert binary rasters to compressed rasters via combo quad tree hilbert curve encoding """ import os from matrix.matrix import Matrix from combo.quadTreeHilbert import QuadtreeHilbertCompressedMatrix inDir = '/data/geo716/final project/data/bins' outDir = '/data/geo716/final project/data/combos' orders = [6, 8, 10] for i in xrange(1000): binFn = os.path.join(inDir, '%s.bin' % i) mtx = Matrix() mtx.readFile(binFn) for order in orders: print i, '-', order cmpFn = os.path.join('%s%s' % (outDir, order), '%s.combo%s' % (i, order)) mtx2 = QuadtreeHilbertCompressedMatrix(rleThreshold=order) mtx2.compress(mtx) mtx2.writeFile(cmpFn)
@pytest.mark.parametrize("test_input, expected_exception", [((()), None), (((1, ), ), None), (((1, 2.5), (-3, -4)), None), (None, TypeError), (1, TypeError), ((("1", ), ), TypeError), (((), (1, )), ValueError)]) def test_is_valid_matrix(test_input, expected_exception): if expected_exception is None: Matrix.is_valid_matrix(test_input) else: with pytest.raises(expected_exception): Matrix.is_valid_matrix(test_input) ######################################################################################################################## @pytest.mark.parametrize('expected_matrix, expected_tuples', [(Matrix((())), (())), (Matrix(((1, ), )), ((1, ), )), (Matrix( ((1, 2.5), (-3, -4))), ((1, 2.5), (-3, -4)))]) def test_matrix_tuples(expected_matrix, expected_tuples): assert expected_matrix.tuples == expected_tuples ######################################################################################################################## @pytest.mark.parametrize('expected_matrix, expected_str', [(Matrix((())), '()'), (Matrix(((1, ), )), '((1,),)'), (Matrix( ((1, 2.5), (-3, -4))), '((1, 2.5), (-3, -4))')]) def test_matrix_str(expected_matrix, expected_str): assert str(expected_matrix) == expected_str