comparison libinterp/octave-value/ov-cx-sparse.cc @ 28131:4c21f99b4ad5

handle interleaved complex data and new typed data access functions for mex * mexproto.h, mex.cc, mxarray.h (mxMakeArrayReal, mxMakeArrayComplex, mxGetDoubles, mxGetSingles, mxGetInt8s, mxGetInt16s, mxGetInt32s, mxGetInt64s, mxGetUint8s, mxGetUint16s, mxGetUint32s, mxGetUint64s, mxGetComplexDoubles, mxGetComplexSingles, mxSetDoubles, mxSetSingles, mxSetInt8s, mxSetInt16s, mxSetInt32s, mxSetInt64s, mxSetUint8s, mxSetUint16s, mxSetUint32s, mxSetUint64s, mxSetComplexDoubles, mxSetComplexSingles): New functions. Provide corresponding member functions in mxArray class hierarchy to handle the actual operations. (mxGetComplexInt8s, mxGetComplexInt16s, mxGetComplexInt32s, mxGetComplexInt64s, mxGetComplexUint8s, mxGetComplexUint16s, mxGetComplexUint32s, mxGetComplexUint64s, mxSetComplexInt8s, mxSetComplexInt16s, mxSetComplexInt32s, mxSetComplexInt64s, mxSetComplexUint8s, mxSetComplexUint16s, mxSetComplexUint32s, mxSetComplexUint64s): Add prototypes and functions, but leave commented out since we don't have complex integer data. (class mxArray_number, class mxArray_sparse): Handle interleaved complex data. In mxArray_octave_value and mxArray_matlab constructors, handle interleaved flag in constructor to determine data layout to use when creating mxArray_number or mxArray_sparse objects. (mex::make_value): Check flag in mex function to determine whether to create arrays with interleaved complex. * ov.h, ov.cc, ov-base.h, ov-base.cc, ov-base-diag.h, ov-base-diag.cc, ov-bool-mat.h, ov-bool-mat.cc, ov-bool-sparse.h, ov-bool-sparse.cc, ov-bool.h, ov-bool.cc, ov-cell.h, ov-cell.cc, ov-ch-mat.h, ov-ch-mat.cc, ov-class.h, ov-class.cc, ov-complex.h, ov-complex.cc, ov-cx-mat.h, ov-cx-mat.cc, ov-cx-sparse.h, ov-cx-sparse.cc, ov-float.h, ov-float.cc, ov-flt-complex.h, ov-flt-complex.cc, ov-flt-cx-mat.h, ov-flt-cx-mat.cc, ov-flt-re-mat.h, ov-flt-re-mat.cc, ov-intx.h, ov-lazy-idx.h, ov-perm.h, ov-perm.cc, ov-range.h, ov-range.cc, ov-re-mat.h, ov-re-mat.cc, ov-re-sparse.h, ov-re-sparse.cc, ov-scalar.h, ov-scalar.cc, ov-struct.h, ov-struct.cc: In all as_mxArray methods, handle new interleaved input to optionally create objects that will use interleaved complex data.
author John W. Eaton <jwe@octave.org>
date Tue, 18 Feb 2020 13:16:41 -0500
parents b018f553fd85
children 0a6ed9dcd601
comparison
equal deleted inserted replaced
28130:0a88a4743096 28131:4c21f99b4ad5
872 872
873 return retval; 873 return retval;
874 } 874 }
875 875
876 mxArray * 876 mxArray *
877 octave_sparse_complex_matrix::as_mxArray (void) const 877 octave_sparse_complex_matrix::as_mxArray (bool interleaved) const
878 { 878 {
879 mwSize nz = nzmax (); 879 mwSize nz = nzmax ();
880 mxArray *retval = new mxArray (mxDOUBLE_CLASS, rows (), columns (), 880 mwSize nr = rows ();
881 nz, mxCOMPLEX); 881 mwSize nc = columns ();
882 double *pr = static_cast<double *> (retval->get_data ()); 882
883 double *pi = static_cast<double *> (retval->get_imag_data ()); 883 mxArray *retval = new mxArray (interleaved, mxDOUBLE_CLASS, nr, nc, nz,
884 mxCOMPLEX);
885
884 mwIndex *ir = retval->get_ir (); 886 mwIndex *ir = retval->get_ir ();
887
888 const Complex *pdata = matrix.data ();
889 const octave_idx_type *pridx = matrix.ridx ();
890
891 if (interleaved)
892 {
893 mxComplexDouble *pd
894 = static_cast<mxComplexDouble *> (retval->get_data ());
895
896 for (mwIndex i = 0; i < nz; i++)
897 {
898 pd[i].real = pdata[i].real ();
899 pd[i].imag = pdata[i].imag ();
900
901 ir[i] = pridx[i];
902 }
903 }
904 else
905 {
906 mxDouble *pr = static_cast<mxDouble *> (retval->get_data ());
907 mxDouble *pi = static_cast<mxDouble *> (retval->get_imag_data ());
908
909 for (mwIndex i = 0; i < nz; i++)
910 {
911 pr[i] = pdata[i].real ();
912 pi[i] = pdata[i].imag ();
913
914 ir[i] = pridx[i];
915 }
916 }
917
885 mwIndex *jc = retval->get_jc (); 918 mwIndex *jc = retval->get_jc ();
886 919
887 for (mwIndex i = 0; i < nz; i++) 920 const octave_idx_type *pcidx = matrix.cidx ();
888 { 921
889 Complex val = matrix.data (i); 922 for (mwIndex i = 0; i < nc + 1; i++)
890 pr[i] = val.real (); 923 jc[i] = pcidx[i];
891 pi[i] = val.imag ();
892 ir[i] = matrix.ridx (i);
893 }
894
895 for (mwIndex i = 0; i < columns () + 1; i++)
896 jc[i] = matrix.cidx (i);
897 924
898 return retval; 925 return retval;
899 } 926 }
900 927
901 octave_value 928 octave_value