def unbroadcast(a, b):
<EOL>spa = sps.issparse(a)<EOL>spb = sps.issparse(b)<EOL>if   spa and spb: return (a,b)<EOL>elif spa or  spb:<EOL><INDENT>def fix(sp,nm):<EOL><INDENT>nm = np.asarray(nm)<EOL>dnm = len(nm.shape)<EOL>nnm = np.prod(nm.shape)<EOL>if   dnm == <NUM_LIT:0>: return (sp, np.reshape(nm, (<NUM_LIT:1>,   <NUM_LIT:1>)))<EOL>elif dnm == <NUM_LIT:1>: return (sp, np.reshape(nm, (nnm, <NUM_LIT:1>)))<EOL>elif dnm == <NUM_LIT:2>: return (sp, nm)<EOL>else:          return unbroadcast(sp.toarray(), nm)<EOL><DEDENT>return fix(a, b) if spa else tuple(reversed(fix(b, a)))<EOL><DEDENT>a = np.asarray(a)<EOL>b = np.asarray(b)<EOL>da = len(a.shape)<EOL>db = len(b.shape)<EOL>if   da > db: return (a, np.reshape(b, b.shape + tuple(np.ones(da-db, dtype=np.int))))<EOL>elif da < db: return (np.reshape(a, a.shape + tuple(np.ones(db-da, dtype=np.int))), b)<EOL>else:         return (a, b)<EOL>
unbroadcast(a, b) yields a tuple (aa, bb) that is equivalent to (a, b) except that aa and bb
  have been reshaped such that arithmetic numpy operations such as aa * bb will result in
  row-wise operation instead of column-wise broadcasting.