<commit_before>## Automatically adapted for scipy Oct 19, 2005 by convertcode.py

#!/usr/bin/env python

# This python script tests the numpyio module.
# also check out numpyio.fread.__doc__ and other method docstrings.

import os,sys
import unittest
from unittest import TestCase
from scipy.test.testing import *
set_package_path()
import io
from io import numpyio
del sys.path[0]


import scipy.base as Numeric
N = Numeric
import tempfile

class test_numpyio(TestCase):
    def check_basic(self):
        # Generate some data
        a = 255*rand(20)
        # Open a file
        fname = tempfile.mktemp('.dat')
        fid = open(fname,"wb")
        # Write the data as shorts
        numpyio.fwrite(fid,20,a,Numeric.Int16)
        fid.close()
        # Reopen the file and read in data
        fid = open(fname,"rb")
        print "\nDon't worry about a warning regarding the number of bytes read."
        b = numpyio.fread(fid,1000000,Numeric.Int16,Numeric.Int)
        fid.close()
        assert(N.product(a.astype(N.Int16) == b))
        os.remove(fname)

class test_read_array(TestCase):
    def check_complex(self):
        a = rand(13,4) + 1j*rand(13,4)
        fname = tempfile.mktemp('.dat')
        io.write_array(fname,a)
        b = io.read_array(fname,atype=N.Complex)
        assert_array_almost_equal(a,b,decimal=4)
        os.remove(fname)

    def check_float(self):
        a = rand(3,4)*30
        fname = tempfile.mktemp('.dat')
        io.write_array(fname,a)
        b = io.read_array(fname)
        assert_array_almost_equal(a,b,decimal=4)
        os.remove(fname)

    def check_integer(self):
        from scipy import stats
        a = stats.randint.rvs(1,20,size=(3,4))
        fname = tempfile.mktemp('.dat')
        io.write_array(fname,a)
        b = io.read_array(fname,atype=N.Int)
        assert_array_equal(a,b)
        os.remove(fname)

if __name__ == "__main__":
    ScipyTest().run()
<commit_msg>Fix up test for io on 64-bit<commit_after>## Automatically adapted for scipy Oct 19, 2005 by convertcode.py

#!/usr/bin/env python

# This python script tests the numpyio module.
# also check out numpyio.fread.__doc__ and other method docstrings.

import os,sys
import unittest
from unittest import TestCase
from scipy.test.testing import *
set_package_path()
import io
from io import numpyio
del sys.path[0]


import scipy.base as Numeric
N = Numeric
import tempfile

class test_numpyio(TestCase):
    def check_basic(self):
        # Generate some data
        a = 255*rand(20)
        # Open a file
        fname = tempfile.mktemp('.dat')
        fid = open(fname,"wb")
        # Write the data as shorts
        numpyio.fwrite(fid,20,a,Numeric.Int16)
        fid.close()
        # Reopen the file and read in data
        fid = open(fname,"rb")
        print "\nDon't worry about a warning regarding the number of bytes read."
        b = numpyio.fread(fid,1000000,Numeric.Int16,Numeric.Int)
        fid.close()
        assert(N.product(a.astype(N.Int16) == b))
        os.remove(fname)

class test_read_array(TestCase):
    def check_complex(self):
        a = rand(13,4) + 1j*rand(13,4)
        fname = tempfile.mktemp('.dat')
        io.write_array(fname,a)
        b = io.read_array(fname,atype=N.Complex)
        assert_array_almost_equal(a,b,decimal=4)
        os.remove(fname)

    def check_float(self):
        a = rand(3,4)*30
        fname = tempfile.mktemp('.dat')
        io.write_array(fname,a)
        b = io.read_array(fname)
        assert_array_almost_equal(a,b,decimal=4)
        os.remove(fname)

    def check_integer(self):
        from scipy import stats
        a = stats.randint.rvs(1,20,size=(3,4))
        fname = tempfile.mktemp('.dat')
        io.write_array(fname,a)
        b = io.read_array(fname,atype=a.dtypechar)
        assert_array_equal(a,b)
        os.remove(fname)

if __name__ == "__main__":
    ScipyTest().run()

{'fraction_non_alphanumeric': 0.1147036181678214, 'fraction_numerical': 0.02360790351552476, 'mean_word_length': 2.698292220113852, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '501166', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1358, 'n_words': 304}