ó R;]c @`s¡dZddlmZddlmZy$ddlmZddlmZWn1e k r}ddl mZddl mZnXddl Z ddl Z ddl Z ddlmZdd d d d d ddddg ZddlZddlmZddlmZmZddlmZmZmZddlmZmZmZddlmZddlm Z ddlm!Z!yddl"TWne k r‘nXddl m#Z#ddl$m%Z%m&Z&m'Z'm(Z(ddl$m)Z)m*Z*m+Z+ddl$m,Z,m-Z-dd l$m.Z/ddl$mZ0dd!l$m1Z1yddl2j3Z4Wne k rRe5Z4nXiej6gd"6ej6ej6gd#6Z7e5d$„Z8d e%fd%„ƒYZ9d e9fd&„ƒYZ:d e9fd'„ƒYZ;d(„Z<d)„Z=d*„Z>e5e5e5d+„Z?e5e5e5e5e5d,„Z@e5e5e5d-„ZAe5e5e5e5d.„ZBeCe,d/„ZDe#eDƒd0„ZEd1„ZFd2„ZGd3„ZHe5e5d4„Z.e5e5d5„ZIe5e5d6„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(tContexti(t _internal(top(t*(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((RtnptdtypetNotImplementedErrortintRttypetNonetlentpy_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.2.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(tselfRIt shape_info((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt__repr__qs) cC`s t||ƒS(N(R (RNtother((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt__add__xscC`s t||ƒS(N(R (RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt__sub__{scC`s t||ƒS(N(R (RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt__mul__~scC`s t||ƒS(N(R(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt__div__scC`s tƒ‚dS(N(R/(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt__iadd__„scC`s tƒ‚dS(N(R/(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt__isub__‡scC`s tƒ‚dS(N(R/(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt__imul__ŠscC`s tƒ‚dS(N(R/(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt__idiv__scC`s tƒ‚dS(N(R/(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt __itruediv__scC`s tƒ‚dS(N(R/(RNt source_array((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt_sync_copyfrom“scC`st|jd|ƒ‚dS(Ns[idx](Rt_at(RNtidx((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR]–scC`st|jd||ƒ‚dS(N(Rt_sliceR2(RNtstarttstop((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR_™scO`st|jd|ƒ‚dS(N(RtreshapeR2(RNR=tkwargs((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRbœscC`s tƒ‚dS(N(R/(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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. ( R6R7RRtMXNDArrayGetAuxTypethandleR;R tvalue(RNR,taux_type((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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. (R3t_STORAGE_AUX_TYPESR<(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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. (RktrangetappendRi(RNR@RGR,((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRqÀ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=RMR<tcopyto(RNR.tcopytres((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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 isinstanceRRftwarningstwarntRuntimeWarningtFalseRt_copytoRRRHR<R=tTrueR.Rnt TypeErrortstrR1(RNRQthret((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRrß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(RRtMXNDArraySyncCheckFormatRfR6tc_bool(RNt full_check((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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_readRRRtMXNDArrayGetDataNDArrayRfR6R;R(RNRB((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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…RRRtMXNDArrayGetAuxNDArrayRfR6R;R(RNR,RB((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt _aux_datas  %(RLt __module__t__doc__RPRRRSRTRURVRWRXRYRZR\R]R_RbtpropertyRdRiRkRnRqR}RuRrR„R‡R‰(((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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 R2tsupert __getstate__(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt __reduce__8scC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRV;scC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRW?scC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRXCscC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRYGscC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRZKscC`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( RwR0R=RRtpy_slicetstepR2t ValueErrorR`Rattupletformat(RNtkeyRR‘((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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”RwR’R“R2R`RaRRfRrRR-tndarraytgenericRxRyRzt_arrayR~RR1R0R•tAssertionErrort Exception(RNR—Rgttmp((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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‰(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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‰(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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‡(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pytdataÒs cC`s tƒ‚dS(N(R/(RNR¡((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR¡ÞscC`s tƒ‚dS(N(R/(RNR¢((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR¢âscC`s tƒ‚dS(N(R/(RNR£((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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(RNR<((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRpës cC`s¤t|tƒr%tt|ƒj|ƒSt|tƒr„|j}|dksU|dkrktt|ƒ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``. RoR)s2copyto does not support destination NDArray stype scopyto does not support type N( RwRRR RrRR<R~RR1(RNRQR<((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRrù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£RqR¡R¢tspspt ImportErrorRR=R.(RNR£R¡R¢((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pytasscipys  (RLRŠR‹RRVRWRXRYRZR˜R RŒR¡R¢R£tsetterRpRrR§(((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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 R2RRŽ(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRUscC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRVXscC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRW\scC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRX`scC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRYdscC`s||j|ƒ|S(N(Rr(RNRQ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRZhscC`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( RwR0RžR’R“R2R`RaR•R”R–(RNR—((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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.RvsAAssigning non-NDArray object to RowSparseNDArray is not efficientstype %s not supporteds1RowSparseNDArray only supports [:] for assignmentN(R™R”RwR’R“R2R`RaRRfRrRRt _set_valuetfloatR-RšR›RxRyRzRœR~RR1R0R•R(RNR—RgRŸ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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‰(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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‡(RN((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR£Îs cC`s tƒ‚dS(N(R/(RNR¡((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR¡ÚscC`s tƒ‚dS(N(R/(RNR£((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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¤(RNR<((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRpâs cC`s¤t|tƒr%tt|ƒj|ƒSt|tƒr„|j}|dksU|dkrktt|ƒ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``. RoR(s2copyto does not support destination NDArray stype scopyto does not support type N( RwRRR RrRR<R~RR1(RNRQR<((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRrðs cO`st|||ŽS(s˜Convenience fluent method for :py:func:`retain`. The arguments are the same as for :py:func:`retain`, with this array as data. (tretain(RNtargsRc((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR«s(RLRŠR‹RRVRWRXRYRZR˜R RŒR¡R£R¨RpRrR«(((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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(RwRR-RšRR~(R[R.((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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( R2RwRR-RšR.R¥R)RR(t src_arrayR.((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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.2.1-py2.7.egg/mxnet/ndarray/sparse.pyt _check_shape0sc 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(RwR•R3RRqR¥t coo_matrixR²R=ttocsrRtemptyt_csr_matrix_from_definitionR”RR R)RR R¯RœR2RMt as_in_contextRp( targ1R=R>R.targ_lenR£trowtcoltcooR)tdns((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR5s@i  )!   ! *c C`s|d}|dkrtjn|}t||ƒ}|dkrJt|dn|}|dkrjt|dn|}t||ƒ}t||ƒ}t||ƒ}t|tƒsÁt|||ƒ}nt|tƒsåt|||ƒ}nt|tƒs t|||ƒ}n|dkrc|j ddkr7t dƒ‚nt |ƒdt j |ƒjƒdf}n|j |j g} |jdksÇ|jdksÇ|jdksÇ|j ddksÇ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(R2Rt default_ctxR¯RjR­RwRRœR=R”R3RtmaxtasscalartndimR RHR{RRtMXNDArraySyncCopyFromNDArrayRfR6R7( R£R¡R¢R=R>R.t indices_typet indptr_typet storage_typeRAtresult((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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(RwR•R3R”RR²RµRt#_row_sparse_ndarray_from_definitionR R=RR R¯RœR2RMR·Rp(R¸R=R>R.R¹R½((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRøs.S    & c C`sæd}|dkrtjn|}t||ƒ}|dkrJt|dn|}t||ƒ}t||ƒ}t|tƒs’t|||ƒ}nt|tƒs¶t|||ƒ}n|dkr|j d}|dkrêt dƒ‚n||dj ƒd}|f|j d}n|j t |ƒksV|j dksVtj|dƒdkret dƒ‚ntt|||t||g|j gƒƒ} ttj| j|jtjdƒƒƒttj| j|jtjdƒƒƒ| S(s5Create a `RowSparseNDArray` based on data and indicesR(is invalid shapeiiÿÿÿÿN(R2RR¾R¯RjR­RwRRœR=R”RÀRÁR3R-tprodR RHR{RRRÂRfR6R7( R£R¡R=R>R.RÃRÅt num_indicestdim0RÆ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRÇrs.    =((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ž(RfR™R<((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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( RwRR=R'Rt elemwise_addtoperatorR Rt _plus_scalarR2t broadcast_add(tlhstrhs((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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( RwRR=R'Rt elemwise_subRÌtsubRt _minus_scalarR2t broadcast_sub(RÏRÐ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.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( RwRR=R'Rt elemwise_mulRÌtmulRt _mul_scalarR2t broadcast_mul(RÏRÐ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR 5sA0cC`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( RwRR=R'Rt elemwise_divRÌttruedivRt _div_scalarR2t broadcast_div(RÏRÐ((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR‰sC0c K`sÐ|dkr%t|d|d||S|d kr=tj}n|d krOtn|}|dksm|dkrzt|}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) RoR>R.R(R)sunknown storage typeR=RvN( t_zeros_ndarrayR2RR¾RRjR”RRHR}Rt_zeros(R<R=R>R.RcR@Rv((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR&ßs    !cC`s¥t|tƒr|f}n|dkr3tj}n|dkrHt}n|dk sZt‚|dksr|dkr‹t||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( RwR0R2RR¾RRR&RžR(R<R=R>R.((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyRµs     cC`s|dkrtjn|}t|tƒrÒ|jdksEtdƒ‚t||ƒ}|j|kr¦|j |kr¦t |j|j d|ƒ}||(|j |ƒ}n(t |j|j d|d|ƒ}||(|St rCt|t jjƒ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))) RosMPlease 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(R2RR¾RwRR<RR¯R.RMRµR=R·R¥R)Rtsorted_indicestsum_duplicatesR£R¡R¢R-RšR›R”R1(R[R>R.tarrR)((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyR's, !  $ (JR‹t __future__RRt __builtin__RR’RR4R¦tbuiltinsR6RxRÌRR8t__all__tnumpyR-tbaseRRRRRRRRRRMRtRRt gen_sparseRRšRRRR R!R"R#R$R%R&RÝRœR't scipy.sparsetsparseR¥R2R*RjRHRR R R­R¯R²RR¶RRÇR}RR R R RRµ(((sT/usr/local/lib/python2.7/site-packages/mxnet-1.2.1-py2.7.egg/mxnet/ndarray/sparse.pyts€        "    #²ÿé ™)z"  H H T V(