home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!mintaka.lcs.mit.edu!ai-lab!life.ai.mit.edu!tmb
- From: tmb@arolla.idiap.ch (Thomas M. Breuel)
- Newsgroups: comp.lang.c++
- Subject: Re: Proposal: Subscripting with multiple arguments
- Message-ID: <TMB.92Sep16020514@arolla.idiap.ch>
- Date: 16 Sep 92 06:05:14 GMT
- Article-I.D.: arolla.TMB.92Sep16020514
- References: <1992Sep14.182942.1986@athena.mit.edu>
- <MATT.92Sep14161955@physics.berkeley.edu>
- <TMB.92Sep15134433@arolla.idiap.ch> <jac.716576376@moonshine>
- Sender: news@ai.mit.edu
- Reply-To: tmb@idiap.ch
- Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
- Perceptive)
- Lines: 36
- In-reply-to: jac@moonshine.llnl.gov's message of 15 Sep 92 16:59:36 GMT
-
- In article <jac.716576376@moonshine> jac@moonshine.llnl.gov (James A. Crotinger) writes:
-
- tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
- > What you can do, however, is to share a lot of code among the
- > different array classes. For example, you might have your
- > multidimensional array inherit from your 1D array.
-
- Not publicly, I hope. There is no "is a" relationship in that
- direction. (Well, you can say that a 2D array of floats is a 1D array
- of 1D arrays of floats, but that's not the same as inheritance since
- the types of the 2D and "outer" 1D arrays are different.) In one of
- our class libraries we did implement "Vector" (1D array) as inheriting
- from "Matrix" (2D array). This makes sense since a Vector is just a
- Matrix with only 1 column. Thus you can safely pass a Vector to any
- function which operates on Matrices, etc. You would not want to try to
- do the reverse.
-
- Actually, an n-dimensional array "is a" concatenation of n-1
- dimensional arrays, quite naturally, so public inheritance does make
- sense. For reasons of efficiency, it may still be better to have a
- specialized class unrelated to all the others for each dimensionality.
-
- The case of vectors and matrices is very different from the case of
- arrays, since there is a lot of additional structure. In fact, I don't
- think there is a single clean way to express the relationship between
- vectors and matrices within the OO paradigm, since these relationships
- don't form a taxonomy. Sometimes, it makes sense to view a vector as a
- one-column (or one-row) matrix, while at other times, it makes sense
- to view an N x M matrix as an NM dimensional vector.
-
- In such cases where different taxonomies are plausible, it is usually
- best not to use any taxonomy and rely on explicity conversion
- functions. So, I think Vector should not inherit from Matrix, and
- Matrix should not inherit from Vector.
-
- Thomas.
-