⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matlib.h

📁 《MATLAB实用指南》系列丛书源代码。
💻 H
📖 第 1 页 / 共 5 页
字号:
};


struct M_types {
  unsigned int str;
  unsigned int sparse;
  unsigned int logical;
  unsigned int scalar;
  unsigned int persistent;
  unsigned int global;
  mt_matrix_types type;
};


class Mm {
  friend class Mr;

protected:
  int ndims;
  int dims[max_ndims];
  int p;
  int* pc;
  m_type* pr;
  m_type* pi;
  int nnz;
  int* index;
  const char* self_name;
  const char** fields;
  int nfields;
  int classid;
public:
  Mm* old_me;
  M_types flags;

  void new_p(int isc, int iss);
  void delete_p();

  static void PDLLI operator new(size_t sz);
  static void PDLLI operator new(size_t sz, void* p);
  static void DLLI operator delete(void *p);

  DLLI Mm();
  DLLI Mm(int isc, int iss, int nonzeros, int nrows, int ncols, mt_matrix_types new_type=mt_double_matrix);
  DLLI Mm(int isc, int iss, int nonzeros, int new_ndims, const int new_dims[max_ndims], mt_matrix_types new_type=mt_double_matrix);
  DLLI Mm(i_o_t, const char* mname, int isglobal);
  DLLI Mm(const char* mname, int m, int n);
  DLLI Mm(int aisc, cMm x, cMm y, cMm dim1, op_t op, int do_dim, Mm& minmax_idx);

  DLLI Mm(m_type src);
  DLLI Mm(cMm src);
  DLLI Mm(cMm src, const char* mname);
  DLLI Mm(const Mc& src);
  DLLI Mm(cMr src, int err=1);
  DLLI ~Mm();

  Mm RDLLI operator =(cMm src);
  void DLLI deepcopy(cMm src, mt_matrix_types new_type=mt_uninit_matrix);
  void DLLI deepcopy(int isc, cMm src, mt_matrix_types new_type=mt_uninit_matrix);
  void DLLI deepcopy(int isc, int iss, cMm src, mt_matrix_types new_type=mt_uninit_matrix);
  int DLLI getreal(int force=0) const;
  int DLLI getcomplex();
  void DLLI collapse();

  inline int DLLI rows() const { return dims[0]; }
  inline int DLLI cols() const { return dims[1]; }
  int DLLI size() const;
  int DLLI size(int dim) const;
  int DLLI nsingleton() const;
  int DLLI vectordim() const;
  int DLLI length() const;
  const char PDLLI getname() const { return self_name; }
  void DLLI setname(const char* new_name);
  int DLLI isstr() const { return (flags.str!=0); }
  void DLLI setstr(int newd);
  inline int DLLI issparse() const { return (flags.sparse!=0); }
  void DLLI setsparse(int sp);
  inline int DLLI islogical() const { return (flags.logical!=0); }
  void DLLI setlogical(int newd);
  inline int DLLI isglobal() const { return (flags.global!=0); }
  inline int DLLI isstruct() const { return (fields!=NULL); }
  inline int RDLLI getndims() const { return (int&)ndims; }
  inline int PDLLI getdims() const { return (int*)dims; }
  inline M_types RDLLI getflags() { return flags; }
  inline mt_matrix_types DLLI gettype() const { return flags.type; }
  inline int DLLI getnfields() const { return nfields; }
  inline const char PPDLLI getfields() const { return fields; }
  inline int DLLI isc() const { return (pi!=NULL); }
  int DLLI issamename(const char *s) const { return s==self_name; }
  int DLLI dirty() const;
  int DLLI getp() const { return p; }

  Mm DLLI safebr(int i0) const;

  inline m_type PDLLI getpr(m_type*) const { return (m_type*)pr; }
  inline m_type PDLLI getpi(m_type*) const { return (m_type*)pi; }
  inline uint8  PDLLI getpr(uint8*)  const { return (uint8*)pr; }
  inline uint8  PDLLI getpi(uint8*)  const { return (uint8*)pi; }
  inline Mm     PDLLI getpr(Mm*)     const { return (Mm*)pr; }
  inline Mm     PDLLI getpi(Mm*)     const { return (Mm*)pi; }

  inline m_type PDLLI getpr(m_type*,int i0) const { return i0-1+(m_type*)pr; }
  inline m_type PDLLI getpi(m_type*,int i0) const { return i0-1+(m_type*)pi; }
  inline uint8  PDLLI getpr(uint8*,int i0)  const { return i0-1+(uint8*)pr; }
  inline uint8  PDLLI getpi(uint8*,int i0)  const { return i0-1+(uint8*)pi; }
  inline Mm     PDLLI getpr(Mm*,int i0)     const { return i0-1+(Mm*)pr; }
  inline Mm     PDLLI getpi(Mm*,int i0)     const { return i0-1+(Mm*)pi; }

  inline m_type PDLLI getpr(m_type*,int i0,int i1) const { return i0-1+(i1-1)*dims[0]+(m_type*)pr; }
  inline m_type PDLLI getpi(m_type*,int i0,int i1) const { return i0-1+(i1-1)*dims[0]+(m_type*)pi; }
  inline uint8  PDLLI getpr(uint8*,int i0,int i1)  const { return i0-1+(i1-1)*dims[0]+(uint8*)pr; }
  inline uint8  PDLLI getpi(uint8*,int i0,int i1)  const { return i0-1+(i1-1)*dims[0]+(uint8*)pi; }
  inline Mm     PDLLI getpr(Mm*,int i0,int i1)     const { return i0-1+(i1-1)*dims[0]+(Mm*)pr; }
  inline Mm     PDLLI getpi(Mm*,int i0,int i1)     const { return i0-1+(i1-1)*dims[0]+(Mm*)pi; }

  m_type PDLLI addr() const;
  m_type PDLLI addr(int i0) const;
  m_type PDLLI addr(int i0,int i1) const;
  m_type PDLLI addi() const;
  m_type PDLLI addi(int i0) const;
  m_type PDLLI addi(int i0,int i1) const;
  inline int PDLLI getindex() const { return index; }
  inline int RDLLI getnnz() const { return (int&)nnz; }

  m_type RDLLI r() const;
  m_type RDLLI r(double i0) const;
  m_type RDLLI r(double i0, double i1) const;
  m_type RDLLI r(double i0, double i1, double i2) const;
  m_type RDLLI i() const;
  m_type RDLLI i(double i0) const;
  m_type RDLLI i(double i0, double i1) const;
  m_type RDLLI i(double i0, double i1, double i2) const;
  uint8 RDLLI ur(int i0) const;
  uint8 RDLLI ur(int i0, int i1) const;
  Mm RDLLI mr(int i0) const;
  Mm RDLLI mr(int i0, int i1) const;
/*
  Sr<T> DLLI operator ()(m_type i0) const { return Sr<T>(*this, i0); }
  Sr<T> DLLI operator ()(m_type i0, m_type i1) const { return Sr<T>(*this, i0, i1); }
  Sr<T> DLLI operator ()(m_type i0, m_type i1, m_type i2) const { return Sr<T>(*this, i0, i1, i2); }
  Sr<T> DLLI operator ()(m_type i0, m_type i1, m_type i2, m_type i3) const { return Sr<T>(*this, i0, i1, i2, i3); }
*/
  Mr DLLI member(const char* field) const { return Mr(*this, field); }
  Mr DLLI operator ()(cMm i0) const { return Mr(Mr_idx_paren, *this, i0); }
  Mr DLLI operator ()(cMm i0, cMm i1) const { return Mr(Mr_idx_paren, *this, i0, i1); }
  Mr DLLI operator ()(cMm i0, cMm i1, cMm i2) const { return Mr(Mr_idx_paren, *this, i0, i1, i2); }
  Mr DLLI operator ()(cMm i0, cMm i1, cMm i2, cMm i3) const { return Mr(Mr_idx_paren, *this, i0, i1, i2, i3); }

  Mr DLLI br(cMm i0) const {  return Mr(Mr_idx_br,*this, i0); }
  Mr DLLI br(cMm i0, cMm i1) const { return Mr(Mr_idx_br,*this, i0, i1); }
  Mr DLLI br(cMm i0, cMm i1, cMm i2) const { return Mr(Mr_idx_br,*this, i0, i1, i2); }
  Mr DLLI br(cMm i0, cMm i1, cMm i2, cMm i3) const { return Mr(Mr_idx_br,*this, i0, i1, i2, i3); }

  m_type& fastindex(double i0) const { return pr[int(i0)-1]; }
  m_type& fastindex(double i0, double i1) const { return pr[int(i0)-1+(int(i1)-1)*dims[0]]; }

  void DLLI vwcopy1(cMm src, cMm v);
  void DLLI vwcopy2(cMm src, cMm v, cMm w);
  void DLLI vwcopyn(cMr src, cMm rhs);
  void DLLI vwcopy0(cMr src);

  int DLLI findfield(const char* field, int err) const;
  const char PDLLI getfield(int i) const;
  int DLLI addfield(const char* field,int quick);
  int DLLI rmfield(const char* field);
  void DLLI extend_nfields(int new_nfields);

  int DLLI getclassid() const { return classid; }
  void DLLI setclassid(int new_classid) { classid=new_classid; }

  void DLLI reshape(const int m, const int n);
  void DLLI reshape(const int new_ndims, const int new_dims[max_ndims]);

  void DLLI print(int full) const;

  void DLLI warn_uninit() const;

  void DLLI resparse();
  int  DLLI search(int idx) const;
  void DLLI sort();
  void DLLI extend_nnz(int new_nnz);

}; // M

Mc DLLI BR(cMm src);
Mc DLLI BR(const char* src);
Mc DLLI BR(double src);
Mc DLLI CL(cMm src);
Mc DLLI CL(const char* src);
Mc DLLI CL(double src);
m_type DLLI scalar(m_type x);
m_type DLLI scalar(cMm x);
Mm DLLI switchinit(cMm x);

char* op_name(op_t op);
#endif // mH


extern const long      Mmaxsize;

extern DLLW i_o_t      DLLI i_o;
extern DLLW int        DLLI switchfalse;
extern DLLW int        DLLI switchdepth;

typedef int eval_type(const char*);
typedef Mm feval_type(Mm , Mm, i_o_t, Mm&, Mm&, Mm&, Mm& , Mm& , Mm& );
typedef Mm callback_type(Mm);
extern eval_type    	PDLLI eval_func;
extern feval_type 	PDLLI feval_func;
extern callback_type 	PDLLI callback_func;
Mm feval_func_1(cMm fun, cMm varargin);

extern DLLW void PDLLI mpath_pointer;

extern DLLW double     DLLI nargin_val;
extern DLLW double     DLLI nargout_val;
extern DLLW int        DLLI nargin_set;
extern DLLW int        DLLI nargout_set;
extern DLLW Mm	DLLI TICTOC;
extern DLLW Mm	DLLI ans;
extern DLLW Mm	DLLI i;
extern DLLW Mm	DLLI j;
extern DLLW Mm	DLLI pi;
extern DLLW Mm	DLLI Inf;
extern DLLW Mm	DLLI NaN;
extern DLLW Mm	DLLI eps;
extern DLLW Mm	DLLI x_M;
extern DLLW Mm	DLLI semi;
extern DLLW Mm	DLLI c_p;
extern DLLW Mm	DLLI nop_M;
extern DLLW Mm	DLLI zero_M;
extern DLLW Mm	DLLI one_M;
extern DLLW Mm	DLLI l_M;
extern DLLW Mm	DLLI page_screen_output;
extern DLLW Mm	DLLI implicit_str_to_num_ok;
extern DLLW Mm	DLLI empty_list_elements_ok;
extern DLLW Mm	DLLI switchvar;

Mm DLLI airy(cMm z);
Mm DLLI airy(cMm k, cMm z);
Mm DLLI airy(cMm z, i_o_t, Mm& w, Mm& err);
Mm DLLI airy(cMm k, cMm z, i_o_t, Mm& w, Mm& err);

Mm DLLI bessel(cMm nu);
Mm DLLI bessel(cMm nu, cMm z);
Mm DLLI bessel(cMm nu, cMm z, i_o_t,  Mm& w, Mm& err);

Mm DLLI bessela(cMm nu);
Mm DLLI bessela(cMm nu, cMm z);
Mm DLLI bessela(cMm nu, cMm z, i_o_t, Mm& J, Mm& ndigits);

Mm DLLI besselh(cMm nu);
Mm DLLI besselh(cMm nu, cMm z);
Mm DLLI besselh(cMm nu, cMm k, cMm z);
Mm DLLI besselh(cMm nu, cMm k, cMm z, cMm scale1);
Mm DLLI besselh(cMm nu, cMm z, i_o_t,  Mm& w, Mm& err);
Mm DLLI besselh(cMm nu, cMm k, cMm z, i_o_t,  Mm& w, Mm& err);
Mm DLLI besselh(cMm nu, cMm k, cMm z, cMm scale1, i_o_t,  Mm& w, Mm& err);

Mm DLLI besseli(cMm nu);
Mm DLLI besseli(cMm nu, cMm z);
Mm DLLI besseli(cMm nu, cMm z, cMm scale1);
Mm DLLI besseli(cMm nu, cMm z, i_o_t,  Mm& w, Mm& err);
Mm DLLI besseli(cMm nu, cMm z, cMm scale1, i_o_t,  Mm& w, Mm& err);

Mm DLLI besselj(cMm nu);
Mm DLLI besselj(cMm nu, cMm z);
Mm DLLI besselj(cMm nu, cMm z, cMm scale1);
Mm DLLI besselj(cMm nu, cMm z, i_o_t,  Mm& w, Mm& err);
Mm DLLI besselj(cMm nu, cMm z, cMm scale1, i_o_t,  Mm& w, Mm& err);

Mm DLLI besselk(cMm nu);
Mm DLLI besselk(cMm nu, cMm z);
Mm DLLI besselk(cMm nu, cMm z, cMm scale1);
Mm DLLI besselk(cMm nu, cMm z, i_o_t,  Mm& w, Mm& err);
Mm DLLI besselk(cMm nu, cMm z, cMm scale1, i_o_t,  Mm& w, Mm& err);

Mm DLLI bessely(cMm nu);
Mm DLLI bessely(cMm nu, cMm z);
Mm DLLI bessely(cMm nu, cMm z, cMm scale1);
Mm DLLI bessely(cMm nu, cMm z, i_o_t,  Mm& w, Mm& err);
Mm DLLI bessely(cMm nu, cMm z, cMm scale1, i_o_t,  Mm& w, Mm& err);

Mm DLLI colon();
Mm DLLI colon(cMm j);
Mm DLLI colon(double j, double k);
Mm DLLI colon(cMm j, cMm k);
Mm DLLI colon(double j, double i, double k);
Mm DLLI colon(cMm j, cMm i, cMm k);
#define ramp colon


Mm DLLI cputime();
Mm DLLI date();
Mm DLLI datenum(cMm x);
Mm DLLI datenum(cMm year, cMm month);
Mm DLLI datenum(cMm year, cMm month, cMm day);
Mm DLLI datenum(cMm year, cMm month, cMm day, cMm hour);
Mm DLLI datenum(cMm year, cMm month, cMm day, cMm hour, cMm minute);
Mm DLLI datenum(Mm year, Mm month, cMm day, cMm hour, cMm minute, cMm second);
Mm DLLI datevec(cMm J);
Mm DLLI datevec(cMm J, i_o_t, Mm& year, Mm& month);
Mm DLLI datevec(cMm J, i_o_t, Mm& year, Mm& month, Mm& day);
Mm DLLI datevec(cMm J, i_o_t, Mm& year, Mm& month, Mm& day, Mm& hour);
Mm DLLI datevec(cMm J, i_o_t, Mm& year, Mm& month, Mm& day, Mm& hour, Mm& minute);
Mm DLLI datevec(Mm J, i_o_t, Mm& year, Mm& month, Mm& day, Mm& hour, Mm& minute, Mm& second);
Mm DLLI eomday(cMm y);
Mm DLLI eomday(cMm y, cMm m);
Mm DLLI etime(cMm );
Mm DLLI etime(Mm t1, Mm t0);
Mm DLLI mclock();
Mm DLLI now();
Mm DLLI tic();
Mm DLLI toc();
Mm DLLI weekday(cMm j);
Mm DLLI weekday(Mm j, i_o_t, Mm& D, Mm& W);
Mm DLLI diag(cMm x);
Mm DLLI diag(cMm x, cMm kk);

Mm DLLI row2col(Mm x);
Mm DLLI permute(cMm x);
Mm DLLI permute(Mm x, Mm order);
Mm DLLI ipermute(cMm x);
Mm DLLI ipermute(cMm x, Mm order);
Mm DLLI ndims(cMm x);
Mm DLLI squeeze(Mm x);
Mm DLLI ind2sub(cMm sz);
Mm DLLI ind2sub(cMm sz, i_o_t, Mm& i0, Mm& i1);
Mm DLLI ind2sub(cMm sz, i_o_t, Mm& i0, Mm& i1, Mm& i2);
Mm DLLI ind2sub(cMm sz, i_o_t, Mm& i0, Mm& i1, Mm& i2, Mm& i3);
Mm DLLI ind2sub(cMm sz, cMm i);
Mm DLLI ind2sub(cMm sz, Mm i, i_o_t, Mm& i0, Mm& i1);
Mm DLLI ind2sub(cMm sz, Mm i, i_o_t, Mm& i0, Mm& i1, Mm& i2);
Mm DLLI ind2sub(cMm sz, Mm i, i_o_t, Mm& i0, Mm& i1, Mm& i2, Mm& i3);
Mm DLLI sub2ind(cMm sz);
Mm DLLI sub2ind(cMm sz, cMm i0);
Mm DLLI sub2ind(cMm sz, cMm i0, cMm i1);
Mm DLLI sub2ind(cMm sz, cMm i0, cMm i1, cMm i2);
Mm DLLI sub2ind(cMm sz, cMm i0, cMm i1, cMm i2, cMm i3);
Mm DLLI subsasgn(cMm a);
Mm DLLI subsasgn(cMm a, cMm s);
Mm DLLI subsasgn(cMm a, cMm s, cMm b);
Mm DLLI subsindex(cMm x);
Mm DLLI subsref(cMm a);
Mm DLLI subsref(cMm a, cMm s);



#ifdef MATLIB_MEMDEBUG


#define LOWER_FENCE 0x55
#define UPPER_FENCE 0x33
#define new_data(p,siz) 		\
  {					\
    int i=((siz)+1)*sizeof(*p); 	\
    void* v=malloc(sizeof(int)+1+i+1);	\
    if (v==NULL) {			\
      error(out_of_memory);		\
    }					\
    char* c=(char*)v;			\
    *(int*)c=i; c+=sizeof(int); 	\
    *c=LOWER_FENCE; c++;		\
    v=c; c+=i;				\
    *c=UPPER_FENCE;			\
    *((void **)&p)=v;			\
  }

#define delete_data(p)			\
  {					\
    void* v;				\
    assert(p!=NULL);			\
    char* c=(char*)p;			\
    c--;				\
    c-=sizeof(int);			\
    v=c;				\
    int i=*(int*)c;			\
    c+=sizeof(int);			\
    assert(*c==LOWER_FENCE);		\
    c++;				\
    c+=i;				\
    assert(*c==UPPER_FENCE);		\
    free(v);				\
  }

#else

#define new_data(p,siz) 				\
  *((void **)&p)=malloc(((siz)+1)*sizeof(*p));	\
  if (p==NULL) {					\
    error(s_out_of_memory);				\
  }

#define delete_data(p)	\
  free(p);

#endif

#define copy_data(dest, src, n) \
  {for (int zcdi=0;zcdi<(n);zcdi++) (dest)[zcdi]=(src)[zcdi];}

#define zero_data(dest, n)	\
  { for (int zzdi=0;(zzdi<(n))&&(sizeof(*(dest))<=12);zzdi++) (dest)[zzdi]=0;}

#define fill_data(dest, n, val) \
  {for (int zfdi=0;zfdi<(n);zfdi++) (dest)[zfdi]=(val);}

#define neg_data(dest, n)	\
  {for (int zndi=0;zndi<(n);zndi++) (dest)[zndi]=-(dest)[zndi];}

typedef Mm func11M(Mm);
typedef Mm func12M(Mm, Mm);
typedef Mm func13M(Mm, Mm, Mm);
typedef Mm func22M(Mm, Mm, i_o_t, Mm&, Mm&);
void DLLI register_class_function(const char* classname, const char* funcname, func11M* func);
void DLLI register_class_function(const char* classname, const char* funcname, func12M* func);
void DLLI register_class_function(const char* classname, const char* funcname, func13M* func);
void DLLI register_class_function(const char* classname, const char* funcname, func22M* func);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -