File: test_miobase.py

package info (click to toggle)
python-scipy 0.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 75,464 kB
  • ctags: 79,406
  • sloc: python: 143,495; cpp: 89,357; fortran: 81,650; ansic: 79,778; makefile: 364; sh: 265
file content (30 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
""" Testing miobase module
"""

import numpy as np

from numpy.testing import assert_raises, assert_equal

from scipy.io.matlab.miobase import matdims


def test_matdims():
    # Test matdims dimension finder
    assert_equal(matdims(np.array(1)), (1, 1))  # numpy scalar
    assert_equal(matdims(np.array([1])), (1, 1))  # 1d array, 1 element
    assert_equal(matdims(np.array([1,2])), (2, 1))  # 1d array, 2 elements
    assert_equal(matdims(np.array([[2],[3]])), (2, 1))  # 2d array, column vector
    assert_equal(matdims(np.array([[2,3]])), (1, 2))  # 2d array, row vector
    # 3d array, rowish vector
    assert_equal(matdims(np.array([[[2,3]]])), (1, 1, 2))
    assert_equal(matdims(np.array([])), (0, 0))  # empty 1d array
    assert_equal(matdims(np.array([[]])), (0, 0))  # empty 2d
    assert_equal(matdims(np.array([[[]]])), (0, 0, 0))  # empty 3d
    # Optional argument flips 1-D shape behavior.
    assert_equal(matdims(np.array([1,2]), 'row'), (1, 2))  # 1d array, 2 elements
    # The argument has to make sense though
    assert_raises(ValueError, matdims, np.array([1,2]), 'bizarre')
    # Check empty sparse matrices get their own shape
    from scipy.sparse import csr_matrix, csc_matrix
    assert_equal(matdims(csr_matrix(np.zeros((3, 3)))), (3, 3))
    assert_equal(matdims(csc_matrix(np.zeros((2, 2)))), (2, 2))