def func(s1, s2, sm1, sm2): shapein = broadcast_shapes(s1 + sm2[1:], s2 + sm2[1:]) data1 = np.arange(product(s1 + sm1)).reshape(s1 + sm1) data2 = np.arange(product(s2 + sm2)).reshape(s2 + sm2) op1 = DenseBlockDiagonalOperator(data1) op2 = DenseBlockDiagonalOperator(data2) comp1 = op1 * op2 assert_is_instance(comp1, DenseBlockDiagonalOperator) with rule_manager(none=True): comp2 = op1 * op2 assert_equal(comp1.todense(shapein), comp2.todense(shapein))
def func(shapein, shapeout, extradata, extrainput): datashape = extradata + shapeout + shapein d = np.arange(product(datashape)).reshape(datashape) b = DenseBlockDiagonalOperator(d, naxesin=len(shapein), naxesout=len(shapeout)) new_shape = broadcast_shapes(extradata, extrainput) bdense = b.todense(shapein=new_shape + shapein) d_ = reshape_broadcast(d, new_shape + shapeout + shapein) d_ = d_.reshape(-1, product(shapeout), product(shapein)) expected = BlockDiagonalOperator( [_ for _ in d_], axisin=0).todense(shapein=product(new_shape + shapein)) assert_same(bdense, expected) bTdense = b.T.todense(shapein=new_shape + shapeout) assert_same(bTdense, expected.T)
def func(shape, expected): assert_equal(broadcast_shapes(*shape), expected)