<s> '''<STR_LIT>''' <EOL> from bnpy . suffstats . ParamBag import ParamBag <EOL> import numpy as np <EOL> import unittest <EOL> class TestParamBag ( unittest . TestCase ) : <EOL> def shortDescription ( self ) : <EOL> return None <EOL> def test_setAllFieldsToZero_K1_D1 ( self , K = <NUM_LIT:1> , D = <NUM_LIT:1> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> s = <NUM_LIT> <EOL> N = np . ones ( K ) <EOL> x = np . ones ( ( K , D ) ) <EOL> xxT = np . ones ( ( K , D , D ) ) <EOL> W = np . ones ( ( K , K ) ) <EOL> A . setField ( '<STR_LIT:s>' , s ) <EOL> A . setField ( '<STR_LIT:N>' , N , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , x , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , xxT , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , W , dims = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> A . setAllFieldsToZero ( ) <EOL> assert np . allclose ( A . s , <NUM_LIT:0.0> ) <EOL> assert np . allclose ( A . N , np . zeros ( K ) ) <EOL> assert np . allclose ( A . x , np . zeros ( K ) ) <EOL> assert np . allclose ( A . xxT , np . zeros ( K ) ) <EOL> assert np . allclose ( A . xxT , np . zeros ( ( K , K ) ) ) <EOL> def test_insertEmptyComps_K1_D1 ( self , K = <NUM_LIT:1> , D = <NUM_LIT:1> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> s = <NUM_LIT> <EOL> N = np . zeros ( K ) <EOL> x = np . zeros ( ( K , D ) ) <EOL> xxT = np . zeros ( ( K , D , D ) ) <EOL> W = np . zeros ( ( K , K ) ) <EOL> A . setField ( '<STR_LIT:s>' , s ) <EOL> A . setField ( '<STR_LIT:N>' , N , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , x , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , xxT , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , W , dims = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> A . insertEmptyComps ( <NUM_LIT:2> ) <EOL> assert np . allclose ( A . s , <NUM_LIT> ) <EOL> assert np . allclose ( A . N , np . zeros ( K + <NUM_LIT:2> ) ) <EOL> assert np . allclose ( A . x , np . zeros ( K + <NUM_LIT:2> ) ) <EOL> assert np . allclose ( A . xxT , np . zeros ( K + <NUM_LIT:2> ) ) <EOL> assert np . allclose ( A . W , np . zeros ( ( K + <NUM_LIT:2> , K + <NUM_LIT:2> ) ) ) <EOL> def test_insertEmptyComps_K1_D1 ( self , K = <NUM_LIT:1> , D = <NUM_LIT:2> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> s = <NUM_LIT> <EOL> N = np . zeros ( K ) <EOL> x = np . zeros ( ( K , D ) ) <EOL> xxT = np . zeros ( ( K , D , D ) ) <EOL> W = np . zeros ( ( K , K ) ) <EOL> A . setField ( '<STR_LIT:s>' , s ) <EOL> A . setField ( '<STR_LIT:N>' , N , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , x , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , xxT , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , W , dims = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> A . insertEmptyComps ( <NUM_LIT:2> ) <EOL> assert np . allclose ( A . s , <NUM_LIT> ) <EOL> assert np . allclose ( A . N , np . zeros ( K + <NUM_LIT:2> ) ) <EOL> assert np . allclose ( A . x , np . zeros ( ( K + <NUM_LIT:2> , D ) ) ) <EOL> assert np . allclose ( A . xxT , np . zeros ( ( K + <NUM_LIT:2> , D , D ) ) ) <EOL> assert np . allclose ( A . W , np . zeros ( ( K + <NUM_LIT:2> , K + <NUM_LIT:2> ) ) ) <EOL> def test_insertEmptyComps_K3_D1 ( self , K = <NUM_LIT:3> , D = <NUM_LIT:1> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> s = <NUM_LIT> <EOL> N = np . zeros ( K ) <EOL> x = np . zeros ( ( K , D ) ) <EOL> xxT = np . zeros ( ( K , D , D ) ) <EOL> W = np . zeros ( ( K , K ) ) <EOL> A . setField ( '<STR_LIT:s>' , s ) <EOL> A . setField ( '<STR_LIT:N>' , N , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , x , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , xxT , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , W , dims = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> A . insertEmptyComps ( <NUM_LIT:2> ) <EOL> assert np . allclose ( A . s , <NUM_LIT> ) <EOL> assert np . allclose ( A . N , np . zeros ( K + <NUM_LIT:2> ) ) <EOL> assert np . allclose ( A . x , np . zeros ( K + <NUM_LIT:2> ) ) <EOL> assert np . allclose ( A . xxT , np . zeros ( K + <NUM_LIT:2> ) ) <EOL> assert np . allclose ( A . W , np . zeros ( ( K + <NUM_LIT:2> , K + <NUM_LIT:2> ) ) ) <EOL> def test_insertEmptyComps_K3_D3 ( self , K = <NUM_LIT:3> , D = <NUM_LIT:3> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> s = <NUM_LIT> <EOL> N = np . zeros ( K ) <EOL> x = np . zeros ( ( K , D ) ) <EOL> xxT = np . zeros ( ( K , D , D ) ) <EOL> W = np . zeros ( ( K , K ) ) <EOL> A . setField ( '<STR_LIT:s>' , s ) <EOL> A . setField ( '<STR_LIT:N>' , N , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , x , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , xxT , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , W , dims = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> A . insertEmptyComps ( <NUM_LIT:2> ) <EOL> assert np . allclose ( A . s , <NUM_LIT> ) <EOL> assert np . allclose ( A . N , np . zeros ( K + <NUM_LIT:2> ) ) <EOL> assert np . allclose ( A . x , np . zeros ( ( K + <NUM_LIT:2> , D ) ) ) <EOL> assert np . allclose ( A . xxT , np . zeros ( ( K + <NUM_LIT:2> , D , D ) ) ) <EOL> assert np . allclose ( A . W , np . zeros ( ( K + <NUM_LIT:2> , K + <NUM_LIT:2> ) ) ) <EOL> def test_insertComps_K1_D1 ( self ) : <EOL> A = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:1> ) <EOL> s = <NUM_LIT> <EOL> A . setField ( '<STR_LIT>' , s , dims = None ) <EOL> A . setField ( '<STR_LIT:N>' , [ <NUM_LIT:1> ] , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , [ [ <NUM_LIT:1> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , [ [ [ <NUM_LIT:1> ] ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> Abig = A . copy ( ) <EOL> Abig . insertComps ( A ) <EOL> assert Abig . K == <NUM_LIT:2> <EOL> assert np . allclose ( Abig . N , np . hstack ( [ A . N , A . N ] ) ) <EOL> assert Abig . scalar == <NUM_LIT:2> * s <EOL> Abig . insertComps ( A ) <EOL> assert Abig . K == <NUM_LIT:3> <EOL> assert np . allclose ( Abig . N , np . hstack ( [ A . N , A . N , A . N ] ) ) <EOL> assert Abig . scalar == <NUM_LIT:3> * s <EOL> A . insertComps ( Abig ) <EOL> assert A . K == <NUM_LIT:4> <EOL> assert A . scalar == <NUM_LIT:4> * s <EOL> assert np . allclose ( A . N , np . hstack ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) <EOL> def test_insertComps_K1_D3 ( self , K = <NUM_LIT:1> , D = <NUM_LIT:3> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> s = <NUM_LIT> <EOL> A . setField ( '<STR_LIT>' , s , dims = None ) <EOL> A . setField ( '<STR_LIT:N>' , [ <NUM_LIT:1.0> ] , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , np . random . rand ( K , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , np . random . rand ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> Abig = A . copy ( ) <EOL> Abig . insertComps ( A ) <EOL> assert Abig . K == <NUM_LIT:2> <EOL> assert np . allclose ( Abig . N , np . hstack ( [ A . N , A . N ] ) ) <EOL> assert Abig . scalar == <NUM_LIT:2> * s <EOL> assert Abig . xxT . shape == ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> assert np . allclose ( Abig . xxT [ <NUM_LIT:0> ] , A . xxT ) <EOL> assert np . allclose ( Abig . xxT [ <NUM_LIT:1> ] , A . xxT ) <EOL> Abig . insertComps ( A ) <EOL> assert Abig . K == <NUM_LIT:3> <EOL> assert np . allclose ( Abig . N , np . hstack ( [ A . N , A . N , A . N ] ) ) <EOL> assert Abig . scalar == <NUM_LIT:3> * s <EOL> assert Abig . xxT . shape == ( <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> assert np . allclose ( Abig . xxT [ <NUM_LIT:0> ] , A . xxT ) <EOL> assert np . allclose ( Abig . xxT [ <NUM_LIT:1> ] , A . xxT ) <EOL> A . insertComps ( Abig ) <EOL> assert A . K == <NUM_LIT:4> <EOL> assert A . scalar == <NUM_LIT:4> * s <EOL> assert np . allclose ( A . N , np . hstack ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) <EOL> def test_removeComp_K1_D1 ( self ) : <EOL> A = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:1> ) <EOL> A . setField ( '<STR_LIT:N>' , [ <NUM_LIT:1> ] , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , [ [ <NUM_LIT:1> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> A . removeComp ( <NUM_LIT:0> ) <EOL> def test_removeComp_K3_D1 ( self ) : <EOL> A = ParamBag ( K = <NUM_LIT:3> , D = <NUM_LIT:1> ) <EOL> A . setField ( '<STR_LIT:N>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , [ [ <NUM_LIT:4> ] , [ <NUM_LIT:5> ] , [ <NUM_LIT:6> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , np . ones ( ( <NUM_LIT:3> , <NUM_LIT:3> ) ) , dims = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> Aorig = A . copy ( ) <EOL> A . removeComp ( <NUM_LIT:1> ) <EOL> assert Aorig . K == A . K + <NUM_LIT:1> <EOL> assert A . N [ <NUM_LIT:0> ] == Aorig . N [ <NUM_LIT:0> ] <EOL> assert A . N [ <NUM_LIT:1> ] == Aorig . N [ <NUM_LIT:2> ] <EOL> assert np . allclose ( A . x , [ [ <NUM_LIT:4> ] , [ <NUM_LIT:6> ] ] ) <EOL> assert np . allclose ( A . W , np . ones ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) <EOL> def test_remove_K3_D2 ( self , K = <NUM_LIT:3> , D = <NUM_LIT:2> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> s = <NUM_LIT> <EOL> N = np . random . rand ( K ) <EOL> x = np . random . rand ( K , D ) <EOL> xxT = np . random . randn ( K , D , D ) <EOL> A . setField ( '<STR_LIT:s>' , s ) <EOL> A . setField ( '<STR_LIT:N>' , N , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , x , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT>' , xxT , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> Abig = A . copy ( ) <EOL> for k in range ( K - <NUM_LIT:1> ) : <EOL> A . removeComp ( <NUM_LIT:0> ) <EOL> assert A . K == K - k - <NUM_LIT:1> <EOL> assert A . s == s <EOL> assert np . allclose ( A . getComp ( <NUM_LIT:0> ) . x , x [ k + <NUM_LIT:1> ] ) <EOL> assert np . allclose ( A . getComp ( <NUM_LIT:0> ) . xxT , xxT [ k + <NUM_LIT:1> ] ) <EOL> def test_getComp_K1_D1 ( self ) : <EOL> A = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:1> ) <EOL> A . setField ( '<STR_LIT>' , <NUM_LIT:1> , dims = None ) <EOL> A . setField ( '<STR_LIT:N>' , [ <NUM_LIT:1> ] , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , [ [ <NUM_LIT:1> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> c = A . getComp ( <NUM_LIT:0> ) <EOL> assert c . K == <NUM_LIT:1> <EOL> assert c . N == A . N <EOL> assert c . x == A . x <EOL> assert id ( c . scalar ) != id ( A . scalar ) <EOL> assert id ( c . N ) != id ( A . N ) <EOL> assert id ( c . x ) != id ( A . x ) <EOL> def test_getComp_K3_D1 ( self ) : <EOL> A = ParamBag ( K = <NUM_LIT:3> , D = <NUM_LIT:1> ) <EOL> A . setField ( '<STR_LIT:N>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , dims = '<STR_LIT>' ) <EOL> A . setField ( '<STR_LIT:x>' , [ [ <NUM_LIT:4> ] , [ <NUM_LIT:5> ] , [ <NUM_LIT:6> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> c = A . getComp ( <NUM_LIT:0> ) <EOL> assert c . K == <NUM_LIT:1> <EOL> assert c . N == A . N [ <NUM_LIT:0> ] <EOL> assert c . x == A . x [ <NUM_LIT:0> ] <EOL> assert id ( c . N ) != id ( A . N ) <EOL> assert id ( c . x ) != id ( A . x ) <EOL> def test_add_K1_D1 ( self ) : <EOL> A = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:1> ) <EOL> B = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:1> ) <EOL> C = A + B <EOL> assert C . K == A . K and C . D == A . D <EOL> A . setField ( '<STR_LIT:N>' , [ <NUM_LIT:1> ] , dims = '<STR_LIT>' ) <EOL> B . setField ( '<STR_LIT:N>' , [ <NUM_LIT:10> ] , dims = '<STR_LIT>' ) <EOL> C = A + B <EOL> assert C . N [ <NUM_LIT:0> ] == <NUM_LIT> <EOL> def test_add_K3_D2 ( self , K = <NUM_LIT:3> , D = <NUM_LIT:2> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> A . setField ( '<STR_LIT>' , np . random . randn ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> B = ParamBag ( K = K , D = D ) <EOL> B . setField ( '<STR_LIT>' , np . random . randn ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> C = A + B <EOL> assert np . allclose ( C . xxT , A . xxT + B . xxT ) <EOL> def test_sub_K3_D2 ( self , K = <NUM_LIT:3> , D = <NUM_LIT:2> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> A . setField ( '<STR_LIT>' , np . random . randn ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> B = ParamBag ( K = K , D = D ) <EOL> B . setField ( '<STR_LIT>' , np . random . randn ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> C = A - B <EOL> assert np . allclose ( C . xxT , A . xxT - B . xxT ) <EOL> def test_iadd_K3_D2 ( self , K = <NUM_LIT:3> , D = <NUM_LIT:2> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> A . setField ( '<STR_LIT>' , np . random . randn ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT:x>' , np . random . randn ( K , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> B = ParamBag ( K = K , D = D ) <EOL> B . setField ( '<STR_LIT:x>' , np . random . randn ( K , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> B . setField ( '<STR_LIT>' , np . random . randn ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> origID = hex ( id ( A ) ) <EOL> A += B <EOL> newID = hex ( id ( A ) ) <EOL> assert origID == newID <EOL> A = A + B <EOL> newnewID = hex ( id ( A ) ) <EOL> assert newnewID != origID <EOL> def test_isub_K3_D2 ( self , K = <NUM_LIT:3> , D = <NUM_LIT:2> ) : <EOL> A = ParamBag ( K = K , D = D ) <EOL> A . setField ( '<STR_LIT>' , np . random . randn ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> A . setField ( '<STR_LIT:x>' , np . random . randn ( K , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> B = ParamBag ( K = K , D = D ) <EOL> B . setField ( '<STR_LIT:x>' , np . random . randn ( K , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> B . setField ( '<STR_LIT>' , np . random . randn ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> origID = hex ( id ( A ) ) <EOL> A -= B <EOL> newID = hex ( id ( A ) ) <EOL> assert origID == newID <EOL> A = A - B <EOL> newnewID = hex ( id ( A ) ) <EOL> assert newnewID != origID <EOL> def test_parseArr_dim0_passes ( self ) : <EOL> PB1 = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:1> ) <EOL> x = PB1 . parseArr ( <NUM_LIT> , dims = None ) <EOL> assert x . ndim == <NUM_LIT:0> and x . size == <NUM_LIT:1> <EOL> x = PB1 . parseArr ( [ <NUM_LIT> ] , dims = ( '<STR_LIT>' ) ) <EOL> assert x . ndim == <NUM_LIT:1> and x . size == <NUM_LIT:1> <EOL> PB2 = ParamBag ( K = <NUM_LIT:2> , D = <NUM_LIT:1> ) <EOL> x = PB2 . parseArr ( <NUM_LIT> , dims = None ) <EOL> assert x . ndim == <NUM_LIT:0> and x . size == <NUM_LIT:1> <EOL> PB5 = ParamBag ( K = <NUM_LIT:5> , D = <NUM_LIT> ) <EOL> x = PB5 . parseArr ( <NUM_LIT> , dims = None ) <EOL> assert x . ndim == <NUM_LIT:0> and x . size == <NUM_LIT:1> <EOL> def test_parseArr_dim0_fails ( self ) : <EOL> '''<STR_LIT>''' <EOL> PB2 = ParamBag ( K = <NUM_LIT:2> , D = <NUM_LIT:1> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB2 . parseArr ( <NUM_LIT> , dims = ( '<STR_LIT>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB2 . parseArr ( <NUM_LIT> , dims = '<STR_LIT>' ) <EOL> def test_parseArr_dim1_passes ( self ) : <EOL> PB1 = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:1> ) <EOL> x = PB1 . parseArr ( [ <NUM_LIT> ] , dims = '<STR_LIT>' ) <EOL> assert x . ndim == <NUM_LIT:1> and x . size == <NUM_LIT:1> <EOL> x = PB1 . parseArr ( [ [ <NUM_LIT> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> assert x . ndim == <NUM_LIT:2> and x . size == <NUM_LIT:1> <EOL> PB2 = ParamBag ( K = <NUM_LIT:2> , D = <NUM_LIT:1> ) <EOL> x = PB2 . parseArr ( [ <NUM_LIT:1.> , <NUM_LIT> ] , dims = '<STR_LIT>' ) <EOL> assert x . ndim == <NUM_LIT:1> and x . size == <NUM_LIT:2> <EOL> x = PB2 . parseArr ( [ [ <NUM_LIT:1.> ] , [ <NUM_LIT> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> assert x . ndim == <NUM_LIT:2> and x . size == <NUM_LIT:2> <EOL> PB3 = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:3> ) <EOL> x = PB3 . parseArr ( [ [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> assert x . ndim == <NUM_LIT:2> and x . size == <NUM_LIT:3> <EOL> PB2 = ParamBag ( K = <NUM_LIT:4> , D = <NUM_LIT:1> ) <EOL> x = PB2 . parseArr ( [ [ <NUM_LIT:1.> ] , [ <NUM_LIT> ] , [ <NUM_LIT> ] , [ <NUM_LIT> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> assert x . ndim == <NUM_LIT:2> and x . size == <NUM_LIT:4> <EOL> N = PB2 . parseArr ( [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , dims = '<STR_LIT>' ) <EOL> assert N . ndim == <NUM_LIT:1> and N . size == <NUM_LIT:4> <EOL> def test_parseArr_dim1_fails ( self ) : <EOL> PB1 = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:1> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB1 . parseArr ( [ <NUM_LIT> ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> PB2 = ParamBag ( K = <NUM_LIT:2> , D = <NUM_LIT:1> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB2 . parseArr ( [ <NUM_LIT> ] , dims = ( '<STR_LIT>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB2 . parseArr ( [ <NUM_LIT> ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> PB3 = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:3> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB3 . parseArr ( [ <NUM_LIT:1.> , <NUM_LIT> ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> PB3 = ParamBag ( K = <NUM_LIT:2> , D = <NUM_LIT:3> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB3 . parseArr ( [ <NUM_LIT:1.> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> def test_parseArr_dim2_passes ( self ) : <EOL> PB2 = ParamBag ( K = <NUM_LIT:2> , D = <NUM_LIT:2> ) <EOL> x = PB2 . parseArr ( np . eye ( <NUM_LIT:2> ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> assert x . ndim == <NUM_LIT:2> and x . size == <NUM_LIT:4> <EOL> PB31 = ParamBag ( K = <NUM_LIT:3> , D = <NUM_LIT:1> ) <EOL> x = PB31 . parseArr ( [ [ <NUM_LIT:10> ] , [ <NUM_LIT:11> ] , [ <NUM_LIT:12> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> assert x . ndim == <NUM_LIT:2> and x . size == <NUM_LIT:3> <EOL> def test_parseArr_dim2_fails ( self ) : <EOL> PB2 = ParamBag ( K = <NUM_LIT:2> , D = <NUM_LIT:2> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB2 . parseArr ( [ [ <NUM_LIT:1.> , <NUM_LIT:2> ] ] , dims = ( '<STR_LIT>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB2 . parseArr ( [ [ <NUM_LIT:1.> , <NUM_LIT:2> ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB2 . parseArr ( np . eye ( <NUM_LIT:3> ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> PB1 = ParamBag ( K = <NUM_LIT:1> , D = <NUM_LIT:2> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB1 . parseArr ( np . eye ( <NUM_LIT:2> ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> def test_parseArr_dim3_passes ( self ) : <EOL> K = <NUM_LIT:2> <EOL> D = <NUM_LIT:2> <EOL> PB = ParamBag ( K = K , D = D ) <EOL> x = PB . parseArr ( np . random . randn ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> assert x . ndim == <NUM_LIT:3> and x . size == K * D * D <EOL> K = <NUM_LIT:1> <EOL> D = <NUM_LIT:2> <EOL> PB = ParamBag ( K = K , D = D ) <EOL> x = PB . parseArr ( np . random . rand ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> assert x . ndim == <NUM_LIT:3> and x . size == K * D * D <EOL> K = <NUM_LIT:3> <EOL> D = <NUM_LIT:1> <EOL> PB = ParamBag ( K = K , D = D ) <EOL> x = PB . parseArr ( np . random . rand ( K , D , D ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) <EOL> assert x . ndim == <NUM_LIT:3> and x . size == K * D * D <EOL> def test_parseArr_dim3_fails ( self ) : <EOL> PB = ParamBag ( K = <NUM_LIT:2> , D = <NUM_LIT:2> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB . parseArr ( [ [ [ <NUM_LIT:1.> , <NUM_LIT:2> ] ] ] , dims = ( '<STR_LIT>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB . parseArr ( [ [ [ <NUM_LIT:1.> , <NUM_LIT:2> ] ] ] , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB . parseArr ( np . random . randn ( <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> x = PB . parseArr ( np . random . randn ( <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> ) , dims = ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) ) </s>
