Add graph references
This commit is contained in:
+502
@@ -0,0 +1,502 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
NOTE: Files in this subdirectory are NOT part of the GLPK package, but
|
||||
are used with GLPK.
|
||||
|
||||
The original code was modified according to GLPK requirements by
|
||||
Andrew Makhorin <mao@gnu.org>.
|
||||
************************************************************************
|
||||
AMD Version 2.2, Copyright (C) 2007 by Timothy A. Davis,
|
||||
Patrick R. Amestoy, and Iain S. Duff. All Rights Reserved.
|
||||
|
||||
Description:
|
||||
|
||||
AMD is a set of routines for pre-ordering sparse matrices prior to
|
||||
Cholesky or LU factorization, using the approximate minimum degree
|
||||
ordering algorithm. Written in ANSI/ISO C with a MATLAB interface,
|
||||
and in Fortran 77.
|
||||
|
||||
Authors:
|
||||
|
||||
Timothy A. Davis (davis at cise.ufl.edu), University of Florida.
|
||||
Patrick R. Amestoy, ENSEEIHT, Toulouse, France.
|
||||
Iain S. Duff, Rutherford Appleton Laboratory, UK.
|
||||
|
||||
AMD License:
|
||||
|
||||
Your use or distribution of AMD or any modified version of AMD
|
||||
implies that you agree to this License.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License
|
||||
as published by the Free Software Foundation; either version 2.1 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
||||
USA.
|
||||
|
||||
Permission is hereby granted to use or copy this program under the
|
||||
terms of the GNU LGPL, provided that the Copyright, this License,
|
||||
and the Availability of the original version is retained on all
|
||||
copies. User documentation of any code that uses this code or any
|
||||
modified version of this code must cite the Copyright, this License,
|
||||
the Availability note, and "Used by permission." Permission to
|
||||
modify the code and to distribute modified code is granted, provided
|
||||
the Copyright, this License, and the Availability note are retained,
|
||||
and a notice that the code was modified is included.
|
||||
|
||||
AMD is available under alternate licences; contact T. Davis for
|
||||
details.
|
||||
|
||||
Availability:
|
||||
|
||||
http://www.cise.ufl.edu/research/sparse/amd
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/* amd.h */
|
||||
|
||||
/* Written by Andrew Makhorin <mao@gnu.org>. */
|
||||
|
||||
#ifndef GLPAMD_H
|
||||
#define GLPAMD_H
|
||||
|
||||
#define AMD_DATE "May 31, 2007"
|
||||
#define AMD_VERSION_CODE(main, sub) ((main) * 1000 + (sub))
|
||||
#define AMD_MAIN_VERSION 2
|
||||
#define AMD_SUB_VERSION 2
|
||||
#define AMD_SUBSUB_VERSION 0
|
||||
#define AMD_VERSION AMD_VERSION_CODE(AMD_MAIN_VERSION, AMD_SUB_VERSION)
|
||||
|
||||
#define AMD_CONTROL 5
|
||||
#define AMD_INFO 20
|
||||
|
||||
#define AMD_DENSE 0
|
||||
#define AMD_AGGRESSIVE 1
|
||||
|
||||
#define AMD_DEFAULT_DENSE 10.0
|
||||
#define AMD_DEFAULT_AGGRESSIVE 1
|
||||
|
||||
#define AMD_STATUS 0
|
||||
#define AMD_N 1
|
||||
#define AMD_NZ 2
|
||||
#define AMD_SYMMETRY 3
|
||||
#define AMD_NZDIAG 4
|
||||
#define AMD_NZ_A_PLUS_AT 5
|
||||
#define AMD_NDENSE 6
|
||||
#define AMD_MEMORY 7
|
||||
#define AMD_NCMPA 8
|
||||
#define AMD_LNZ 9
|
||||
#define AMD_NDIV 10
|
||||
#define AMD_NMULTSUBS_LDL 11
|
||||
#define AMD_NMULTSUBS_LU 12
|
||||
#define AMD_DMAX 13
|
||||
|
||||
#define AMD_OK 0
|
||||
#define AMD_OUT_OF_MEMORY (-1)
|
||||
#define AMD_INVALID (-2)
|
||||
#define AMD_OK_BUT_JUMBLED 1
|
||||
|
||||
#define amd_order _glp_amd_order
|
||||
int amd_order(int n, const int Ap[], const int Ai[], int P[],
|
||||
double Control[], double Info[]);
|
||||
|
||||
#define amd_2 _glp_amd_2
|
||||
void amd_2(int n, int Pe[], int Iw[], int Len[], int iwlen, int pfree,
|
||||
int Nv[], int Next[], int Last[], int Head[], int Elen[],
|
||||
int Degree[], int W[], double Control[], double Info[]);
|
||||
|
||||
#define amd_valid _glp_amd_valid
|
||||
int amd_valid(int n_row, int n_col, const int Ap[], const int Ai[]);
|
||||
|
||||
#define amd_defaults _glp_amd_defaults
|
||||
void amd_defaults(double Control[]);
|
||||
|
||||
#define amd_control _glp_amd_control
|
||||
void amd_control(double Control[]);
|
||||
|
||||
#define amd_info _glp_amd_info
|
||||
void amd_info(double Info[]);
|
||||
|
||||
#endif
|
||||
|
||||
/* eof */
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_1 =============================================================== */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* AMD_1: Construct A+A' for a sparse matrix A and perform the AMD ordering.
|
||||
*
|
||||
* The n-by-n sparse matrix A can be unsymmetric. It is stored in MATLAB-style
|
||||
* compressed-column form, with sorted row indices in each column, and no
|
||||
* duplicate entries. Diagonal entries may be present, but they are ignored.
|
||||
* Row indices of column j of A are stored in Ai [Ap [j] ... Ap [j+1]-1].
|
||||
* Ap [0] must be zero, and nz = Ap [n] is the number of entries in A. The
|
||||
* size of the matrix, n, must be greater than or equal to zero.
|
||||
*
|
||||
* This routine must be preceded by a call to AMD_aat, which computes the
|
||||
* number of entries in each row/column in A+A', excluding the diagonal.
|
||||
* Len [j], on input, is the number of entries in row/column j of A+A'. This
|
||||
* routine constructs the matrix A+A' and then calls AMD_2. No error checking
|
||||
* is performed (this was done in AMD_valid).
|
||||
*/
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
GLOBAL void AMD_1
|
||||
(
|
||||
Int n, /* n > 0 */
|
||||
const Int Ap [ ], /* input of size n+1, not modified */
|
||||
const Int Ai [ ], /* input of size nz = Ap [n], not modified */
|
||||
Int P [ ], /* size n output permutation */
|
||||
Int Pinv [ ], /* size n output inverse permutation */
|
||||
Int Len [ ], /* size n input, undefined on output */
|
||||
Int slen, /* slen >= sum (Len [0..n-1]) + 7n,
|
||||
* ideally slen = 1.2 * sum (Len) + 8n */
|
||||
Int S [ ], /* size slen workspace */
|
||||
double Control [ ], /* input array of size AMD_CONTROL */
|
||||
double Info [ ] /* output array of size AMD_INFO */
|
||||
)
|
||||
{
|
||||
Int i, j, k, p, pfree, iwlen, pj, p1, p2, pj2, *Iw, *Pe, *Nv, *Head,
|
||||
*Elen, *Degree, *s, *W, *Sp, *Tp ;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* construct the matrix for AMD_2 */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
ASSERT (n > 0) ;
|
||||
|
||||
iwlen = slen - 6*n ;
|
||||
s = S ;
|
||||
Pe = s ; s += n ;
|
||||
Nv = s ; s += n ;
|
||||
Head = s ; s += n ;
|
||||
Elen = s ; s += n ;
|
||||
Degree = s ; s += n ;
|
||||
W = s ; s += n ;
|
||||
Iw = s ; s += iwlen ;
|
||||
|
||||
ASSERT (AMD_valid (n, n, Ap, Ai) == AMD_OK) ;
|
||||
|
||||
/* construct the pointers for A+A' */
|
||||
Sp = Nv ; /* use Nv and W as workspace for Sp and Tp [ */
|
||||
Tp = W ;
|
||||
pfree = 0 ;
|
||||
for (j = 0 ; j < n ; j++)
|
||||
{
|
||||
Pe [j] = pfree ;
|
||||
Sp [j] = pfree ;
|
||||
pfree += Len [j] ;
|
||||
}
|
||||
|
||||
/* Note that this restriction on iwlen is slightly more restrictive than
|
||||
* what is strictly required in AMD_2. AMD_2 can operate with no elbow
|
||||
* room at all, but it will be very slow. For better performance, at
|
||||
* least size-n elbow room is enforced. */
|
||||
ASSERT (iwlen >= pfree + n) ;
|
||||
|
||||
#ifndef NDEBUG
|
||||
for (p = 0 ; p < iwlen ; p++) Iw [p] = EMPTY ;
|
||||
#endif
|
||||
|
||||
for (k = 0 ; k < n ; k++)
|
||||
{
|
||||
AMD_DEBUG1 (("Construct row/column k= "ID" of A+A'\n", k)) ;
|
||||
p1 = Ap [k] ;
|
||||
p2 = Ap [k+1] ;
|
||||
|
||||
/* construct A+A' */
|
||||
for (p = p1 ; p < p2 ; )
|
||||
{
|
||||
/* scan the upper triangular part of A */
|
||||
j = Ai [p] ;
|
||||
ASSERT (j >= 0 && j < n) ;
|
||||
if (j < k)
|
||||
{
|
||||
/* entry A (j,k) in the strictly upper triangular part */
|
||||
ASSERT (Sp [j] < (j == n-1 ? pfree : Pe [j+1])) ;
|
||||
ASSERT (Sp [k] < (k == n-1 ? pfree : Pe [k+1])) ;
|
||||
Iw [Sp [j]++] = k ;
|
||||
Iw [Sp [k]++] = j ;
|
||||
p++ ;
|
||||
}
|
||||
else if (j == k)
|
||||
{
|
||||
/* skip the diagonal */
|
||||
p++ ;
|
||||
break ;
|
||||
}
|
||||
else /* j > k */
|
||||
{
|
||||
/* first entry below the diagonal */
|
||||
break ;
|
||||
}
|
||||
/* scan lower triangular part of A, in column j until reaching
|
||||
* row k. Start where last scan left off. */
|
||||
ASSERT (Ap [j] <= Tp [j] && Tp [j] <= Ap [j+1]) ;
|
||||
pj2 = Ap [j+1] ;
|
||||
for (pj = Tp [j] ; pj < pj2 ; )
|
||||
{
|
||||
i = Ai [pj] ;
|
||||
ASSERT (i >= 0 && i < n) ;
|
||||
if (i < k)
|
||||
{
|
||||
/* A (i,j) is only in the lower part, not in upper */
|
||||
ASSERT (Sp [i] < (i == n-1 ? pfree : Pe [i+1])) ;
|
||||
ASSERT (Sp [j] < (j == n-1 ? pfree : Pe [j+1])) ;
|
||||
Iw [Sp [i]++] = j ;
|
||||
Iw [Sp [j]++] = i ;
|
||||
pj++ ;
|
||||
}
|
||||
else if (i == k)
|
||||
{
|
||||
/* entry A (k,j) in lower part and A (j,k) in upper */
|
||||
pj++ ;
|
||||
break ;
|
||||
}
|
||||
else /* i > k */
|
||||
{
|
||||
/* consider this entry later, when k advances to i */
|
||||
break ;
|
||||
}
|
||||
}
|
||||
Tp [j] = pj ;
|
||||
}
|
||||
Tp [k] = p ;
|
||||
}
|
||||
|
||||
/* clean up, for remaining mismatched entries */
|
||||
for (j = 0 ; j < n ; j++)
|
||||
{
|
||||
for (pj = Tp [j] ; pj < Ap [j+1] ; pj++)
|
||||
{
|
||||
i = Ai [pj] ;
|
||||
ASSERT (i >= 0 && i < n) ;
|
||||
/* A (i,j) is only in the lower part, not in upper */
|
||||
ASSERT (Sp [i] < (i == n-1 ? pfree : Pe [i+1])) ;
|
||||
ASSERT (Sp [j] < (j == n-1 ? pfree : Pe [j+1])) ;
|
||||
Iw [Sp [i]++] = j ;
|
||||
Iw [Sp [j]++] = i ;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
for (j = 0 ; j < n-1 ; j++) ASSERT (Sp [j] == Pe [j+1]) ;
|
||||
ASSERT (Sp [n-1] == pfree) ;
|
||||
#endif
|
||||
|
||||
/* Tp and Sp no longer needed ] */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* order the matrix */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
AMD_2 (n, Pe, Iw, Len, iwlen, pfree,
|
||||
Nv, Pinv, P, Head, Elen, Degree, W, Control, Info) ;
|
||||
}
|
||||
+1842
File diff suppressed because it is too large
Load Diff
+185
@@ -0,0 +1,185 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_aat ============================================================= */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* AMD_aat: compute the symmetry of the pattern of A, and count the number of
|
||||
* nonzeros each column of A+A' (excluding the diagonal). Assumes the input
|
||||
* matrix has no errors, with sorted columns and no duplicates
|
||||
* (AMD_valid (n, n, Ap, Ai) must be AMD_OK, but this condition is not
|
||||
* checked).
|
||||
*/
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
GLOBAL size_t AMD_aat /* returns nz in A+A' */
|
||||
(
|
||||
Int n,
|
||||
const Int Ap [ ],
|
||||
const Int Ai [ ],
|
||||
Int Len [ ], /* Len [j]: length of column j of A+A', excl diagonal*/
|
||||
Int Tp [ ], /* workspace of size n */
|
||||
double Info [ ]
|
||||
)
|
||||
{
|
||||
Int p1, p2, p, i, j, pj, pj2, k, nzdiag, nzboth, nz ;
|
||||
double sym ;
|
||||
size_t nzaat ;
|
||||
|
||||
#ifndef NDEBUG
|
||||
AMD_debug_init ("AMD AAT") ;
|
||||
for (k = 0 ; k < n ; k++) Tp [k] = EMPTY ;
|
||||
ASSERT (AMD_valid (n, n, Ap, Ai) == AMD_OK) ;
|
||||
#endif
|
||||
|
||||
if (Info != (double *) NULL)
|
||||
{
|
||||
/* clear the Info array, if it exists */
|
||||
for (i = 0 ; i < AMD_INFO ; i++)
|
||||
{
|
||||
Info [i] = EMPTY ;
|
||||
}
|
||||
Info [AMD_STATUS] = AMD_OK ;
|
||||
}
|
||||
|
||||
for (k = 0 ; k < n ; k++)
|
||||
{
|
||||
Len [k] = 0 ;
|
||||
}
|
||||
|
||||
nzdiag = 0 ;
|
||||
nzboth = 0 ;
|
||||
nz = Ap [n] ;
|
||||
|
||||
for (k = 0 ; k < n ; k++)
|
||||
{
|
||||
p1 = Ap [k] ;
|
||||
p2 = Ap [k+1] ;
|
||||
AMD_DEBUG2 (("\nAAT Column: "ID" p1: "ID" p2: "ID"\n", k, p1, p2)) ;
|
||||
|
||||
/* construct A+A' */
|
||||
for (p = p1 ; p < p2 ; )
|
||||
{
|
||||
/* scan the upper triangular part of A */
|
||||
j = Ai [p] ;
|
||||
if (j < k)
|
||||
{
|
||||
/* entry A (j,k) is in the strictly upper triangular part,
|
||||
* add both A (j,k) and A (k,j) to the matrix A+A' */
|
||||
Len [j]++ ;
|
||||
Len [k]++ ;
|
||||
AMD_DEBUG3 ((" upper ("ID","ID") ("ID","ID")\n", j,k, k,j));
|
||||
p++ ;
|
||||
}
|
||||
else if (j == k)
|
||||
{
|
||||
/* skip the diagonal */
|
||||
p++ ;
|
||||
nzdiag++ ;
|
||||
break ;
|
||||
}
|
||||
else /* j > k */
|
||||
{
|
||||
/* first entry below the diagonal */
|
||||
break ;
|
||||
}
|
||||
/* scan lower triangular part of A, in column j until reaching
|
||||
* row k. Start where last scan left off. */
|
||||
ASSERT (Tp [j] != EMPTY) ;
|
||||
ASSERT (Ap [j] <= Tp [j] && Tp [j] <= Ap [j+1]) ;
|
||||
pj2 = Ap [j+1] ;
|
||||
for (pj = Tp [j] ; pj < pj2 ; )
|
||||
{
|
||||
i = Ai [pj] ;
|
||||
if (i < k)
|
||||
{
|
||||
/* A (i,j) is only in the lower part, not in upper.
|
||||
* add both A (i,j) and A (j,i) to the matrix A+A' */
|
||||
Len [i]++ ;
|
||||
Len [j]++ ;
|
||||
AMD_DEBUG3 ((" lower ("ID","ID") ("ID","ID")\n",
|
||||
i,j, j,i)) ;
|
||||
pj++ ;
|
||||
}
|
||||
else if (i == k)
|
||||
{
|
||||
/* entry A (k,j) in lower part and A (j,k) in upper */
|
||||
pj++ ;
|
||||
nzboth++ ;
|
||||
break ;
|
||||
}
|
||||
else /* i > k */
|
||||
{
|
||||
/* consider this entry later, when k advances to i */
|
||||
break ;
|
||||
}
|
||||
}
|
||||
Tp [j] = pj ;
|
||||
}
|
||||
/* Tp [k] points to the entry just below the diagonal in column k */
|
||||
Tp [k] = p ;
|
||||
}
|
||||
|
||||
/* clean up, for remaining mismatched entries */
|
||||
for (j = 0 ; j < n ; j++)
|
||||
{
|
||||
for (pj = Tp [j] ; pj < Ap [j+1] ; pj++)
|
||||
{
|
||||
i = Ai [pj] ;
|
||||
/* A (i,j) is only in the lower part, not in upper.
|
||||
* add both A (i,j) and A (j,i) to the matrix A+A' */
|
||||
Len [i]++ ;
|
||||
Len [j]++ ;
|
||||
AMD_DEBUG3 ((" lower cleanup ("ID","ID") ("ID","ID")\n",
|
||||
i,j, j,i)) ;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* compute the symmetry of the nonzero pattern of A */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/* Given a matrix A, the symmetry of A is:
|
||||
* B = tril (spones (A), -1) + triu (spones (A), 1) ;
|
||||
* sym = nnz (B & B') / nnz (B) ;
|
||||
* or 1 if nnz (B) is zero.
|
||||
*/
|
||||
|
||||
if (nz == nzdiag)
|
||||
{
|
||||
sym = 1 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sym = (2 * (double) nzboth) / ((double) (nz - nzdiag)) ;
|
||||
}
|
||||
|
||||
nzaat = 0 ;
|
||||
for (k = 0 ; k < n ; k++)
|
||||
{
|
||||
nzaat += Len [k] ;
|
||||
}
|
||||
|
||||
AMD_DEBUG1 (("AMD nz in A+A', excluding diagonal (nzaat) = %g\n",
|
||||
(double) nzaat)) ;
|
||||
AMD_DEBUG1 ((" nzboth: "ID" nz: "ID" nzdiag: "ID" symmetry: %g\n",
|
||||
nzboth, nz, nzdiag, sym)) ;
|
||||
|
||||
if (Info != (double *) NULL)
|
||||
{
|
||||
Info [AMD_STATUS] = AMD_OK ;
|
||||
Info [AMD_N] = n ;
|
||||
Info [AMD_NZ] = nz ;
|
||||
Info [AMD_SYMMETRY] = sym ; /* symmetry of pattern of A */
|
||||
Info [AMD_NZDIAG] = nzdiag ; /* nonzeros on diagonal of A */
|
||||
Info [AMD_NZ_A_PLUS_AT] = nzaat ; /* nonzeros in A+A' */
|
||||
}
|
||||
|
||||
return (nzaat) ;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_control ========================================================= */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* User-callable. Prints the control parameters for AMD. See amd.h
|
||||
* for details. If the Control array is not present, the defaults are
|
||||
* printed instead.
|
||||
*/
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
GLOBAL void AMD_control
|
||||
(
|
||||
double Control [ ]
|
||||
)
|
||||
{
|
||||
double alpha ;
|
||||
Int aggressive ;
|
||||
|
||||
if (Control != (double *) NULL)
|
||||
{
|
||||
alpha = Control [AMD_DENSE] ;
|
||||
aggressive = Control [AMD_AGGRESSIVE] != 0 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
alpha = AMD_DEFAULT_DENSE ;
|
||||
aggressive = AMD_DEFAULT_AGGRESSIVE ;
|
||||
}
|
||||
|
||||
PRINTF (("\nAMD version %d.%d.%d, %s: approximate minimum degree ordering\n"
|
||||
" dense row parameter: %g\n", AMD_MAIN_VERSION, AMD_SUB_VERSION,
|
||||
AMD_SUBSUB_VERSION, AMD_DATE, alpha)) ;
|
||||
|
||||
if (alpha < 0)
|
||||
{
|
||||
PRINTF ((" no rows treated as dense\n")) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINTF ((
|
||||
" (rows with more than max (%g * sqrt (n), 16) entries are\n"
|
||||
" considered \"dense\", and placed last in output permutation)\n",
|
||||
alpha)) ;
|
||||
}
|
||||
|
||||
if (aggressive)
|
||||
{
|
||||
PRINTF ((" aggressive absorption: yes\n")) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINTF ((" aggressive absorption: no\n")) ;
|
||||
}
|
||||
|
||||
PRINTF ((" size of AMD integer: %d\n\n", sizeof (Int))) ;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_defaults ======================================================== */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* User-callable. Sets default control parameters for AMD. See amd.h
|
||||
* for details.
|
||||
*/
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
/* ========================================================================= */
|
||||
/* === AMD defaults ======================================================== */
|
||||
/* ========================================================================= */
|
||||
|
||||
GLOBAL void AMD_defaults
|
||||
(
|
||||
double Control [ ]
|
||||
)
|
||||
{
|
||||
Int i ;
|
||||
|
||||
if (Control != (double *) NULL)
|
||||
{
|
||||
for (i = 0 ; i < AMD_CONTROL ; i++)
|
||||
{
|
||||
Control [i] = 0 ;
|
||||
}
|
||||
Control [AMD_DENSE] = AMD_DEFAULT_DENSE ;
|
||||
Control [AMD_AGGRESSIVE] = AMD_DEFAULT_AGGRESSIVE ;
|
||||
}
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_dump ============================================================ */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* Debugging routines for AMD. Not used if NDEBUG is not defined at compile-
|
||||
* time (the default). See comments in amd_internal.h on how to enable
|
||||
* debugging. Not user-callable.
|
||||
*/
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
/* This global variable is present only when debugging */
|
||||
GLOBAL Int AMD_debug = -999 ; /* default is no debug printing */
|
||||
|
||||
/* ========================================================================= */
|
||||
/* === AMD_debug_init ====================================================== */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* Sets the debug print level, by reading the file debug.amd (if it exists) */
|
||||
|
||||
GLOBAL void AMD_debug_init ( char *s )
|
||||
{
|
||||
FILE *f ;
|
||||
f = fopen ("debug.amd", "r") ;
|
||||
if (f == (FILE *) NULL)
|
||||
{
|
||||
AMD_debug = -999 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
fscanf (f, ID, &AMD_debug) ;
|
||||
fclose (f) ;
|
||||
}
|
||||
if (AMD_debug >= 0)
|
||||
{
|
||||
printf ("%s: AMD_debug_init, D= "ID"\n", s, AMD_debug) ;
|
||||
}
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
/* === AMD_dump ============================================================ */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* Dump AMD's data structure, except for the hash buckets. This routine
|
||||
* cannot be called when the hash buckets are non-empty.
|
||||
*/
|
||||
|
||||
GLOBAL void AMD_dump (
|
||||
Int n, /* A is n-by-n */
|
||||
Int Pe [ ], /* pe [0..n-1]: index in iw of start of row i */
|
||||
Int Iw [ ], /* workspace of size iwlen, iwlen [0..pfree-1]
|
||||
* holds the matrix on input */
|
||||
Int Len [ ], /* len [0..n-1]: length for row i */
|
||||
Int iwlen, /* length of iw */
|
||||
Int pfree, /* iw [pfree ... iwlen-1] is empty on input */
|
||||
Int Nv [ ], /* nv [0..n-1] */
|
||||
Int Next [ ], /* next [0..n-1] */
|
||||
Int Last [ ], /* last [0..n-1] */
|
||||
Int Head [ ], /* head [0..n-1] */
|
||||
Int Elen [ ], /* size n */
|
||||
Int Degree [ ], /* size n */
|
||||
Int W [ ], /* size n */
|
||||
Int nel
|
||||
)
|
||||
{
|
||||
Int i, pe, elen, nv, len, e, p, k, j, deg, w, cnt, ilast ;
|
||||
|
||||
if (AMD_debug < 0) return ;
|
||||
ASSERT (pfree <= iwlen) ;
|
||||
AMD_DEBUG3 (("\nAMD dump, pfree: "ID"\n", pfree)) ;
|
||||
for (i = 0 ; i < n ; i++)
|
||||
{
|
||||
pe = Pe [i] ;
|
||||
elen = Elen [i] ;
|
||||
nv = Nv [i] ;
|
||||
len = Len [i] ;
|
||||
w = W [i] ;
|
||||
|
||||
if (elen >= EMPTY)
|
||||
{
|
||||
if (nv == 0)
|
||||
{
|
||||
AMD_DEBUG3 (("\nI "ID": nonprincipal: ", i)) ;
|
||||
ASSERT (elen == EMPTY) ;
|
||||
if (pe == EMPTY)
|
||||
{
|
||||
AMD_DEBUG3 ((" dense node\n")) ;
|
||||
ASSERT (w == 1) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT (pe < EMPTY) ;
|
||||
AMD_DEBUG3 ((" i "ID" -> parent "ID"\n", i, FLIP (Pe[i])));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AMD_DEBUG3 (("\nI "ID": active principal supervariable:\n",i));
|
||||
AMD_DEBUG3 ((" nv(i): "ID" Flag: %d\n", nv, (nv < 0))) ;
|
||||
ASSERT (elen >= 0) ;
|
||||
ASSERT (nv > 0 && pe >= 0) ;
|
||||
p = pe ;
|
||||
AMD_DEBUG3 ((" e/s: ")) ;
|
||||
if (elen == 0) AMD_DEBUG3 ((" : ")) ;
|
||||
ASSERT (pe + len <= pfree) ;
|
||||
for (k = 0 ; k < len ; k++)
|
||||
{
|
||||
j = Iw [p] ;
|
||||
AMD_DEBUG3 ((" "ID"", j)) ;
|
||||
ASSERT (j >= 0 && j < n) ;
|
||||
if (k == elen-1) AMD_DEBUG3 ((" : ")) ;
|
||||
p++ ;
|
||||
}
|
||||
AMD_DEBUG3 (("\n")) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e = i ;
|
||||
if (w == 0)
|
||||
{
|
||||
AMD_DEBUG3 (("\nE "ID": absorbed element: w "ID"\n", e, w)) ;
|
||||
ASSERT (nv > 0 && pe < 0) ;
|
||||
AMD_DEBUG3 ((" e "ID" -> parent "ID"\n", e, FLIP (Pe [e]))) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
AMD_DEBUG3 (("\nE "ID": unabsorbed element: w "ID"\n", e, w)) ;
|
||||
ASSERT (nv > 0 && pe >= 0) ;
|
||||
p = pe ;
|
||||
AMD_DEBUG3 ((" : ")) ;
|
||||
ASSERT (pe + len <= pfree) ;
|
||||
for (k = 0 ; k < len ; k++)
|
||||
{
|
||||
j = Iw [p] ;
|
||||
AMD_DEBUG3 ((" "ID"", j)) ;
|
||||
ASSERT (j >= 0 && j < n) ;
|
||||
p++ ;
|
||||
}
|
||||
AMD_DEBUG3 (("\n")) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* this routine cannot be called when the hash buckets are non-empty */
|
||||
AMD_DEBUG3 (("\nDegree lists:\n")) ;
|
||||
if (nel >= 0)
|
||||
{
|
||||
cnt = 0 ;
|
||||
for (deg = 0 ; deg < n ; deg++)
|
||||
{
|
||||
if (Head [deg] == EMPTY) continue ;
|
||||
ilast = EMPTY ;
|
||||
AMD_DEBUG3 ((ID": \n", deg)) ;
|
||||
for (i = Head [deg] ; i != EMPTY ; i = Next [i])
|
||||
{
|
||||
AMD_DEBUG3 ((" "ID" : next "ID" last "ID" deg "ID"\n",
|
||||
i, Next [i], Last [i], Degree [i])) ;
|
||||
ASSERT (i >= 0 && i < n && ilast == Last [i] &&
|
||||
deg == Degree [i]) ;
|
||||
cnt += Nv [i] ;
|
||||
ilast = i ;
|
||||
}
|
||||
AMD_DEBUG3 (("\n")) ;
|
||||
}
|
||||
ASSERT (cnt == n - nel) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_info ============================================================ */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* User-callable. Prints the output statistics for AMD. See amd.h
|
||||
* for details. If the Info array is not present, nothing is printed.
|
||||
*/
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
#define PRI(format,x) { if (x >= 0) { PRINTF ((format, x)) ; }}
|
||||
|
||||
GLOBAL void AMD_info
|
||||
(
|
||||
double Info [ ]
|
||||
)
|
||||
{
|
||||
double n, ndiv, nmultsubs_ldl, nmultsubs_lu, lnz, lnzd ;
|
||||
|
||||
PRINTF (("\nAMD version %d.%d.%d, %s, results:\n",
|
||||
AMD_MAIN_VERSION, AMD_SUB_VERSION, AMD_SUBSUB_VERSION, AMD_DATE)) ;
|
||||
|
||||
if (!Info)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
n = Info [AMD_N] ;
|
||||
ndiv = Info [AMD_NDIV] ;
|
||||
nmultsubs_ldl = Info [AMD_NMULTSUBS_LDL] ;
|
||||
nmultsubs_lu = Info [AMD_NMULTSUBS_LU] ;
|
||||
lnz = Info [AMD_LNZ] ;
|
||||
lnzd = (n >= 0 && lnz >= 0) ? (n + lnz) : (-1) ;
|
||||
|
||||
/* AMD return status */
|
||||
PRINTF ((" status: ")) ;
|
||||
if (Info [AMD_STATUS] == AMD_OK)
|
||||
{
|
||||
PRINTF (("OK\n")) ;
|
||||
}
|
||||
else if (Info [AMD_STATUS] == AMD_OUT_OF_MEMORY)
|
||||
{
|
||||
PRINTF (("out of memory\n")) ;
|
||||
}
|
||||
else if (Info [AMD_STATUS] == AMD_INVALID)
|
||||
{
|
||||
PRINTF (("invalid matrix\n")) ;
|
||||
}
|
||||
else if (Info [AMD_STATUS] == AMD_OK_BUT_JUMBLED)
|
||||
{
|
||||
PRINTF (("OK, but jumbled\n")) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINTF (("unknown\n")) ;
|
||||
}
|
||||
|
||||
/* statistics about the input matrix */
|
||||
PRI (" n, dimension of A: %.20g\n", n);
|
||||
PRI (" nz, number of nonzeros in A: %.20g\n",
|
||||
Info [AMD_NZ]) ;
|
||||
PRI (" symmetry of A: %.4f\n",
|
||||
Info [AMD_SYMMETRY]) ;
|
||||
PRI (" number of nonzeros on diagonal: %.20g\n",
|
||||
Info [AMD_NZDIAG]) ;
|
||||
PRI (" nonzeros in pattern of A+A' (excl. diagonal): %.20g\n",
|
||||
Info [AMD_NZ_A_PLUS_AT]) ;
|
||||
PRI (" # dense rows/columns of A+A': %.20g\n",
|
||||
Info [AMD_NDENSE]) ;
|
||||
|
||||
/* statistics about AMD's behavior */
|
||||
PRI (" memory used, in bytes: %.20g\n",
|
||||
Info [AMD_MEMORY]) ;
|
||||
PRI (" # of memory compactions: %.20g\n",
|
||||
Info [AMD_NCMPA]) ;
|
||||
|
||||
/* statistics about the ordering quality */
|
||||
PRINTF (("\n"
|
||||
" The following approximate statistics are for a subsequent\n"
|
||||
" factorization of A(P,P) + A(P,P)'. They are slight upper\n"
|
||||
" bounds if there are no dense rows/columns in A+A', and become\n"
|
||||
" looser if dense rows/columns exist.\n\n")) ;
|
||||
|
||||
PRI (" nonzeros in L (excluding diagonal): %.20g\n",
|
||||
lnz) ;
|
||||
PRI (" nonzeros in L (including diagonal): %.20g\n",
|
||||
lnzd) ;
|
||||
PRI (" # divide operations for LDL' or LU: %.20g\n",
|
||||
ndiv) ;
|
||||
PRI (" # multiply-subtract operations for LDL': %.20g\n",
|
||||
nmultsubs_ldl) ;
|
||||
PRI (" # multiply-subtract operations for LU: %.20g\n",
|
||||
nmultsubs_lu) ;
|
||||
PRI (" max nz. in any column of L (incl. diagonal): %.20g\n",
|
||||
Info [AMD_DMAX]) ;
|
||||
|
||||
/* total flop counts for various factorizations */
|
||||
|
||||
if (n >= 0 && ndiv >= 0 && nmultsubs_ldl >= 0 && nmultsubs_lu >= 0)
|
||||
{
|
||||
PRINTF (("\n"
|
||||
" chol flop count for real A, sqrt counted as 1 flop: %.20g\n"
|
||||
" LDL' flop count for real A: %.20g\n"
|
||||
" LDL' flop count for complex A: %.20g\n"
|
||||
" LU flop count for real A (with no pivoting): %.20g\n"
|
||||
" LU flop count for complex A (with no pivoting): %.20g\n\n",
|
||||
n + ndiv + 2*nmultsubs_ldl,
|
||||
ndiv + 2*nmultsubs_ldl,
|
||||
9*ndiv + 8*nmultsubs_ldl,
|
||||
ndiv + 2*nmultsubs_lu,
|
||||
9*ndiv + 8*nmultsubs_lu)) ;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/* amd_internal.h */
|
||||
|
||||
/* Written by Andrew Makhorin <mao@gnu.org>. */
|
||||
|
||||
#ifndef AMD_INTERNAL_H
|
||||
#define AMD_INTERNAL_H
|
||||
|
||||
/* AMD will be exceedingly slow when running in debug mode. */
|
||||
#ifndef NDEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
#include "amd.h"
|
||||
#include "env.h"
|
||||
|
||||
#define Int int
|
||||
#define ID "%d"
|
||||
#define Int_MAX INT_MAX
|
||||
|
||||
#if 0 /* 15/II-2012 */
|
||||
/* now this macro is defined in glpenv.h; besides, the definiton below
|
||||
depends on implementation, because size_t is an unsigned type */
|
||||
#define SIZE_T_MAX ((size_t)(-1))
|
||||
#endif
|
||||
|
||||
#define EMPTY (-1)
|
||||
#define FLIP(i) (-(i)-2)
|
||||
#define UNFLIP(i) ((i < EMPTY) ? FLIP (i) : (i))
|
||||
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#define IMPLIES(p, q) (!(p) || (q))
|
||||
|
||||
#define GLOBAL
|
||||
|
||||
#define AMD_order amd_order
|
||||
#define AMD_defaults amd_defaults
|
||||
#define AMD_control amd_control
|
||||
#define AMD_info amd_info
|
||||
#define AMD_1 amd_1
|
||||
#define AMD_2 amd_2
|
||||
#define AMD_valid amd_valid
|
||||
#define AMD_aat amd_aat
|
||||
#define AMD_postorder amd_postorder
|
||||
#define AMD_post_tree amd_post_tree
|
||||
#define AMD_dump amd_dump
|
||||
#define AMD_debug amd_debug
|
||||
#define AMD_debug_init amd_debug_init
|
||||
#define AMD_preprocess amd_preprocess
|
||||
|
||||
#define amd_malloc xmalloc
|
||||
#if 0 /* 24/V-2009 */
|
||||
#define amd_free xfree
|
||||
#else
|
||||
#define amd_free(ptr) { if ((ptr) != NULL) xfree(ptr); }
|
||||
#endif
|
||||
#define amd_printf xprintf
|
||||
|
||||
#define PRINTF(params) { amd_printf params; }
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ASSERT(expr) xassert(expr)
|
||||
#define AMD_DEBUG0(params) { PRINTF(params); }
|
||||
#define AMD_DEBUG1(params) { if (AMD_debug >= 1) PRINTF(params); }
|
||||
#define AMD_DEBUG2(params) { if (AMD_debug >= 2) PRINTF(params); }
|
||||
#define AMD_DEBUG3(params) { if (AMD_debug >= 3) PRINTF(params); }
|
||||
#define AMD_DEBUG4(params) { if (AMD_debug >= 4) PRINTF(params); }
|
||||
#else
|
||||
#define ASSERT(expression)
|
||||
#define AMD_DEBUG0(params)
|
||||
#define AMD_DEBUG1(params)
|
||||
#define AMD_DEBUG2(params)
|
||||
#define AMD_DEBUG3(params)
|
||||
#define AMD_DEBUG4(params)
|
||||
#endif
|
||||
|
||||
#define amd_aat _glp_amd_aat
|
||||
size_t AMD_aat(Int n, const Int Ap[], const Int Ai[], Int Len[],
|
||||
Int Tp[], double Info[]);
|
||||
|
||||
#define amd_1 _glp_amd_1
|
||||
void AMD_1(Int n, const Int Ap[], const Int Ai[], Int P[], Int Pinv[],
|
||||
Int Len[], Int slen, Int S[], double Control[], double Info[]);
|
||||
|
||||
#define amd_postorder _glp_amd_postorder
|
||||
void AMD_postorder(Int nn, Int Parent[], Int Npiv[], Int Fsize[],
|
||||
Int Order[], Int Child[], Int Sibling[], Int Stack[]);
|
||||
|
||||
#define amd_post_tree _glp_amd_post_tree
|
||||
#ifndef NDEBUG
|
||||
Int AMD_post_tree(Int root, Int k, Int Child[], const Int Sibling[],
|
||||
Int Order[], Int Stack[], Int nn);
|
||||
#else
|
||||
Int AMD_post_tree(Int root, Int k, Int Child[], const Int Sibling[],
|
||||
Int Order[], Int Stack[]);
|
||||
#endif
|
||||
|
||||
#define amd_preprocess _glp_amd_preprocess
|
||||
void AMD_preprocess(Int n, const Int Ap[], const Int Ai[], Int Rp[],
|
||||
Int Ri[], Int W[], Int Flag[]);
|
||||
|
||||
#define amd_debug _glp_amd_debug
|
||||
extern Int AMD_debug;
|
||||
|
||||
#define amd_debug_init _glp_amd_debug_init
|
||||
void AMD_debug_init(char *s);
|
||||
|
||||
#define amd_dump _glp_amd_dump
|
||||
void AMD_dump(Int n, Int Pe[], Int Iw[], Int Len[], Int iwlen,
|
||||
Int pfree, Int Nv[], Int Next[], Int Last[], Int Head[],
|
||||
Int Elen[], Int Degree[], Int W[], Int nel);
|
||||
|
||||
#endif
|
||||
|
||||
/* eof */
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_order =========================================================== */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* User-callable AMD minimum degree ordering routine. See amd.h for
|
||||
* documentation.
|
||||
*/
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
/* ========================================================================= */
|
||||
/* === AMD_order =========================================================== */
|
||||
/* ========================================================================= */
|
||||
|
||||
GLOBAL Int AMD_order
|
||||
(
|
||||
Int n,
|
||||
const Int Ap [ ],
|
||||
const Int Ai [ ],
|
||||
Int P [ ],
|
||||
double Control [ ],
|
||||
double Info [ ]
|
||||
)
|
||||
{
|
||||
Int *Len, *S, nz, i, *Pinv, info, status, *Rp, *Ri, *Cp, *Ci, ok ;
|
||||
size_t nzaat, slen ;
|
||||
double mem = 0 ;
|
||||
|
||||
#ifndef NDEBUG
|
||||
AMD_debug_init ("amd") ;
|
||||
#endif
|
||||
|
||||
/* clear the Info array, if it exists */
|
||||
info = Info != (double *) NULL ;
|
||||
if (info)
|
||||
{
|
||||
for (i = 0 ; i < AMD_INFO ; i++)
|
||||
{
|
||||
Info [i] = EMPTY ;
|
||||
}
|
||||
Info [AMD_N] = n ;
|
||||
Info [AMD_STATUS] = AMD_OK ;
|
||||
}
|
||||
|
||||
/* make sure inputs exist and n is >= 0 */
|
||||
if (Ai == (Int *) NULL || Ap == (Int *) NULL || P == (Int *) NULL || n < 0)
|
||||
{
|
||||
if (info) Info [AMD_STATUS] = AMD_INVALID ;
|
||||
return (AMD_INVALID) ; /* arguments are invalid */
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
return (AMD_OK) ; /* n is 0 so there's nothing to do */
|
||||
}
|
||||
|
||||
nz = Ap [n] ;
|
||||
if (info)
|
||||
{
|
||||
Info [AMD_NZ] = nz ;
|
||||
}
|
||||
if (nz < 0)
|
||||
{
|
||||
if (info) Info [AMD_STATUS] = AMD_INVALID ;
|
||||
return (AMD_INVALID) ;
|
||||
}
|
||||
|
||||
/* check if n or nz will cause size_t overflow */
|
||||
if (((size_t) n) >= SIZE_T_MAX / sizeof (Int)
|
||||
|| ((size_t) nz) >= SIZE_T_MAX / sizeof (Int))
|
||||
{
|
||||
if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
|
||||
return (AMD_OUT_OF_MEMORY) ; /* problem too large */
|
||||
}
|
||||
|
||||
/* check the input matrix: AMD_OK, AMD_INVALID, or AMD_OK_BUT_JUMBLED */
|
||||
status = AMD_valid (n, n, Ap, Ai) ;
|
||||
|
||||
if (status == AMD_INVALID)
|
||||
{
|
||||
if (info) Info [AMD_STATUS] = AMD_INVALID ;
|
||||
return (AMD_INVALID) ; /* matrix is invalid */
|
||||
}
|
||||
|
||||
/* allocate two size-n integer workspaces */
|
||||
Len = amd_malloc (n * sizeof (Int)) ;
|
||||
Pinv = amd_malloc (n * sizeof (Int)) ;
|
||||
mem += n ;
|
||||
mem += n ;
|
||||
if (!Len || !Pinv)
|
||||
{
|
||||
/* :: out of memory :: */
|
||||
amd_free (Len) ;
|
||||
amd_free (Pinv) ;
|
||||
if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
|
||||
return (AMD_OUT_OF_MEMORY) ;
|
||||
}
|
||||
|
||||
if (status == AMD_OK_BUT_JUMBLED)
|
||||
{
|
||||
/* sort the input matrix and remove duplicate entries */
|
||||
AMD_DEBUG1 (("Matrix is jumbled\n")) ;
|
||||
Rp = amd_malloc ((n+1) * sizeof (Int)) ;
|
||||
Ri = amd_malloc (MAX (nz,1) * sizeof (Int)) ;
|
||||
mem += (n+1) ;
|
||||
mem += MAX (nz,1) ;
|
||||
if (!Rp || !Ri)
|
||||
{
|
||||
/* :: out of memory :: */
|
||||
amd_free (Rp) ;
|
||||
amd_free (Ri) ;
|
||||
amd_free (Len) ;
|
||||
amd_free (Pinv) ;
|
||||
if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
|
||||
return (AMD_OUT_OF_MEMORY) ;
|
||||
}
|
||||
/* use Len and Pinv as workspace to create R = A' */
|
||||
AMD_preprocess (n, Ap, Ai, Rp, Ri, Len, Pinv) ;
|
||||
Cp = Rp ;
|
||||
Ci = Ri ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* order the input matrix as-is. No need to compute R = A' first */
|
||||
Rp = NULL ;
|
||||
Ri = NULL ;
|
||||
Cp = (Int *) Ap ;
|
||||
Ci = (Int *) Ai ;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* determine the symmetry and count off-diagonal nonzeros in A+A' */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
nzaat = AMD_aat (n, Cp, Ci, Len, P, Info) ;
|
||||
AMD_DEBUG1 (("nzaat: %g\n", (double) nzaat)) ;
|
||||
ASSERT ((MAX (nz-n, 0) <= nzaat) && (nzaat <= 2 * (size_t) nz)) ;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* allocate workspace for matrix, elbow room, and 6 size-n vectors */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
S = NULL ;
|
||||
slen = nzaat ; /* space for matrix */
|
||||
ok = ((slen + nzaat/5) >= slen) ; /* check for size_t overflow */
|
||||
slen += nzaat/5 ; /* add elbow room */
|
||||
for (i = 0 ; ok && i < 7 ; i++)
|
||||
{
|
||||
ok = ((slen + n) > slen) ; /* check for size_t overflow */
|
||||
slen += n ; /* size-n elbow room, 6 size-n work */
|
||||
}
|
||||
mem += slen ;
|
||||
ok = ok && (slen < SIZE_T_MAX / sizeof (Int)) ; /* check for overflow */
|
||||
ok = ok && (slen < Int_MAX) ; /* S[i] for Int i must be OK */
|
||||
if (ok)
|
||||
{
|
||||
S = amd_malloc (slen * sizeof (Int)) ;
|
||||
}
|
||||
AMD_DEBUG1 (("slen %g\n", (double) slen)) ;
|
||||
if (!S)
|
||||
{
|
||||
/* :: out of memory :: (or problem too large) */
|
||||
amd_free (Rp) ;
|
||||
amd_free (Ri) ;
|
||||
amd_free (Len) ;
|
||||
amd_free (Pinv) ;
|
||||
if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
|
||||
return (AMD_OUT_OF_MEMORY) ;
|
||||
}
|
||||
if (info)
|
||||
{
|
||||
/* memory usage, in bytes. */
|
||||
Info [AMD_MEMORY] = mem * sizeof (Int) ;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* order the matrix */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
AMD_1 (n, Cp, Ci, P, Pinv, Len, slen, S, Control, Info) ;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* free the workspace */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
amd_free (Rp) ;
|
||||
amd_free (Ri) ;
|
||||
amd_free (Len) ;
|
||||
amd_free (Pinv) ;
|
||||
amd_free (S) ;
|
||||
if (info) Info [AMD_STATUS] = status ;
|
||||
return (status) ; /* successful ordering */
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_post_tree ======================================================= */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* Post-ordering of a supernodal elimination tree. */
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
GLOBAL Int AMD_post_tree
|
||||
(
|
||||
Int root, /* root of the tree */
|
||||
Int k, /* start numbering at k */
|
||||
Int Child [ ], /* input argument of size nn, undefined on
|
||||
* output. Child [i] is the head of a link
|
||||
* list of all nodes that are children of node
|
||||
* i in the tree. */
|
||||
const Int Sibling [ ], /* input argument of size nn, not modified.
|
||||
* If f is a node in the link list of the
|
||||
* children of node i, then Sibling [f] is the
|
||||
* next child of node i.
|
||||
*/
|
||||
Int Order [ ], /* output order, of size nn. Order [i] = k
|
||||
* if node i is the kth node of the reordered
|
||||
* tree. */
|
||||
Int Stack [ ] /* workspace of size nn */
|
||||
#ifndef NDEBUG
|
||||
, Int nn /* nodes are in the range 0..nn-1. */
|
||||
#endif
|
||||
)
|
||||
{
|
||||
Int f, head, h, i ;
|
||||
|
||||
#if 0
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* recursive version (Stack [ ] is not used): */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/* this is simple, but can caouse stack overflow if nn is large */
|
||||
i = root ;
|
||||
for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
|
||||
{
|
||||
k = AMD_post_tree (f, k, Child, Sibling, Order, Stack, nn) ;
|
||||
}
|
||||
Order [i] = k++ ;
|
||||
return (k) ;
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* non-recursive version, using an explicit stack */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/* push root on the stack */
|
||||
head = 0 ;
|
||||
Stack [0] = root ;
|
||||
|
||||
while (head >= 0)
|
||||
{
|
||||
/* get head of stack */
|
||||
ASSERT (head < nn) ;
|
||||
i = Stack [head] ;
|
||||
AMD_DEBUG1 (("head of stack "ID" \n", i)) ;
|
||||
ASSERT (i >= 0 && i < nn) ;
|
||||
|
||||
if (Child [i] != EMPTY)
|
||||
{
|
||||
/* the children of i are not yet ordered */
|
||||
/* push each child onto the stack in reverse order */
|
||||
/* so that small ones at the head of the list get popped first */
|
||||
/* and the biggest one at the end of the list gets popped last */
|
||||
for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
|
||||
{
|
||||
head++ ;
|
||||
ASSERT (head < nn) ;
|
||||
ASSERT (f >= 0 && f < nn) ;
|
||||
}
|
||||
h = head ;
|
||||
ASSERT (head < nn) ;
|
||||
for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
|
||||
{
|
||||
ASSERT (h > 0) ;
|
||||
Stack [h--] = f ;
|
||||
AMD_DEBUG1 (("push "ID" on stack\n", f)) ;
|
||||
ASSERT (f >= 0 && f < nn) ;
|
||||
}
|
||||
ASSERT (Stack [h] == i) ;
|
||||
|
||||
/* delete child list so that i gets ordered next time we see it */
|
||||
Child [i] = EMPTY ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the children of i (if there were any) are already ordered */
|
||||
/* remove i from the stack and order it. Front i is kth front */
|
||||
head-- ;
|
||||
AMD_DEBUG1 (("pop "ID" order "ID"\n", i, k)) ;
|
||||
Order [i] = k++ ;
|
||||
ASSERT (k <= nn) ;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
AMD_DEBUG1 (("\nStack:")) ;
|
||||
for (h = head ; h >= 0 ; h--)
|
||||
{
|
||||
Int j = Stack [h] ;
|
||||
AMD_DEBUG1 ((" "ID, j)) ;
|
||||
ASSERT (j >= 0 && j < nn) ;
|
||||
}
|
||||
AMD_DEBUG1 (("\n\n")) ;
|
||||
ASSERT (head < nn) ;
|
||||
#endif
|
||||
|
||||
}
|
||||
return (k) ;
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_postorder ======================================================= */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* Perform a postordering (via depth-first search) of an assembly tree. */
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
GLOBAL void AMD_postorder
|
||||
(
|
||||
/* inputs, not modified on output: */
|
||||
Int nn, /* nodes are in the range 0..nn-1 */
|
||||
Int Parent [ ], /* Parent [j] is the parent of j, or EMPTY if root */
|
||||
Int Nv [ ], /* Nv [j] > 0 number of pivots represented by node j,
|
||||
* or zero if j is not a node. */
|
||||
Int Fsize [ ], /* Fsize [j]: size of node j */
|
||||
|
||||
/* output, not defined on input: */
|
||||
Int Order [ ], /* output post-order */
|
||||
|
||||
/* workspaces of size nn: */
|
||||
Int Child [ ],
|
||||
Int Sibling [ ],
|
||||
Int Stack [ ]
|
||||
)
|
||||
{
|
||||
Int i, j, k, parent, frsize, f, fprev, maxfrsize, bigfprev, bigf, fnext ;
|
||||
|
||||
for (j = 0 ; j < nn ; j++)
|
||||
{
|
||||
Child [j] = EMPTY ;
|
||||
Sibling [j] = EMPTY ;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* place the children in link lists - bigger elements tend to be last */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
for (j = nn-1 ; j >= 0 ; j--)
|
||||
{
|
||||
if (Nv [j] > 0)
|
||||
{
|
||||
/* this is an element */
|
||||
parent = Parent [j] ;
|
||||
if (parent != EMPTY)
|
||||
{
|
||||
/* place the element in link list of the children its parent */
|
||||
/* bigger elements will tend to be at the end of the list */
|
||||
Sibling [j] = Child [parent] ;
|
||||
Child [parent] = j ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
Int nels, ff, nchild ;
|
||||
AMD_DEBUG1 (("\n\n================================ AMD_postorder:\n"));
|
||||
nels = 0 ;
|
||||
for (j = 0 ; j < nn ; j++)
|
||||
{
|
||||
if (Nv [j] > 0)
|
||||
{
|
||||
AMD_DEBUG1 (( ""ID" : nels "ID" npiv "ID" size "ID
|
||||
" parent "ID" maxfr "ID"\n", j, nels,
|
||||
Nv [j], Fsize [j], Parent [j], Fsize [j])) ;
|
||||
/* this is an element */
|
||||
/* dump the link list of children */
|
||||
nchild = 0 ;
|
||||
AMD_DEBUG1 ((" Children: ")) ;
|
||||
for (ff = Child [j] ; ff != EMPTY ; ff = Sibling [ff])
|
||||
{
|
||||
AMD_DEBUG1 ((ID" ", ff)) ;
|
||||
ASSERT (Parent [ff] == j) ;
|
||||
nchild++ ;
|
||||
ASSERT (nchild < nn) ;
|
||||
}
|
||||
AMD_DEBUG1 (("\n")) ;
|
||||
parent = Parent [j] ;
|
||||
if (parent != EMPTY)
|
||||
{
|
||||
ASSERT (Nv [parent] > 0) ;
|
||||
}
|
||||
nels++ ;
|
||||
}
|
||||
}
|
||||
}
|
||||
AMD_DEBUG1 (("\n\nGo through the children of each node, and put\n"
|
||||
"the biggest child last in each list:\n")) ;
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* place the largest child last in the list of children for each node */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
for (i = 0 ; i < nn ; i++)
|
||||
{
|
||||
if (Nv [i] > 0 && Child [i] != EMPTY)
|
||||
{
|
||||
|
||||
#ifndef NDEBUG
|
||||
Int nchild ;
|
||||
AMD_DEBUG1 (("Before partial sort, element "ID"\n", i)) ;
|
||||
nchild = 0 ;
|
||||
for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
|
||||
{
|
||||
ASSERT (f >= 0 && f < nn) ;
|
||||
AMD_DEBUG1 ((" f: "ID" size: "ID"\n", f, Fsize [f])) ;
|
||||
nchild++ ;
|
||||
ASSERT (nchild <= nn) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* find the biggest element in the child list */
|
||||
fprev = EMPTY ;
|
||||
maxfrsize = EMPTY ;
|
||||
bigfprev = EMPTY ;
|
||||
bigf = EMPTY ;
|
||||
for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
|
||||
{
|
||||
ASSERT (f >= 0 && f < nn) ;
|
||||
frsize = Fsize [f] ;
|
||||
if (frsize >= maxfrsize)
|
||||
{
|
||||
/* this is the biggest seen so far */
|
||||
maxfrsize = frsize ;
|
||||
bigfprev = fprev ;
|
||||
bigf = f ;
|
||||
}
|
||||
fprev = f ;
|
||||
}
|
||||
ASSERT (bigf != EMPTY) ;
|
||||
|
||||
fnext = Sibling [bigf] ;
|
||||
|
||||
AMD_DEBUG1 (("bigf "ID" maxfrsize "ID" bigfprev "ID" fnext "ID
|
||||
" fprev " ID"\n", bigf, maxfrsize, bigfprev, fnext, fprev)) ;
|
||||
|
||||
if (fnext != EMPTY)
|
||||
{
|
||||
/* if fnext is EMPTY then bigf is already at the end of list */
|
||||
|
||||
if (bigfprev == EMPTY)
|
||||
{
|
||||
/* delete bigf from the element of the list */
|
||||
Child [i] = fnext ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* delete bigf from the middle of the list */
|
||||
Sibling [bigfprev] = fnext ;
|
||||
}
|
||||
|
||||
/* put bigf at the end of the list */
|
||||
Sibling [bigf] = EMPTY ;
|
||||
ASSERT (Child [i] != EMPTY) ;
|
||||
ASSERT (fprev != bigf) ;
|
||||
ASSERT (fprev != EMPTY) ;
|
||||
Sibling [fprev] = bigf ;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
AMD_DEBUG1 (("After partial sort, element "ID"\n", i)) ;
|
||||
for (f = Child [i] ; f != EMPTY ; f = Sibling [f])
|
||||
{
|
||||
ASSERT (f >= 0 && f < nn) ;
|
||||
AMD_DEBUG1 ((" "ID" "ID"\n", f, Fsize [f])) ;
|
||||
ASSERT (Nv [f] > 0) ;
|
||||
nchild-- ;
|
||||
}
|
||||
ASSERT (nchild == 0) ;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* postorder the assembly tree */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
for (i = 0 ; i < nn ; i++)
|
||||
{
|
||||
Order [i] = EMPTY ;
|
||||
}
|
||||
|
||||
k = 0 ;
|
||||
|
||||
for (i = 0 ; i < nn ; i++)
|
||||
{
|
||||
if (Parent [i] == EMPTY && Nv [i] > 0)
|
||||
{
|
||||
AMD_DEBUG1 (("Root of assembly tree "ID"\n", i)) ;
|
||||
k = AMD_post_tree (i, k, Child, Sibling, Order, Stack
|
||||
#ifndef NDEBUG
|
||||
, nn
|
||||
#endif
|
||||
) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_preprocess ====================================================== */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* Sorts, removes duplicate entries, and transposes from the nonzero pattern of
|
||||
* a column-form matrix A, to obtain the matrix R. The input matrix can have
|
||||
* duplicate entries and/or unsorted columns (AMD_valid (n,Ap,Ai) must not be
|
||||
* AMD_INVALID).
|
||||
*
|
||||
* This input condition is NOT checked. This routine is not user-callable.
|
||||
*/
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
/* ========================================================================= */
|
||||
/* === AMD_preprocess ====================================================== */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* AMD_preprocess does not check its input for errors or allocate workspace.
|
||||
* On input, the condition (AMD_valid (n,n,Ap,Ai) != AMD_INVALID) must hold.
|
||||
*/
|
||||
|
||||
GLOBAL void AMD_preprocess
|
||||
(
|
||||
Int n, /* input matrix: A is n-by-n */
|
||||
const Int Ap [ ], /* size n+1 */
|
||||
const Int Ai [ ], /* size nz = Ap [n] */
|
||||
|
||||
/* output matrix R: */
|
||||
Int Rp [ ], /* size n+1 */
|
||||
Int Ri [ ], /* size nz (or less, if duplicates present) */
|
||||
|
||||
Int W [ ], /* workspace of size n */
|
||||
Int Flag [ ] /* workspace of size n */
|
||||
)
|
||||
{
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* local variables */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Int i, j, p, p2 ;
|
||||
|
||||
ASSERT (AMD_valid (n, n, Ap, Ai) != AMD_INVALID) ;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* count the entries in each row of A (excluding duplicates) */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
for (i = 0 ; i < n ; i++)
|
||||
{
|
||||
W [i] = 0 ; /* # of nonzeros in row i (excl duplicates) */
|
||||
Flag [i] = EMPTY ; /* Flag [i] = j if i appears in column j */
|
||||
}
|
||||
for (j = 0 ; j < n ; j++)
|
||||
{
|
||||
p2 = Ap [j+1] ;
|
||||
for (p = Ap [j] ; p < p2 ; p++)
|
||||
{
|
||||
i = Ai [p] ;
|
||||
if (Flag [i] != j)
|
||||
{
|
||||
/* row index i has not yet appeared in column j */
|
||||
W [i]++ ; /* one more entry in row i */
|
||||
Flag [i] = j ; /* flag row index i as appearing in col j*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* compute the row pointers for R */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Rp [0] = 0 ;
|
||||
for (i = 0 ; i < n ; i++)
|
||||
{
|
||||
Rp [i+1] = Rp [i] + W [i] ;
|
||||
}
|
||||
for (i = 0 ; i < n ; i++)
|
||||
{
|
||||
W [i] = Rp [i] ;
|
||||
Flag [i] = EMPTY ;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* construct the row form matrix R */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/* R = row form of pattern of A */
|
||||
for (j = 0 ; j < n ; j++)
|
||||
{
|
||||
p2 = Ap [j+1] ;
|
||||
for (p = Ap [j] ; p < p2 ; p++)
|
||||
{
|
||||
i = Ai [p] ;
|
||||
if (Flag [i] != j)
|
||||
{
|
||||
/* row index i has not yet appeared in column j */
|
||||
Ri [W [i]++] = j ; /* put col j in row i */
|
||||
Flag [i] = j ; /* flag row index i as appearing in col j*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
ASSERT (AMD_valid (n, n, Rp, Ri) == AMD_OK) ;
|
||||
for (j = 0 ; j < n ; j++)
|
||||
{
|
||||
ASSERT (W [j] == Rp [j+1]) ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/* ========================================================================= */
|
||||
/* === AMD_valid =========================================================== */
|
||||
/* ========================================================================= */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* AMD, Copyright (c) Timothy A. Davis, */
|
||||
/* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
|
||||
/* email: davis at cise.ufl.edu CISE Department, Univ. of Florida. */
|
||||
/* web: http://www.cise.ufl.edu/research/sparse/amd */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* Check if a column-form matrix is valid or not. The matrix A is
|
||||
* n_row-by-n_col. The row indices of entries in column j are in
|
||||
* Ai [Ap [j] ... Ap [j+1]-1]. Required conditions are:
|
||||
*
|
||||
* n_row >= 0
|
||||
* n_col >= 0
|
||||
* nz = Ap [n_col] >= 0 number of entries in the matrix
|
||||
* Ap [0] == 0
|
||||
* Ap [j] <= Ap [j+1] for all j in the range 0 to n_col.
|
||||
* Ai [0 ... nz-1] must be in the range 0 to n_row-1.
|
||||
*
|
||||
* If any of the above conditions hold, AMD_INVALID is returned. If the
|
||||
* following condition holds, AMD_OK_BUT_JUMBLED is returned (a warning,
|
||||
* not an error):
|
||||
*
|
||||
* row indices in Ai [Ap [j] ... Ap [j+1]-1] are not sorted in ascending
|
||||
* order, and/or duplicate entries exist.
|
||||
*
|
||||
* Otherwise, AMD_OK is returned.
|
||||
*
|
||||
* In v1.2 and earlier, this function returned TRUE if the matrix was valid
|
||||
* (now returns AMD_OK), or FALSE otherwise (now returns AMD_INVALID or
|
||||
* AMD_OK_BUT_JUMBLED).
|
||||
*/
|
||||
|
||||
#include "amd_internal.h"
|
||||
|
||||
GLOBAL Int AMD_valid
|
||||
(
|
||||
/* inputs, not modified on output: */
|
||||
Int n_row, /* A is n_row-by-n_col */
|
||||
Int n_col,
|
||||
const Int Ap [ ], /* column pointers of A, of size n_col+1 */
|
||||
const Int Ai [ ] /* row indices of A, of size nz = Ap [n_col] */
|
||||
)
|
||||
{
|
||||
Int nz, j, p1, p2, ilast, i, p, result = AMD_OK ;
|
||||
|
||||
if (n_row < 0 || n_col < 0 || Ap == NULL || Ai == NULL)
|
||||
{
|
||||
return (AMD_INVALID) ;
|
||||
}
|
||||
nz = Ap [n_col] ;
|
||||
if (Ap [0] != 0 || nz < 0)
|
||||
{
|
||||
/* column pointers must start at Ap [0] = 0, and Ap [n] must be >= 0 */
|
||||
AMD_DEBUG0 (("column 0 pointer bad or nz < 0\n")) ;
|
||||
return (AMD_INVALID) ;
|
||||
}
|
||||
for (j = 0 ; j < n_col ; j++)
|
||||
{
|
||||
p1 = Ap [j] ;
|
||||
p2 = Ap [j+1] ;
|
||||
AMD_DEBUG2 (("\nColumn: "ID" p1: "ID" p2: "ID"\n", j, p1, p2)) ;
|
||||
if (p1 > p2)
|
||||
{
|
||||
/* column pointers must be ascending */
|
||||
AMD_DEBUG0 (("column "ID" pointer bad\n", j)) ;
|
||||
return (AMD_INVALID) ;
|
||||
}
|
||||
ilast = EMPTY ;
|
||||
for (p = p1 ; p < p2 ; p++)
|
||||
{
|
||||
i = Ai [p] ;
|
||||
AMD_DEBUG3 (("row: "ID"\n", i)) ;
|
||||
if (i < 0 || i >= n_row)
|
||||
{
|
||||
/* row index out of range */
|
||||
AMD_DEBUG0 (("index out of range, col "ID" row "ID"\n", j, i));
|
||||
return (AMD_INVALID) ;
|
||||
}
|
||||
if (i <= ilast)
|
||||
{
|
||||
/* row index unsorted, or duplicate entry present */
|
||||
AMD_DEBUG1 (("index unsorted/dupl col "ID" row "ID"\n", j, i));
|
||||
result = AMD_OK_BUT_JUMBLED ;
|
||||
}
|
||||
ilast = i ;
|
||||
}
|
||||
}
|
||||
return (result) ;
|
||||
}
|
||||
Reference in New Issue
Block a user