[PYTHON MATRIX-SIG] Who wants to test my complex number module?
P. Dubois
dubois@kristen.llnl.gov
Fri, 3 Nov 1995 09:42:46 +0800
(This is the middle of a conversation about the complex
module that Hinsen has developed, but some issues I wanted to mention
to everyone).
a. It is a surprising thing (to me) that while tan is in the Fortran standard,
cot isn't. We put one in Basis because it drove us crazy.
b. The conjugation function in Fortran is called conjg, not conj.
We probably should have a functional equivalent, too, conjg(c).
Actually, the conjugate not really an attribute of the object,
it is a transform, and so I'd rather see a method which conjugates
the given object and a conjg(c) which returns copy(c).conjg().
c. However, that leads us to the whole discussion of naming. I think if
you read "Reusable Software" by Bertrand Meyer, and have some experience
with constructing large scale reusable component libraries (which is
what Python is generating on a frightening scale) it turns out that
a consistent naming convention is very, very important. Some of the
lessons the Eiffel community has learned are:
1. Abbreviations should be avoided. Basically, if you don't abbreviate
you can't forget which abbreviation to use. So in the immediate case,
I would favor conjugate rather than conjg. This tends to be against
the traditions in a rapid prototyping language but the components
we are building aren't the rapid prototype they are elements of
the reusable software library. (Although, you can make a case that
conjg isn't an abbreviation, it is the Fortran name which everyone
knows!)
2. It is more important for the names to be consistent than traditional.
For example, the size of an object like a list, stack, or queue is
invariably called count, and the operation to place an element at
a certain position is put. In stacks, put might more traditionally
be called "push" and the top item "top" or "first" but an Eiffel user
will know without looking that the top item is going to be called
"item", as is the current item in a list.
Fortunately, Python's name scoping mitigates quite a bit of the worry
about name clashes, but the problem of a user learning a large body of
components is still there.
d. In the matrix class, one ought to worry about putting a name like
"pp". Not only are some users going to accidentally call one of their
variables pp, when you read it you haven't a clue what it is.
PrintMatrix ? (Unless, has pp become a standard Python abbreviation for
PrettyPrint?)
e. About the printed representation of a complex: shouldn't it be
complex(1.0, 1.1) not 1j1.1 ? There are two components to this thought.
One is that the two parts should be presented with equal precision.
Second is that it might come in handy if the printed form was readable
back into Python, and there seems to be some "tradition" of this sort
of convention in Python components already. The Fortran representation
for code literals is (1.0, 1.1) which is also suggestive.
f. Note to ourselves: the printing of large matrices needs to be more
orderly and labeled.
An example follows from Basis. Note the control variable available to
change the printing precision on a "class-wide" basis.
kristen[51] basis
Basis (basis, Version 951101)
Run at 09:20:46 on 11/03/95 on the sun4m machine, suffix 8544x
Initializing Basis System
Basis 11.0
Initializing 3-D Surface Plotting Routine
Initializing 3-D Isosurface Plotting Routine
Initializing Device Package
EZD Graphics Devices 3.4 NCAR
Initializing EZCURVE/NCAR Graphics
EZN Graphics Interface Version 5.5
Initializing Singular Value Decomposition
Initializing Polynomial Fitting
Initializing PFB Interface
PFB 4.1
Basis> real x = ones(5, 20)
Basis> x
x shape: (5,20)
row col = 1 2 3 4
1: 1.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
2: 0.00000E+00 1.00000E+00 0.00000E+00 0.00000E+00
3: 0.00000E+00 0.00000E+00 1.00000E+00 0.00000E+00
4: 0.00000E+00 0.00000E+00 0.00000E+00 1.00000E+00
5: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
row col = 5 6 7 8
1: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
2: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
3: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
4: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
5: 1.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
row col = 9 10 11 12
1: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
2: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
3: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
4: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
5: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
row col = 13 14 15 16
1: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
2: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
3: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
4: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
5: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
row col = 17 18 19 20
1: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
2: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
3: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
4: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
5: 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00
Basis> [x, x+2.]
[x,x+2.] shape: (5,20,2)
Number of dimensions: 3, lengths: 5 20 2
INDEX(row,col,1)
row col = 1 2 3 4
1: 1.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
2: 0.00000D+00 1.00000D+00 0.00000D+00 0.00000D+00
3: 0.00000D+00 0.00000D+00 1.00000D+00 0.00000D+00
4: 0.00000D+00 0.00000D+00 0.00000D+00 1.00000D+00
5: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
row col = 5 6 7 8
1: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
2: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
3: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
4: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
5: 1.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
row col = 9 10 11 12
1: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
2: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
3: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
4: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
5: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
row col = 13 14 15 16
1: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
2: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
3: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
4: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
5: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
row col = 17 18 19 20
1: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
2: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
3: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
4: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
5: 0.00000D+00 0.00000D+00 0.00000D+00 0.00000D+00
INDEX(row,col,2)
row col = 1 2 3 4
1: 3.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
2: 2.00000D+00 3.00000D+00 2.00000D+00 2.00000D+00
3: 2.00000D+00 2.00000D+00 3.00000D+00 2.00000D+00
4: 2.00000D+00 2.00000D+00 2.00000D+00 3.00000D+00
5: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
row col = 5 6 7 8
1: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
2: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
3: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
4: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
5: 3.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
row col = 9 10 11 12
1: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
2: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
3: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
4: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
5: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
row col = 13 14 15 16
1: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
2: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
3: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
4: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
5: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
row col = 17 18 19 20
1: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
2: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
3: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
4: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
5: 2.00000D+00 2.00000D+00 2.00000D+00 2.00000D+00
================================================
Basis> fuzz=14; x
x shape: (5,20)
row col = 1 2
1: 1.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 1.00000000000000E+00
3: 0.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 0.00000000000000E+00
5: 0.00000000000000E+00 0.00000000000000E+00
row col = 3 4
1: 0.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 0.00000000000000E+00
3: 1.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 1.00000000000000E+00
5: 0.00000000000000E+00 0.00000000000000E+00
row col = 5 6
1: 0.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 0.00000000000000E+00
3: 0.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 0.00000000000000E+00
5: 1.00000000000000E+00 0.00000000000000E+00
row col = 7 8
1: 0.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 0.00000000000000E+00
3: 0.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 0.00000000000000E+00
5: 0.00000000000000E+00 0.00000000000000E+00
row col = 9 10
1: 0.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 0.00000000000000E+00
3: 0.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 0.00000000000000E+00
5: 0.00000000000000E+00 0.00000000000000E+00
row col = 11 12
1: 0.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 0.00000000000000E+00
3: 0.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 0.00000000000000E+00
5: 0.00000000000000E+00 0.00000000000000E+00
row col = 13 14
1: 0.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 0.00000000000000E+00
3: 0.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 0.00000000000000E+00
5: 0.00000000000000E+00 0.00000000000000E+00
row col = 15 16
1: 0.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 0.00000000000000E+00
3: 0.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 0.00000000000000E+00
5: 0.00000000000000E+00 0.00000000000000E+00
row col = 17 18
1: 0.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 0.00000000000000E+00
3: 0.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 0.00000000000000E+00
5: 0.00000000000000E+00 0.00000000000000E+00
row col = 19 20
1: 0.00000000000000E+00 0.00000000000000E+00
2: 0.00000000000000E+00 0.00000000000000E+00
3: 0.00000000000000E+00 0.00000000000000E+00
4: 0.00000000000000E+00 0.00000000000000E+00
5: 0.00000000000000E+00 0.00000000000000E+00
"Compression" is also useful, can be turned off by user:
Basis> real x= [1.,2.,3] // ones(1000)
Basis> x
x shape: (1003)
1: 1.00000000000000E+00 2.00000000000000E+00
3: 3.00000000000000E+00 1.00000000000000E+00
5:1000 1.00000000000000E+00 1.00000000000000E+00
1001: 1.00000000000000E+00 1.00000000000000E+00
1003: 1.00000000000000E+00
Basis> [x,x/2.]
[x,x/2.] shape: (1003,2)
row col = 1 2
1: 1.00000000000000D+00 5.00000000000000D-01
2: 2.00000000000000D+00 1.00000000000000D+00
3: 3.00000000000000D+00 1.50000000000000D+00
4:1003 1.00000000000000D+00 5.00000000000000D-01
Basis>
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================