ó ùµÈ[c @`s³dZddlmZddlmZy$ddlmZddlmZWn1e k r}ddl mZddl mZnXddl Z ddl Z ddl Z ddlmZdd d d d d ddddg ZddlZddlmZddlmZmZddlmZmZmZddlmZmZmZddlmZmZddl m!Z!ddl m"Z"yddl#m$Z%Wne k r£e&Z%nXddl!m'Z'ddl(m)Z)m*Z*m+Z+m,Z,ddl(m-Z-m.Z.m/Z/ddl(m0Z0m1Z1dd l(m2Z3ddl(mZ4dd!l(m5Z5yddl6j7Z8Wne k rde&Z8nXiej9gd"6ej9ej9gd#6Z:e&d$„Z;d e)fd%„ƒYZ<d e<fd&„ƒYZ=d e<fd'„ƒYZ>d(„Z?d)„Z@d*„ZAe&e&e&d+„ZBe&e&e&e&e&d,„ZCe&e&e&d-„ZDe&e&e&e&d.„ZEeFe0d/„ZGe'eGƒd0„ZHd1„ZId2„ZJd3„ZKe&e&d4„Z2e&e&d5„ZLe&e&d6„ZdS(7sSparse NDArray API of MXNet.i(tabsolute_import(tdivision(tslice(tsumN(tarrayt _ndarray_clst csr_matrixtrow_sparse_arraytBaseSparseNDArrayt CSRNDArraytRowSparseNDArraytaddtsubtracttmultiplytdividei(tNotSupportedForSparseNDArray(t_LIBt numeric_types(t c_array_buft mx_real_tt integer_types(tmx_uintt NDArrayHandlet check_call(tContexttcurrent_contexti(t _internal(top(tretain(t_set_ndarray_class(tNDArrayt _storage_typet_DTYPE_NP_TO_MXt_DTYPE_MX_TO_NP(t_STORAGE_TYPE_STR_TO_IDt_STORAGE_TYPE_ROW_SPARSEt_STORAGE_TYPE_CSR(t_STORAGE_TYPE_UNDEFINEDt_STORAGE_TYPE_DEFAULT(tzeros(t _ufunc_helpert row_sparsetcsrc C`sÒtƒ}x;|D]3}tj|ƒtjdƒkrtdƒ‚qqWg|D]"}tttj|ƒjƒ^qN} |dkr›g|D]}d^q‰n|}g|D]} t| ƒ^q¨} t |dƒ}t t|ƒƒ} t t j tjtt|ƒƒtt td|ƒƒt t|ƒƒtj|jƒtj|jƒtjt|ƒƒtjtttj|ƒjƒƒ| ttjtd| ƒƒtt td| ƒƒtt td|ƒƒtj|ƒƒ ƒ|S( sÅReturn a new handle with specified storage type, shape, dtype and context. Empty handle is only used to hold results Returns ------- handle A new empty ndarray handle tint64s%only int64 is supported for aux typesitItiN(i((RtnptdtypetNotImplementedErrortintR ttypetNonetlentpy_sumRRRtMXNDArrayCreateSparseExtctypestc_intR"Rt native_arrayt device_typeidt device_idtbyref( tstypetshapetctxt delay_allocR/t aux_typest aux_shapesthdltaux_tt aux_type_idst aux_shapetaux_shape_lenstnum_aux((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt_new_alloc_handleHs.  /+ "cB`sþeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zed„ƒZd„Zed„ƒZed„ƒZd„Zed„Zd„Zed„Zd„Zd„ZRS(sThe base class of an NDArray stored in a sparse storage format. See CSRNDArray and RowSparseNDArray for more details. cC`sCdjg|jD]}d|^qƒ}d|jj||jfS(s4Returns a string representation of the sparse array.txs%ds <%s %s @%s>(tjoinR>t __class__t__name__tcontext(tselfRJt shape_info((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt__repr__qs) cC`s t||ƒS(N(R (ROtother((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt__add__xscC`s t||ƒS(N(R (RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt__sub__{scC`s t||ƒS(N(R (RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt__mul__~scC`s t||ƒS(N(R(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt__div__scC`s tƒ‚dS(N(R0(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt__iadd__„scC`s tƒ‚dS(N(R0(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt__isub__‡scC`s tƒ‚dS(N(R0(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt__imul__ŠscC`s tƒ‚dS(N(R0(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt__idiv__scC`s tƒ‚dS(N(R0(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt __itruediv__scC`s tƒ‚dS(N(R0(ROt source_array((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt_sync_copyfrom“scC`st|jd|ƒ‚dS(Ns[idx](Rt_at(ROtidx((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR^–scC`st|jd||ƒ‚dS(N(Rt_sliceR3(ROtstarttstop((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR`™scO`st|jd|ƒ‚dS(N(RtreshapeR3(ROR>tkwargs((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRcœscC`s tƒ‚dS(N(R0(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pytsizeŸscC`s<tjƒ}ttj|j|tj|ƒƒƒt|jS(s˜Data-type of the array's ith aux data. Returns ------- numpy.dtype This BaseSparseNDArray's aux data type. ( R7R8RRtMXNDArrayGetAuxTypethandleR<R!tvalue(ROR-taux_type((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt _aux_type¤s %cC`stt|jƒS(sFThe number of aux data used to help store the sparse ndarray. (R4t_STORAGE_AUX_TYPESR=(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt_num_aux°scC`s@g}|j}x*t|ƒD]}|j|j|ƒƒqW|S(sBThe data types of the aux data for the BaseSparseNDArray. (RltrangetappendRj(RORARHR-((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt _aux_types¶s  cC`s|jdƒjƒS(sRReturn a dense ``numpy.ndarray`` object with value copied from this array tdefault(ttostypetasnumpy(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRrÀsc C`s^| r#tj|ƒ|jkr#|Std|jd|jd|d|jƒ}|j|ƒ|S(s¡Returns a copy of the array after casting to a specified type. Parameters ---------- dtype : numpy.dtype or str The type of the returned array. copy : bool Default `True`. By default, astype always returns a newly allocated ndarray on the same context. If this is set to `False`, and the dtype requested is the same as the ndarray's dtype, the ndarray is returned instead of a copy. Examples -------- >>> x = mx.nd.sparse.zeros('row_sparse', (2,3), dtype='float32') >>> y = x.astype('int32') >>> y.dtype R>R?R/R=(R.R/R'R>RNR=tcopyto(ROR/tcopytres((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pytastypeÅs  cC`s·t|tƒrH|j|jkr5tjdtƒtStj|d|ƒSt|t ƒr—t t |j |j |t|j|jƒƒ}tj|d|ƒStdtt|ƒƒƒ‚dS(sDCopies the value of this array to another array. Parameters ---------- other : NDArray or CSRNDArray or RowSparseNDArray or Context The destination array or context. Returns ------- NDArray or CSRNDArray or RowSparseNDArray The copied array. s-You are attempting to copy an array to itselftoutscopyto does not support type N(t isinstanceRRgtwarningstwarntRuntimeWarningtFalseRt_copytoRRRIR=R>tTrueR/Rot TypeErrortstrR2(RORRthret((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRsßscC`s&ttj|jtj|ƒƒƒdS(sùCheck whether the NDArray format is valid. Parameters ---------- full_check : bool, optional If `True`, rigorous check, O(N) operations. Otherwise basic check, O(1) operations (default True). N(RRtMXNDArraySyncCheckFormatRgR7tc_bool(ROt full_check((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt check_formatús cC`s?|jƒtƒ}ttj|jtj|ƒƒƒt|ƒS(s A deep copy NDArray of the data array associated with the BaseSparseNDArray. This function blocks. Do not use it in performance critical code. ( t wait_to_readRRRtMXNDArrayGetDataNDArrayRgR7R<R(RORC((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt_datas  "cC`sB|jƒtƒ}ttj|j|tj|ƒƒƒt|ƒS(s¶ Get a deep copy NDArray of the i-th aux data array associated with the BaseSparseNDArray. This function blocks. Do not use it in performance critical code. ( R†RRRtMXNDArrayGetAuxNDArrayRgR7R<R(ROR-RC((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt _aux_datas  %(RMt __module__t__doc__RQRSRTRURVRWRXRYRZR[R]R^R`RctpropertyReRjRlRoRrR~RvRsR…RˆRŠ(((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRks2                   cB`sÔeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z e d „ƒZ e d „ƒZ e d „ƒZe jd „ƒZ e jd „ƒZ ejd„ƒZd„Zd„Zd„ZRS(s‹A sparse representation of 2D NDArray in the Compressed Sparse Row format. A CSRNDArray represents an NDArray as three separate arrays: `data`, `indptr` and `indices`. It uses the CSR representation where the column indices for row i are stored in ``indices[indptr[i]:indptr[i+1]]`` and their corresponding values are stored in ``data[indptr[i]:indptr[i+1]]``. The column indices for a given row are expected to be sorted in ascending order. Duplicate column entries for the same row are not allowed. Example ------- >>> a = mx.nd.array([[0, 1, 0], [2, 0, 0], [0, 0, 0], [0, 0, 3]]) >>> a = a.tostype('csr') >>> a.data.asnumpy() array([ 1., 2., 3.], dtype=float32) >>> a.indices.asnumpy() array([1, 0, 2]) >>> a.indptr.asnumpy() array([0, 1, 2, 2, 3]) See Also -------- csr_matrix: Several ways to construct a CSRNDArray cC`stdtt|ƒjƒfS(N(N(R R3tsupert __getstate__(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt __reduce__8scC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRW;scC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRX?scC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRYCscC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRZGscC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR[KscC`s+t|tƒrR|dkr/|jdd}n|}tj|d|d|dƒSt|tƒrô|jd k rtdƒ‚n|j d k s|j d k rí|j r¯|j nd}|j rÇ|j n |jd}tj|d|d|ƒS|Snt|t ƒrtdƒ‚ntdj |ƒƒ‚d S( s/x.__getitem__(i) <=> x[i] Returns a newly created NDArray based on the indexing key. Parameters ---------- key : int or slice Indexing key. Examples -------- >>> indptr = np.array([0, 2, 3, 6]) >>> indices = np.array([0, 2, 2, 0, 1, 2]) >>> data = np.array([1, 2, 3, 4, 5, 6]) >>> a = mx.nd.sparse.csr_matrix((data, indices, indptr), shape=(3, 3)) >>> a.asnumpy() array([[ 1., 0., 2.], [ 0., 0., 3.], [ 4., 5., 6.]], dtype=float32) >>> a[1:2].asnumpy() array([[ 0., 0., 3.]], dtype=float32) >>> a[1].asnumpy() array([[ 0., 0., 3.]], dtype=float32) >>> a[-1].asnumpy() array([[ 4., 5., 6.]], dtype=float32) iÿÿÿÿiitbegintends5CSRNDArray only supports continuous slicing on axis 0s)Multi-dimension indexing is not supportedsUndefined behaviour for {}N( RxR1R>RRtpy_slicetstepR3t ValueErrorRaRbttupletformat(ROtkeyR‘R’((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt __getitem__Os  cC`sF|jstdƒ‚nt|tƒr|jdk sT|jdk sT|jdk rctdƒ‚nt|tƒr—|j |j k r|j |ƒqqBt|t ƒrµtdƒ‚qBt|t j t jfƒrütjdtƒt|ƒ}|j |ƒqBtdtt|ƒƒƒ‚n't|ttfƒs6t‚tdƒ‚dS(sÚx.__setitem__(i, y) <=> x[i]=y Set self[key] to value. Only slice key [:] is supported. Parameters ---------- key : slice The indexing key. value : NDArray or CSRNDArray or numpy.ndarray The value to set. Examples -------- >>> src = mx.nd.sparse.zeros('csr', (3,3)) >>> src.asnumpy() array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]], dtype=float32) >>> # assign CSRNDArray with same storage type >>> x = mx.nd.ones((3,3)).tostype('csr') >>> x[:] = src >>> x.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> # assign NDArray to CSRNDArray >>> x[:] = mx.nd.ones((3,3)) * 2 >>> x.asnumpy() array([[ 2., 2., 2.], [ 2., 2., 2.], [ 2., 2., 2.]], dtype=float32) s)Failed to assign to a readonly CSRNDArrays;Assignment with slice for CSRNDArray is not implmented yet.s=Assigning numeric types to CSRNDArray is not implemented yet.s;Assigning non-NDArray object to CSRNDArray is not efficientstype %s not supporteds+CSRNDArray only supports [:] for assignmentN(twritableR•RxR“R”R3RaRbRRgRsRR.tndarraytgenericRyRzR{t_arrayRR€R2R1R–tAssertionErrort Exception(ROR˜Rhttmp((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt __setitem__s$! -  cC`s |jdƒS(søA deep copy NDArray of the indices array of the CSRNDArray. This generates a deep copy of the column indices of the current `csr` matrix. Returns ------- NDArray This CSRNDArray's indices array. i(RŠ(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pytindicesºs cC`s |jdƒS(sðA deep copy NDArray of the indptr array of the CSRNDArray. This generates a deep copy of the `indptr` of the current `csr` matrix. Returns ------- NDArray This CSRNDArray's indptr array. i(RŠ(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pytindptrÆs cC`s |jƒS(sêA deep copy NDArray of the data array of the CSRNDArray. This generates a deep copy of the `data` of the current `csr` matrix. Returns ------- NDArray This CSRNDArray's data array. (Rˆ(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pytdataÒs cC`s tƒ‚dS(N(R0(ROR¢((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR¢ÞscC`s tƒ‚dS(N(R0(ROR£((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR£âscC`s tƒ‚dS(N(R0(ROR¤((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR¤æscC`s.|dkrtdƒ‚ntj|d|ƒS(sºReturn a copy of the array with chosen storage type. Returns ------- NDArray or CSRNDArray A copy of the array with the chosen storage stype R)s4cast_storage from csr to row_sparse is not supportedR=(R•Rt cast_storage(ROR=((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRqës cC`s˜t|tƒr%tt|ƒj|ƒSt|tƒrx|j}|dkr_tt|ƒj|ƒStdt|ƒƒ‚ntdtt |ƒƒƒ‚dS(sCopies the value of this array to another array. If ``other`` is a ``NDArray`` or ``CSRNDArray`` object, then ``other.shape`` and ``self.shape`` should be the same. This function copies the value from ``self`` to ``other``. If ``other`` is a context, a new ``CSRNDArray`` will be first created on the target context, and the value of ``self`` is copied. Parameters ---------- other : NDArray or CSRNDArray or Context The destination array or context. Returns ------- NDArray or CSRNDArray The copied array. If ``other`` is an ``NDArray`` or ``CSRNDArray``, then the return value and ``other`` will point to the same ``NDArray`` or ``CSRNDArray``. RpR*s2copyto does not support destination NDArray stype scopyto does not support type N(sdefaultscsr( RxRRŽR RsRR=RR€R2(RORRR=((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRsùs  cC`sj|jjƒ}|jjƒ}|jjƒ}tsBtdƒ‚ntj|||fd|jd|jƒS(s–Returns a ``scipy.sparse.csr.csr_matrix`` object with value copied from this array Examples -------- >>> x = mx.nd.sparse.zeros('csr', (2,3)) >>> y = x.asscipy() >>> type(y) >>> y <2x3 sparse matrix of type '' with 0 stored elements in Compressed Sparse Row format> soscipy is not available. Please check if the scipy python bindings are installed.R>R/( R¤RrR¢R£tspspt ImportErrorRR>R/(ROR¤R¢R£((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pytasscipys  (RMR‹RŒRRWRXRYRZR[R™R¡RR¢R£R¤tsetterRqRsR¨(((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR s$       0 ;     cB`s³eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z e d „ƒZ e d „ƒZ e jd „ƒZ e jd „ƒZ d „Zd„Zd„ZRS(sôA sparse representation of a set of NDArray row slices at given indices. A RowSparseNDArray represents a multidimensional NDArray using two separate arrays: `data` and `indices`. The number of dimensions has to be at least 2. - data: an NDArray of any dtype with shape [D0, D1, ..., Dn]. - indices: a 1-D int64 NDArray with shape [D0] with values sorted in ascending order. The `indices` stores the indices of the row slices with non-zeros, while the values are stored in `data`. The corresponding NDArray ``dense`` represented by RowSparseNDArray ``rsp`` has ``dense[rsp.indices[i], :, :, :, ...] = rsp.data[i, :, :, :, ...]`` >>> dense.asnumpy() array([[ 1., 2., 3.], [ 0., 0., 0.], [ 4., 0., 5.], [ 0., 0., 0.], [ 0., 0., 0.]], dtype=float32) >>> rsp = dense.tostype('row_sparse') >>> rsp.indices.asnumpy() array([0, 2], dtype=int64) >>> rsp.data.asnumpy() array([[ 1., 2., 3.], [ 4., 0., 5.]], dtype=float32) A RowSparseNDArray is typically used to represent non-zero row slices of a large NDArray of shape [LARGE0, D1, .. , Dn] where LARGE0 >> D0 and most row slices are zeros. RowSparseNDArray is used principally in the definition of gradients for operations that have sparse gradients (e.g. sparse dot and sparse embedding). See Also -------- row_sparse_array: Several ways to construct a RowSparseNDArray cC`stdtt|ƒjƒfS(N(N(R R3RŽR(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRUscC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRWXscC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRX\scC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRY`scC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRZdscC`s||j|ƒ|S(N(Rs(RORR((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR[hscC`s§t|tƒrtdƒ‚nt|tƒrp|jdk sZ|jdk sZ|jdk ritdƒ‚qp|Snt|tƒrŽt dƒ‚nt dj |ƒƒ‚dS(slx.__getitem__(i) <=> x[i] Returns a sliced view of this array. Parameters ---------- key : slice Indexing key. Examples -------- >>> x = mx.nd.sparse.zeros('row_sparse', (2, 3)) >>> x[:].asnumpy() array([[ 0., 0., 0.], [ 0., 0., 0.]], dtype=float32) sD__getitem__ with int key is not implemented for RowSparseNDArray yets2RowSparseNDArray only supports [:] for __getitem__s)Multi-dimension indexing is not supportedsUndefined behaviour for {}N( RxR1RŸR“R”R3RaRbR–R•R—(ROR˜((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR™ls-cC`sS|jstdƒ‚nt|tƒr(|jdk sT|jdk sT|jdk rctdƒ‚nt|tƒr—|j |j k r%|j |ƒq%qOt|t ƒrÂt j t|ƒd|ƒqOt|tjtjfƒr tjdtƒt|ƒ}|j |ƒqOtdtt|ƒƒƒ‚n't|ttfƒsCt‚tdƒ‚dS(sòx.__setitem__(i, y) <=> x[i]=y Set self[key] to value. Only slice key [:] is supported. Parameters ---------- key : slice The indexing key. value : NDArray or numpy.ndarray The value to set. Examples -------- >>> src = mx.nd.row_sparse([[1, 0, 2], [4, 5, 6]], [0, 2], (3,3)) >>> src.asnumpy() array([[ 1., 0., 2.], [ 0., 0., 0.], [ 4., 5., 6.]], dtype=float32) >>> # assign RowSparseNDArray with same storage type >>> x = mx.nd.sparse.zeros('row_sparse', (3,3)) >>> x[:] = src >>> x.asnumpy() array([[ 1., 0., 2.], [ 0., 0., 0.], [ 4., 5., 6.]], dtype=float32) >>> # assign NDArray to RowSparseNDArray >>> x[:] = mx.nd.ones((3,3)) >>> x.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) s/Failed to assign to a readonly RowSparseNDArraysAAssignment with slice for RowSparseNDArray is not implmented yet.RwsAAssigning non-NDArray object to RowSparseNDArray is not efficientstype %s not supporteds1RowSparseNDArray only supports [:] for assignmentN(RšR•RxR“R”R3RaRbRRgRsRRt _set_valuetfloatR.R›RœRyRzR{RRR€R2R1R–Rž(ROR˜RhR ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR¡ˆs$" -  cC`s |jdƒS(sA deep copy NDArray of the indices array of the RowSparseNDArray. This generates a deep copy of the row indices of the current `row_sparse` matrix. Returns ------- NDArray This RowSparseNDArray's indices array. i(RŠ(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR¢Âs cC`s |jƒS(sýA deep copy NDArray of the data array of the RowSparseNDArray. This generates a deep copy of the `data` of the current `row_sparse` matrix. Returns ------- NDArray This RowSparseNDArray's data array. (Rˆ(RO((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR¤Îs cC`s tƒ‚dS(N(R0(ROR¢((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR¢ÚscC`s tƒ‚dS(N(R0(ROR¤((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR¤ÞscC`s.|dkrtdƒ‚ntj|d|ƒS(sÀReturn a copy of the array with chosen storage type. Returns ------- NDArray or RowSparseNDArray A copy of the array with the chosen storage stype R*s4cast_storage from row_sparse to csr is not supportedR=(R•RR¥(ROR=((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRqâs cC`s˜t|tƒr%tt|ƒj|ƒSt|tƒrx|j}|dkr_tt|ƒj|ƒStdt|ƒƒ‚ntdtt |ƒƒƒ‚dS(s3Copies the value of this array to another array. If ``other`` is a ``NDArray`` or ``RowSparseNDArray`` object, then ``other.shape`` and ``self.shape`` should be the same. This function copies the value from ``self`` to ``other``. If ``other`` is a context, a new ``RowSparseNDArray`` will be first created on the target context, and the value of ``self`` is copied. Parameters ---------- other : NDArray or RowSparseNDArray or Context The destination array or context. Returns ------- NDArray or RowSparseNDArray The copied array. If ``other`` is an ``NDArray`` or ``RowSparseNDArray``, then the return value and ``other`` will point to the same ``NDArray`` or ``RowSparseNDArray``. RpR)s2copyto does not support destination NDArray stype scopyto does not support type N(sdefaults row_sparse( RxRRŽR RsRR=RR€R2(RORRR=((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRsðs  cO`s"tstdƒ‚nt||ŽS(s˜Convenience fluent method for :py:func:`retain`. The arguments are the same as for :py:func:`retain`, with this array as data. s gen_sparse could not be imported(t gs_retainR§(ROtargsRd((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRs(RMR‹RŒRRWRXRYRZR[R™R¡RR¢R¤R©RqRsR(((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR /s %        :    cC`sYt|tƒ rUt|tjƒ rUytj|d|ƒ}WqUtdƒ‚qUXn|S(s°Prepare `source_array` so that it can be used to construct NDArray. `source_array` is converted to a `np.ndarray` if it's neither an `NDArray` nor an `np.ndarray`. R/s values must be array like object(RxRR.R›RR(R\R/((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt_prepare_src_arrays #cC`sd|dkr`t|ttjfƒr0|j}q`trWt|tjjƒrW|j}q`t }n|S(sµPrepare the value of dtype if `dtype` is None. If `src_array` is an NDArray, numpy.ndarray or scipy.sparse.csr.csr_matrix, return src_array.dtype. float32 is returned otherwise.N( R3RxRR.R›R/R¦R*RR(t src_arrayR/((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt_prepare_default_dtype&s    cC`sC|r?|r?||kr?tdt|ƒdt|ƒƒ‚ndS(s#check s1 == s2 if both are not NonesShape mismatch detected. s v.s. N(R•R€(ts1ts2((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyt _check_shape2sc C`sht|tƒr‹t|ƒ}|dkr8t|dtƒrt|dƒdkr|\}\}}t|tƒr€|jƒ}nt|tƒrž|jƒ}nt|tƒr¼|jƒ}ntj|||ffd|ƒ}t|j|ƒ|j ƒ} t | d|d|ƒSt||ƒt d|d|d|ƒSqd|dkrrt |d|d|dd|d|d|ƒSt d t|ƒƒ‚nÙt|tƒsµtrÛt|tjjƒrÛt|j|ƒt |d|d|ƒSt|tƒrùt d ƒ‚nkt||ƒ}t|d|ƒ} |d k rG| j|krG| j|ƒ} nt| j|ƒ| jdƒSd S( sCreates a `CSRNDArray`, an 2D array with compressed sparse row (CSR) format. The CSRNDArray can be instantiated in several ways: - csr_matrix(D): to construct a CSRNDArray with a dense 2D array ``D`` - **D** (*array_like*) - An object exposing the array interface, an object whose `__array__` method returns an array, or any (nested) sequence. - **ctx** (*Context, optional*) - Device context (default is the current default context). - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. The default dtype is ``D.dtype`` if ``D`` is an NDArray or numpy.ndarray, float32 otherwise. - csr_matrix(S) to construct a CSRNDArray with a sparse 2D array ``S`` - **S** (*CSRNDArray or scipy.sparse.csr.csr_matrix*) - A sparse matrix. - **ctx** (*Context, optional*) - Device context (default is the current default context). - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. The default dtype is ``S.dtype``. - csr_matrix((M, N)) to construct an empty CSRNDArray with shape ``(M, N)`` - **M** (*int*) - Number of rows in the matrix - **N** (*int*) - Number of columns in the matrix - **ctx** (*Context, optional*) - Device context (default is the current default context). - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. The default dtype is float32. - csr_matrix((data, indices, indptr)) to construct a CSRNDArray based on the definition of compressed sparse row format using three separate arrays, where the column indices for row i are stored in ``indices[indptr[i]:indptr[i+1]]`` and their corresponding values are stored in ``data[indptr[i]:indptr[i+1]]``. The column indices for a given row are expected to be **sorted in ascending order.** Duplicate column entries for the same row are not allowed. - **data** (*array_like*) - An object exposing the array interface, which holds all the non-zero entries of the matrix in row-major order. - **indices** (*array_like*) - An object exposing the array interface, which stores the column index for each non-zero element in ``data``. - **indptr** (*array_like*) - An object exposing the array interface, which stores the offset into ``data`` of the first non-zero element number of each row of the matrix. - **shape** (*tuple of int, optional*) - The shape of the array. The default shape is inferred from the indices and indptr arrays. - **ctx** (*Context, optional*) - Device context (default is the current default context). - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. The default dtype is ``data.dtype`` if ``data`` is an NDArray or numpy.ndarray, float32 otherwise. - csr_matrix((data, (row, col))) to construct a CSRNDArray based on the COOrdinate format using three seperate arrays, where ``row[i]`` is the row index of the element, ``col[i]`` is the column index of the element and ``data[i]`` is the data corresponding to the element. All the missing elements in the input are taken to be zeroes. - **data** (*array_like*) - An object exposing the array interface, which holds all the non-zero entries of the matrix in COO format. - **row** (*array_like*) - An object exposing the array interface, which stores the row index for each non zero element in ``data``. - **col** (*array_like*) - An object exposing the array interface, which stores the col index for each non zero element in ``data``. - **shape** (*tuple of int, optional*) - The shape of the array. The default shape is inferred from the ``row`` and ``col`` arrays. - **ctx** (*Context, optional*) - Device context (default is the current default context). - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. The default dtype is float32. Parameters ---------- arg1: tuple of int, tuple of array_like, array_like, CSRNDArray, scipy.sparse.csr_matrix, scipy.sparse.coo_matrix, tuple of int or tuple of array_like The argument to help instantiate the csr matrix. See above for further details. shape : tuple of int, optional The shape of the csr matrix. ctx: Context, optional Device context (default is the current default context). dtype: str or numpy.dtype, optional The data type of the output array. Returns ------- CSRNDArray A `CSRNDArray` with the `csr` storage representation. Example ------- >>> a = mx.nd.sparse.csr_matrix(([1, 2, 3], [1, 0, 2], [0, 1, 2, 2, 3]), shape=(4, 3)) >>> a.asnumpy() array([[ 0., 1., 0.], [ 2., 0., 0.], [ 0., 0., 0.], [ 0., 0., 3.]], dtype=float32) See Also -------- CSRNDArray : MXNet NDArray in compressed sparse row format. iiR>R?R/R*iis"Unexpected length of input tuple: s'Unexpected input type: RowSparseNDArrayN(RxR–R4RRrR¦t coo_matrixR³R>ttocsrRtemptyt_csr_matrix_from_definitionR•R€R R*RR R°RR3RNt as_in_contextRq( targ1R>R?R/targ_lenR¤trowtcoltcooR*tdns((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR7s@i  )!   ! *c C`s|d}|dkrtƒn|}t||ƒ}|dkrJt|dn|}|dkrjt|dn|}t||ƒ}t||ƒ}t||ƒ}t|tƒsÁt|||ƒ}nt|tƒsåt|||ƒ}nt|tƒs t|||ƒ}n|dkrc|jddkr7t dƒ‚nt |ƒdt j |ƒj ƒdf}n|j|jg} |jdksÇ|jdksÇ|jdksÇ|jddksÇt |ƒdkrÖt dƒ‚ntt|||t|||g| ƒƒ} ttj| j|jtjdƒƒƒttj| j|jtjdƒƒƒttj| j|jtjdƒƒƒ| S(s7Create a `CSRNDArray` based on data, indices and indptrR*iis invalid shapeiiÿÿÿÿN(R3RR°RkR®RxRRR>R•R4RtmaxtasscalartndimR RIR|RRtMXNDArraySyncCopyFromNDArrayRgR7R8( R¤R¢R£R>R?R/t indices_typet indptr_typet storage_typeRBtresult((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR·Ðs8   ,-%(((c C`sªt|tƒrèt|ƒ}|dkr@tdt|ƒƒ‚q¦|dkrrt||ƒtd|d|d|ƒSt|dtƒr¾t|dtƒr¾t||ƒtd|d|d|ƒSt|d|dd|d|d|ƒSn¾t|t ƒrt|j |ƒt |d|d|ƒSt|t ƒr;td ƒ‚nkt ||ƒ}t|d|ƒ}|d k r‰|j|kr‰|j|ƒ}nt|j |ƒ|jdƒSd S( sùCreates a `RowSparseNDArray`, a multidimensional row sparse array with a set of tensor slices at given indices. The RowSparseNDArray can be instantiated in several ways: - row_sparse_array(D): to construct a RowSparseNDArray with a dense ndarray ``D`` - **D** (*array_like*) - An object exposing the array interface, an object whose `__array__` method returns an array, or any (nested) sequence. - **ctx** (*Context, optional*) - Device context (default is the current default context). - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. The default dtype is ``D.dtype`` if ``D`` is an NDArray or numpy.ndarray, float32 otherwise. - row_sparse_array(S) to construct a RowSparseNDArray with a sparse ndarray ``S`` - **S** (*RowSparseNDArray*) - A sparse ndarray. - **ctx** (*Context, optional*) - Device context (default is the current default context). - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. The default dtype is ``S.dtype``. - row_sparse_array((D0, D1 .. Dn)) to construct an empty RowSparseNDArray with shape ``(D0, D1, ... Dn)`` - **D0, D1 .. Dn** (*int*) - The shape of the ndarray - **ctx** (*Context, optional*) - Device context (default is the current default context). - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. The default dtype is float32. - row_sparse_array((data, indices)) to construct a RowSparseNDArray based on the definition of row sparse format using two separate arrays, where the `indices` stores the indices of the row slices with non-zeros, while the values are stored in `data`. The corresponding NDArray ``dense`` represented by RowSparseNDArray ``rsp`` has ``dense[rsp.indices[i], :, :, :, ...] = rsp.data[i, :, :, :, ...]`` The row indices for are expected to be **sorted in ascending order.** - **data** (*array_like*) - An object exposing the array interface, which holds all the non-zero row slices of the array. - **indices** (*array_like*) - An object exposing the array interface, which stores the row index for each row slice with non-zero elements. - **shape** (*tuple of int, optional*) - The shape of the array. The default shape is inferred from the indices and indptr arrays. - **ctx** (*Context, optional*) - Device context (default is the current default context). - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. The default dtype is float32. Parameters ---------- arg1: NDArray, numpy.ndarray, RowSparseNDArray, tuple of int or tuple of array_like The argument to help instantiate the row sparse ndarray. See above for further details. shape : tuple of int, optional The shape of the row sparse ndarray. ctx : Context, optional Device context (default is the current default context). dtype : str or numpy.dtype, optional The data type of the output array. Returns ------- RowSparseNDArray An `RowSparseNDArray` with the `row_sparse` storage representation. Example ------- >>> a = mx.nd.sparse.row_sparse_array(([[1, 2], [3, 4]], [1, 4]), shape=(6, 2)) >>> a.asnumpy() array([[ 0., 0.], [ 1., 2.], [ 0., 0.], [ 0., 0.], [ 3., 4.], [ 0., 0.]], dtype=float32) See Also -------- RowSparseNDArray : MXNet NDArray in row sparse format. is"Unexpected length of input tuple: R)R?R/iiR>s!Unexpected input type: CSRNDArrayN(RxR–R4R•R€R³R¶Rt#_row_sparse_ndarray_from_definitionR R>RR R°RR3RNR¸Rq(R¹R>R?R/RºR¾((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRús.S    & c C`sæd}|dkrtƒn|}t||ƒ}|dkrJt|dn|}t||ƒ}t||ƒ}t|tƒs’t|||ƒ}nt|tƒs¶t|||ƒ}n|dkr|jd}|dkrêt dƒ‚n||dj ƒd}|f|jd}n|j t |ƒksV|j dksVt j|dƒdkret dƒ‚ntt|||t||g|jgƒƒ} ttj| j|jtjdƒƒƒttj| j|jtjdƒƒƒ| S(s5Create a `RowSparseNDArray` based on data and indicesR)is invalid shapeiiÿÿÿÿN(R3RR°RkR®RxRRR>R•RÀRÁR4R.tprodR RIR|RRRÂRgR7R8( R¤R¢R>R?R/RÃRÅt num_indicestdim0RÆ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyRÇts.    =((cC`sƒ|tkrt|ƒ}n|tkr7t|d|ƒS|tkrSt|d|ƒS|tkrot|d|ƒStd|ƒ‚dS(NRšsunknown storage type: %s( R%RR&RR$R R#R RŸ(RgRšR=((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR—s    cC`stt|tƒrRt|tƒrR|j|jkrRt||tjtjtj dƒSt||tj tjtj dƒS(sBReturns element-wise sum of the input arrays with broadcasting. Equivalent to ``lhs + rhs``, ``mx.nd.broadcast_add(lhs, rhs)`` and ``mx.nd.broadcast_plus(lhs, rhs)`` when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape, this is equivalent to ``mx.nd.elemwise_add(lhs, rhs)`` .. note:: If the corresponding dimensions of two arrays have the same size or one of them has size 1, then the arrays are broadcastable to a common shape.abs Parameters ---------- lhs : scalar or array First array to be added. rhs : scalar or array Second array to be added. If ``lhs.shape != rhs.shape``, they must be broadcastable to a common shape. Returns ------- NDArray The element-wise sum of the input arrays. Examples -------- >>> a = mx.nd.ones((2,3)).tostype('csr') >>> b = mx.nd.ones((2,3)).tostype('csr') >>> a.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> b.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> (a+b).asnumpy() array([[ 2., 2., 2.], [ 2., 2., 2.]], dtype=float32) >>> c = mx.nd.ones((2,3)).tostype('row_sparse') >>> d = mx.nd.ones((2,3)).tostype('row_sparse') >>> c.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> d.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> (c+d).asnumpy() array([[ 2., 2., 2.], [ 2., 2., 2.]], dtype=float32) N( RxRR>R(Rt elemwise_addtoperatorR Rt _plus_scalarR3t broadcast_add(tlhstrhs((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR §s50cC`stt|tƒrRt|tƒrR|j|jkrRt||tjtjtj dƒSt||tj tjtj dƒS(s`Returns element-wise difference of the input arrays with broadcasting. Equivalent to ``lhs - rhs``, ``mx.nd.broadcast_sub(lhs, rhs)`` and ``mx.nd.broadcast_minus(lhs, rhs)`` when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape, this is equivalent to ``mx.nd.elemwise_sub(lhs, rhs)`` .. note:: If the corresponding dimensions of two arrays have the same size or one of them has size 1, then the arrays are broadcastable to a common shape. Parameters ---------- lhs : scalar or array First array to be subtracted. rhs : scalar or array Second array to be subtracted. If ``lhs.shape != rhs.shape``, they must be broadcastable to a common shape.__spec__ Returns ------- NDArray The element-wise difference of the input arrays. Examples -------- >>> a = mx.nd.ones((2,3)).tostype('csr') >>> b = mx.nd.ones((2,3)).tostype('csr') >>> a.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> b.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> (a-b).asnumpy() array([[ 0., 0., 0.], [ 0., 0., 0.]], dtype=float32) >>> c = mx.nd.ones((2,3)).tostype('row_sparse') >>> d = mx.nd.ones((2,3)).tostype('row_sparse') >>> c.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> d.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> (c-d).asnumpy() array([[ 0., 0., 0.], [ 0., 0., 0.]], dtype=float32) N( RxRR>R(Rt elemwise_subRÌtsubRt _minus_scalarR3t broadcast_sub(RÏRÐ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR ïs50cC`stt|tƒrRt|tƒrR|j|jkrRt||tjtjtj dƒSt||tj tjtj dƒS(sàReturns element-wise product of the input arrays with broadcasting. Equivalent to ``lhs * rhs`` and ``mx.nd.broadcast_mul(lhs, rhs)`` when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape, this is equivalent to ``mx.nd.elemwise_mul(lhs, rhs)`` .. note:: If the corresponding dimensions of two arrays have the same size or one of them has size 1, then the arrays are broadcastable to a common shape. Parameters ---------- lhs : scalar or array First array to be multiplied. rhs : scalar or array Second array to be multiplied. If ``lhs.shape != rhs.shape``, they must be broadcastable to a common shape. Returns ------- NDArray The element-wise multiplication of the input arrays. Examples -------- >>> x = mx.nd.ones((2,3)).tostype('csr') >>> y = mx.nd.arange(2).reshape((2,1)) >>> z = mx.nd.arange(3) >>> x.asnumpy() array([[ 1., 1., 1.], [ 1., 1., 1.]], dtype=float32) >>> y.asnumpy() array([[ 0.], [ 1.]], dtype=float32) >>> z.asnumpy() array([ 0., 1., 2.], dtype=float32) >>> (x*2).asnumpy() array([[ 2., 2., 2.], [ 2., 2., 2.]], dtype=float32) >>> (x*y).asnumpy() array([[ 0., 0., 0.], [ 1., 1., 1.]], dtype=float32) >>> mx.nd.sparse.multiply(x, y).asnumpy() array([[ 0., 0., 0.], [ 1., 1., 1.]], dtype=float32) >>> (x*z).asnumpy() array([[ 0., 1., 2.], [ 0., 1., 2.]], dtype=float32) >>> mx.nd.sparse.multiply(x, z).asnumpy() array([[ 0., 1., 2.], [ 0., 1., 2.]], dtype=float32) >>> z = z.reshape((1, 3)) >>> z.asnumpy() array([[ 0., 1., 2.]], dtype=float32) >>> (x*z).asnumpy() array([[ 0., 1., 2.], [ 0., 1., 2.]], dtype=float32) >>> mx.nd.sparse.multiply(x, z).asnumpy() array([[ 0., 1., 2.], [ 0., 1., 2.]], dtype=float32) N( RxRR>R(Rt elemwise_mulRÌtmulRt _mul_scalarR3t broadcast_mul(RÏRÐ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR 7sA0cC`stt|tƒrRt|tƒrR|j|jkrRt||tjtjtj dƒSt||tj tjtj dƒS(sReturns element-wise division of the input arrays with broadcasting. Equivalent to ``lhs / rhs`` and ``mx.nd.broadcast_div(lhs, rhs)`` when shapes of lhs and rhs do not match. If lhs.shape == rhs.shape, this is equivalent to ``mx.nd.elemwise_div(lhs, rhs)`` .. note:: If the corresponding dimensions of two arrays have the same size or one of them has size 1, then the arrays are broadcastable to a common shape. Parameters ---------- lhs : scalar or array First array in division. rhs : scalar or array Second array in division. The arrays to be divided. If ``lhs.shape != rhs.shape``, they must be broadcastable to a common shape. Returns ------- NDArray The element-wise division of the input arrays. Examples -------- >>> x = (mx.nd.ones((2,3))*6).tostype('csr') >>> y = mx.nd.arange(2).reshape((2,1)) + 1 >>> z = mx.nd.arange(3) + 1 >>> x.asnumpy() array([[ 6., 6., 6.], [ 6., 6., 6.]], dtype=float32) >>> y.asnumpy() array([[ 1.], [ 2.]], dtype=float32) >>> z.asnumpy() array([ 1., 2., 3.], dtype=float32) >>> x/2 >>> (x/3).asnumpy() array([[ 2., 2., 2.], [ 2., 2., 2.]], dtype=float32) >>> (x/y).asnumpy() array([[ 6., 6., 6.], [ 3., 3., 3.]], dtype=float32) >>> mx.nd.sparse.divide(x,y).asnumpy() array([[ 6., 6., 6.], [ 3., 3., 3.]], dtype=float32) >>> (x/z).asnumpy() array([[ 6., 3., 2.], [ 6., 3., 2.]], dtype=float32) >>> mx.nd.sprase.divide(x,z).asnumpy() array([[ 6., 3., 2.], [ 6., 3., 2.]], dtype=float32) >>> z = z.reshape((1,3)) >>> z.asnumpy() array([[ 1., 2., 3.]], dtype=float32) >>> (x/z).asnumpy() array([[ 6., 3., 2.], [ 6., 3., 2.]], dtype=float32) >>> mx.nd.sparse.divide(x,z).asnumpy() array([[ 6., 3., 2.], [ 6., 3., 2.]], dtype=float32) N( RxRR>R(Rt elemwise_divRÌttruedivRt _div_scalarR3t broadcast_div(RÏRÐ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR‹sC0c K`sÄ|dkr%t|d|d||S|d kr=tƒ}n|d krOtn|}|d krnt|}ntd|ƒ‚tt|||t||ƒƒ}t j d|d|d|d||S( sReturn a new array of given shape and type, filled with zeros. Parameters ---------- stype: string The storage type of the empty array, such as 'row_sparse', 'csr', etc shape : int or tuple of int The shape of the empty array ctx : Context, optional An optional device context (default is the current default context) dtype : str or numpy.dtype, optional An optional value type (default is `float32`) Returns ------- RowSparseNDArray or CSRNDArray A created array Examples -------- >>> mx.nd.sparse.zeros('csr', (1,2)) >>> mx.nd.sparse.zeros('row_sparse', (1,2), ctx=mx.cpu(), dtype='float16').asnumpy() array([[ 0., 0.]], dtype=float16) RpR?R/R)R*sunknown storage typeR>RwN(s row_sparsescsr( t_zeros_ndarrayR3RRRkR•RRIR~Rt_zeros(R=R>R?R/RdRARw((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR'ás     !cC`s™t|tƒr|f}n|dkr3tƒ}n|dkrHt}n|dk sZt‚|dkrt||d|d|ƒStdt|ƒƒ‚dS(s2Returns a new array of given shape and type, without initializing entries. Parameters ---------- stype: string The storage type of the empty array, such as 'row_sparse', 'csr', etc shape : int or tuple of int The shape of the empty array. ctx : Context, optional An optional device context (default is the current default context). dtype : str or numpy.dtype, optional An optional value type (default is `float32`). Returns ------- CSRNDArray or RowSparseNDArray A created array. R*R)R?R/sunknown stype : N(scsrs row_sparse( RxR1R3RRRžR'RŸR€(R=R>R?R/((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR¶ s      cC`s|dkrtƒn|}t|tƒrÒ|jdksEtdƒ‚t||ƒ}|j|kr¦|j|kr¦t |j|j d|ƒ}||(|j |ƒ}n(t |j|j d|d|ƒ}||(|St rCt|t j jƒrC|jƒ}|jƒt||ƒ}t|j|j|jfd|j d|d|ƒSt|tjtjfƒrvtdt|ƒƒ‚ntdt|ƒƒ‚dS( s[Creates a sparse array from any object exposing the array interface. Parameters ---------- source_array : RowSparseNDArray, CSRNDArray or scipy.sparse.csr.csr_matrix The source sparse array ctx : Context, optional The default context is ``source_array.context`` if ``source_array`` is an NDArray. The current default context otherwise. dtype : str or numpy.dtype, optional The data type of the output array. The default dtype is ``source_array.dtype`` if `source_array` is an `NDArray`, `numpy.ndarray` or `scipy.sparse.csr.csr_matrix`, `float32` otherwise. Returns ------- RowSparseNDArray or CSRNDArray An array with the same contents as the `source_array`. Examples -------- >>> import scipy.sparse as spsp >>> csr = spsp.csr_matrix((2, 100)) >>> mx.nd.sparse.array(csr) >>> mx.nd.sparse.array(mx.nd.sparse.zeros('csr', (3, 2))) >>> mx.nd.sparse.array(mx.nd.sparse.zeros('row_sparse', (3, 2))) RpsMPlease use `tostype` to create RowSparseNDArray or CSRNDArray from an NDArrayR/R?R>sFPlease use mx.nd.array to create an NDArray with source_array of type sUnexpected source_array type: N(R3RRxRR=RžR°R/RNR¶R>R¸R¦R*Rtsorted_indicestsum_duplicatesR¤R¢R£R.R›RœR•R2(R\R?R/tarrR*((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyR)s, !  $ (MRŒt __future__RRt __builtin__RR“RR5R§tbuiltinsR7RyRÌRR9t__all__tnumpyR.tbaseRRRRRRRRRRNRRtRRt gen_sparseRR¬R3RR›RRR R!R"R#R$R%R&R'RÝRR(t scipy.sparsetsparseR¦R+RkRIRR R R®R°R³RR·RRÇR~RR R R RR¶(((sT/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/ndarray/sparse.pyts€         "    #²ÿë ™)z"  H H T V(