def test_compresses_images_specified(self):
     "Test function compresses images with filename and input dir args."
     args = self.parser.parse_args(['test.png', '-i', self.testdir])
     compress(args)
     result = os.listdir(self.testdir)[1]
     expected = 'test_compressed.png'
     self.assertEqual(result, expected)
 def test_compresses_images_specified(self):
     "Test function compresses images with filename and input dir args."
     args = self.parser.parse_args(['test.png', '-i', self.testdir])
     compress(args)
     result = os.listdir(self.testdir)[1]
     expected = 'test_compressed.png'
     self.assertEqual(result, expected)
Ejemplo n.º 3
0
 def send_diagram_execute():
     global now
     global diagram_filename
     now = datetime.now()
     if diagram_filename is "":
         print("Select valid type")
     else:
         compressor.compress(diagram_filename, topic_name, now)
     diagram_filename=""
 def test_compresses_images_and_puts_in_output_dir(self):
     """
     Test function compresses images with filename, input dir and output dir
     args specified. Should also create the output dir if it doesn't exist.
     """
     args = self.parser.parse_args(
         ['test.png', '-i', self.testdir, '-o', self.outputdir])
     compress(args)
     result = os.listdir(self.outputdir)[0]
     expected = 'test.png'
     self.assertEqual(result, expected)
 def test_compresses_images_and_puts_in_output_dir(self):
     """
     Test function compresses images with filename, input dir and output dir
     args specified. Should also create the output dir if it doesn't exist.
     """
     args = self.parser.parse_args(
         ['test.png', '-i', self.testdir, '-o', self.outputdir])
     compress(args)
     result = os.listdir(self.outputdir)[0]
     expected = 'test.png'
     self.assertEqual(result, expected)
Ejemplo n.º 6
0
    def on_complete(self):
        self.cache.release(len(self.page.response))
        self.page.response = self.page.partial_response
        self.page.partial_response = ''
        self.page.complete = True
        self.close()

        # start compression
        if len(self.page.response) > 100:
            response = self.page.response
            def on_compressed(data):
                if response != self.page.response:
                    return
                headers = re.sub(r'(!\r)\n', '\r\n', response[:self.page.response_headers_len])
                headers = re.sub(r'content-length\s*:[^\r]*\r\n', '', headers)
                headers = headers[:-2] + ('content-length: %i\r\ncontent-encoding: deflate\r\n\r\n' % len(data))
                self.page.compressed = headers + data
            compress(self.loop, response[self.page.response_headers_len:], on_compressed)
 def test_with_bad_filename(self):
     "Test function errors out with non-existant filename."
     with self.assertRaises(FileNotFoundError):
         args = self.parser.parse_args(['test_bad.png', '-i', self.testdir])
         compress(args)
Ejemplo n.º 8
0
import sys
import compressor

file = sys.argv[1]

try:
    extension = file.split('.')[1]
except IndexError:
    print('File without extension! please enter the complete file name.')
    exit(0)

compressor.compress(file)
Ejemplo n.º 9
0
from compressor import compress
from wiki_converter import wiki_knml_converter
import os

file_name = input("Enter path of XML file:")
wiki_knml_converter(file_name)
file_name = file_name[:-4] + '.knml'
compress(file_name)
os.remove(file_name)
Ejemplo n.º 10
0
def compress(data):
    try:
        return compressor.compress(data)
    except OSError:
        return pycompressor.compress(data)
Ejemplo n.º 11
0
import torch
import sys
import time

torch.cuda.set_device(0)

a = torch.randn(22, 100, 224, 224)
a = a.cuda()

#print('before sending')
#print(a)

compressor = compressor.compressor(using_cuda=True)

# warmups to amortize allocation costs
c, size = compressor.compress(a)
d = compressor.uncompress(c, size)
del c, size, d
c, size = compressor.compress(a)
d = compressor.uncompress(c, size)
del c, size, d

# benchmark
torch.cuda.synchronize()
start = time.time()
c, size = compressor.compress(a)
torch.cuda.synchronize()
end = time.time()
print('Compression time cost')
print(str(end - start))
#print('during sending')
Ejemplo n.º 12
0
from matplotlib import cm
from matplotlib import gridspec
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
from compressor import compress, decompress
from smoothing import smooth

if __name__ == '__main__':
    sample_rate = 48000
    silence_length = 0.4

    raw_data = np.fromfile('wtf.bin', dtype=np.int8)
    comp_data = compress(raw_data)

    smooth_data = smooth(comp_data, int(sample_rate * silence_length))

    # print(list(filter(lambda x: x > int(sample_rate * silence_length), zeros)))
    # print(list(filter(lambda x: x > int(sample_rate * silence_length), ones)))

    # plt.figure(figsize=(13, 8))
    #
    # ax = plt.subplot(1, 1, 1)
    # ax.set_title("Validation Data")
    #
    # ax.set_autoscaley_on(False)
    # ax.set_ylim([32, 43])
    # ax.set_autoscalex_on(False)
    # # ax.set_xlim([-126, -112])
    # plt.scatter(list(range(int(len(comp_data)))),
    #                  comp_data,
Ejemplo n.º 13
0
def compress(data):
    try:
        return compressor.compress(data)
    except OSError:
        return pycompressor.compress(data)
 def test_with_bad_filename(self):
     "Test function errors out with non-existant filename."
     with self.assertRaises(FileNotFoundError):
         args = self.parser.parse_args(['test_bad.png', '-i', self.testdir])
         compress(args)
    torch.cuda.synchronize()
    ATOMO_coding_time = time.time() - ATOMO_coding_start
    ATOMO_decoding_start = time.time()

    result = ATOMO_coder.decode(code)

    torch.cuda.synchronize()
    ATOMO_decoding_time = time.time() - ATOMO_decoding_start
    ATOMO_time = time.time() - ATOMO_start

    #Signum
    torch.cuda.synchronize()
    Signum_start = time.time()
    Signum_coding_start = time.time()

    temp, tensor_size = compressor.compress(sample)

    torch.cuda.synchronize()
    Signum_coding_time = time.time() - Signum_coding_start
    Signum_decoding_start = time.time()

    result = compressor.uncompress(temp, tensor_size)

    torch.cuda.synchronize()
    Signum_decoding_time = time.time() - Signum_decoding_start
    Signum_time = time.time() - Signum_start

print('---------')
print('Signum_full_time', Signum_time)
print('Signum_coding_time', Signum_coding_time)
print('Signum_decoding_time', Signum_decoding_time)