instant-2017.2.0/0000755000231000000010000000000013211253757012543 5ustar chrisdaemoninstant-2017.2.0/.mailmap0000644000231000000010000001636413211253757014176 0ustar chrisdaemonAnders Logg Anders Logg Anders Logg Anders Logg Anders Logg logg Anders Logg fenics Anders Logg hg Anders Logg root Anders Logg Anders Logg Anders Logg Anders Logg Anders Logg Anders Logg anders Anders Logg logg Anders Logg logg Anders Logg logg Anders Logg logg Andy R. Terrel Andy R. Terrel Andy R. Terrel aterrel Andy R. Terrel Benjamin Kehlet Benjamin Kehlet Benjamin Kehlet Benjamin Kehlet Benjamin Kehlet Chris Richardson Chris Richardson chris Chris Richardson Chris Richardson Chris Richardson root Corrado Maurini Corrado Maurini Dag Lindbo Dag Lindbo dag Dag Lindbo dag David Ham David Ham david.ham@imperial.ac.uk <> Evan Lezar Evan Lezar Evan Lezar elezar Evan Lezar elezar Fredrik Valdmanis Fredrik Valdmanis Fredrik Valdmanis Garth N. Wells Garth N. Wells root Garth N. Wells garth Garth N. Wells Garth N. Wells Garth N. Wells Garth N. Wells Garth N. Wells Garth N. Wells Garth N. Wells Garth N. Wells Garth N. Wells Garth N. Wells Garth N. Wells gnw20@cam.ac.uk <> gideonsimpson Gustav Magnus Vikström Gustav Magnus Vikström Gustav Magnus Vikström Gustav Magnus Vikström Harish Narayanan Harish Narayanan Harish Narayanan Johan Hoffman Johan Hoffman hoffman Johan Hoffman Johan Hoffman Ilmar Wilbers Ilmar Wilbers Ilmar Wilbers Jack S. Hale Jack S. Hale Johan Hake Johan Hake Johan Hake Johan Jansson Johan Jansson johan Johan Jansson johan Johan Jansson johanjan Johan Jansson johanjan Johan Jansson Johan Jansson Johannes Ring Johannes Ring Kent-Andre Mardal Kent-Andre Mardal anonymous Kent-Andre Mardal Kent-Andre Mardal kent-and Kent-Andre Mardal Kristian B. Ølgaard Kristian B. Ølgaard Kristian B. Ølgaard Magnus Vikstrøm Marco Morandini Marco Morandini Marie E. Rognes Marie E. Rognes Marie E. Rognes Marie E. Rognes Marie E. Rognes (meg@simula.no) Marie E. Rognes meg@simula.no <> Martin Sandve Alnæs Martin Sandve Alnæs Martin Sandve Alnæs Martin Sandve Alnæs Michele Zaffalon Mikael Mortensen Mikael Mortensen Nate Sime Nate Sime Nuno Lopes Nuno Lopes N.Lopes Patrick Farrell Patrick Farrell Patrick Farrell Quang Ha Kristoffer Selim Kristoffer Selim Simon Funke Simon Funke Simon Funke Solveig Bruvoll Solveig Masvie Steven Vandekerckhove Steven Vandekerckhove stockli stockli Tianyi Li Steffen Müthing Steffen Müthing Steffen Müthing steffen.muething@ipvs.uni-stuttgart.de <> Miklós Homolya Åsmund Ødegård Åsmund Ødegård Ola Skavhaug Andre Massing Andrew McRae instant-2017.2.0/COPYING0000644000231000000010000010451313211253757013602 0ustar chrisdaemon GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, 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 them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If 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 convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . instant-2017.2.0/LICENSE0000644000231000000010000000501213211253757013546 0ustar chrisdaemonLicense ------- Instant is licensed under a dual license, i.e. both the conditions of the GNU LGPL version 3 (or any later version) and the BSD 3-clause license apply to Instant. See below for the actual license texts. GNU Lesser General Public License --------------------------------- Instant 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 3 of the License, or (at your option) any later version. Instant 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 Instant. If not, see . BSD 3-clause License -------------------- Copyright (C) 2004-2014, Magne Westlie, Kent-Andre Mardal, Martin Sandve Alnæs, Ilmar Wilbers and Simula Research Laboratory. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Simula Research Laboratory nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. instant-2017.2.0/TODO0000644000231000000010000000135613211253757013240 0ustar chrisdaemonTODO: - Print error when tmp directory can't be deleted (in instant-clean). Maybe add username to tmp dir name suffix? /tmp on cluster contains instant directories of many users. - Keep a most recently used list add a max cache size option to ~/.instant/intantrc clean up the oldest modules whenever we exceed this quota - Add argument to provide a cache subfolder name. Then instant-clean can take an argument to clean only the "ffc" cache subfolder etc. - Does instant handle full disk properly? (Does any software? Define properly!) - Fix arguments not used in setup.py - Use object files argument. - Improve documentation - Add tests for all variants of cache mechanisms available now - Clean up imports, don't use import * instant-2017.2.0/bitbucket-pipelines.yml0000644000231000000010000000041013211253757017223 0ustar chrisdaemonimage: quay.io/fenicsproject/pipelines pipelines: default: - step: script: - pip2 install . - pip3 install . - cd test/ - python2 -m pytest -v . - git clean -fdx . - python3 -m pytest -v . instant-2017.2.0/MANIFEST.in0000644000231000000010000000027013211253757014300 0ustar chrisdaemoninclude AUTHORS include COPYING include COPYING.LESSER include ChangeLog include LICENSE include TODO recursive-include doc * recursive-include test * global-exclude __pycache__ *.pyc instant-2017.2.0/COPYING.LESSER0000644000231000000010000001672713211253757014607 0ustar chrisdaemon GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. 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 that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. instant-2017.2.0/scripts/0000755000231000000010000000000013211253757014232 5ustar chrisdaemoninstant-2017.2.0/scripts/instant-showcache0000755000231000000010000000251013211253757017600 0ustar chrisdaemon#!/usr/bin/env python # # This script prints all modules found in the instant cache __author__ = "Martin Alnes (martinal@simula.no)" __date__ = "2008-09-02 -- 2008-10-16" __copyright__ = "Copyright (C) 2008 Martin Alnes" __license__ = "GNU GPL version 3 or any later version" import os, sys, shutil, tempfile, glob try: import instant except: print("Instant not installed, exiting...") sys.exit(1) files = sys.argv[1:] if files: print("Showing contents of files: ", files) modules = instant.cached_modules() lockfiles = [m for m in modules if m.endswith(".lock")] modules = [m for m in modules if not m.endswith(".lock")] print("Found %d modules in Instant cache:" % len(modules)) for module in modules: print(module) if files: for f in files: filepath = os.path.join(instant.get_default_cache_dir(), module, f) filenames = glob.glob(filepath) for filename in filenames: print("Contents of file '%s':" % filename) try: lines = open(filename).readlines() print("".join(lines)) except: print("Failed to open.") print() print() print("Found %d lock files in Instant cache:" % len(lockfiles)) for lockfile in lockfiles: print(lockfile) instant-2017.2.0/scripts/instant-clean0000755000231000000010000000503013211253757016716 0ustar chrisdaemon#!/usr/bin/env python # # This script cleans the Instant cache __author__ = "Ilmar Wilbers (ilmarw@simula.no)" __date__ = "2008-08-08 -- 2013-05-02" __copyright__ = "Copyright (C) 2008 Ilmar Wilbers" __license__ = "GNU GPL version 3 or any later version" # Modified by Martin Alnes import os, sys, shutil, glob, re try: import instant except: print("Instant not installed, exiting...") sys.exit(1) instant_tmp_dir_suffix = instant.compute_checksum(instant.get_instant_dir()) # Check if any temp directories exists tmp = instant.get_temp_dir() tmp_dir_prefix = os.path.split(tmp)[0] # FIXME: Is it safe to assume that the prefix to tempdirs is constant on a platform? s = re.search(r"(.*)%s[^%s]*instant_%s" % (os.path.pathsep, os.path.pathsep, \ instant_tmp_dir_suffix), tmp) instant.delete_temp_dir() tmp_dirs = glob.glob(os.path.join(tmp_dir_prefix, '*instant_' + instant_tmp_dir_suffix)) for d in tmp_dirs: if os.path.isdir(d): print("Deleting temp directory", d) shutil.rmtree(d, ignore_errors=True) # Get default cache dir (won't and can't touch userdefined cache dirs in this script) cache_dir = instant.get_default_cache_dir() error_dir = instant.get_default_error_dir() # Check if directory exists (it always should after calling get_default_cache_dir) assert os.path.isdir(cache_dir) assert os.path.isdir(error_dir) # Get list of cached forms modules = os.listdir(cache_dir) error_logs = os.listdir(error_dir) if len(modules+error_logs) == 0: print("Instant cache is empty") sys.exit(0) # Remove cached forms lockfiles = [m for m in modules if m.endswith(".lock")] modules = [m for m in modules if not m.endswith(".lock")] error_lockfiles = [f for f in error_logs if f.endswith(".lock")] error_logs = [f for f in error_logs if not f.endswith(".lock")] print("Removing %d modules from Instant cache..." % len(modules)) for module in modules: directory = os.path.join(cache_dir, module) shutil.rmtree(directory, ignore_errors=True) print("Removing %d error logs from Instant cache..." % len(error_logs)) for error_log in error_logs: if os.path.isdir(os.path.join(error_dir, error_log)): shutil.rmtree(os.path.join(error_dir, error_log)) else: os.remove(os.path.join(error_dir, error_log)) print("Removing %d lock files from Instant cache..." % len(lockfiles+error_lockfiles)) for lf in lockfiles: f = os.path.join(cache_dir, lf) os.remove(f) for lf in error_lockfiles: f = os.path.join(error_dir, lf) os.remove(f) instant-2017.2.0/instant/0000755000231000000010000000000013211253757014223 5ustar chrisdaemoninstant-2017.2.0/instant/codegeneration.py0000644000231000000010000005433713211253757017577 0ustar chrisdaemon"""This module contains helper functions for code generation.""" # Copyright (C) 2010, 2013 Kent-Andre Mardal # Copyright (C) 2008 Martin Sandve Alnes # Copyright (C) 2009 Ilmar Wilbers # Copyright (C) 2013 Garth N. Wells # # This file is part of Instant. # # Instant 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 3 of the License, or # (at your option) any later version. # # Instant 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 Instant. If not, see . # # Alternatively, Instant may be distributed under the terms of the BSD license. import sys import re, os, io from .output import instant_assert, instant_warning, instant_debug, write_file from .config import get_swig_binary def mapstrings(format, sequence): return "\n".join(format % i for i in sequence) def reindent(code): '''Reindent a multiline string to allow easier to read syntax. Each line will be indented relative to the first non-empty line. Start the first line without text like shown in this example:: code = reindent(""" Foo Bar Blatti Ping """) makes all indentation relative to Foo. ''' lines = code.split("\n") space = "" # Get initial spaces from first non-empty line: for l in lines: if l: r = re.search(r"^( [ ]*)", l) if r is not None: space = r.groups()[0] break if not space: return code n = len(space) instant_assert(space == " "*n, "Logic breach in reindent.") return "\n".join(re.sub(r"^%s" % space, "", l) for l in lines) def write_interfacefile(filename, modulename, code, init_code, additional_definitions, additional_declarations, system_headers, local_headers, wrap_headers, arrays): """Generate a SWIG interface file. Intended for internal library use. The input arguments are as follows: - modulename (Name of the module) - code (Code to be wrapped) - init_code (Code to put in the init section of the interface file) - additional_definitions (Definitions to be placed in initial block with C code as well as in the main section of the SWIG interface file) - additional_declarations (Declarations to be placed in the main section of the SWIG interface file) - system_headers (A list of system headers with declarations needed by the wrapped code) - local_headers (A list of local headers with declarations needed by the wrapped code) - wrap_headers (A list of local headers that will be included in the code and wrapped by SWIG) - arrays (A nested list, the inner lists describing the different arrays) The result of this function is that a SWIG interface with the name modulename.i is written to the current directory. """ instant_debug("Generating SWIG interface file '%s'." % filename) # create typemaps typemaps = "" valid_types = ['float', 'double', 'short', 'int', 'long', 'long long', 'unsigned short', 'unsigned int', 'unsigned long', 'unsigned long long'] for a in arrays: if isinstance(a, tuple): a = list(a) DATA_TYPE = 'double' for vt in valid_types: if vt in a: DATA_TYPE = vt a.remove(vt) if 'in' in a: # input arrays a.remove('in') instant_assert(len(a) > 1 and len(a) < 5, "Wrong number of elements in input array") if len(a) == 2: # 1-dimensional arrays, i.e. vectors typemaps += reindent(""" %%apply (int DIM1, %(dtype)s* IN_ARRAY1) {(int %(n1)s, %(dtype)s* %(array)s)}; """ % { 'n1' : a[0], 'array' : a[1], 'dtype' : DATA_TYPE }) elif len(a) == 3: # 2-dimensional arrays, i.e. matrices typemaps += reindent(""" %%apply (int DIM1, int DIM2, %(dtype)s* IN_ARRAY2) {(int %(n1)s, int %(n2)s, %(dtype)s* %(array)s)}; """ % { 'n1' : a[0], 'n2' : a[1], 'array' : a[2], 'dtype' : DATA_TYPE }) else: # 3-dimensional arrays, i.e. tensors typemaps += reindent(""" %%apply (int DIM1, int DIM2, int DIM3, %(dtype)s* IN_ARRAY3) {(int %(n1)s, int %(n2)s, int %(n3)s, %(dtype)s* %(array)s)}; """ % { 'n1' : a[0], 'n2' : a[1], 'n3' : a[2], 'array' : a[3], 'dtype' : DATA_TYPE }) elif 'out' in a: # output arrays a.remove('out') instant_assert(len(a) == 2, "Output array must be 1-dimensional") # 1-dimensional arrays, i.e. vectors typemaps += reindent(""" %%apply (int DIM1, %(dtype)s* ARGOUT_ARRAY1) {(int %(n1)s, %(dtype)s* %(array)s)}; """ % { 'n1' : a[0], 'array' : a[1], 'dtype' : DATA_TYPE }) else: # in-place arrays instant_assert(len(a) > 1 and len(a) < 5, "Wrong number of elements in output array") if 'multi' in a: # n-dimensional arrays, i.e. tensors > 3-dimensional a.remove('multi') typemaps += reindent(""" %%typemap(in) (int %(n)s,int* %(ptv)s,%(dtype)s* %(array)s){ if (!PyArray_Check($input)) { PyErr_SetString(PyExc_TypeError, "Not a NumPy array"); return NULL; ; } PyArrayObject* pyarray; pyarray = (PyArrayObject*)$input; $1 = int(pyarray->nd); int* dims = new int[$1]; for (int d=0; d<$1; d++) { dims[d] = int(pyarray->dimensions[d]); } $2 = dims; $3 = (%(dtype)s*)pyarray->data; } %%typemap(freearg) (int %(n)s,int* %(ptv)s,%(dtype)s* %(array)s){ // deleting dims delete $2; } """ % { 'n' : a[0] , 'ptv' : a[1], 'array' : a[2], 'dtype' : DATA_TYPE }) elif len(a) == 2: # 1-dimensional arrays, i.e. vectors typemaps += reindent(""" %%apply (int DIM1, %(dtype)s* INPLACE_ARRAY1) {(int %(n1)s, %(dtype)s* %(array)s)}; """ % { 'n1' : a[0], 'array' : a[1], 'dtype' : DATA_TYPE }) elif len(a) == 3: # 2-dimensional arrays, i.e. matrices typemaps += reindent(""" %%apply (int DIM1, int DIM2, %(dtype)s* INPLACE_ARRAY2) {(int %(n1)s, int %(n2)s, %(dtype)s* %(array)s)}; """ % { 'n1' : a[0], 'n2' : a[1], 'array' : a[2], 'dtype' : DATA_TYPE }) else: # 3-dimensional arrays, i.e. tensors typemaps += reindent(""" %%apply (int DIM1, int DIM2, int DIM3, %(dtype)s* INPLACE_ARRAY3) {(int %(n1)s, int %(n2)s, int %(n3)s, %(dtype)s* %(array)s)}; """ % { 'n1' : a[0], 'n2' : a[1], 'n3' : a[2], 'array' : a[3], 'dtype' : DATA_TYPE}) # end # end if # end for system_headers_code = mapstrings('#include <%s>', system_headers) local_headers_code = mapstrings('#include "%s"', local_headers) wrap_headers_code1 = mapstrings('#include "%s"', wrap_headers) wrap_headers_code2 = mapstrings('%%include "%s"', wrap_headers) numpy_i_include = '' if arrays: numpy_i_include = r'%include "numpy.i"' # Do not reindent as SWIG interface code can also include Python code. interface_string = """%%module %(modulename)s //%%module (directors="1") %(modulename)s //%%feature("director"); %%{ #include %(additional_definitions)s %(system_headers_code)s %(local_headers_code)s %(wrap_headers_code1)s %(code)s %%} //%%feature("autodoc", "1"); %(numpy_i_include)s %%init%%{ %(init_code)s %%} %(additional_definitions)s %(additional_declarations)s %(wrap_headers_code2)s //%(typemaps)s %(code)s; """ % locals() write_file(filename, interface_string) instant_debug("Done generating interface file.") def write_setup(filename, modulename, csrcs, cppsrcs, local_headers, include_dirs, library_dirs, libraries, swig_include_dirs, swigargs, cppargs, lddargs): """Generate a setup.py file. Intended for internal library use.""" instant_debug("Generating %s." % filename) swig_include_dirs.append(os.path.join(os.path.dirname(__file__), 'swig')) # Handle arguments swigfilename = "%s.i" % modulename wrapperfilename = "%s_wrap.cxx" % modulename # Treat C and C++ files in the same way for now cppsrcs = cppsrcs + csrcs + [wrapperfilename] swig_args = "" if swigargs: swig_args = " ".join(swigargs) compile_args = "" if cppargs: compile_args = ", extra_compile_args=%r" % cppargs link_args = "" if lddargs: link_args = ", extra_link_args=%r" % lddargs swig_include_dirs = " ".join("-I%s"%d for d in swig_include_dirs) if len(local_headers) > 0: swig_include_dirs += " -I.." py3 = "" if sys.version_info[0] < 3 else "-py3" # Generate code code = reindent(""" import os from distutils.core import setup, Extension name = '%s' swig_cmd =r'%s -python %s %s %s %s' os.system(swig_cmd) sources = %s setup(name = '%s', ext_modules = [Extension('_' + '%s', sources, include_dirs=%s, library_dirs=%s, libraries=%s %s %s)]) """ % (modulename, get_swig_binary(), py3, swig_include_dirs, swig_args, \ swigfilename, cppsrcs, modulename, modulename, include_dirs, \ library_dirs, libraries, compile_args, link_args)) write_file(filename, code) instant_debug("Done writing setup.py file.") def _test_write_interfacefile(): modulename = "testmodule" code = "void foo() {}" init_code = "/* custom init code */" additional_definitions = "/* custom definitions */" additional_declarations = "/* custom declarations */" system_headers = ["system_header1.h", "system_header2.h"] local_headers = ["local_header1.h", "local_header2.h"] wrap_headers = ["wrap_header1.h", "wrap_header2.h"] arrays = [["length1", "array1"], ["dims", "lengths", "array2"]] write_interfacefile("%s.i" % modulename, modulename, code, init_code, additional_definitions, additional_declarations, system_headers, local_headers, wrap_headers, arrays) print("".join(io.open("%s.i" % modulename, encoding="utf8").readlines())) def _test_write_setup(): modulename = "testmodule" csrcs = ["csrc1.c", "csrc2.c"] cppsrcs = ["cppsrc1.cpp", "cppsrc2.cpp"] local_headers = ["local_header1.h", "local_header2.h"] include_dirs = ["includedir1", "includedir2"] library_dirs = ["librarydir1", "librarydir2"] libraries = ["lib1", "lib2"] swig_include_dirs = ["swigdir1", "swigdir2"], swigargs = ["-Swigarg1", "-Swigarg2"] cppargs = ["-cpparg1", "-cpparg2"] lddargs = ["-Lddarg1", "-Lddarg2"] write_setup("setup.py", modulename, csrcs, cppsrcs, local_headers, \ include_dirs, library_dirs, libraries, swig_include_dirs, \ swigargs, cppargs, lddargs) print("".join(io.open("setup.py", encoding="utf8").readlines())) def unique(sequence): return list(set(sequence)) def find_vtk_classes(str): pattern = "vtk\w*" l = unique(re.findall(pattern, str)) return l def create_typemaps(classes): s = "" typemap_template = """ %%typemap(in) %(class_name)s * { vtkObjectBase* obj = vtkPythonGetPointerFromObject($input, "%(class_name)s"); %(class_name)s * oobj = NULL; if (obj->IsA("%(class_name)s")) { oobj = %(class_name)s::SafeDownCast(obj); $1 = oobj; } } %%typemap(out) %(class_name)s * { $result = vtkPythonGetObjectFromPointer($1); } """ for cl in classes: s += typemap_template % { "class_name" : cl } return s def generate_vtk_includes(classes): s = """ #include "vtkPythonUtil.h" """ for cl in classes: s += """ #include \"%s.h\" """ % cl return s def generate_interface_file_vtk(signature, code): interface_template = """ %%module test %%{ %(includes)s %(code)s %%} %(typemaps)s %(code)s """ class_list = find_vtk_classes(code) includes = generate_vtk_includes(class_list) typemaps = create_typemaps(class_list) s = interface_template % { "typemaps" : typemaps, "code" : code, "includes" : includes } return s def write_cmakefile(module_name, cmake_packages, csrcs, cppsrcs, local_headers, include_dirs, library_dirs, libraries, swig_include_dirs, swigargs, cppargs, lddargs): find_package_template = """ # Configuration for package %(package)s FIND_PACKAGE(%(package)s REQUIRED) IF(%(package)s_FOUND) INCLUDE(${%(PACKAGE)s_USE_FILE}) ENDIF(%(package)s_FOUND) """ cmake_form = dict(module_name=module_name) # Major hack to adress # https://bitbucket.org/fenics-project/dolfin/pull-requests/358/add-petsc-and-slepc-include-directories-in/ p = "" for package in cmake_packages: p += package.lower() + " " cmake_form["cmake_dep_targets"] = p cmake_form["python_executable"] = sys.executable cmake_form["extra_libraries"] = ";".join(libraries) cmake_form["extra_include_dirs"] = ";".join(include_dirs) cmake_form["extra_library_dirs"] = ";".join(library_dirs) cmake_form["extra_swig_include_dirs"] = " -I".join([" "] + swig_include_dirs) cmake_form["extra_swigargs"] = " ".join(swigargs) cmake_form["swig_executable"] = "\n".join(\ """if (DEFINED %(package)s_SWIG_EXECUTABLE) set(SWIG_EXECUTABLE ${%(package)s_SWIG_EXECUTABLE}) endif() """ % dict(package=package.upper()) for package in cmake_packages) cmake_form["find_packages"] = "\n\n".join(find_package_template % \ dict(package=package, PACKAGE=package.upper())\ for package in cmake_packages) cmake_form["packages_definitions"] = "\n".join( "${%s_CXX_DEFINITIONS}" % package.upper() for package in cmake_packages) cmake_form["packages_definitions"] += "\n"+"\n".join( "${%s_PYTHON_DEFINITIONS}" % package.upper() for package in cmake_packages) cmake_form["package_include_dirs"] = "\n".join(\ "include_directories(${%(package)s_PYTHON_INCLUDE_DIRS} ${%(package)s_3RD_PARTY_INCLUDE_DIRS} ${${NAME}_SOURCE_DIR})" % dict(package=package.upper()) for package in cmake_packages) cmake_form["package_flags"] = "\n".join(\ """set(CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS} ${%(package)s_LINK_FLAGS}\") set(CMAKE_SHARED_LINKER_FLAGS \"${CMAKE_SHARED_LINKER_FLAGS} ${%(package)s_LINK_FLAGS}\") """ % dict(package=package.upper()) for package in cmake_packages) cmake_form["package_swig_link_libraries"] = "\n".join(\ """if (DEFINED %(package)s_LIBRARIES OR DEFINED %(package)s_3RD_PARTY_LIBRARIES OR DEFINED %(package)s_PYTHON_LIBRARIES) swig_link_libraries(${SWIG_MODULE_NAME} ${%(package)s_LIBRARIES} ${%(package)s_3RD_PARTY_LIBRARIES} ${%(package)s_PYTHON_LIBRARIES} ${EXTRA_SOURCE_LIB}) endif()""" % dict(package=package.upper()) for package in cmake_packages) cmake_form["package_python_definitions"] = "\n".join(\ """if (DEFINED %(package)s_PYTHON_DEFINITIONS) add_definitions(${%(package)s_PYTHON_DEFINITIONS}) endif()""" % dict(package=package.upper()) for package in cmake_packages) cppsrcs.extend(csrcs) if len(cppsrcs) > 0: cmake_form["extra_sources_files"] = "set(SOURCE_FILES %s) " % " ".join(cppsrcs) else: cmake_form["extra_sources_files"] = "set(SOURCE_FILES)" if cppargs: cmake_form["cppargs"] = "set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} %s\")" % \ (" ".join(cppargs)) else: cmake_form["cppargs"] = "" if lddargs: cmake_form["lddargs"] = "set(CMAKE_EXE_LINKER_FLAGS \""\ "${CMAKE_EXE_LINKER_FLAGS} %s\")" % (" ".join(lddargs)) else: cmake_form["lddargs"] = "" cmake_template = """ cmake_minimum_required(VERSION 3.5.0) set (NAME %(module_name)s) PROJECT(${NAME}) set(PYTHON_EXECUTABLE %(python_executable)s) %(find_packages)s %(cppargs)s %(lddargs)s %(swig_executable)s find_package(SWIG REQUIRED) include(${SWIG_USE_FILE}) set(SWIG_MODULE_NAME ${NAME}) set(CMAKE_SWIG_FLAGS -module ${SWIG_MODULE_NAME} -shadow -modern -modernargs -fastdispatch -fvirtual -nosafecstrings -noproxydel -fastproxy -fastinit -fastunpack -fastquery -nobuildnone %(packages_definitions)s %(extra_swigargs)s %(extra_swig_include_dirs)s ) set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) set(SWIG_SOURCES ${NAME}.i) set_source_files_properties(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) set(EXTRA_INCLUDE_DIRS \"%(extra_include_dirs)s\") if(EXTRA_INCLUDE_DIRS) include_directories(${EXTRA_INCLUDE_DIRS}) endif() %(package_include_dirs)s %(package_flags)s set(EXTRA_LIBRARY_DIRS \"%(extra_library_dirs)s\") if(EXTRA_LIBRARY_DIRS) link_directories(${EXTRA_LIBRARY_DIRS}) endif() %(extra_sources_files)s %(package_python_definitions)s swig_add_module(${SWIG_MODULE_NAME} python ${SWIG_SOURCES}) set(EXTRA_LIBRARIES %(extra_libraries)s) if(SOURCE_FILES) set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -fpic\") add_library(source_file_lib STATIC ${SOURCE_FILES}) set(EXTRA_LIBRARIES \"source_file_lib;${EXTRA_LIBRARIES}\") target_link_libraries(source_file_lib %(cmake_dep_targets)s) endif() if(EXTRA_LIBRARIES) string(STRIP \"${EXTRA_LIBRARIES}\" EXTRA_LIBRARIES) swig_link_libraries(${SWIG_MODULE_NAME} ${EXTRA_LIBRARIES}) endif() %(package_swig_link_libraries)s """ % cmake_form filename = "CMakeLists.txt" write_file(filename, cmake_template) def write_itk_cmakefile(name): file_template = """ cmake_minimum_required(VERSION 2.6.0) # This project is designed to be built outside the Insight source tree. PROJECT(%(name)%s) # Find ITK. FIND_PACKAGE(ITK REQUIRED) IF(ITK_FOUND) INCLUDE(${ITK_USE_FILE}) ENDIF(ITK_FOUND) # Find VTK. FIND_PACKAGE(VTK REQUIRED) IF(VTK_FOUND) INCLUDE(${VTK_USE_FILE}) ENDIF(VTK_FOUND) find_package(SWIG REQUIRED) include(${SWIG_USE_FILE}) set(SWIG_MODULE_NAME %(name)s) set(CMAKE_SWIG_FLAGS -module ${SWIG_MODULE_NAME} -shadow -modern -modernargs -fastdispatch -fvirtual -nosafecstrings -noproxydel -fastproxy -fastinit -fastunpack -fastquery -nobuildnone -Iinclude/swig ) set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) set(SWIG_SOURCES %(name)s.i) set_source_files_properties(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) include_directories(${PYTHON_INCLUDE_PATH} ${%(name)s_SOURCE_DIR}) set(VTK_LIBS ITKCommon vtkCommon vtkImaging vtkIO vtkFiltering vtkRendering vtkGraphics vtkCommonPythonD vtkFilteringPythonD) # Work-around for bug in CMake 3.0.0 (see # http://www.cmake.org/Bug/view.php?id=14990) set(SWIG_MODULE_NAME_ORIG "${SWIG_MODULE_NAME}") if (${CMAKE_VERSION} MATCHES "3.0.0") set(SWIG_MODULE_NAME "_${SWIG_MODULE_NAME}") endif() swig_add_module(${SWIG_MODULE_NAME} python ${SWIG_SOURCES}) swig_link_libraries(${SWIG_MODULE_NAME} ${PYTHON_LIBRARIES} ${VTK_LIBS}) """ % { "name" : name } with io.open("CMakeLists.txt", 'w', encoding="utf8") as f: f.write(file_template) def write_vmtk_cmakefile(name): file_template = """ cmake_minimum_required(VERSION 2.6.0) # This project is designed to be built outside the Insight source tree. PROJECT(%(name)%s) # Find ITK. FIND_PACKAGE(ITK REQUIRED) IF(ITK_FOUND) INCLUDE(${ITK_USE_FILE}) ENDIF(ITK_FOUND) # Find VTK. FIND_PACKAGE(VTK REQUIRED) IF(VTK_FOUND) INCLUDE(${VTK_USE_FILE}) ENDIF(VTK_FOUND) # Find VMTK. #FIND_PACKAGE(VMTK REQUIRED) #IF(VMTK_FOUND) # INCLUDE(${VMTK_USE_FILE}) #ENDIF(ITK_FOUND) find_package(SWIG REQUIRED) include(${SWIG_USE_FILE}) set(SWIG_MODULE_NAME %(name)s) set(CMAKE_SWIG_FLAGS -module ${SWIG_MODULE_NAME} -shadow -modern -modernargs -fastdispatch -fvirtual -nosafecstrings -noproxydel -fastproxy -fastinit -fastunpack -fastquery -nobuildnone -Iinclude/swig ) set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}) set(SWIG_SOURCES %(name)s.i) set_source_files_properties(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) include_directories(${PYTHON_INCLUDE_PATH} ${%(name)s_SOURCE_DIR} /usr/local/include/vmtk) link_directories(/usr/local/lib/vmtk .) set(VTK_LIBS ITKCommon vtkCommon vtkImaging vtkIO vtkFiltering vtkRendering vtkGraphics vtkCommonPythonD vtkFilteringPythonD) set(VMTK_LIBS vtkvmtkCommonPythonD vtkvmtkITKPythonD vtkvmtkCommon vtkvmtkITK vtkvmtkComputationalGeometryPythonD vtkvmtkMiscPythonD vtkvmtkComputationalGeometry vtkvmtkMisc vtkvmtkDifferentialGeometryPythonD vtkvmtkSegmentationPythonD vtkvmtkDifferentialGeometry vtkvmtkSegmentation vtkvmtkIOPythonD) # Work-around for bug in CMake 3.0.0 (see # http://www.cmake.org/Bug/view.php?id=14990) set(SWIG_MODULE_NAME_ORIG "${SWIG_MODULE_NAME}") if (${CMAKE_VERSION} MATCHES "3.0.0") set(SWIG_MODULE_NAME "_${SWIG_MODULE_NAME}") endif() swig_add_module(${SWIG_MODULE_NAME} python ${SWIG_SOURCES}) swig_link_libraries(${SWIG_MODULE_NAME} ${PYTHON_LIBRARIES} ${VTK_LIBS} ${VMTK_LIBS}) """ % { "name" : name } with io.open("CMakeLists.txt", 'w', encoding="utf8") as f: f.write(file_template) def write_vtk_interface_file(signature, code): filename = signature ifile = filename + ".i" ifile_code = generate_interface_file_vtk(signature, code) with io.open(ifile, 'w', encoding="utf8") as iff: iff.write(ifile_code) if __name__ == "__main__": _test_write_interfacefile() print("\n"*3) _test_write_setup() instant-2017.2.0/instant/inlining.py0000644000231000000010000001407013211253757016406 0ustar chrisdaemon"""This module contains the inline* functions, which allows easy inlining of C/C++ functions.""" # Copyright (C) 2008-2010 Kent-Andre Mardal # Copyright (C) 2008-2010 Martin Sandve Alnes # # This file is part of Instant. # # Instant 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 3 of the License, or # (at your option) any later version. # # Instant 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 Instant. If not, see . # # Alternatively, Instant may be distributed under the terms of the BSD license. from .output import instant_assert, instant_warning, instant_error from .build import build_module, build_module_vtk, build_module_vmtk def get_func_name(c_code): # TODO: Something more robust? Regexp? try: func = c_code[:c_code.index('(')] ret, func_name = func.split() except: instant_error("Failed to extract function name from c_code.") return func_name def inline(c_code, **kwargs): """This is a short wrapper around the build_module function in instant. It creates a module given that the input is a valid C function. It is only possible to inline one C function each time. Usage: >>> from instant import inline >>> add_func = inline("double add(double a, double b){ return a+b; }") >>> print "The sum of 3 and 4.5 is ", add_func(3, 4.5) """ instant_assert("code" not in kwargs, "Cannot specify code twice.") kwargs["code"] = c_code func_name = get_func_name(c_code) module = build_module(**kwargs) if hasattr(module, func_name): return getattr(module, func_name) else: instant_warning("Didn't find function '%s', returning module." % func_name) return module def inline_module(c_code, **kwargs): """This is a short wrapper around the build_module function in instant. It creates a module given that the input is a valid C function. It is only possible to inline one C function each time. Usage: >>> from instant import inline >>> add_func = inline("double add(double a, double b){ return a+b; }") >>> print "The sum of 3 and 4.5 is ", add_func(3, 4.5) """ instant_assert("code" not in kwargs, "Cannot specify code twice.") kwargs["code"] = c_code module = build_module(**kwargs) return module def inline_with_numpy(c_code, **kwargs): '''This is a short wrapper around the build_module function in instant. It creates a module given that the input is a valid C function. It is only possible to inline one C function each time. The difference between this function and the inline function is that C-arrays can be used. The following example illustrates that. Usage: >>> import numpy >>> import time >>> from instant import inline_with_numpy >>> c_code = """ double sum (int n1, double* array1){ double tmp = 0.0; for (int i=0; i>> sum_func = inline_with_numpy(c_code, arrays = [['n1', 'array1']]) >>> a = numpy.arange(10000000); a = numpy.sin(a) >>> sum_func(a) ''' import numpy instant_assert("code" not in kwargs, "Cannot specify code twice.") kwargs["code"] = c_code kwargs["init_code"] = kwargs.get("init_code", "") + "\nimport_array();\n" kwargs["system_headers"] = kwargs.get("system_headers", []) + ["numpy/arrayobject.h"] kwargs["include_dirs"] = kwargs.get("include_dirs", []) + ["%s" %numpy.get_include()] func_name = get_func_name(c_code) module = build_module(**kwargs) if hasattr(module, func_name): return getattr(module, func_name) else: instant_warning("Didn't find function '%s', returning module." % func_name) return module def inline_module_with_numpy(c_code, **kwargs): '''This is a short wrapper around the build_module function in instant. It creates a module given that the input is a valid C function. It is only possible to inline one C function each time. The difference between this function and the inline function is that C-arrays can be used. The following example illustrates that. Usage: >>> import numpy >>> import time >>> from instant import inline_with_numpy >>> c_code = """ double sum (int n1, double* array1){ double tmp = 0.0; for (int i=0; i>> sum_func = inline_with_numpy(c_code, arrays = [['n1', 'array1']]) >>> a = numpy.arange(10000000); a = numpy.sin(a) >>> sum_func(a) ''' import numpy instant_assert("code" not in kwargs, "Cannot specify code twice.") kwargs["code"] = c_code kwargs["init_code"] = kwargs.get("init_code", "") + "\nimport_array();\n" kwargs["system_headers"] = kwargs.get("system_headers", []) + ["numpy/arrayobject.h"] kwargs["include_dirs"] = kwargs.get("include_dirs", []) + ["%s" % numpy.get_include()] module = build_module(**kwargs) return module def inline_vtk(c_code, cache_dir=None): module = build_module_vtk(c_code) func_name = get_func_name(c_code) if hasattr(module, func_name): return getattr(module, func_name) else: instant_warning("Didn't find function '%s', returning module." % func_name) return module def inline_vmtk(c_code, cache_dir=None): module = build_module_vmtk(c_code) func_name = get_func_name(c_code) if hasattr(module, func_name): return getattr(module, func_name) else: instant_warning("Didn't find function '%s', returning module." % func_name) return module instant-2017.2.0/instant/signatures.py0000644000231000000010000000442513211253757016766 0ustar chrisdaemon"""This module contains helper functions for working with checksums.""" # Copyright (C) 2008 Martin Sandve Alnes # # This file is part of Instant. # # Instant 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 3 of the License, or # (at your option) any later version. # # Instant 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 Instant. If not, see . # # Alternatively, Instant may be distributed under the terms of the BSD license. from six import string_types import io import hashlib from .output import instant_assert, instant_debug, instant_error def compute_checksum(text="", filenames=[]): """ Get the checksum value of filename modified based on Python24\Tools\Scripts\md5.py """ instant_assert(isinstance(text, string_types), "Expecting string.") instant_assert(isinstance(filenames, (list, tuple)), "Expecting sequence.") m = hashlib.new('sha1') if text: m.update(text.encode('utf-8')) for filename in sorted(filenames): instant_debug("Adding file '%s' to checksum." % filename) try: fp = io.open(filename, 'rb') except IOError as e: instant_error("Can't open file '%s': %s" % (filename, e)) try: while True: data = fp.read() if not data: break m.update(data) except IOError as e: instant_error("I/O error reading '%s': %s" % (filename, e)) fp.close() return m.hexdigest().lower() def _test(): signature = "(Test signature)" files = ["signatures.py", "__init__.py"] print() print("Signature:", repr(signature)) print("Checksum:", compute_checksum(signature, [])) print() print("Files:", files) print("Checksum:", compute_checksum("", files)) print() if __name__ == "__main__": _test() instant-2017.2.0/instant/build.py0000644000231000000010000006763313211253757015713 0ustar chrisdaemon"""This module contains the main part of Instant, the build_module function.""" # Copyright (C) 2008-2013 Kent-Andre Mardal # Copyright (C) 2008-2013 Martin Sandve Alnes # Copyright (C) 2009-2014 Johan Hake # Copyright (C) 2009 Ilmar Wilbers # # This file is part of Instant. # # Instant 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 3 of the License, or # (at your option) any later version. # # Instant 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 Instant. If not, see . # # Alternatively, Instant may be distributed under the terms of the BSD license. import six from six import string_types import io, os, sys, shutil, glob, errno from itertools import chain # TODO: Import only the official interface from .output import * from .paths import * from .signatures import * from .cache import * from .codegeneration import * from .locking import file_lock def assert_is_str(x): instant_assert(isinstance(x, string_types), "In instant.build_module: Expecting string.") def assert_is_bool(x): instant_assert(isinstance(x, bool), "In instant.build_module: Expecting bool.") def assert_is_str_list(x): instant_assert(isinstance(x, (list, tuple)), "In instant.build_module: Expecting sequence.") instant_assert(all(isinstance(i, string_types) for i in x), "In instant.build_module: Expecting sequence of strings.") def strip_strings(x): assert_is_str_list(x) return [s.strip() for s in x] def arg_strings(x): if isinstance(x, string_types): x = x.split() return strip_strings(x) def makedirs(path): """ Creates a directory (tree). If directory already excists it does nothing. """ try: os.makedirs(path) except os.error as e: if e.errno != errno.EEXIST: raise def copy_files(source, dest, files): """Copy a list of files from a source directory to a destination directory. This may seem a bit complicated, but a lot of this code is error checking. """ if os.path.exists(dest): overwriting = set(files) & set(glob.glob(os.path.join(dest, "*"))) if overwriting: instant_warning("In instant.copy_files: Path '%s' already exists, "\ "overwriting existing files: %r." % (dest, list(overwriting))) else: makedirs(dest) if source != dest: instant_debug("In instant.copy_files: Copying files %r from %r to %r"\ % (files, source, dest)) for f in files: a = os.path.join(source, f) b = os.path.join(dest, f) instant_assert(a != b, "In instant.copy_files: Seems like the "\ "input files are absolute paths, should be relative to "\ "source. (%r, %r)" % (a, b)) instant_assert(os.path.isfile(a), "In instant.copy_files: "\ "Missing source file '%s'." % a) if os.path.isfile(b): os.remove(b) shutil.copyfile(a, b) def recompile(modulename, module_path, new_compilation_checksum, build_system="distutils"): """Recompile module if the new checksum is different from the one in the checksum file in the module directory.""" assert(build_system in ["distutils", "cmake"]) # Check if the old checksum matches the new one compilation_checksum_filename = "%s.checksum" % modulename if os.path.exists(compilation_checksum_filename): checksum_file = io.open(compilation_checksum_filename, encoding="utf8") old_compilation_checksum = checksum_file.readline() checksum_file.close() if old_compilation_checksum == new_compilation_checksum: return # Create log file for logging of compilation errors compile_log_filename = os.path.join(module_path, "compile.log") compile_log_filename_dest = os.path.join(get_default_error_dir(), \ modulename, "compile.log") ret = 1 try: compile_log_contents = None instant_info("--- Instant: compiling ---") # TODO: The three blocks below can be made a function and # three calls if build_system == "distutils": # Build extension module with distutils python_interp = sys.executable cmd = python_interp + " setup.py build_ext install --install-platlib=." instant_debug("cmd = %s" % cmd) ret, output = get_status_output(cmd) write_file(compile_log_filename, output) if ret != 0: compile_log_contents = output if os.path.exists(compilation_checksum_filename): os.remove(compilation_checksum_filename) msg = "In instant.recompile: The module did not compile with command '%s', see '%s'" instant_error(msg % (cmd, compile_log_filename_dest)) else: # Build makefile for extension module with cmake cmd = "cmake -DDEBUG=TRUE ."; #cmd = "cmake ."; instant_debug("cmd = %s" % cmd) ret, output = get_status_output(cmd) write_file(compile_log_filename, output) if ret != 0: compile_log_contents = output if os.path.exists(compilation_checksum_filename): os.remove(compilation_checksum_filename) msg = "In instant.recompile: The module did not compile with command '%s', see '%s'" instant_error(msg % (cmd, compile_log_filename_dest)) # Build extension module with cmake generated makefile cmd = "make VERBOSE=1" instant_debug("cmd = %s" % cmd) ret, output = get_status_output(cmd) write_file(compile_log_filename, output, mode="a") if ret != 0: compile_log_contents = output if os.path.exists(compilation_checksum_filename): os.remove(compilation_checksum_filename) msg = "In instant.recompile: The module did not compile with command '%s', see '%s'" instant_error(msg % (cmd, compile_log_filename_dest)) finally: if ret != 0: if "INSTANT_DISPLAY_COMPILE_LOG" in list(os.environ.keys()): instant_warning("") instant_warning("Content of instant compile.log") instant_warning("==============================") instant_warning(compile_log_contents) instant_warning("") # Copy module to error dir module_path = copy_to_cache(module_path, get_default_error_dir(), modulename, check_for_existing_path=False) # Compilation succeeded, write new_compilation_checksum to # checksum_file write_file(compilation_checksum_filename, new_compilation_checksum) def copy_to_cache(module_path, cache_dir, modulename, check_for_existing_path=True): "Copy module directory to cache." # Get lock, check if the module exists, _otherwise_ copy the # finished compiled module from /tmp/foo to the cache directory, # and then release lock with file_lock(cache_dir, modulename) as lock: # Validate the path cache_module_path = os.path.join(cache_dir, modulename) if check_for_existing_path and os.path.exists(os.path.join(\ cache_module_path, "finished_copying")): # This indicates a race condition has happened (and is # being avoided!). instant_warning("In instant.build_module: Path '%s' already exists,"\ " but module wasn't found in cache previously. Not overwriting,"\ " assuming this module is valid." % cache_module_path) return cache_module_path # Not deleting anymore, relying on locking system #shutil.rmtree(cache_module_path, ignore_errors=True) # Error checks instant_assert(os.path.isdir(module_path), "In instant.build_module:"\ " Cannot copy non-existing directory %r!" % module_path) if check_for_existing_path and os.path.isdir(cache_module_path): instant_error("In instant.build_module: Cache directory %r shouldn't"\ " exist at this point!" % cache_module_path) instant_debug("In instant.build_module: Copying built module from %r"\ " to cache at %r" % (module_path, cache_module_path)) # Do the copying and mark that we are finished by creating an # empty file finished_copying try: shutil.copytree(module_path, cache_module_path) with io.open(os.path.join(cache_module_path, "finished_copying"), "w", encoding="utf8") as dummy: pass except OSError as e: if e.errno != errno.EEXIST: raise finally: delete_temp_dir() return cache_module_path def build_module(modulename=None, source_directory=".", code="", init_code="", additional_definitions="", additional_declarations="", sources=[], wrap_headers=[], local_headers=[], system_headers=[], include_dirs=['.'], library_dirs=[], libraries=[], swigargs=['-c++', '-fcompact', '-O', '-I.', '-small'], swig_include_dirs = [], cppargs=['-O2'], lddargs=[], object_files=[], arrays=[], generate_interface=True, generate_setup=True, cmake_packages=[], signature=None, cache_dir=None): """Generate and compile a module from C/C++ code using SWIG. Arguments: ========== The keyword arguments are as follows: - B{modulename}: - The name you want for the module. If specified, the module will not be cached. If missing, a name will be constructed based on a checksum of the other arguments, and the module will be placed in the global cache. String. - B{source_directory}: - The directory where user supplied files reside. The files given in B{sources}, B{wrap_headers}, and B{local_headers} are expected to exist in this directory. String. - B{code}: - A string containing C or C++ code to be compiled and wrapped. String. - B{init_code}: - Code that should be executed when the Instant module is imported. This code is inserted in the SWIG interface file, and is used for instance for calling C{import_array()} used for the initialization of NumPy arrays. String. - B{additional_definitions}: - Additional definitions (typically needed for inheritance) for interface file. These definitions should be given as triple-quoted strings in the case they span multiple lines, and are placed both in the initial block for C/C++ code (C{%{,%}}-block), and the main section of the interface file. String. - B{additional_declarations}: - Additional declarations (typically needed for inheritance) for interface file. These declarations should be given as triple-quoted strings in the case they span multiple lines, and are plaves in the main section of the interface file. String. - B{sources}: - Source files to compile and link with the module. These files are compiled togehter with the SWIG-generated wrapper file into the final library file. Should reside in directory specified in B{source_directory}. List of strings. - B{wrap_headers}: - Local header files that should be wrapped by SWIG. The files specified will be included both in the initial block for C/C++ code (with a C directive) and in the main section of the interface file (with a SWIG directive). Should reside in directory specified in B{source_directory}. List of strings. - B{local_headers}: - Local header files required to compile the wrapped code. The files specified will be included in the initial block for C/C++ code (with a C directive). Should reside in directory specified in B{source_directory}. List of strings. - B{system_headers}: - System header files required to compile the wrapped code. The files specified will be included in the initial block for C/C++ code (with a C directive). List of strings. - B{include_dirs}: - Directories to search for header files for building the extension module. Needs to be absolute path names. List of strings. - B{library_dirs}: - Directories to search for libraries (C{-l}) for building the extension module. Needs to be absolute paths. List of strings. - B{libraries}: - Libraries needed by the Instant module. The libraries will be linked in from the shared object file. The initial C{-l} is added automatically. List of strings. - B{swigargs}: - List of arguments to swig, e.g. C{["-lpointers.i"]} to include the SWIG pointers.i library. - B{swig_include_dirs}: - A list of directories to include in the 'swig' command. - B{cppargs}: - List of arguments to the compiler, e.g. C{["-Wall", "-fopenmp"]}. - B{lddargs}: - List of arguments to the linker, e.g. C{["-E", "-U"]}. - B{object_files}: - If you want to compile the files yourself. TODO: Not yet supported. - B{arrays}: - A nested list describing the C arrays to be made from NumPy arrays. The SWIG interface for fil NumPy is used. For 1D arrays, the inner list should contain strings with the variable names for the length of the arrays and the array itself. 2D matrices should contain the names of the dimensions in the two directions as well as the name of the array, and 3D tensors should contain the names of the dimensions in the three directions in addition to the name of the array. If the NumPy array har more than four dimensions, the inner list should contain strings with variable names for the number of dimensions, the length in each dimension as a pointer, and the array itself, respectively. - B{generate_interface}: - A bool to indicate if you want to generate the interface files. - B{generate_setup}: - A bool to indicate if you want to generate the setup.py file. - B{cmake_packages}: - A list with CMake configured packages which are used to configure and build the extension module. If used it will override the default behaviour of using distutils. - B{signature}: - A signature string to identify the form instead of the source code. - B{cache_dir}: - A directory to look for cached modules and place new ones. If missing, a default directory is used. Note that the module will not be cached if B{modulename} is specified. The cache directory should not be used for anything else. """ # Store original directory to be able to restore later original_path = os.getcwd() # --- Validate arguments if sys.version_info[0] > 2: swigargs = swigargs + ['-py3'] instant_assert(modulename is None or isinstance(modulename, string_types), "In instant.build_module: Expecting modulename to be string or None.") assert_is_str(source_directory) source_directory = os.path.abspath(source_directory) assert_is_str(code) assert_is_str(init_code) assert_is_str(additional_definitions) assert_is_str(additional_declarations) sources = strip_strings(sources) wrap_headers = strip_strings(wrap_headers) local_headers = strip_strings(local_headers) system_headers = strip_strings(system_headers) include_dirs = strip_strings(include_dirs) library_dirs = strip_strings(library_dirs) libraries = strip_strings(libraries) swigargs = arg_strings(swigargs) swig_include_dirs = strip_strings(swig_include_dirs) cppargs = arg_strings(cppargs) lddargs = arg_strings(lddargs) object_files = strip_strings(object_files) arrays = [strip_strings(a) for a in arrays] assert_is_bool(generate_interface) assert_is_bool(generate_setup) cmake_packages = strip_strings(cmake_packages) instant_assert(signature is None \ or isinstance(signature, string_types) \ or hasattr(signature, "signature"), "In instant.build_module: Expecting modulename to be string or None.") instant_assert(not (signature is not None and modulename is not None), "In instant.build_module: Can't have both modulename and signature.") # --- Replace arguments with defaults if necessary cache_dir = validate_cache_dir(cache_dir) # Split sources by file-suffix (.c or .cpp) csrcs = [f for f in sources if f.endswith('.c') or f.endswith('.C')] cppsrcs = [f for f in sources if f.endswith('.cpp') or f.endswith('.cxx')] instant_assert(len(csrcs) + len(cppsrcs) == len(sources), "In instant.build_module: Source files must have '.c' or '.cpp' suffix") # --- Debugging code instant_debug('In instant.build_module:') instant_debug('::: Begin Arguments :::') instant_debug(' modulename: %r' % modulename) instant_debug(' source_directory: %r' % source_directory) instant_debug(' code: %r' % code) instant_debug(' init_code: %r' % init_code) instant_debug(' additional_definitions: %r' % additional_definitions) instant_debug(' additional_declarations: %r' % additional_declarations) instant_debug(' sources: %r' % sources) instant_debug(' csrcs: %r' % csrcs) instant_debug(' cppsrcs: %r' % cppsrcs) instant_debug(' wrap_headers: %r' % wrap_headers) instant_debug(' local_headers: %r' % local_headers) instant_debug(' system_headers: %r' % system_headers) instant_debug(' include_dirs: %r' % include_dirs) instant_debug(' library_dirs: %r' % library_dirs) instant_debug(' libraries: %r' % libraries) instant_debug(' swigargs: %r' % swigargs) instant_debug(' swig_include_dirs: %r' % swig_include_dirs) instant_debug(' cppargs: %r' % cppargs) instant_debug(' lddargs: %r' % lddargs) instant_debug(' object_files: %r' % object_files) instant_debug(' arrays: %r' % arrays) instant_debug(' generate_interface: %r' % generate_interface) instant_debug(' generate_setup: %r' % generate_setup) instant_debug(' cmake_packages: %r' % cmake_packages) instant_debug(' signature: %r' % signature) instant_debug(' cache_dir: %r' % cache_dir) instant_debug('::: End Arguments :::') # --- Setup module directory, making it and copying # files to it if necessary, and compute a modulename # if it isn't specified explicitly if modulename is None: # Compute a signature if we have none passed by the user: if signature is None: # Collect arguments used for checksum creation, # including everything that affects the interface # file generation and module compilation. checksum_args = ( \ # We don't care about the modulename, that's what # we're trying to construct! #modulename, # We don't care where the user code resides: #source_directory, code, init_code, additional_definitions, additional_declarations, # Skipping filenames, since we use the file contents: #sources, wrap_headers, #local_headers, system_headers, include_dirs, library_dirs, libraries, swig_include_dirs, swigargs, cppargs, lddargs, object_files, arrays, generate_interface, generate_setup, cmake_packages, # The signature isn't defined, and the cache_dir # doesn't affect the module: #signature, cache_dir) sys.version ) allfiles = sources + wrap_headers + local_headers allfiles = [os.path.join(source_directory, f) for f in allfiles] text = "\n".join((str(a) for a in checksum_args)) signature = modulename_from_checksum(compute_checksum(text, allfiles)) modulename = signature moduleids = [signature] else: module, moduleids = check_memory_cache(signature) if module: return module modulename = moduleids[-1] # Look for module in disk cache module = check_disk_cache(modulename, cache_dir, moduleids) if module: return module # Make a temporary module path for compilation module_path = os.path.join(get_temp_dir(), modulename) instant_assert(not os.path.exists(module_path), "In instant.build_module: Not expecting module_path to exist: '%s'"\ % module_path) makedirs(module_path) use_cache = True else: use_cache = False moduleids = [] module_path = os.path.join(original_path, modulename) makedirs(module_path) ## Look for module in memory cache #module, moduleids = check_memory_cache(modulename) #if module: return module #instant_assert(modulename == moduleids[-1] and len(moduleids) == 1, "Logic breach.") ## Look for module in local directory #module = check_disk_cache(modulename, original_path, moduleids) #if module: return module # Wrapping rest of code in try-block to # clean up at the end if something fails. try: # --- Copy user-supplied files to module path module_path = os.path.abspath(module_path) files_to_copy = sources + wrap_headers + local_headers + object_files copy_files(source_directory, module_path, files_to_copy) # At this point, all user input files should reside in module_path # --- Generate additional files in module directory os.chdir(module_path) # Generate __init__.py which imports compiled module contents write_file("__init__.py", "from __future__ import absolute_import\nfrom .%s import *" \ % modulename) # Generate SWIG interface if wanted ifile_name = "%s.i" % modulename if generate_interface: write_interfacefile(ifile_name, modulename, code, init_code, additional_definitions, additional_declarations, system_headers, local_headers, wrap_headers, arrays) # Generate setup.py if wanted if generate_setup and not cmake_packages: setup_name = "setup.py" write_setup(setup_name, modulename, csrcs, cppsrcs, local_headers, include_dirs, library_dirs, libraries, swig_include_dirs, swigargs, cppargs, lddargs) build_system = "distutils" else: write_cmakefile(modulename, cmake_packages, csrcs, cppsrcs, local_headers, include_dirs, library_dirs, libraries, swig_include_dirs, swigargs, cppargs, lddargs) build_system = "cmake" # --- Build module # At this point we have all the files, and can make the total # checksum from all file contents. This is used to decide # whether the module needs recompilation or not. # Compute new_compilation_checksum # Collect arguments used for checksum creation, # including everything that affects the module compilation. # Since the interface file is included in allfiles, # we don't need stuff that modifies it here. checksum_args = ( \ # We don't care about the modulename, that's what # we're trying to construct! #modulename, # We don't care where the user code resides: #source_directory, #code, init_code, #additional_definitions, additional_declarations, # Skipping filenames, since we use the file contents: #sources, wrap_headers, #local_headers, system_headers, include_dirs, library_dirs, libraries, swigargs, swig_include_dirs, cppargs, lddargs, object_files, #arrays, #generate_interface, generate_setup, # The signature isn't defined, and the # cache_dir doesn't affect the module: #signature, cache_dir) ) text = "\n".join((str(a) for a in checksum_args)) allfiles = sources + wrap_headers + local_headers + [ifile_name] new_compilation_checksum = compute_checksum(text, allfiles) # Recompile if necessary recompile(modulename, module_path, new_compilation_checksum, build_system) # --- Load, cache, and return module # Copy compiled module to cache if use_cache: module_path = copy_to_cache(module_path, cache_dir, modulename) # Import module and place in memory cache module = import_and_cache_module(module_path, modulename, moduleids) if not module: instant_error("Failed to import newly compiled module!") instant_debug("In instant.build_module: Returning %s from build_module."\ % module) return module # The end! finally: # Always get back to original directory. os.chdir(original_path) instant_error("In instant.build_module: Should never reach this point!") # end build_module def build_module_vtk(c_code, cache_dir=None): original_path = os.getcwd() cache_dir = validate_cache_dir(cache_dir) signature = modulename_from_checksum(compute_checksum(c_code)) modulename = signature moduleids = [signature] module_path = os.path.join(get_temp_dir(), modulename) makedirs(module_path) os.chdir(module_path) write_cmakefile(modulename) s = generate_interface_file_vtk(signature, c_code) write_vtk_interface_file(signature, c_code) ret, output = get_status_output("cmake -DDEBUG=TRUE . > cmake.log ") ret, output = get_status_output("make > compile.log ") module_path = copy_to_cache(module_path, cache_dir, modulename) os.chdir(original_path) module = import_and_cache_module(module_path, modulename, moduleids) return module def build_module_vmtk(c_code, cache_dir=None): original_path = os.getcwd() cache_dir = validate_cache_dir(cache_dir) signature = modulename_from_checksum(compute_checksum(c_code)) modulename = signature moduleids = [signature] module_path = os.path.join(get_temp_dir(), modulename) makedirs(module_path) os.chdir(module_path) write_vmtk_cmakefile(modulename) s = generate_interface_file_vtk(signature, c_code) write_vtk_interface_file(signature, c_code) ret, output = get_status_output("cmake -DDEBUG=TRUE . > cmake.log ") ret, output = get_status_output("make > compile.log ") module_path = copy_to_cache(module_path, cache_dir, modulename) os.chdir(original_path) module = import_and_cache_module(module_path, modulename, moduleids) return module instant-2017.2.0/instant/locking.py0000644000231000000010000001230613211253757016225 0ustar chrisdaemon"""File locking for the cache system, to avoid problems when multiple processes work with the same module. Only works on UNIX systems. Two Python libraries can be used: flufl.lock : A nfs safe which can be downloaded from: https://launchpad.net/flufl.lock fcntl : A builtin Python module which only works on posix machines and it is does unfortunately not work on nfs """ # Copyright (C) 2009 Martin Sandve Alnes # Copyright (C) 2011-2013 Johan Hake # # This file is part of Instant. # # Instant 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 3 of the License, or # (at your option) any later version. # # Instant 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 Instant. If not, see . # # Alternatively, Instant may be distributed under the terms of the BSD license. __all__ = ["get_lock", "release_lock", "release_all_lock", "file_lock"] import os.path from .output import instant_error, instant_assert, instant_debug from .paths import validate_cache_dir try: import flufl.lock fcntl = None except: flufl = None try: import fcntl except: fcntl = None # Keeping an overview of locks currently held, to avoid deadlocks # within a single process _lock_names = {} # lock.fileno() -> lockname _lock_files = {} # lockname -> lock _lock_count = {} # lockname -> number of times this lock has been aquired and not yet released if flufl: def get_lock(cache_dir, module_name): "Get a new file lock." from flufl.lock import Lock from datetime import timedelta lockname = module_name + ".lock" count = _lock_count.get(lockname, 0) instant_debug("Acquiring lock %s, count is %d." % (lockname, count)) cache_dir = validate_cache_dir(cache_dir) lockname = os.path.join(cache_dir, lockname) lock = Lock(lockname) lock.lock() return lock def release_lock(lock): "Release a lock currently held by Instant." if lock.is_locked: hostname, pid, lockname = lock.details instant_debug("Releasing lock %s." % (lockname)) lock.unlock() def release_all_locks(): pass elif fcntl: def get_lock(cache_dir, module_name): "Get a new file lock." global _lock_names, _lock_files, _lock_count lockname = module_name + ".lock" count = _lock_count.get(lockname, 0) import inspect frame = inspect.currentframe().f_back instant_debug("Acquiring lock %s, count is %d. Called from: %s line: %d" % \ (lockname, count, inspect.getfile(frame), frame.f_lineno)) if count == 0: cache_dir = validate_cache_dir(cache_dir) lock = open(os.path.join(cache_dir, lockname), "w") fcntl.flock(lock.fileno(), fcntl.LOCK_EX) _lock_names[lock.fileno()] = lockname _lock_files[lockname] = lock else: lock = _lock_files[lockname] _lock_count[lockname] = count + 1 return lock def release_lock(lock): "Release a lock currently held by Instant." global _lock_names, _lock_files, _lock_count lockname = _lock_names[lock.fileno()] count = _lock_count[lockname] import inspect frame = inspect.currentframe().f_back instant_debug("Releasing lock %s, count is %d. Called from: %s line: %d" % \ (lockname, count, inspect.getfile(frame), frame.f_lineno)) instant_assert(count > 0, "Releasing lock that Instant is supposedly not holding.") instant_assert(lock is _lock_files[lockname], "Lock mismatch, might be something wrong in locking logic.") del _lock_files[lockname] del _lock_names[lock.fileno()] _lock_count[lockname] = count - 1 fcntl.flock(lock.fileno(), fcntl.LOCK_UN) lock.close() def release_all_locks(): "Release all locks currently held by Instant." locks = list(_lock_files.values()) for lock in locks: release_lock(lock) instant_assert(all(_lock_count[lockname] == 0 for lockname in _lock_count), "Lock counts not zero after releasing all locks.") else: # Windows systems have no fcntl, implement these otherwise if # locking is needed on windows def get_lock(cache_dir, module_name): return None def release_lock(lock): pass def release_all_locks(): pass class file_lock(object): """ File lock using with statement """ def __init__(self, cache_dir, module_name): self.cache_dir = cache_dir self.module_name = module_name def __enter__(self): self.lock = get_lock(self.cache_dir, self.module_name) return self.lock def __exit__(self, type, value, tb): release_lock(self.lock) instant-2017.2.0/instant/paths.py0000644000231000000010000001056513211253757015723 0ustar chrisdaemon"""This module contains helper functions for working with temp and cache directories.""" # Copyright (C) 2008 Martin Sandve Alnes # Copyright (C) 2012 Florian Rathgeber # # This file is part of Instant. # # Instant 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 3 of the License, or # (at your option) any later version. # # Instant 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 Instant. If not, see . # # Alternatively, Instant may be distributed under the terms of the BSD license. # Utilities for directory handling: from six import string_types import os import sys import errno import shutil import tempfile import time from .signatures import compute_checksum from .output import instant_debug, instant_assert _tmp_dir = None def get_temp_dir(): """Return a temporary directory for the duration of this process. Multiple calls in the same process returns the same directory. Remember to call delete_temp_dir() before exiting.""" global _tmp_dir if _tmp_dir is None: datestring = "%d-%d-%d-%02d-%02d" % time.localtime()[:5] suffix = datestring + "_instant_" + compute_checksum(get_default_cache_dir()) _tmp_dir = tempfile.mkdtemp(suffix) instant_debug("Created temp directory '%s'." % _tmp_dir) return _tmp_dir def delete_temp_dir(): """Delete the temporary directory created by get_temp_dir().""" global _tmp_dir if _tmp_dir and os.path.isdir(_tmp_dir): shutil.rmtree(_tmp_dir, ignore_errors=True) _tmp_dir = None def get_instant_dir(): "Return the default instant directory, creating it if necessary." # Place default cache dir in virtualenv or conda prefix # if one of them are active, or under user's home directory home = os.path.expanduser("~") venv = os.environ.get("VIRTUAL_ENV") cenv = os.environ.get("CONDA_PREFIX") if venv == sys.prefix: env = venv elif cenv == sys.prefix: env = cenv else: env = home instant_dir = os.path.join(env, ".cache", "instant") # If placed in home directory, add python version for safety, # since C extensions are not compatible across versions. # (for python 3, it's possible to use the stable C API, # however we don't know if the instant user has done that) if env == home: ver = "python%d.%d" % sys.version_info[:2] instant_dir = os.path.join(instant_dir, ver) makedirs(instant_dir) return instant_dir def get_default_cache_dir(): "Return the default cache directory." cache_dir = os.environ.get("INSTANT_CACHE_DIR") # Catches the cases where INSTANT_CACHE_DIR is not set or '' if not cache_dir: cache_dir = os.path.join(get_instant_dir(), "cache") makedirs(cache_dir) return cache_dir def get_default_error_dir(): "Return the default error directory." error_dir = os.environ.get("INSTANT_ERROR_DIR") # Catches the cases where INSTANT_ERROR_DIR is not set or '' if not error_dir: error_dir = os.path.join(get_instant_dir(), "error") makedirs(error_dir) return error_dir def validate_cache_dir(cache_dir): if cache_dir is None: return get_default_cache_dir() instant_assert(isinstance(cache_dir, string_types), "Expecting cache_dir to be a string.") cache_dir = os.path.abspath(cache_dir) makedirs(cache_dir) return cache_dir def makedirs(path): """ Creates a directory (tree). If directory already excists it does nothing. """ try: os.makedirs(path) instant_debug("In instant.makedirs: Creating directory %r" % path) except os.error as e: if e.errno != errno.EEXIST: raise def _test(): from .output import set_logging_level set_logging_level("DEBUG") print("Temp dir:", get_temp_dir()) print("Instant dir:", get_instant_dir()) print("Default cache dir:", get_default_cache_dir()) print("Default error dir:", get_default_error_dir()) delete_temp_dir() if __name__ == "__main__": _test() instant-2017.2.0/instant/__init__.py0000644000231000000010000000206613211253757016340 0ustar chrisdaemon""" Instant allows compiled C/C++ modules to be created at runtime in your Python application, using SWIG to wrap the C/C++ code. A simple example: >>> from instant import inline >>> add_func = inline(\"double add(double a, double b){ return a+b; }\") >>> print "The sum of 3 and 4.5 is ", add_func(3, 4.5) The main functions are C{build_module}, C{write_code}, and C{inline*} see their documentation for more details. For more examples, see the tests/ directory in the Instant distribution. Questions, bugs and patches should be sent to fenics-dev@googlegroups.com. """ import pkg_resources __authors__ = "Magne Westlie, Kent-Andre Mardal , Martin Alnes , Ilmar M. Wilbers " __date__ = "2016-11-30" __version__ = pkg_resources.get_distribution("fenics-instant").version # TODO: Import only the official interface from .output import * from .config import * from .paths import * from .signatures import * from .cache import * from .codegeneration import * from .build import * from .inlining import * instant-2017.2.0/instant/config.py0000644000231000000010000001512313211253757016044 0ustar chrisdaemon"""This module contains helper functions for configuration using pkg-config.""" # Copyright (C) 2008-2009 Kent-Andre Mardal # Copyright (C) 2008 Martin Sandve Alnes # Copyright (C) 2011-2013 Johan Hake # Copyright (C) 2011 Joachim Berdal Haga # # This file is part of Instant. # # Instant 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 3 of the License, or # (at your option) any later version. # # Instant 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 Instant. If not, see . # # Alternatively, Instant may be distributed under the terms of the BSD # license. from six import string_types import os from .output import get_status_output import re # Global cache variables _swig_binary_cache = None _swig_version_cache = None _pkg_config_installed = None _header_and_library_cache = {} def check_and_set_swig_binary(binary="swig", path=""): """ Check if a particular swig binary is available""" global _swig_binary_cache if not isinstance(binary, string_types): raise TypeError("expected a 'str' as first argument") if not isinstance(path, string_types): raise TypeError("expected a 'str' as second argument") swig_binary = os.path.join(path, binary) if swig_binary == _swig_binary_cache: return True result, output = get_status_output("%s -version"%swig_binary) if result != 0: return False # Set binary cache _swig_binary_cache = swig_binary # Reset SWIG version cache pattern = "SWIG Version (.*)" r = re.search(pattern, output) _swig_version_cache = r.groups(0)[0] return True def get_swig_binary(): "Return any cached swig binary" return _swig_binary_cache if _swig_binary_cache else "swig" def get_swig_version(): """ Return the current swig version in a 'str'""" global _swig_version_cache if _swig_version_cache is None: # Check for swig installation result, output = get_status_output("%s -version"%get_swig_binary()) if result != 0: raise OSError("SWIG is not installed on the system.") pattern = "SWIG Version (.*)" r = re.search(pattern, output) _swig_version_cache = r.groups(0)[0] return _swig_version_cache def check_swig_version(version, same=False): """Check the swig version Returns True if the version of the installed swig is equal or greater than the version passed to the function. If same is True, the function returns True if and only if the two versions are the same. Usage: if instant.check_swig_version('1.3.36'): print "Swig version is greater than or equal to 1.3.36" else: print "Swig version is lower than 1.3.36" """ assert isinstance(version, string_types), "Provide the first version number as a 'str'" assert len(version.split(".")) == 3, "Provide the version number as three numbers seperated by '.'" installed_version = list(map(int, get_swig_version().split('.'))) handed_version = list(map(int, version.split('.'))) # If same is True then just check that all numbers are equal if same: return all(i == h for i, h in zip(installed_version, handed_version)) swig_enough = True for i, v in enumerate([v for v in installed_version]): if handed_version[i] < v: break elif handed_version[i] == v: continue else: swig_enough = False break return swig_enough def header_and_libs_from_pkgconfig(*packages, **kwargs): """This function returns list of include files, flags, libraries and library directories obtain from a pkgconfig file. The usage is: (includes, flags, libraries, libdirs) = \ header_and_libs_from_pkgconfig(*list_of_packages) or: (includes, flags, libraries, libdirs, linkflags) = \ header_and_libs_from_pkgconfig(*list_of_packages, \ returnLinkFlags=True) """ global _pkg_config_installed, _header_and_library_cache returnLinkFlags = kwargs.get("returnLinkFlags", False) if _pkg_config_installed is None: result, output = get_status_output("pkg-config --version ") _pkg_config_installed = (result == 0) if not _pkg_config_installed: raise OSError("The pkg-config package is not installed on the system.") env = os.environ.copy() try: assert env["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] == "0" except: env["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "1" includes = [] flags = [] libs = [] libdirs = [] linkflags = [] for pack in packages: if not pack in _header_and_library_cache: result, output = get_status_output(\ "pkg-config --exists %s " % pack, env=env) if result == 0: tmp = get_status_output(\ "pkg-config --cflags-only-I %s " % pack, env=env)[1].split() _includes = [i[2:] for i in tmp] _flags = get_status_output(\ "pkg-config --cflags-only-other %s " % pack, env=env)[1].split() tmp = get_status_output(\ "pkg-config --libs-only-l %s " % pack, env=env)[1].split() _libs = [i[2:] for i in tmp] tmp = get_status_output(\ "pkg-config --libs-only-L %s " % pack, env=env)[1].split() _libdirs = [i[2:] for i in tmp] _linkflags = get_status_output(\ "pkg-config --libs-only-other %s " % pack, env=env)[1].split() _header_and_library_cache[pack] = (_includes, _flags, _libs, \ _libdirs, _linkflags) else: _header_and_library_cache[pack] = None result = _header_and_library_cache[pack] if not result: raise OSError("The pkg-config file %s does not exist" % pack) _includes, _flags, _libs, _libdirs, _linkflags = result includes.extend(_includes) flags.extend(_flags) libs.extend(_libs) libdirs.extend(_libdirs) linkflags.extend(_linkflags) if returnLinkFlags: return (includes, flags, libs, libdirs, linkflags) return (includes, flags, libs, libdirs) instant-2017.2.0/instant/output.py0000644000231000000010000001431413211253757016140 0ustar chrisdaemon"""This module contains internal logging utilities.""" # Copyright (C) 2008 Martin Sandve Alnes # Copyright (C) 2014 Jan Blechta # # This file is part of Instant. # # Instant 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 3 of the License, or # (at your option) any later version. # # Instant 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 Instant. If not, see . # # Alternatively, Instant may be distributed under the terms of the BSD license. from six import string_types import io, logging, os, platform, sys # Logging wrappers _log = logging.getLogger("instant") _loghandler = logging.StreamHandler() _log.addHandler(_loghandler) #_log.setLevel(logging.WARNING) _log.setLevel(logging.INFO) #_log.setLevel(logging.DEBUG) # Choose method for calling external programs. use subprocess by # default, and os.system on Windows _default_call_method = 'SUBPROCESS' if 'Windows' in platform.system() or 'CYGWIN' in platform.system(): _default_call_method = 'OS_SYSTEM' _call_method = os.environ.get("INSTANT_SYSTEM_CALL_METHOD", _default_call_method) _log.debug('Using call method: %s'%_call_method) def get_log_handler(): return _loghandler def get_logger(): return _log def set_log_handler(handler): global _loghandler _log.removeHandler(_loghandler) _loghandler = handler _log.addHandler(_loghandler) def set_logging_level(level): import inspect frame = inspect.currentframe().f_back instant_warning("set_logging_level is deprecated but was called "\ "from %s, at line %d. Use set_log_level instead." % \ (inspect.getfile(frame), frame.f_lineno)) set_log_level(level) def set_log_level(level): if isinstance(level, string_types): level = level.upper() assert level in ("INFO", "WARNING", "ERROR", "DEBUG") level = getattr(logging, level) else: assert isinstance(level, int) _log.setLevel(level) # Aliases for calling log consistently: def instant_debug(*message): _log.debug(*message) def instant_info(*message): _log.info(*message) def instant_warning(*message): _log.warning(*message) def instant_error(*message): _log.error(*message) text = message[0] % message[1:] raise RuntimeError(text) def instant_assert(condition, *message): if not condition: _log.error(*message) text = message[0] % message[1:] raise AssertionError(text) # Utility functions for file handling: def write_file(filename, text, mode="w"): "Write text to a file and close it." try: if isinstance(text, bytes): text = text.decode("utf8") with io.open(filename, mode, encoding="utf8") as f: f.write(text) f.flush() except IOError as e: instant_error("Can't open '%s': %s" % (filename, e)) if _call_method == 'SUBPROCESS': # NOTE: subprocess in Python 2 is not OFED-fork-safe! Check subprocess.py, # http://bugs.python.org/issue1336#msg146685 # OFED-fork-safety means that parent should not # touch anything between fork() and exec(), # which is not met in subprocess module. See # https://www.open-mpi.org/faq/?category=openfabrics#ofa-fork # http://www.openfabrics.org/downloads/OFED/release_notes/OFED_3.12_rc1_release_notes#3.03 # However, subprocess32 backports the fix from Python 3 to 2.7. if os.name == "posix" and sys.version_info[0] < 3: try: import subprocess32 as subprocess except: import subprocess else: import subprocess def get_status_output(cmd, input=None, cwd=None, env=None): if isinstance(cmd, string_types): cmd = cmd.strip().split() instant_debug("Running: " + str(cmd)) # NOTE: This is not OFED-fork-safe! Check subprocess.py, # http://bugs.python.org/issue1336#msg146685 # OFED-fork-safety means that parent should not # touch anything between fork() and exec(), # which is not met in subprocess module. See # https://www.open-mpi.org/faq/?category=openfabrics#ofa-fork # http://www.openfabrics.org/downloads/OFED/release_notes/OFED_3.12_rc1_release_notes#3.03 pipe = subprocess.Popen(cmd, shell=False, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (output, errout) = pipe.communicate(input=input) assert not errout status = pipe.returncode output = output.decode('utf-8') if sys.version_info[0] > 2 else output return (status, output) elif _call_method == 'OS_SYSTEM': import tempfile from .paths import get_default_error_dir def get_status_output(cmd, input=None, cwd=None, env=None): # We don't need function with such a generality. # We only need output and return code. if not isinstance(cmd, string_types) or input is not None or \ cwd is not None or env is not None: raise NotImplementedError( 'This implementation (%s) of get_status_output does' ' not accept \'input\', \'cwd\' and \'env\' kwargs.' %_call_method) f = tempfile.NamedTemporaryFile(dir=get_default_error_dir(), delete=True) # Execute cmd with redirection cmd += ' > ' + f.name + ' 2>&1' instant_debug("Running: " + str(cmd)) # NOTE: Possibly OFED-fork-safe, tests needed! status = os.system(cmd) output = f.read() f.close() output = output.decode('utf-8') if sys.version_info[0] > 2 else output return (status, output) else: instant_error('Incomprehensible environment variable' ' INSTANT_SYSTEM_CALL_METHOD=%s'%_call_method) instant-2017.2.0/instant/cache.py0000644000231000000010000001653513211253757015652 0ustar chrisdaemon"""This module contains helper functions for working with the module cache. Example operations: - modulename = modulename_from_checksum(checksum) - modulename = modulename_from_checksum(compute_checksum(signature)) - module = import_module_directly(path, modulename) - module = import_module(modulename) - module = import_module(checksum) - module = import_module(compute_checksum(signature)) - modules = cached_modules() - modules = cached_modules(cache_dir) """ # Copyright (C) 2008 Martin Sandve Alnes # # This file is part of Instant. # # Instant 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 3 of the License, or # (at your option) any later version. # # Instant 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 Instant. If not, see . # # Alternatively, Instant may be distributed under the terms of the BSD license. import os, sys, re from .output import instant_warning, instant_assert, instant_debug from .paths import get_default_cache_dir, validate_cache_dir from .signatures import compute_checksum # TODO: We could make this an argument, but it's used indirectly # several places so take care. _modulename_prefix = "instant_module_" def modulename_from_checksum(checksum): "Construct a module name from a checksum for use in cache." return _modulename_prefix + checksum def checksum_from_modulename(modulename): "Construct a module name from a checksum for use in cache." return modulename.remove(_modulename_prefix) def import_module_directly(path, modulename): "Import a module with the given module name that resides in the given path." sys.path.insert(0, path) er = None try: module = __import__(modulename) except BaseException as e: instant_warning("In instant.import_module_directly: Failed to import module '%s' from '%s';\n%s:%s;" % (modulename, path, type(e).__name__, e)) module = None er = e finally: sys.path.pop(0) return module, er _memory_cache = {} def memory_cached_module(moduleid): "Returns the cached module if found." import sys module = _memory_cache.get(moduleid, None) instant_debug("Found '%s' in memory cache with key '%r'." % (module, moduleid)) return module def place_module_in_memory_cache(moduleid, module): "Place a compiled module in cache with given id." _memory_cache[moduleid] = module instant_debug("Added module '%s' to cache with key '%r'." % (module, moduleid)) def is_valid_module_name(name): NAMELENGTHLIMIT = 200 return len(name) < NAMELENGTHLIMIT and bool(re.search(r"^[a-zA-Z_][\w]*$", name)) def import_and_cache_module(path, modulename, moduleids): module, e = import_module_directly(path, modulename) instant_assert(module is not None, "Failed to import module found in cache. Modulename: '%s';\nPath: '%s';\n%s:%s;" % (modulename, path, type(e).__name__, e)) for moduleid in moduleids: place_module_in_memory_cache(moduleid, module) return module def check_memory_cache(moduleid): # Check memory cache first with the given moduleid moduleids = [moduleid] module = memory_cached_module(moduleid) if module: return module, moduleids # Get signature from moduleid if it isn't a string, # and check memory cache again if hasattr(moduleid, "signature"): moduleid = moduleid.signature() instant_debug("In instant.check_memory_cache: Got signature "\ "'%s' from moduleid.signature()." % moduleid) module = memory_cached_module(moduleid) if module: # FIXME (GNW): I haved commented this out since it can continually # insert indentical objects into the cache. This # function checks the cache, so why should it also # insert? #for moduleid in moduleids: # place_module_in_memory_cache(moduleid, module) return module, moduleids moduleids.append(moduleid) # Construct a filename from the checksum of moduleid if it # isn't already a valid name, and check memory cache again if not is_valid_module_name(moduleid): moduleid = modulename_from_checksum(compute_checksum(moduleid)) instant_debug("In instant.check_memory_cache: Constructed module name "\ "'%s' from moduleid '%s'." % (moduleid, moduleids[-1])) module = memory_cached_module(moduleid) if module: return module, moduleids moduleids.append(moduleid) instant_debug("In instant.check_memory_cache: Failed to find module: %s." % moduleid) return None, moduleids def check_disk_cache(modulename, cache_dir, moduleids): # Ensure a valid cache_dir cache_dir = validate_cache_dir(cache_dir) # Check on disk, in current directory and cache directory for path in (os.getcwd(), cache_dir): if os.path.exists(os.path.join(path, modulename, "finished_copying")): # Found existing directory, try to import and place in memory cache module = import_and_cache_module(path, modulename, moduleids) if module: instant_debug("In instant.check_disk_cache: Imported module "\ "'%s' from '%s'." % (modulename, path)) return module else: instant_debug("In instant.check_disk_cache: Failed to import "\ "module '%s' from '%s'." % (modulename, path)) # All attempts failed instant_debug("In instant.check_disk_cache: Can't import module with modulename "\ "%r using cache directory %r." % (modulename, cache_dir)) return None def import_module(moduleid, cache_dir=None): """Import module from cache given its moduleid and an optional cache directory. The moduleid can be either - the module name - a signature string, of which a checksum is taken to look up in the cache - a checksum string, which is used directly to look up in the cache - a hashable non-string object with a function moduleid.signature() which is used to get a signature string The hashable object is used to look up in the memory cache before signature() is called. If the module is found on disk, it is placed in the memory cache. """ # Look for module in memory cache module, moduleids = check_memory_cache(moduleid) if module: return module # Look for module in disk cache modulename = moduleids[-1] return check_disk_cache(modulename, cache_dir, moduleids) def cached_modules(cache_dir=None): "Return a list with the names of all cached modules." cache_dir = validate_cache_dir(cache_dir) return os.listdir(cache_dir) instant-2017.2.0/instant/swig/0000755000231000000010000000000013211253757015174 5ustar chrisdaemoninstant-2017.2.0/instant/swig/numpy.i0000644000231000000010000016367713211253757016542 0ustar chrisdaemon/* -*- C -*- (not really, but good for syntax highlighting) */ #ifdef SWIGPYTHON %{ #ifndef SWIG_FILE_WITH_INIT # define NO_IMPORT_ARRAY #endif #include "stdio.h" #include %} /**********************************************************************/ %fragment("NumPy_Backward_Compatibility", "header") { /* Support older NumPy data type names */ %#if NDARRAY_VERSION < 0x01000000 %#define NPY_BOOL PyArray_BOOL %#define NPY_BYTE PyArray_BYTE %#define NPY_UBYTE PyArray_UBYTE %#define NPY_SHORT PyArray_SHORT %#define NPY_USHORT PyArray_USHORT %#define NPY_INT PyArray_INT %#define NPY_UINT PyArray_UINT %#define NPY_LONG PyArray_LONG %#define NPY_ULONG PyArray_ULONG %#define NPY_LONGLONG PyArray_LONGLONG %#define NPY_ULONGLONG PyArray_ULONGLONG %#define NPY_FLOAT PyArray_FLOAT %#define NPY_DOUBLE PyArray_DOUBLE %#define NPY_LONGDOUBLE PyArray_LONGDOUBLE %#define NPY_CFLOAT PyArray_CFLOAT %#define NPY_CDOUBLE PyArray_CDOUBLE %#define NPY_CLONGDOUBLE PyArray_CLONGDOUBLE %#define NPY_OBJECT PyArray_OBJECT %#define NPY_STRING PyArray_STRING %#define NPY_UNICODE PyArray_UNICODE %#define NPY_VOID PyArray_VOID %#define NPY_NTYPES PyArray_NTYPES %#define NPY_NOTYPE PyArray_NOTYPE %#define NPY_CHAR PyArray_CHAR %#define NPY_USERDEF PyArray_USERDEF %#define npy_intp intp %#define NPY_MAX_BYTE MAX_BYTE %#define NPY_MIN_BYTE MIN_BYTE %#define NPY_MAX_UBYTE MAX_UBYTE %#define NPY_MAX_SHORT MAX_SHORT %#define NPY_MIN_SHORT MIN_SHORT %#define NPY_MAX_USHORT MAX_USHORT %#define NPY_MAX_INT MAX_INT %#define NPY_MIN_INT MIN_INT %#define NPY_MAX_UINT MAX_UINT %#define NPY_MAX_LONG MAX_LONG %#define NPY_MIN_LONG MIN_LONG %#define NPY_MAX_ULONG MAX_ULONG %#define NPY_MAX_LONGLONG MAX_LONGLONG %#define NPY_MIN_LONGLONG MIN_LONGLONG %#define NPY_MAX_ULONGLONG MAX_ULONGLONG %#define NPY_MAX_INTP MAX_INTP %#define NPY_MIN_INTP MIN_INTP %#define NPY_FARRAY FARRAY %#define NPY_F_CONTIGUOUS F_CONTIGUOUS %#endif } /**********************************************************************/ /* The following code originally appeared in * enthought/kiva/agg/src/numeric.i written by Eric Jones. It was * translated from C++ to C by John Hunter. Bill Spotz has modified * it to fix some minor bugs, upgrade from Numeric to numpy (all * versions), add some comments and functionality, and convert from * direct code insertion to SWIG fragments. */ %fragment("NumPy_Macros", "header") { /* Macros to extract array attributes. */ %#define is_array(a) ((a) && PyArray_Check((PyArrayObject *)a)) %#define array_type(a) (int)(PyArray_TYPE(a)) %#define array_numdims(a) (((PyArrayObject *)a)->nd) %#define array_dimensions(a) (((PyArrayObject *)a)->dimensions) %#define array_size(a,i) (((PyArrayObject *)a)->dimensions[i]) %#define array_data(a) (((PyArrayObject *)a)->data) %#define array_is_contiguous(a) (PyArray_ISCONTIGUOUS(a)) %#define array_is_native(a) (PyArray_ISNOTSWAPPED(a)) %#define array_is_fortran(a) (PyArray_ISFORTRAN(a)) } /**********************************************************************/ %fragment("NumPy_Utilities", "header") { /* Given a PyObject, return a string describing its type. */ const char* pytype_string(PyObject* py_obj) { if (py_obj == NULL ) return "C NULL value"; if (py_obj == Py_None ) return "Python None" ; if (PyCallable_Check(py_obj)) return "callable" ; if (PyString_Check( py_obj)) return "string" ; if (PyInt_Check( py_obj)) return "int" ; if (PyFloat_Check( py_obj)) return "float" ; if (PyDict_Check( py_obj)) return "dict" ; if (PyList_Check( py_obj)) return "list" ; if (PyTuple_Check( py_obj)) return "tuple" ; if (PyModule_Check( py_obj)) return "module" ; %#if PY_MAJOR_VERSION < 3 if (PyFile_Check( py_obj)) return "file" ; if (PyInstance_Check(py_obj)) return "instance" ; %#endif return "unkown type"; } /* Given a NumPy typecode, return a string describing the type. */ const char* typecode_string(int typecode) { static const char* type_names[25] = {"bool", "byte", "unsigned byte", "short", "unsigned short", "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long", "float", "double", "long double", "complex float", "complex double", "complex long double", "object", "string", "unicode", "void", "ntypes", "notype", "char", "unknown"}; return typecode < 24 ? type_names[typecode] : type_names[24]; } /* Make sure input has correct numpy type. Allow character and byte * to match. Also allow int and long to match. This is deprecated. * You should use PyArray_EquivTypenums() instead. */ int type_match(int actual_type, int desired_type) { return PyArray_EquivTypenums(actual_type, desired_type); } } /**********************************************************************/ %fragment("NumPy_Object_to_Array", "header", fragment="NumPy_Backward_Compatibility", fragment="NumPy_Macros", fragment="NumPy_Utilities") { /* Given a PyObject pointer, cast it to a PyArrayObject pointer if * legal. If not, set the python error string appropriately and * return NULL. */ PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode) { PyArrayObject* ary = NULL; if (is_array(input) && (typecode == NPY_NOTYPE || PyArray_EquivTypenums(array_type(input), typecode))) { ary = (PyArrayObject*) input; } else if is_array(input) { const char* desired_type = typecode_string(typecode); const char* actual_type = typecode_string(array_type(input)); PyErr_Format(PyExc_TypeError, "Array of type '%s' required. Array of type '%s' given", desired_type, actual_type); ary = NULL; } else { const char * desired_type = typecode_string(typecode); const char * actual_type = pytype_string(input); PyErr_Format(PyExc_TypeError, "Array of type '%s' required. A '%s' was given", desired_type, actual_type); ary = NULL; } return ary; } /* Convert the given PyObject to a NumPy array with the given * typecode. On success, return a valid PyArrayObject* with the * correct type. On failure, the python error string will be set and * the routine returns NULL. */ PyArrayObject* obj_to_array_allow_conversion(PyObject* input, int typecode, int* is_new_object) { PyArrayObject* ary = NULL; PyObject* py_obj; if (is_array(input) && (typecode == NPY_NOTYPE || PyArray_EquivTypenums(array_type(input),typecode))) { ary = (PyArrayObject*) input; *is_new_object = 0; } else { py_obj = PyArray_FROMANY(input, typecode, 0, 0, NPY_DEFAULT); /* If NULL, PyArray_FromObject will have set python error value.*/ ary = (PyArrayObject*) py_obj; *is_new_object = 1; } return ary; } /* Given a PyArrayObject, check to see if it is contiguous. If so, * return the input pointer and flag it as not a new object. If it is * not contiguous, create a new PyArrayObject using the original data, * flag it as a new object and return the pointer. */ PyArrayObject* make_contiguous(PyArrayObject* ary, int* is_new_object, int min_dims, int max_dims) { PyArrayObject* result; if (array_is_contiguous(ary)) { result = ary; *is_new_object = 0; } else { result = (PyArrayObject*) PyArray_ContiguousFromObject((PyObject*)ary, array_type(ary), min_dims, max_dims); *is_new_object = 1; } return result; } /* Given a PyArrayObject, check to see if it is Fortran-contiguous. * If so, return the input pointer, but do not flag it as not a new * object. If it is not Fortran-contiguous, create a new * PyArrayObject using the original data, flag it as a new object * and return the pointer. */ PyArrayObject* make_fortran(PyArrayObject* ary, int* is_new_object, int min_dims, int max_dims) { PyArrayObject* result; if (array_is_fortran(ary)) { result = ary; *is_new_object = 0; } else { Py_INCREF(ary->descr); result = (PyArrayObject*) PyArray_FromArray(ary, ary->descr, NPY_FORTRAN); *is_new_object = 1; } return result; } /* Convert a given PyObject to a contiguous PyArrayObject of the * specified type. If the input object is not a contiguous * PyArrayObject, a new one will be created and the new object flag * will be set. */ PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject* input, int typecode, int* is_new_object) { int is_new1 = 0; int is_new2 = 0; PyArrayObject* ary2; PyArrayObject* ary1 = obj_to_array_allow_conversion(input, typecode, &is_new1); if (ary1) { ary2 = make_contiguous(ary1, &is_new2, 0, 0); if ( is_new1 && is_new2) { Py_DECREF(ary1); } ary1 = ary2; } *is_new_object = is_new1 || is_new2; return ary1; } /* Convert a given PyObject to a Fortran-ordered PyArrayObject of the * specified type. If the input object is not a Fortran-ordered * PyArrayObject, a new one will be created and the new object flag * will be set. */ PyArrayObject* obj_to_array_fortran_allow_conversion(PyObject* input, int typecode, int* is_new_object) { int is_new1 = 0; int is_new2 = 0; PyArrayObject* ary2; PyArrayObject* ary1 = obj_to_array_allow_conversion(input, typecode, &is_new1); if (ary1) { ary2 = make_fortran(ary1, &is_new2, 0, 0); if (is_new1 && is_new2) { Py_DECREF(ary1); } ary1 = ary2; } *is_new_object = is_new1 || is_new2; return ary1; } /* The following code was added by Ilmar M. Wilbers for forcing a copy of the * object even when it is a NumPy array. This is meant for use with the * IN_ARRAY typemaps, and allows the user to perform changes on an array * without these chenges being reflected in the calling code. */ /* Convert the given PyObject to a NumPy array with the given * typecode as a copy. On success, return a valid PyArrayObject* with the * correct type. On failure, the python error string will be set and * the routine returns NULL. */ PyArrayObject* obj_to_array_force_conversion(PyObject* input, int typecode, int* is_new_object) { PyArrayObject* ary = NULL; PyObject* py_obj; if (is_array(input) && (typecode == NPY_NOTYPE || PyArray_EquivTypenums(array_type(input),typecode))) { py_obj = PyArray_Copy((PyArrayObject*) input); ary = (PyArrayObject*) py_obj; *is_new_object = 1; } else { py_obj = PyArray_FROMANY(input, typecode, 0, 0, NPY_DEFAULT); /* If NULL, PyArray_FromObject will have set python error value.*/ ary = (PyArrayObject*) py_obj; *is_new_object = 1; } return ary; } /* Convert a given PyObject to a contiguous PyArrayObject of the * specified type. If the input object is not a contiguous * PyArrayObject, a new one will be created and the new object flag * will be set. */ PyArrayObject* obj_to_array_contiguous_force_conversion(PyObject* input, int typecode, int* is_new_object) { int is_new1 = 0; int is_new2 = 0; PyArrayObject* ary2; PyArrayObject* ary1 = obj_to_array_force_conversion(input, typecode, &is_new1); if (ary1) { ary2 = make_contiguous(ary1, &is_new2, 0, 0); if ( is_new1 && is_new2) { Py_DECREF(ary1); } ary1 = ary2; } *is_new_object = is_new1 || is_new2; return ary1; } /* Convert a given PyObject to a Fortran-ordered PyArrayObject of the * specified type. If the input object is not a Fortran-ordered * PyArrayObject, a new one will be created and the new object flag * will be set. */ PyArrayObject* obj_to_array_fortran_force_conversion(PyObject* input, int typecode, int* is_new_object) { int is_new1 = 0; int is_new2 = 0; PyArrayObject* ary2; PyArrayObject* ary1 = obj_to_array_force_conversion(input, typecode, &is_new1); if (ary1) { ary2 = make_fortran(ary1, &is_new2, 0, 0); if (is_new1 && is_new2) { Py_DECREF(ary1); } ary1 = ary2; } *is_new_object = is_new1 || is_new2; return ary1; } /* End modifications by Ilmar M. Wilbers */ } /* end fragment */ /**********************************************************************/ %fragment("NumPy_Array_Requirements", "header", fragment="NumPy_Backward_Compatibility", fragment="NumPy_Macros") { /* Test whether a python object is contiguous. If array is * contiguous, return 1. Otherwise, set the python error string and * return 0. */ int require_contiguous(PyArrayObject* ary) { int contiguous = 1; if (!array_is_contiguous(ary)) { PyErr_SetString(PyExc_TypeError, "Array must be contiguous. A non-contiguous array was given"); contiguous = 0; } return contiguous; } /* Require that a numpy array is not byte-swapped. If the array is * not byte-swapped, return 1. Otherwise, set the python error string * and return 0. */ int require_native(PyArrayObject* ary) { int native = 1; if (!array_is_native(ary)) { PyErr_SetString(PyExc_TypeError, "Array must have native byteorder. " "A byte-swapped array was given"); native = 0; } return native; } /* Require the given PyArrayObject to have a specified number of * dimensions. If the array has the specified number of dimensions, * return 1. Otherwise, set the python error string and return 0. */ int require_dimensions(PyArrayObject* ary, int exact_dimensions) { int success = 1; if (array_numdims(ary) != exact_dimensions) { PyErr_Format(PyExc_TypeError, "Array must have %d dimensions. Given array has %d dimensions", exact_dimensions, array_numdims(ary)); success = 0; } return success; } /* Require the given PyArrayObject to have one of a list of specified * number of dimensions. If the array has one of the specified number * of dimensions, return 1. Otherwise, set the python error string * and return 0. */ int require_dimensions_n(PyArrayObject* ary, int* exact_dimensions, int n) { int success = 0; int i; char dims_str[255] = ""; char s[255]; for (i = 0; i < n && !success; i++) { if (array_numdims(ary) == exact_dimensions[i]) { success = 1; } } if (!success) { for (i = 0; i < n-1; i++) { sprintf(s, "%d, ", exact_dimensions[i]); strcat(dims_str,s); } sprintf(s, " or %d", exact_dimensions[n-1]); strcat(dims_str,s); PyErr_Format(PyExc_TypeError, "Array must have %s dimensions. Given array has %d dimensions", dims_str, array_numdims(ary)); } return success; } /* Require the given PyArrayObject to have a specified shape. If the * array has the specified shape, return 1. Otherwise, set the python * error string and return 0. */ int require_size(PyArrayObject* ary, npy_intp* size, int n) { int i; int success = 1; int len; char desired_dims[255] = "["; char s[255]; char actual_dims[255] = "["; for(i=0; i < n;i++) { if (size[i] != -1 && size[i] != array_size(ary,i)) { success = 0; } } if (!success) { for (i = 0; i < n; i++) { if (size[i] == -1) { sprintf(s, "*,"); } else { sprintf(s, "%ld,", (long int)size[i]); } strcat(desired_dims,s); } len = strlen(desired_dims); desired_dims[len-1] = ']'; for (i = 0; i < n; i++) { sprintf(s, "%ld,", (long int)array_size(ary,i)); strcat(actual_dims,s); } len = strlen(actual_dims); actual_dims[len-1] = ']'; PyErr_Format(PyExc_TypeError, "Array must have shape of %s. Given array has shape of %s", desired_dims, actual_dims); } return success; } /* Require the given PyArrayObject to to be FORTRAN ordered. If the * the PyArrayObject is already FORTRAN ordered, do nothing. Else, * set the FORTRAN ordering flag and recompute the strides. */ int require_fortran(PyArrayObject* ary) { int success = 1; int nd = array_numdims(ary); int i; if (array_is_fortran(ary)) return success; /* Set the FORTRAN ordered flag */ ary->flags = NPY_FARRAY; /* Recompute the strides */ ary->strides[0] = ary->strides[nd-1]; for (i=1; i < nd; ++i) ary->strides[i] = ary->strides[i-1] * array_size(ary,i-1); return success; } } /* Combine all NumPy fragments into one for convenience */ %fragment("NumPy_Fragments", "header", fragment="NumPy_Backward_Compatibility", fragment="NumPy_Macros", fragment="NumPy_Utilities", fragment="NumPy_Object_to_Array", fragment="NumPy_Array_Requirements") { } /* End John Hunter translation (with modifications by Bill Spotz) */ /* %numpy_typemaps() macro * * This macro defines a family of 41 typemaps that allow C arguments * of the form * * (DATA_TYPE IN_ARRAY1[ANY]) * (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1) * (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1) * * (DATA_TYPE IN_ARRAY2[ANY][ANY]) * (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) * (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2) * (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) * (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2) * * (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY]) * (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) * (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3) * (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) * (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3) * * (DATA_TYPE INPLACE_ARRAY1[ANY]) * (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1) * (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1) * * (DATA_TYPE INPLACE_ARRAY2[ANY][ANY]) * (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) * (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2) * (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) * (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2) * * (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY]) * (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) * (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3) * (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) * (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3) * * (DATA_TYPE ARGOUT_ARRAY1[ANY]) * (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1) * (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1) * * (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY]) * * (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY]) * * (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1) * (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1) * * (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) * (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2) * (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) * (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2) * * (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) * (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3) * (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) * (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3) * * where "DATA_TYPE" is any type supported by the NumPy module, and * "DIM_TYPE" is any int-like type suitable for specifying dimensions. * The difference between "ARRAY" typemaps and "FARRAY" typemaps is * that the "FARRAY" typemaps expect FORTRAN ordering of * multidimensional arrays. In python, the dimensions will not need * to be specified (except for the "DATA_TYPE* ARGOUT_ARRAY1" * typemaps). The IN_ARRAYs can be a numpy array or any sequence that * can be converted to a numpy array of the specified type. The * INPLACE_ARRAYs must be numpy arrays of the appropriate type. The * ARGOUT_ARRAYs will be returned as new numpy arrays of the * appropriate type. * * These typemaps can be applied to existing functions using the * %apply directive. For example: * * %apply (double* IN_ARRAY1, int DIM1) {(double* series, int length)}; * double prod(double* series, int length); * * %apply (int DIM1, int DIM2, double* INPLACE_ARRAY2) * {(int rows, int cols, double* matrix )}; * void floor(int rows, int cols, double* matrix, double f); * * %apply (double IN_ARRAY3[ANY][ANY][ANY]) * {(double tensor[2][2][2] )}; * %apply (double ARGOUT_ARRAY3[ANY][ANY][ANY]) * {(double low[2][2][2] )}; * %apply (double ARGOUT_ARRAY3[ANY][ANY][ANY]) * {(double upp[2][2][2] )}; * void luSplit(double tensor[2][2][2], * double low[2][2][2], * double upp[2][2][2] ); * * or directly with * * double prod(double* IN_ARRAY1, int DIM1); * * void floor(int DIM1, int DIM2, double* INPLACE_ARRAY2, double f); * * void luSplit(double IN_ARRAY3[ANY][ANY][ANY], * double ARGOUT_ARRAY3[ANY][ANY][ANY], * double ARGOUT_ARRAY3[ANY][ANY][ANY]); */ %define %numpy_typemaps(DATA_TYPE, DATA_TYPECODE, DIM_TYPE) /************************/ /* Input Array Typemaps */ /************************/ /* Typemap suite for (DATA_TYPE IN_ARRAY1[ANY]) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE IN_ARRAY1[ANY]) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE IN_ARRAY1[ANY]) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[1] = { $1_dim0 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 1) || !require_size(array, size, 1)) SWIG_fail; $1 = ($1_ltype) array_data(array); } %typemap(freearg) (DATA_TYPE IN_ARRAY1[ANY]) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[1] = { -1 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 1) || !require_size(array, size, 1)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = (DIM_TYPE) array_size(array,0); } %typemap(freearg) (DATA_TYPE* IN_ARRAY1, DIM_TYPE DIM1) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[1] = {-1}; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 1) || !require_size(array, size, 1)) SWIG_fail; $1 = (DIM_TYPE) array_size(array,0); $2 = (DATA_TYPE*) array_data(array); } %typemap(freearg) (DIM_TYPE DIM1, DATA_TYPE* IN_ARRAY1) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DATA_TYPE IN_ARRAY2[ANY][ANY]) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE IN_ARRAY2[ANY][ANY]) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE IN_ARRAY2[ANY][ANY]) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[2] = { $1_dim0, $1_dim1 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 2) || !require_size(array, size, 2)) SWIG_fail; $1 = ($1_ltype) array_data(array); } %typemap(freearg) (DATA_TYPE IN_ARRAY2[ANY][ANY]) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[2] = { -1, -1 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 2) || !require_size(array, size, 2)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = (DIM_TYPE) array_size(array,0); $3 = (DIM_TYPE) array_size(array,1); } %typemap(freearg) (DATA_TYPE* IN_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[2] = { -1, -1 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 2) || !require_size(array, size, 2)) SWIG_fail; $1 = (DIM_TYPE) array_size(array,0); $2 = (DIM_TYPE) array_size(array,1); $3 = (DATA_TYPE*) array_data(array); } %typemap(freearg) (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_ARRAY2) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[2] = { -1, -1 }; array = obj_to_array_fortran_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 2) || !require_size(array, size, 2) || !require_fortran(array)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = (DIM_TYPE) array_size(array,0); $3 = (DIM_TYPE) array_size(array,1); } %typemap(freearg) (DATA_TYPE* IN_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[2] = { -1, -1 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 2) || !require_size(array, size, 2) || !require_fortran(array)) SWIG_fail; $1 = (DIM_TYPE) array_size(array,0); $2 = (DIM_TYPE) array_size(array,1); $3 = (DATA_TYPE*) array_data(array); } %typemap(freearg) (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* IN_FARRAY2) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY]) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY]) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY]) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 3) || !require_size(array, size, 3)) SWIG_fail; $1 = ($1_ltype) array_data(array); } %typemap(freearg) (DATA_TYPE IN_ARRAY3[ANY][ANY][ANY]) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, * DIM_TYPE DIM3) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[3] = { -1, -1, -1 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 3) || !require_size(array, size, 3)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = (DIM_TYPE) array_size(array,0); $3 = (DIM_TYPE) array_size(array,1); $4 = (DIM_TYPE) array_size(array,2); } %typemap(freearg) (DATA_TYPE* IN_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, * DATA_TYPE* IN_ARRAY3) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[3] = { -1, -1, -1 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 3) || !require_size(array, size, 3)) SWIG_fail; $1 = (DIM_TYPE) array_size(array,0); $2 = (DIM_TYPE) array_size(array,1); $3 = (DIM_TYPE) array_size(array,2); $4 = (DATA_TYPE*) array_data(array); } %typemap(freearg) (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_ARRAY3) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, * DIM_TYPE DIM3) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[3] = { -1, -1, -1 }; array = obj_to_array_fortran_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 3) || !require_size(array, size, 3) | !require_fortran(array)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = (DIM_TYPE) array_size(array,0); $3 = (DIM_TYPE) array_size(array,1); $4 = (DIM_TYPE) array_size(array,2); } %typemap(freearg) (DATA_TYPE* IN_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, * DATA_TYPE* IN_FARRAY3) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3) { $1 = is_array($input) || PySequence_Check($input); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3) (PyArrayObject* array=NULL, int is_new_object=0) { npy_intp size[3] = { -1, -1, -1 }; array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE, &is_new_object); if (!array || !require_dimensions(array, 3) || !require_size(array, size, 3) || !require_fortran(array)) SWIG_fail; $1 = (DIM_TYPE) array_size(array,0); $2 = (DIM_TYPE) array_size(array,1); $3 = (DIM_TYPE) array_size(array,2); $4 = (DATA_TYPE*) array_data(array); } %typemap(freearg) (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* IN_FARRAY3) { if (is_new_object$argnum && array$argnum) { Py_DECREF(array$argnum); } } /***************************/ /* In-Place Array Typemaps */ /***************************/ /* Typemap suite for (DATA_TYPE INPLACE_ARRAY1[ANY]) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE INPLACE_ARRAY1[ANY]) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE INPLACE_ARRAY1[ANY]) (PyArrayObject* array=NULL) { npy_intp size[1] = { $1_dim0 }; array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,1) || !require_size(array, size, 1) || !require_contiguous(array) || !require_native(array)) SWIG_fail; $1 = ($1_ltype) array_data(array); } /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* INPLACE_ARRAY1, DIM_TYPE DIM1) (PyArrayObject* array=NULL, int i=1) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,1) || !require_contiguous(array) || !require_native(array)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = 1; for (i=0; i < array_numdims(array); ++i) $2 *= array_size(array,i); } /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DATA_TYPE* INPLACE_ARRAY1) (PyArrayObject* array=NULL, int i=0) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,1) || !require_contiguous(array) || !require_native(array)) SWIG_fail; $1 = 1; for (i=0; i < array_numdims(array); ++i) $1 *= array_size(array,i); $2 = (DATA_TYPE*) array_data(array); } /* Typemap suite for (DATA_TYPE INPLACE_ARRAY2[ANY][ANY]) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE INPLACE_ARRAY2[ANY][ANY]) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE INPLACE_ARRAY2[ANY][ANY]) (PyArrayObject* array=NULL) { npy_intp size[2] = { $1_dim0, $1_dim1 }; array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,2) || !require_size(array, size, 2) || !require_contiguous(array) || !require_native(array)) SWIG_fail; $1 = ($1_ltype) array_data(array); } /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* INPLACE_ARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) (PyArrayObject* array=NULL) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,2) || !require_contiguous(array) || !require_native(array)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = (DIM_TYPE) array_size(array,0); $3 = (DIM_TYPE) array_size(array,1); } /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_ARRAY2) (PyArrayObject* array=NULL) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,2) || !require_contiguous(array) || !require_native(array)) SWIG_fail; $1 = (DIM_TYPE) array_size(array,0); $2 = (DIM_TYPE) array_size(array,1); $3 = (DATA_TYPE*) array_data(array); } /* Typemap suite for (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* INPLACE_FARRAY2, DIM_TYPE DIM1, DIM_TYPE DIM2) (PyArrayObject* array=NULL) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,2) || !require_contiguous(array) || !require_native(array) || !require_fortran(array)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = (DIM_TYPE) array_size(array,0); $3 = (DIM_TYPE) array_size(array,1); } /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DIM_TYPE DIM2, DATA_TYPE* INPLACE_FARRAY2) (PyArrayObject* array=NULL) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,2) || !require_contiguous(array) || !require_native(array) || !require_fortran(array)) SWIG_fail; $1 = (DIM_TYPE) array_size(array,0); $2 = (DIM_TYPE) array_size(array,1); $3 = (DATA_TYPE*) array_data(array); } /* Typemap suite for (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY]) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY]) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE INPLACE_ARRAY3[ANY][ANY][ANY]) (PyArrayObject* array=NULL) { npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 }; array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,3) || !require_size(array, size, 3) || !require_contiguous(array) || !require_native(array)) SWIG_fail; $1 = ($1_ltype) array_data(array); } /* Typemap suite for (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, * DIM_TYPE DIM3) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* INPLACE_ARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) (PyArrayObject* array=NULL) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,3) || !require_contiguous(array) || !require_native(array)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = (DIM_TYPE) array_size(array,0); $3 = (DIM_TYPE) array_size(array,1); $4 = (DIM_TYPE) array_size(array,2); } /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, * DATA_TYPE* INPLACE_ARRAY3) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_ARRAY3) (PyArrayObject* array=NULL) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,3) || !require_contiguous(array) || !require_native(array)) SWIG_fail; $1 = (DIM_TYPE) array_size(array,0); $2 = (DIM_TYPE) array_size(array,1); $3 = (DIM_TYPE) array_size(array,2); $4 = (DATA_TYPE*) array_data(array); } /* Typemap suite for (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, * DIM_TYPE DIM3) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DATA_TYPE* INPLACE_FARRAY3, DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3) (PyArrayObject* array=NULL) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,3) || !require_contiguous(array) || !require_native(array) || !require_fortran(array)) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); $2 = (DIM_TYPE) array_size(array,0); $3 = (DIM_TYPE) array_size(array,1); $4 = (DIM_TYPE) array_size(array,2); } /* Typemap suite for (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, * DATA_TYPE* INPLACE_FARRAY3) */ %typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY, fragment="NumPy_Macros") (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3) { $1 = is_array($input) && PyArray_EquivTypenums(array_type($input), DATA_TYPECODE); } %typemap(in, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DIM_TYPE DIM2, DIM_TYPE DIM3, DATA_TYPE* INPLACE_FARRAY3) (PyArrayObject* array=NULL) { array = obj_to_array_no_conversion($input, DATA_TYPECODE); if (!array || !require_dimensions(array,3) || !require_contiguous(array) || !require_native(array) || !require_fortran(array)) SWIG_fail; $1 = (DIM_TYPE) array_size(array,0); $2 = (DIM_TYPE) array_size(array,1); $3 = (DIM_TYPE) array_size(array,2); $4 = (DATA_TYPE*) array_data(array); } /*************************/ /* Argout Array Typemaps */ /*************************/ /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY1[ANY]) */ %typemap(in,numinputs=0, fragment="NumPy_Backward_Compatibility,NumPy_Macros") (DATA_TYPE ARGOUT_ARRAY1[ANY]) (PyObject * array = NULL) { npy_intp dims[1] = { $1_dim0 }; array = PyArray_SimpleNew(1, dims, DATA_TYPECODE); if (!array) SWIG_fail; $1 = ($1_ltype) array_data(array); } %typemap(argout) (DATA_TYPE ARGOUT_ARRAY1[ANY]) { $result = SWIG_Python_AppendOutput($result,array$argnum); } /* Typemap suite for (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1) */ %typemap(in,numinputs=1, fragment="NumPy_Fragments") (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1) (PyObject * array = NULL) { npy_intp dims[1]; if (!PyInt_Check($input)) { const char* typestring = pytype_string($input); PyErr_Format(PyExc_TypeError, "Int dimension expected. '%s' given.", typestring); SWIG_fail; } $2 = (DIM_TYPE) PyInt_AsLong($input); dims[0] = (npy_intp) $2; array = PyArray_SimpleNew(1, dims, DATA_TYPECODE); if (!array) SWIG_fail; $1 = (DATA_TYPE*) array_data(array); } %typemap(argout) (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1) { $result = SWIG_Python_AppendOutput($result,array$argnum); } /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1) */ %typemap(in,numinputs=1, fragment="NumPy_Fragments") (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1) (PyObject * array = NULL) { npy_intp dims[1]; if (!PyInt_Check($input)) { const char* typestring = pytype_string($input); PyErr_Format(PyExc_TypeError, "Int dimension expected. '%s' given.", typestring); SWIG_fail; } $1 = (DIM_TYPE) PyInt_AsLong($input); dims[0] = (npy_intp) $1; array = PyArray_SimpleNew(1, dims, DATA_TYPECODE); if (!array) SWIG_fail; $2 = (DATA_TYPE*) array_data(array); } %typemap(argout) (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1) { $result = SWIG_Python_AppendOutput($result,array$argnum); } /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY]) */ %typemap(in,numinputs=0, fragment="NumPy_Backward_Compatibility,NumPy_Macros") (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY]) (PyObject * array = NULL) { npy_intp dims[2] = { $1_dim0, $1_dim1 }; array = PyArray_SimpleNew(2, dims, DATA_TYPECODE); if (!array) SWIG_fail; $1 = ($1_ltype) array_data(array); } %typemap(argout) (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY]) { $result = SWIG_Python_AppendOutput($result,array$argnum); } /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY]) */ %typemap(in,numinputs=0, fragment="NumPy_Backward_Compatibility,NumPy_Macros") (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY]) (PyObject * array = NULL) { npy_intp dims[3] = { $1_dim0, $1_dim1, $1_dim2 }; array = PyArray_SimpleNew(3, dims, DATA_TYPECODE); if (!array) SWIG_fail; $1 = ($1_ltype) array_data(array); } %typemap(argout) (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY]) { $result = SWIG_Python_AppendOutput($result,array$argnum); } /*****************************/ /* Argoutview Array Typemaps */ /*****************************/ /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1) */ %typemap(in,numinputs=0) (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1 ) (DATA_TYPE* data_temp , DIM_TYPE dim_temp) { $1 = &data_temp; $2 = &dim_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility") (DATA_TYPE** ARGOUTVIEW_ARRAY1, DIM_TYPE* DIM1) { npy_intp dims[1] = { *$2 }; PyObject * array = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$1)); if (!array) SWIG_fail; $result = SWIG_Python_AppendOutput($result,array); } /* Typemap suite for (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1) */ %typemap(in,numinputs=0) (DIM_TYPE* DIM1 , DATA_TYPE** ARGOUTVIEW_ARRAY1) (DIM_TYPE dim_temp, DATA_TYPE* data_temp ) { $1 = &dim_temp; $2 = &data_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility") (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1) { npy_intp dims[1] = { *$1 }; PyObject * array = PyArray_SimpleNewFromData(1, dims, DATA_TYPECODE, (void*)(*$2)); if (!array) SWIG_fail; $result = SWIG_Python_AppendOutput($result,array); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) */ %typemap(in,numinputs=0) (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1 , DIM_TYPE* DIM2 ) (DATA_TYPE* data_temp , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp) { $1 = &data_temp; $2 = &dim1_temp; $3 = &dim2_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility") (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) { npy_intp dims[2] = { *$2, *$3 }; PyObject * array = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1)); if (!array) SWIG_fail; $result = SWIG_Python_AppendOutput($result,array); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2) */ %typemap(in,numinputs=0) (DIM_TYPE* DIM1 , DIM_TYPE* DIM2 , DATA_TYPE** ARGOUTVIEW_ARRAY2) (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DATA_TYPE* data_temp ) { $1 = &dim1_temp; $2 = &dim2_temp; $3 = &data_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility") (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2) { npy_intp dims[2] = { *$1, *$2 }; PyObject * array = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3)); if (!array) SWIG_fail; $result = SWIG_Python_AppendOutput($result,array); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) */ %typemap(in,numinputs=0) (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1 , DIM_TYPE* DIM2 ) (DATA_TYPE* data_temp , DIM_TYPE dim1_temp, DIM_TYPE dim2_temp) { $1 = &data_temp; $2 = &dim1_temp; $3 = &dim2_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements") (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) { npy_intp dims[2] = { *$2, *$3 }; PyObject * obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$1)); PyArrayObject * array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; $result = SWIG_Python_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2) */ %typemap(in,numinputs=0) (DIM_TYPE* DIM1 , DIM_TYPE* DIM2 , DATA_TYPE** ARGOUTVIEW_FARRAY2) (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DATA_TYPE* data_temp ) { $1 = &dim1_temp; $2 = &dim2_temp; $3 = &data_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements") (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2) { npy_intp dims[2] = { *$1, *$2 }; PyObject * obj = PyArray_SimpleNewFromData(2, dims, DATA_TYPECODE, (void*)(*$3)); PyArrayObject * array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; $result = SWIG_Python_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) */ %typemap(in,numinputs=0) (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) (DATA_TYPE* data_temp, DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp) { $1 = &data_temp; $2 = &dim1_temp; $3 = &dim2_temp; $4 = &dim3_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility") (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) { npy_intp dims[3] = { *$2, *$3, *$4 }; PyObject * array = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1)); if (!array) SWIG_fail; $result = SWIG_Python_AppendOutput($result,array); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3) */ %typemap(in,numinputs=0) (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3) (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp) { $1 = &dim1_temp; $2 = &dim2_temp; $3 = &dim3_temp; $4 = &data_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility") (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_ARRAY3) { npy_intp dims[3] = { *$1, *$2, *$3 }; PyObject * array = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$3)); if (!array) SWIG_fail; $result = SWIG_Python_AppendOutput($result,array); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) */ %typemap(in,numinputs=0) (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) (DATA_TYPE* data_temp, DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp) { $1 = &data_temp; $2 = &dim1_temp; $3 = &dim2_temp; $4 = &dim3_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements") (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3) { npy_intp dims[3] = { *$2, *$3, *$4 }; PyObject * obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$1)); PyArrayObject * array = (PyArrayObject*) obj; if (!array || require_fortran(array)) SWIG_fail; $result = SWIG_Python_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3) */ %typemap(in,numinputs=0) (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3) (DIM_TYPE dim1_temp, DIM_TYPE dim2_temp, DIM_TYPE dim3_temp, DATA_TYPE* data_temp) { $1 = &dim1_temp; $2 = &dim2_temp; $3 = &dim3_temp; $4 = &data_temp; } %typemap(argout, fragment="NumPy_Backward_Compatibility,NumPy_Array_Requirements") (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DATA_TYPE** ARGOUTVIEW_FARRAY3) { npy_intp dims[3] = { *$1, *$2, *$3 }; PyObject * obj = PyArray_SimpleNewFromData(3, dims, DATA_TYPECODE, (void*)(*$3)); PyArrayObject * array = (PyArrayObject*) obj; if (!array || require_fortran(array)) SWIG_fail; $result = SWIG_Python_AppendOutput($result,obj); } %enddef /* %numpy_typemaps() macro */ /* *************************************************************** */ /* Concrete instances of the %numpy_typemaps() macro: Each invocation * below applies all of the typemaps above to the specified data type. */ %numpy_typemaps(signed char , NPY_BYTE , int) %numpy_typemaps(unsigned char , NPY_UBYTE , int) %numpy_typemaps(short , NPY_SHORT , int) %numpy_typemaps(unsigned short , NPY_USHORT , int) %numpy_typemaps(int , NPY_INT , int) %numpy_typemaps(unsigned int , NPY_UINT , int) %numpy_typemaps(long , NPY_LONG , int) %numpy_typemaps(unsigned long , NPY_ULONG , int) %numpy_typemaps(long long , NPY_LONGLONG , int) %numpy_typemaps(unsigned long long, NPY_ULONGLONG, int) %numpy_typemaps(float , NPY_FLOAT , int) %numpy_typemaps(double , NPY_DOUBLE , int) /* *************************************************************** * The follow macro expansion does not work, because C++ bool is 4 * bytes and NPY_BOOL is 1 byte * * %numpy_typemaps(bool, NPY_BOOL, int) */ /* *************************************************************** * On my Mac, I get the following warning for this macro expansion: * 'swig/python detected a memory leak of type 'long double *', no destructor found.' * * %numpy_typemaps(long double, NPY_LONGDOUBLE, int) */ /* *************************************************************** * Swig complains about a syntax error for the following macro * expansions: * * %numpy_typemaps(complex float, NPY_CFLOAT , int) * * %numpy_typemaps(complex double, NPY_CDOUBLE, int) * * %numpy_typemaps(complex long double, NPY_CLONGDOUBLE, int) */ #endif /* SWIGPYTHON */ instant-2017.2.0/doc/0000755000231000000010000000000013211253757013310 5ustar chrisdaemoninstant-2017.2.0/doc/sphinx/0000755000231000000010000000000013211253757014621 5ustar chrisdaemoninstant-2017.2.0/doc/sphinx/source/0000755000231000000010000000000013211253757016121 5ustar chrisdaemoninstant-2017.2.0/doc/sphinx/source/conf.py0000644000231000000010000002142413211253757017423 0ustar chrisdaemon# -*- coding: utf-8 -*- # # Instant documentation build configuration file, created by # sphinx-quickstart on Wed Nov 4 14:07:57 2015. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys import os import pkg_resources import datetime # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.coverage', 'sphinx.ext.mathjax', 'sphinx.ext.viewcode', ] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'Instant' this_year = datetime.date.today().year copyright = u'%s, FEniCS Project' % this_year version = pkg_resources.get_distribution("fenics-instant").version release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = [] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. #html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'Instantdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ ('index', 'Instant.tex', u'Instant Documentation', u'FEniCS Project', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'instant', u'Instant Documentation', [u'FEniCS Project'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'Instant', u'Instant Documentation', u'FEniCS Project', 'Instant', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'http://docs.python.org/': None} def run_apidoc(_): modules = ['instant'] # Get location of Sphinx files sphinx_source_dir = os.path.abspath(os.path.dirname(__file__)) repo_dir = os.path.abspath(os.path.join(sphinx_source_dir, os.path.pardir, os.path.pardir, os.path.pardir)) apidoc_dir = os.path.join(sphinx_source_dir, "api-doc") from sphinx.apidoc import main for module in modules: # Generate .rst files ready for autodoc module_dir = os.path.join(repo_dir, module) main(["-f", "-d", "1", "-o", apidoc_dir, module_dir]) def setup(app): app.connect('builder-inited', run_apidoc) instant-2017.2.0/doc/sphinx/source/releases/0000755000231000000010000000000013211253757017724 5ustar chrisdaemoninstant-2017.2.0/doc/sphinx/source/releases/v2016.2.0.rst0000644000231000000010000000046413211253757021536 0ustar chrisdaemon=========================== Changes in version 2016.2.0 =========================== Instant 2016.2.0 was released on 2016-11-30. - Add Python version string to hash signature input - Add pipelines testing, with py2 and py3 coverage - Remove commands module (removed from Py3) - Switch unit tests to pytest instant-2017.2.0/doc/sphinx/source/releases/next.rst0000644000231000000010000000100213211253757021425 0ustar chrisdaemon=========================== Changes in the next release =========================== Summary of changes ================== .. note:: Developers should use this page to track and list changes during development. At the time of release, this page should be published (and renamed) to list the most important changes in the new release. Detailed changes ================ .. note:: At the time of release, make a verbatim copy of the ChangeLog here (and remove this note). instant-2017.2.0/doc/sphinx/source/releases/v2017.1.0.rst0000644000231000000010000000022113211253757021525 0ustar chrisdaemon=========================== Changes in version 2017.1.0 =========================== Instant 2017.1.0 was released on 2017-05-09. - Minor fixes instant-2017.2.0/doc/sphinx/source/releases/v2017.1.0.post1.rst0000644000231000000010000000031113211253757022572 0ustar chrisdaemon================================= Changes in version 2017.1.0.post1 ================================= Instant 2017.1.0.post1 was released on 2017-09-12. - Change PyPI package name to fenics-instant. instant-2017.2.0/doc/sphinx/source/releases/v1.6.0.rst0000644000231000000010000000021113211253757021300 0ustar chrisdaemon======================== Changes in version 1.6.0 ======================== Instant 1.6.0 was released on 2015-07-28. - Minor bug fixes instant-2017.2.0/doc/sphinx/source/releases/v2017.2.0.rst0000644000231000000010000000020213211253757021525 0ustar chrisdaemon=========================== Changes in version 2017.2.0 =========================== Instant 2017.2.0 was released on 2017-11-30. instant-2017.2.0/doc/sphinx/source/releases/v2016.1.0.rst0000644000231000000010000000022113211253757021524 0ustar chrisdaemon=========================== Changes in version 2016.1.0 =========================== Instant 2016.1.0 was released on 2016-06-23. - Minor fixes instant-2017.2.0/doc/sphinx/source/manual.rst0000644000231000000010000000014713211253757020132 0ustar chrisdaemon.. title:: User manual =========== User manual =========== .. note:: This page is work in progress. instant-2017.2.0/doc/sphinx/source/installation.rst0000644000231000000010000000504113211253757021354 0ustar chrisdaemon.. title:: Installation ============ Installation ============ Instant is normally installed as part of an installation of FEniCS. If you are using Instant as part of the FEniCS software suite, it is recommended that you follow the `installation instructions for FEniCS `__. To install Instant itself, read on below for a list of requirements and installation instructions. Requirements and dependencies ============================= Instant requires Python version 2.7 or later and depends on the following Python packages: * NumPy * SWIG These packages will be automatically installed as part of the installation of Instant, if not already present on your system. If running on a cluster with Infiniband with python 2, you also need to install a backport of the subprocess module from python 3 to get safe fork behaviour: * subprocess32 In addition, Instant optionally depends on flufl.lock for NFS safe file locking flufl.lock can be installed * flufl.lock (https://gitlab.com/warsaw/flufl.lock) Installation instructions ========================= To install Instant, download the source code from the `Instant Bitbucket repository `__, and run the following command: .. code-block:: console pip install . To install to a specific location, add the ``--prefix`` flag to the installation command: .. code-block:: console pip install --prefix= . Environment =========== Instant's behaviour depened on following environment variables: - ``INSTANT_CACHE_DIR`` - ``INSTANT_ERROR_DIR`` These options can override placement of default cache and error directories. The default directories are placed below the prefix of the currently active virtualenv or conda environment, in ``.cache/instant/cache`` and ``.cache/instant/error``. If no such environment is active, the default directories are ``~/.cache/instant/pythonM.N/cache`` and ``.cache/instant/pythonM.N/error``. - ``INSTANT_SYSTEM_CALL_METHOD`` Choose method for calling external programs (pkgconfig, swig, cmake, make). Available values: - ``SUBPROCESS`` Uses pipes. Not OFED-fork safe on Python 2 unless subprocess32 has been installed. Default. - ``OS_SYSTEM`` Uses temporary files. Probably OFED-fork safe. .. warning:: OFED-fork safe system call method might be required to avoid crashes on OFED-based (InfiniBand) clusters! If using python 2, installing subprocess32 is recommended. instant-2017.2.0/doc/sphinx/source/releases.rst0000644000231000000010000000037413211253757020462 0ustar chrisdaemon.. title:: Release notes ============= Release notes ============= .. toctree:: :maxdepth: 2 releases/next releases/v2017.2.0 releases/v2017.1.0.post1 releases/v2017.1.0 releases/v2016.2.0 releases/v2016.1.0 releases/v1.6.0 instant-2017.2.0/doc/sphinx/source/index.rst0000644000231000000010000000106513211253757017764 0ustar chrisdaemon.. title:: Instant ======= Instant ======= Instant is a Python module that allows for instant inlining of C and C++ code in Python. It is a small Python module built on top of SWIG and Distutils. Instant is part of the FEniCS Project. For more information, visit http://www.fenicsproject.org. Documentation ============= .. toctree:: :titlesonly: :maxdepth: 1 installation manual API reference releases [FIXME: These links don't belong here, should go under API reference somehow.] * :ref:`genindex` * :ref:`modindex` instant-2017.2.0/doc/sphinx/README0000644000231000000010000000120113211253757015473 0ustar chrisdaemon==================== Sphinx documentation ==================== Instant is documented using Sphinx and reStructured text. The documentation is hosted at http://fenics-instant.readthedocs.org/. The online documentation is automatically updated upon pushes to the Instant master branch. Updating the API documentation ============================== If the Instant API is changed, the script:: ./generate-apidoc must be run to update the autodoc file. The script can be run from any directory. Building the documentation locally ================================== The HTML documentation can be built locally using:: make html instant-2017.2.0/doc/sphinx/Makefile0000644000231000000010000001516713211253757016273 0ustar chrisdaemon# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Instant.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Instant.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/Instant" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Instant" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." latexpdfja: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." xml: $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." pseudoxml: $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." instant-2017.2.0/doc/man/0000755000231000000010000000000013211253757014063 5ustar chrisdaemoninstant-2017.2.0/doc/man/man1/0000755000231000000010000000000013211253757014717 5ustar chrisdaemoninstant-2017.2.0/doc/man/man1/instant-clean.1.gz0000644000231000000010000000056113211253757020162 0ustar chrisdaemon\Hinstant-clean.1]_k0)y,2NA^VRInOh$?s TUVV:j2{̅5ymI3XpB4D&H.7OPB;g*ϑf&}%tFfՏ8Kqz̓8#>8?Ns±5܊ۗ$_ainstant-2017.2.0/doc/man/man1/instant-showcache.1.gz0000644000231000000010000000064213211253757021044 0ustar chrisdaemonHQk0)eaM q_7"V}Ue T~g(\kܸ,qJzƱF<]HhB69Ut^c8g?щ ‰}VmHSHVb=52(-U?_^LћR0ģ滣Wx0D,-<ΓF!:8j|nj-x|H0Z X^;XnVp>'8>={^sɮۏ#MVHI]uN렻Hnw^^=om׸oEs@Oinstant-2017.2.0/AUTHORS0000644000231000000010000000117013211253757013612 0ustar chrisdaemonMain authors: Martin Sandve Alnæs Kent-Andre Mardal Magne Westlie Ilmar Wilbers Suggestions, bugfixes etc: Johan Hake Anders Logg Johannes Ring Ola Skavhaug Garth N. Wells Florian Rathgeber Jan Blechta Mikael Mortensen Andre Massing Joachim B. Haga instant-2017.2.0/release.conf0000644000231000000010000000031013211253757015024 0ustar chrisdaemon# Configuration file for fenics-release PACKAGE="instant" BRANCH="master" FILES="ChangeLog.rst \ setup.py \ doc/sphinx/source/releases/next.rst \ doc/sphinx/source/releases.rst" instant-2017.2.0/ChangeLog.rst0000644000231000000010000000652513211253757015134 0ustar chrisdaemonChangelog ========= 2017.2.0 (2017-10-05) --------------------- - Maintenance release 2017.1.0.post1 (2017-09-12) --------------------- - Change PyPI package name to fenics-instant. 2017.1.0 (2017-05-09) --------------------- - Minor fixes 2016.2.0 (2016-11-30) --------------------- - Add Python version string to hash signature input - Add pipelines testing, with py2 and py3 coverage - Remove commands module (removed from Py3) - Switch unit tests to pytest 2016.1.0 (2016-06-23) --------------------- - Minor fixes 1.6.0 (2015-07-28) ------------------ - Minor fixes 1.5.0 (2015-01-12) ------------------ - Require Python 2.7 - Python 3 support 1.4.0 (2014-06-02) ------------------ - Introduce env var ``INSTANT_SYSTEM_CALL_METHOD`` for switching method for calling external programs and introduce possibly OFED-fork safe implementation 1.3.0 (2014-01-07) ------------------ - Add ``file_lock`` which can be used within a ``with`` statement - Introduce ``set_log_level`` and deprecate ``set_logging_level`` 1.2.0 (2013-03-24) ------------------ - Allow to use CMake instead of distutils/pkg-config 1.1.0 (2013-01-07) ------------------ - Converting python2 syntax to python3 (run 2to3) - Patch to make instant work with python2 - Cache dir is now created if not existing 1.0.0 (2011-12-07) ------------------ - Copy all files to ``~/.instant/error/module_name`` when Instant fails - If environment variable ``INSTANT_DISPLAY_COMPILE_LOG`` is set the content of ``compile.log`` will be displayed - Removed copying of ``compile.log`` to ``~/.instant/error/`` 1.0-beta2 (2011-10-28) ---------------------- - Added support for flufl.lock for NFS safe file locking 1.0-beta (2011-08-11) --------------------- - Error log is now copied to ``~/.instant/error/module_name/compile.log`` and ``~/.instant/error/compile.log`` for easier retrieval 0.9.10 (2011-05-16) ------------------- - Added support for setting swig binary and swig path 0.9.9 (2011-02-23) ------------------ - Optimizations - Added support for VTK and VMTK 0.9.8 (2010-02-15) ------------------ - Fix cache related memory leak 0.9.7 ----- - Use typemaps from the NumPy SWIG interface file (numpy.i) enabling the use of many new data types. - Removed support for Numeric and numarray. 0.9.6 ----- - Minor update with some new utility functions required by FFC. 0.9.5 ----- - Restructured and rewritten much of the code. - Improved multilevel cache functionality. - Added instant-clean and instant-showcache scripts. 0.9.4 ----- - Various new examples with swiginac and sympy implemented. - Bug fix on 64bit. Removed director flag by default. 0.9.3 ----- - Implemented caching 0.9.2 ----- - Bug fix for the JIT in FFC 0.9.1 ----- - Added test example which demonstrate use of external C code. - Added flag to turn of regeneration of the interface file (useful during debugging) 0.9 --- - Port to Windows with mingw by laserjungle, some updates by Martin Alnæs, and some cleanup. 0.8 --- - Added support for NumPy and Numarray. 0.7 --- - Added functionality for the use of pkg-config files. 0.6 --- - Created a more user-friendly interface 0.5 --- - Added SWIG directors for cross language inheritance 0.4 --- - Added md5sum to avoid unnecessary compilation 0.3 --- - Support for NumPy arrays 0.2 --- - Fixed bug in setup script 0.1 --- - Initial release of Instant instant-2017.2.0/README.rst0000644000231000000010000000403413211253757014233 0ustar chrisdaemon======= Instant ======= Instant is a Python module that allows for instant inlining of C and C++ code in Python. It is a small Python module built on top of SWIG and Distutils. Instant is part of the FEniCS Project. For more information, visit http://www.fenicsproject.org. Documentation ============= Documentation can be viewed at http://fenics-instant.readthedocs.org/. .. image:: https://readthedocs.org/projects/fenics-instant/badge/?version=latest :target: http://fenics.readthedocs.io/projects/instant/en/latest/?badge=latest :alt: Documentation Status Automated Testing ================= We use Bitbucket Pipelines and Atlassian Bamboo to perform automated testing. .. image:: https://bitbucket-badges.useast.atlassian.io/badge/fenics-project/instant.svg :target: https://bitbucket.org/fenics-project/instant/addon/pipelines/home :alt: Pipelines Build Status .. image:: http://fenics-bamboo.simula.no:8085/plugins/servlet/wittified/build-status/IN-ID :target: http://fenics-bamboo.simula.no:8085/browse/IN-ID/latest :alt: Bamboo Build Status Code Coverage ============= Code coverage reports can be viewed at https://coveralls.io/bitbucket/fenics-project/instant. .. image:: https://coveralls.io/repos/bitbucket/fenics-project/instant/badge.svg?branch=master :target: https://coveralls.io/bitbucket/fenics-project/instant?branch=master :alt: Coverage Status License ======= This program 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 3 of the License, or (at your option) any later version. This program 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 program. If not, see . instant-2017.2.0/test/0000755000231000000010000000000013211253757013522 5ustar chrisdaemoninstant-2017.2.0/test/_test_ode_omp.py0000755000231000000010000000352713211253757016726 0ustar chrisdaemonfrom __future__ import print_function from instant import inline_with_numpy from numpy import * import time def time_loop2(p, Q, A, B, dt, N, p0): p[0] = p0 for i in range(1, N): p[i] = p[i-1] + dt*(B*Q[i] - A*p[i-1]) c_code = r''' void time_loop(int n, double* p, int m, double* Q, double A, double B, double dt, int N, double p0){ if ( n != m ) { printf("n and m should be equal"); return; } if ( n != N ) { printf("n and N should be equal"); return; } #pragma omp parallel { int id; id = omp_get_thread_num(); printf("Thread %d\n", id); p[0] = p0; #pragma omp for for (int i=1; i tmp) { tmp = array1[i]; } } return tmp; } """ c_module = inline_module_with_numpy(c_code, arrays = [['n1', 'array1']], cache_dir="test_cache") a = numpy.arange(10000000); a = numpy.sin(a) sum_func = c_module.sum max_func = c_module.max sum = sum_func(a) max = max_func(a) print("sum ", sum) print("max ", max) instant-2017.2.0/test/test_instant_system_calls.py0000644000231000000010000000107013211253757021373 0ustar chrisdaemonfrom __future__ import print_function import os from instant import inline def test_system_call_subprocess(): os.environ["INSTANT_SYSTEM_CALL_METHOD"] = "SUBPROCESS" add_func = inline("double add(double a, double b){ return a+b; }", cache_dir="test_cache") print("The sum of 3 and 4.5 is ", add_func(3, 4.5)) def test_system_call_os_system(): os.environ["INSTANT_SYSTEM_CALL_METHOD"] = "OS_SYSTEM" add_func = inline("double add(double c, double d){ return c+d; }", cache_dir="test_cache") print("The sum of 3 and 4.5 is ", add_func(3, 4.5)) instant-2017.2.0/test/pytest.ini0000644000231000000010000000036313211253757015555 0ustar chrisdaemon[pytest] # We use fixture features requiring pytest 2.4 minversion = 2.4 # Make pytest ignore temp folders norecursedirs = .* __pycache__ test_*_tempdir # Make pytest ignore the book files and other utility .py files python_files = test*.py instant-2017.2.0/test/test21.py0000644000231000000010000000161313211253757015217 0ustar chrisdaemonfrom __future__ import print_function import sys, os, threading from instant import inline def compile_stuff(i): c_code = """ double sum(int a, int b) { return a + b; } // Code number %d """ % (i % 2) func = inline(c_code, cache_dir="test_locking_cache") s = func(i, 3) assert s == (i+3) print("In run %d, result is %d as expected." % (i, s)) if __name__ == "__main__": cmd = sys.argv[0] args = sys.argv[1:] if args: print("Compiling with args =", args) i, = args compile_stuff(int(i)) else: print("Starting new processes to compile.") def run(i): os.system("python %s %d" % (cmd, i)) threads = [] for i in range(10): threads.append( threading.Thread(target=run, args=(i,)) ) for t in threads: t.start() for t in threads: t.join() instant-2017.2.0/test/test_ode.py0000644000231000000010000000267313211253757015712 0ustar chrisdaemonfrom __future__ import print_function from instant import inline_with_numpy from numpy import * import time def time_loop2(p, Q, A, B, dt, N, p0): p[0] = p0 for i in range(1, N): p[i] = p[i-1] + dt*(B*Q[i] - A*p[i-1]) c_code = """ void time_loop(int n, double* p, int m, double* Q, double A, double B, double dt, int N, double p0) { if ( n != m ) { printf("n and m should be equal"); return; } if ( n != N ) { printf("n and N should be equal"); return; } p[0] = p0; for (int i=1; i 1 assert t2 < 1 and t2 > 0.4 assert t3 < 1 and t3 > 0.4 assert t4 < 1 and t4 > 0.4 assert t5 < 1 and t5 > 0.4 instant-2017.2.0/test/u000000.vtu0000644000231000000010000011005413211253757015167 0ustar chrisdaemon 13.839100 12.873900 0.000000 13.623200 12.606700 0.000000 13.874600 12.666100 0.000000 13.742100 12.401000 0.000000 13.910000 12.458200 0.000000 10.547900 14.172600 0.000000 10.355600 14.565700 0.000000 10.326900 14.164100 0.000000 10.621100 14.520300 0.000000 10.694300 14.868000 0.000000 10.384300 14.967300 0.000000 10.767400 15.215800 0.000000 10.413000 15.368900 0.000000 9.963150 11.221800 0.000000 10.115600 11.587700 0.000000 9.878450 11.540300 0.000000 10.226700 11.350200 0.000000 10.262900 11.017800 0.000000 10.047900 10.903300 0.000000 10.132600 10.584800 0.000000 10.469000 10.395900 0.000000 10.217300 10.266300 0.000000 10.480900 10.629600 0.000000 10.497700 10.960200 0.000000 10.514500 11.290900 0.000000 10.330500 11.612300 0.000000 10.531300 11.621500 0.000000 10.750000 10.436100 0.000000 11.415600 10.974000 0.000000 11.156800 11.211600 0.000000 11.134500 10.911800 0.000000 11.275500 10.648000 0.000000 11.180300 11.728000 0.000000 11.085100 11.490700 0.000000 11.282100 11.568300 0.000000 10.955000 11.666500 0.000000 10.782000 11.450500 0.000000 10.847800 11.195000 0.000000 10.913600 10.939500 0.000000 10.979300 10.684000 0.000000 11.045100 10.428500 0.000000 11.328500 10.447100 0.000000 11.574800 10.564800 0.000000 11.782600 10.783000 0.000000 11.615800 11.044800 0.000000 11.449000 11.306500 0.000000 11.986700 10.994400 0.000000 11.840200 11.314000 0.000000 11.693700 11.633600 0.000000 11.386000 11.822300 0.000000 11.547200 11.953200 0.000000 11.834300 11.777400 0.000000 11.639200 12.124300 0.000000 12.029400 11.430500 0.000000 12.224500 11.083700 0.000000 12.093300 11.830400 0.000000 12.345200 11.586500 0.000000 12.510600 11.064700 0.000000 12.663100 11.421500 0.000000 12.799100 11.165100 0.000000 12.962000 11.398200 0.000000 12.955400 11.676800 0.000000 12.666100 11.823000 0.000000 12.331100 11.992500 0.000000 11.996000 12.161900 0.000000 11.661000 12.331300 0.000000 13.010000 11.908700 0.000000 12.908600 13.287500 0.000000 12.747700 12.847900 0.000000 13.109900 12.946300 0.000000 12.584700 13.154500 0.000000 12.385600 12.749500 0.000000 12.260800 13.021400 0.000000 12.023400 12.651000 0.000000 11.936900 12.888300 0.000000 11.661200 12.775000 0.000000 11.661300 12.552600 0.000000 13.371400 12.646600 0.000000 13.122400 12.661600 0.000000 13.360800 12.414000 0.000000 13.134900 12.377000 0.000000 13.352900 12.238100 0.000000 13.147400 12.092300 0.000000 13.611900 12.356600 0.000000 11.364700 15.866000 0.000000 11.426000 16.340900 0.000000 11.153700 16.262600 0.000000 11.078200 15.945400 0.000000 15.226600 14.859800 0.000000 15.662200 14.943400 0.000000 15.451000 15.128600 0.000000 15.416800 14.669800 0.000000 15.002100 14.590900 0.000000 15.171300 14.396200 0.000000 14.839700 15.075400 0.000000 14.713100 14.713900 0.000000 15.215500 15.288800 0.000000 14.966300 15.437000 0.000000 14.540000 15.166100 0.000000 14.710800 15.581400 0.000000 14.369200 14.750700 0.000000 14.050300 15.141200 0.000000 14.004500 14.759900 0.000000 14.450300 15.721000 0.000000 14.219900 15.627500 0.000000 13.989500 15.534000 0.000000 13.549000 15.355300 0.000000 13.108500 15.176500 0.000000 13.347500 14.928300 0.000000 13.652600 14.799600 0.000000 13.094400 16.273900 0.000000 13.191200 15.913800 0.000000 13.370800 16.189700 0.000000 12.727400 15.990300 0.000000 12.816500 16.340700 0.000000 12.892200 15.454500 0.000000 12.638200 15.639900 0.000000 12.283400 16.035800 0.000000 12.308000 15.657700 0.000000 12.537800 16.388000 0.000000 12.258800 16.413800 0.000000 11.850500 16.018400 0.000000 11.702200 16.392200 0.000000 11.616400 15.648800 0.000000 11.946000 15.611800 0.000000 11.980000 16.415900 0.000000 10.888800 16.160000 0.000000 10.731000 15.808900 0.000000 10.633900 16.036100 0.000000 10.389400 15.895000 0.000000 10.407800 15.590600 0.000000 10.155200 15.740700 0.000000 9.321390 11.895300 0.000000 9.582190 11.700700 0.000000 9.546900 11.939100 0.000000 9.459500 12.115700 0.000000 9.252960 12.134600 0.000000 9.180660 12.000400 0.000000 9.039940 12.105400 0.000000 11.120200 14.864200 0.000000 11.170800 15.216100 0.000000 11.083700 14.609500 0.000000 11.047100 14.354900 0.000000 10.778100 14.130700 0.000000 12.075900 15.059600 0.000000 11.981200 14.453900 0.000000 12.292000 14.802000 0.000000 11.694200 14.590600 0.000000 11.792200 15.267300 0.000000 11.407200 14.727400 0.000000 11.491600 15.306500 0.000000 12.298700 13.760000 0.000000 12.765900 13.617300 0.000000 12.657200 13.934600 0.000000 12.387200 13.480800 0.000000 11.940100 13.585400 0.000000 12.008400 13.344300 0.000000 11.581500 13.410700 0.000000 11.629700 13.207800 0.000000 11.653500 12.994600 0.000000 14.436600 13.173000 0.000000 14.183700 12.817100 0.000000 14.509300 12.915400 0.000000 14.105800 13.098200 0.000000 14.232600 12.553300 0.000000 14.565100 12.652400 0.000000 14.892900 12.765900 0.000000 14.832800 12.999500 0.000000 14.772600 13.233100 0.000000 15.201600 12.904300 0.000000 15.127900 13.156900 0.000000 15.054300 13.409500 0.000000 15.234800 13.709300 0.000000 15.337500 13.297000 0.000000 15.470700 13.498200 0.000000 15.476600 13.077500 0.000000 15.706500 13.287200 0.000000 15.882600 13.526000 0.000000 15.630200 13.743100 0.000000 15.996300 13.786300 0.000000 15.657800 14.062100 0.000000 16.039100 14.060700 0.000000 15.276400 14.063500 0.000000 16.004700 14.340500 0.000000 15.612500 14.381400 0.000000 15.901700 14.610000 0.000000 11.788700 13.777800 0.000000 11.498400 13.604100 0.000000 12.079000 13.951600 0.000000 12.558300 14.238500 0.000000 11.819500 14.272700 0.000000 12.444700 14.528000 0.000000 11.502900 13.918100 0.000000 11.206700 13.924700 0.000000 11.375500 13.775300 0.000000 11.002600 14.045600 0.000000 9.714110 15.397900 0.000000 10.099000 15.334000 0.000000 9.930380 15.574800 0.000000 9.713240 14.997700 0.000000 10.073600 14.973800 0.000000 9.505400 15.210600 0.000000 9.303300 15.013600 0.000000 9.578800 14.708300 0.000000 10.054300 14.613100 0.000000 9.854300 14.403100 0.000000 10.129800 14.097800 0.000000 9.706900 14.123800 0.000000 9.970830 13.967600 0.000000 9.442970 14.280100 0.000000 9.179030 14.436300 0.000000 9.106850 14.807300 0.000000 8.915100 14.592600 0.000000 9.697300 13.870800 0.000000 9.851230 13.791600 0.000000 9.471900 13.986800 0.000000 9.246500 14.102700 0.000000 8.986800 14.236300 0.000000 8.727110 14.369900 0.000000 9.759630 13.610000 0.000000 8.363620 13.902900 0.000000 8.796040 13.895900 0.000000 8.542120 14.139900 0.000000 8.599120 13.521400 0.000000 8.198950 13.658800 0.000000 8.321450 13.265400 0.000000 8.055620 13.407500 0.000000 8.587270 13.123200 0.000000 8.984230 13.355000 0.000000 8.853100 12.981100 0.000000 9.115370 13.728800 0.000000 8.145440 12.587300 0.000000 7.862930 12.883100 0.000000 7.828560 12.609900 0.000000 8.139680 12.943300 0.000000 8.444440 12.867100 0.000000 8.462310 12.564800 0.000000 8.748160 12.776200 0.000000 8.779180 12.542200 0.000000 9.055730 12.872700 0.000000 9.096060 12.519700 0.000000 9.258360 12.764400 0.000000 7.941110 13.149000 0.000000 7.885870 12.046600 0.000000 8.056330 12.342600 0.000000 7.840170 12.330000 0.000000 8.159570 12.112200 0.000000 8.344530 12.367400 0.000000 8.433270 12.177800 0.000000 8.706970 12.243500 0.000000 8.980670 12.309100 0.000000 8.762100 12.021400 0.000000 8.949530 12.161400 0.000000 8.559720 11.870300 0.000000 8.369810 11.966800 0.000000 8.141540 11.837400 0.000000 7.953890 11.763300 0.000000 8.043210 11.484700 0.000000 8.357340 11.719200 0.000000 9.628670 10.620000 0.000000 9.694410 11.035400 0.000000 9.385690 10.860200 0.000000 9.157050 10.605800 0.000000 9.400030 10.365600 0.000000 9.871640 10.379800 0.000000 9.676280 11.546100 0.000000 9.420820 11.287700 0.000000 9.165360 11.029200 0.000000 8.909890 10.770800 0.000000 8.880950 10.328800 0.000000 8.654430 10.512400 0.000000 9.140420 10.179100 0.000000 9.422630 10.078500 0.000000 9.706910 10.051100 0.000000 9.972540 10.120500 0.000000 8.293950 10.960500 0.000000 8.376100 11.387200 0.000000 8.155880 11.215500 0.000000 8.722100 10.994000 0.000000 8.741750 11.360000 0.000000 8.459450 10.724600 0.000000 9.108280 11.349400 0.000000 9.373230 11.585900 0.000000 9.070180 11.625700 0.000000 8.713760 11.672400 0.000000 10.700400 10.953800 0.000000 10.765600 10.678900 0.000000 10.734800 11.633800 0.000000 12.138500 12.398600 0.000000 12.517000 12.370500 0.000000 12.855800 12.206600 0.000000 13.457300 15.787200 0.000000 13.645200 16.090200 0.000000 13.743400 15.852600 0.000000 13.723400 15.660600 0.000000 13.976200 15.745800 0.000000 14.185600 15.853800 0.000000 13.917000 15.977500 0.000000 11.542500 14.382500 0.000000 11.294800 14.209800 0.000000 11.661200 14.095400 0.000000 9.512360 13.757500 0.000000 9.292440 13.830600 0.000000 9.338380 13.558600 0.000000 9.527760 13.535700 0.000000 9.384330 13.286500 0.000000 9.430270 13.014400 0.000000 9.574700 13.241300 0.000000 9.676580 13.433400 0.000000 9.161640 13.117900 0.000000 8.920990 11.985600 0.000000 9.079880 11.949800 0.000000 0 1 2 1 2 3 2 3 4 5 6 7 5 6 8 6 8 9 6 9 10 9 10 11 10 11 12 13 14 15 13 14 16 13 16 17 13 17 18 17 18 19 19 20 21 19 20 22 17 19 22 17 22 23 17 23 24 16 17 24 24 25 26 16 24 25 14 16 25 20 22 27 28 29 30 28 30 31 32 33 34 32 33 35 33 35 36 33 36 37 29 33 37 29 37 38 29 30 38 30 38 39 30 31 39 31 39 40 31 40 41 31 41 42 28 31 42 28 42 43 28 43 44 28 44 45 28 29 45 29 34 45 29 33 34 43 44 46 44 46 47 44 45 47 45 47 48 34 45 48 34 48 49 48 49 50 50 51 52 48 50 51 48 51 53 47 48 53 46 47 53 46 53 54 51 53 55 53 55 56 53 54 56 54 56 57 56 57 58 57 58 59 58 59 60 58 60 61 58 61 62 56 58 62 56 62 63 55 56 63 55 63 64 52 64 65 51 52 64 51 55 64 61 62 66 67 68 69 67 68 70 68 70 71 70 71 72 71 72 73 72 73 74 73 74 75 73 75 76 69 77 78 77 78 79 78 79 80 79 80 81 80 81 82 79 81 83 1 3 83 1 79 83 1 77 79 84 85 86 84 86 87 88 89 90 88 89 91 88 91 92 91 92 93 88 92 94 92 94 95 88 90 96 88 94 96 94 96 97 97 98 99 94 97 98 94 95 98 95 98 100 100 101 102 98 100 101 98 99 103 98 103 104 98 101 104 101 104 105 101 105 106 106 107 108 106 108 109 101 106 109 101 102 109 110 111 112 110 113 114 110 111 113 111 113 115 113 115 116 113 116 117 116 117 118 113 114 119 113 117 119 117 119 120 85 121 122 84 85 121 84 121 123 121 123 124 117 118 124 117 121 124 117 120 125 117 121 125 121 122 125 86 87 126 126 127 128 87 126 127 127 128 129 127 129 130 129 130 131 132 133 134 132 134 135 132 135 136 132 136 137 136 137 138 11 139 140 9 11 139 9 139 141 8 9 141 8 141 142 8 142 143 5 8 143 144 145 146 144 145 147 144 147 148 147 148 149 148 149 150 140 149 150 139 140 149 151 152 153 151 152 154 151 154 155 154 155 156 155 156 157 156 157 158 67 70 152 70 152 154 70 72 154 72 154 156 72 74 156 74 156 158 74 158 159 160 161 162 160 161 163 0 161 163 0 2 161 2 4 164 2 161 164 161 164 165 161 162 165 162 165 166 162 166 167 162 167 168 160 162 168 166 167 169 167 169 170 167 168 170 168 170 171 172 173 174 171 172 173 170 171 173 169 170 175 170 173 175 173 175 176 173 174 176 174 176 177 174 177 178 177 178 179 179 180 181 178 179 180 178 180 182 172 178 182 172 174 178 180 181 183 180 183 184 183 184 185 89 91 185 91 184 185 91 93 184 93 182 184 180 182 184 155 157 186 157 186 187 155 186 188 151 155 188 151 153 189 151 188 189 145 188 189 145 188 190 145 189 191 145 146 191 192 193 194 142 143 195 196 197 198 196 197 199 197 199 200 196 199 201 199 201 202 199 202 203 199 203 204 199 200 204 203 204 205 204 205 206 7 204 206 6 7 204 6 10 204 10 200 204 10 197 200 10 12 197 12 130 197 130 131 197 131 197 198 205 206 207 206 207 208 205 207 209 203 205 209 203 209 210 202 203 211 203 210 211 210 211 212 207 208 213 208 213 214 207 213 215 207 209 215 209 215 216 209 210 216 210 216 217 210 212 217 212 217 218 213 214 219 220 221 222 220 221 223 220 223 224 224 225 226 223 224 225 223 225 227 227 228 229 223 227 228 223 228 230 221 223 230 216 221 230 216 217 221 217 218 222 217 221 222 231 232 233 231 232 234 231 234 235 231 235 236 235 236 237 236 237 238 238 239 240 239 240 241 237 238 239 229 237 239 227 229 237 227 235 237 225 227 235 225 234 235 225 226 242 225 234 242 232 234 242 243 244 245 243 244 246 244 246 247 246 247 248 247 248 249 238 240 250 238 249 250 236 238 249 236 247 249 231 236 247 231 244 247 231 233 244 233 244 245 248 249 251 249 250 252 249 251 252 248 251 253 248 253 254 246 248 254 246 254 255 243 246 255 243 255 256 255 256 257 255 257 258 254 255 258 253 254 258 259 260 261 259 261 262 259 262 263 259 263 264 13 15 265 13 260 265 260 265 266 260 261 266 261 266 267 261 262 267 262 267 268 268 269 270 262 268 269 262 269 271 262 263 271 263 271 272 263 272 273 263 264 273 264 273 274 21 264 274 19 21 264 19 259 264 18 19 259 18 259 260 13 18 260 275 276 277 275 276 278 276 278 279 275 278 280 268 270 280 268 278 280 267 268 278 267 278 281 278 279 281 266 267 281 265 266 282 266 281 282 281 282 283 279 281 283 279 283 284 276 279 284 258 276 284 257 258 276 257 276 277 22 23 285 22 285 286 22 27 286 27 39 40 27 39 286 38 39 286 38 285 286 37 38 285 24 36 37 26 36 287 24 26 36 24 37 285 23 24 285 35 36 287 32 34 49 63 64 288 63 288 289 63 289 290 62 63 290 62 66 290 66 82 290 80 82 290 78 80 290 68 78 290 68 69 78 68 289 290 68 71 289 71 288 289 71 73 288 65 73 76 65 73 288 64 65 288 74 75 159 111 112 291 112 291 292 291 292 293 291 293 294 293 294 295 105 294 295 104 105 295 103 104 296 104 295 296 295 296 297 293 295 297 292 293 297 106 107 115 111 115 291 106 115 291 106 291 294 105 106 294 147 149 298 141 149 298 139 141 149 141 298 299 141 142 299 142 195 299 193 195 299 192 193 299 192 299 300 298 299 300 190 298 300 145 147 190 147 190 298 186 187 192 187 192 194 186 192 300 186 188 300 188 190 300 213 215 301 215 216 302 215 301 302 301 302 303 301 303 304 303 304 305 305 306 307 304 305 307 304 307 308 219 304 308 219 301 304 213 219 301 239 241 309 241 306 309 305 306 309 228 303 305 230 302 303 216 230 302 228 230 303 228 305 309 228 229 309 229 239 309 283 310 311 283 284 310 251 284 310 251 253 284 253 258 284 251 252 310 138 252 310 138 310 311 137 138 311 132 137 311 133 265 282 132 133 282 132 282 283 132 283 311 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108 111 114 117 120 123 126 129 132 135 138 141 144 147 150 153 156 159 162 165 168 171 174 177 180 183 186 189 192 195 198 201 204 207 210 213 216 219 222 225 228 231 234 237 240 243 246 249 252 255 258 261 264 267 270 273 276 279 282 285 288 291 294 297 300 303 306 309 312 315 318 321 324 327 330 333 336 339 342 345 348 351 354 357 360 363 366 369 372 375 378 381 384 387 390 393 396 399 402 405 408 411 414 417 420 423 426 429 432 435 438 441 444 447 450 453 456 459 462 465 468 471 474 477 480 483 486 489 492 495 498 501 504 507 510 513 516 519 522 525 528 531 534 537 540 543 546 549 552 555 558 561 564 567 570 573 576 579 582 585 588 591 594 597 600 603 606 609 612 615 618 621 624 627 630 633 636 639 642 645 648 651 654 657 660 663 666 669 672 675 678 681 684 687 690 693 696 699 702 705 708 711 714 717 720 723 726 729 732 735 738 741 744 747 750 753 756 759 762 765 768 771 774 777 780 783 786 789 792 795 798 801 804 807 810 813 816 819 822 825 828 831 834 837 840 843 846 849 852 855 858 861 864 867 870 873 876 879 882 885 888 891 894 897 900 903 906 909 912 915 918 921 924 927 930 933 936 939 942 945 948 951 954 957 960 963 966 969 972 975 978 981 984 987 990 993 996 999 1002 1005 1008 1011 1014 1017 1020 1023 1026 1029 1032 1035 1038 1041 1044 1047 1050 1053 1056 1059 1062 1065 1068 1071 1074 1077 1080 1083 1086 1089 1092 1095 1098 1101 1104 1107 1110 1113 1116 1119 1122 1125 1128 1131 1134 1137 1140 1143 1146 1149 1152 1155 1158 1161 1164 1167 1170 1173 1176 1179 1182 1185 1188 1191 1194 1197 1200 1203 1206 1209 1212 1215 1218 1221 1224 1227 1230 1233 1236 1239 1242 1245 1248 1251 1254 1257 1260 1263 1266 1269 1272 1275 1278 1281 1284 1287 1290 1293 1296 1299 1302 1305 1308 1311 1314 1317 1320 1323 1326 1329 1332 1335 1338 1341 1344 1347 1350 1353 1356 1359 1362 1365 1368 1371 1374 1377 1380 1383 1386 1389 1392 1395 1398 1401 1404 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 1.426730e+00 1.374390e+00 1.418458e+00 1.384971e+00 1.414920e+00 1.849535e+00 2.034070e+00 1.853364e+00 1.927511e+00 1.918304e+00 1.981738e+00 1.907446e+00 1.953255e+00 3.827848e-01 4.719162e-01 3.755406e-01 4.808449e-01 4.632717e-01 3.920855e-01 3.913151e-01 4.529437e-01 3.625016e-01 4.907213e-01 5.218821e-01 5.517520e-01 5.339134e-01 5.764968e-01 5.526561e-01 7.511818e-01 6.983820e-01 6.762518e-01 6.948893e-01 7.248998e-01 6.907134e-01 7.548820e-01 6.560157e-01 6.171855e-01 6.222235e-01 6.238414e-01 6.257282e-01 6.378878e-01 6.995318e-01 7.503244e-01 8.197499e-01 8.089605e-01 7.867080e-01 9.149888e-01 9.043851e-01 9.047515e-01 8.217952e-01 9.198666e-01 9.746110e-01 1.011255e+00 9.754204e-01 1.012503e+00 1.053489e+00 1.074722e+00 1.081233e+00 1.118978e+00 1.121136e+00 1.143241e+00 1.170624e+00 1.158676e+00 1.132203e+00 1.102542e+00 1.088778e+00 1.215815e+00 1.396933e+00 1.328120e+00 1.339906e+00 1.380629e+00 1.289094e+00 1.343167e+00 1.231812e+00 1.286913e+00 1.225025e+00 1.156542e+00 1.329536e+00 1.319004e+00 1.321630e+00 1.292160e+00 1.311773e+00 1.266043e+00 1.360820e+00 1.803160e+00 1.797502e+00 1.812828e+00 1.827300e+00 1.661053e+00 1.651653e+00 1.658974e+00 1.651466e+00 1.663744e+00 1.648127e+00 1.678517e+00 1.682506e+00 1.667356e+00 1.677261e+00 1.690835e+00 1.687474e+00 1.698503e+00 1.707990e+00 1.710203e+00 1.697164e+00 1.703861e+00 1.710704e+00 1.721403e+00 1.728308e+00 1.722797e+00 1.717858e+00 1.739873e+00 1.735256e+00 1.731663e+00 1.750118e+00 1.748326e+00 1.737898e+00 1.750604e+00 1.766000e+00 1.766554e+00 1.756886e+00 1.765786e+00 1.782280e+00 1.785295e+00 1.789636e+00 1.780063e+00 1.775074e+00 1.833173e+00 1.876666e+00 1.864950e+00 1.897795e+00 1.932199e+00 1.930100e+00 1.018333e-01 1.901935e-01 1.370078e-01 1.148508e-01 7.679714e-02 4.332885e-02 -4.689006e-02 1.828111e+00 1.825396e+00 1.817515e+00 1.790165e+00 1.805169e+00 1.732487e+00 1.675558e+00 1.697901e+00 1.721164e+00 1.763329e+00 1.771962e+00 1.788127e+00 1.517553e+00 1.471663e+00 1.546011e+00 1.451654e+00 1.486586e+00 1.419212e+00 1.438433e+00 1.366569e+00 1.295728e+00 1.492598e+00 1.458610e+00 1.493502e+00 1.460642e+00 1.456579e+00 1.492974e+00 1.529371e+00 1.529664e+00 1.530722e+00 1.563159e+00 1.565013e+00 1.570135e+00 1.603352e+00 1.586983e+00 1.602954e+00 1.588710e+00 1.606575e+00 1.619019e+00 1.618431e+00 1.626772e+00 1.630269e+00 1.632507e+00 1.627950e+00 1.637952e+00 1.640677e+00 1.642863e+00 1.547722e+00 1.511132e+00 1.570044e+00 1.609958e+00 1.656042e+00 1.660906e+00 1.614478e+00 1.667647e+00 1.587308e+00 1.741102e+00 1.970625e+00 1.971209e+00 1.954892e+00 2.004828e+00 2.027037e+00 1.976867e+00 1.946839e+00 2.057755e+00 2.216105e+00 2.495600e+00 1.795388e+00 3.874548e+00 1.343937e+01 2.265145e+00 1.826013e+00 1.868243e+00 1.704072e+00 1.540359e+01 1.403871e+01 2.572474e+00 1.792538e+00 1.524851e+00 1.419526e+00 1.198732e+01 7.367881e-01 9.953851e-01 1.066362e+00 4.675903e-01 4.762042e-01 2.502890e-01 2.885633e-01 4.164100e-02 -2.196188e-02 -4.374769e-01 8.547196e-01 4.474812e-02 1.096382e-01 6.831169e-02 1.222949e-01 1.219348e-03 -7.202822e-02 -3.278376e-01 -3.396092e-01 -1.086061e+00 -8.824770e-01 -1.847974e+00 1.769271e-01 3.591502e-02 3.499963e-02 4.423750e-02 2.107380e-02 -2.191036e-02 -3.412441e-02 -1.518005e-01 -4.034278e-01 -7.488103e-02 -1.865134e-01 -2.456185e-03 3.779400e-03 3.308297e-02 4.031983e-02 5.730886e-02 3.281579e-02 2.751729e-01 2.970351e-01 2.257219e-01 1.976670e-01 2.345695e-01 3.099983e-01 2.678472e-01 2.074246e-01 1.742941e-01 1.599302e-01 1.776912e-01 1.515901e-01 2.061848e-01 2.343206e-01 2.642638e-01 3.017444e-01 1.009769e-01 6.931094e-02 7.728610e-02 1.243480e-01 8.438257e-02 1.255954e-01 1.296628e-01 1.594904e-01 7.508150e-02 2.972408e-02 5.732027e-01 5.708342e-01 6.115545e-01 1.183636e+00 1.226554e+00 1.240142e+00 1.726964e+00 1.723461e+00 1.719283e+00 1.718734e+00 1.711996e+00 1.706451e+00 1.715162e+00 1.707776e+00 1.716561e+00 1.636974e+00 -1.590347e-01 1.233107e+00 3.092582e-01 1.336676e+01 -2.228967e+00 -3.768477e+00 1.116396e+01 1.227489e+01 -1.422023e+00 -6.062756e-02 9.749067e-03 instant-2017.2.0/test/test05.py0000644000231000000010000000272013211253757015221 0ustar chrisdaemonfrom __future__ import print_function import pytest from instant import build_module import numpy import sys import time from functools import reduce c_code = """ /* add function for vectors with all safety checks removed ..*/ void add(int n1, double* array1, int n2, double* array2, int n3, double* array3){ if ( n1 == n2 && n1 == n3 ) { for (int i=0; idimensions[0]; npy_intp dims[1]; dims[0] = n; PyArrayObject* ret; ret = (PyArrayObject*) PyArray_SimpleNew(1, dims, PyArray_DOUBLE); int i; double aj; double bj; double *retj; for (i=0; i < n; i++) { retj = (double*)(ret->data+ret->strides[0]*i); aj = *(double *)(a->data+ a->strides[0]*i); bj = *(double *)(b->data+ b->strides[0]*i); *retj = aj + bj; } return PyArray_Return(ret); } """ def test_build_module(): test4_ext = build_module(code=s, system_headers=["numpy/arrayobject.h"], include_dirs=[numpy.get_include()], init_code='import_array();', modulename="test4_ext") import time t1 = time.time() d = test4_ext.add(a, b) t2 = time.time() print('With instant:', t2 - t1, 'seconds') t1 = time.time() c = a + b t2 = time.time() print('With numpy: ', t2 - t1, 'seconds') difference = abs(c - d) sum = reduce( lambda a, b: a + b, difference) assert sum < 1.0e-12 instant-2017.2.0/test/test17.py0000644000231000000010000000127013211253757015223 0ustar chrisdaemonfrom __future__ import print_function import pytest from time import time from instant import build_module, import_module def test_repeated_build(): #_t = None def tic(): global _t _t = -time() def toc(msg=""): t = time() + _t print("t = %f (%s)" % (t, msg)) return t c_code = """ double sum(double a, double b) { return a+b; } """ # Time a few builds tic() module = build_module(code=c_code) t1 = toc("first build") tic() module = build_module(code=c_code) t2 = toc("second build") tic() module = build_module(code=c_code) t3 = toc("third build") assert t1 > t2 assert t1 > t3 instant-2017.2.0/test/_test_vmtk.py0000644000231000000010000000067113211253757016257 0ustar chrisdaemonfrom __future__ import print_function from instant import inline_vmtk import vmtk from vmtk import vtkvmtk code = """ void test(vtkvmtkDoubleVector* a) { for (int i=0; iGetNumberOfElements(); i++) { a->SetElement(i,i); } } """ func = inline_vmtk(code, cache_dir="test_vmtk") v = vtkvmtk.vtkvmtkDoubleVector() v.Allocate(12, 1) print("norm of v ", v.ComputeNorm()) func(v) print("norm of v after test ", v.ComputeNorm()) instant-2017.2.0/test/test01.py0000644000231000000010000000037313211253757015217 0ustar chrisdaemonfrom __future__ import print_function import pytest from instant import inline def test_inline(): add_func = inline("double add(double a, double b){ return a+b; }", cache_dir="test_cache") assert add_func(3, 4.5) == 7.5 instant-2017.2.0/test/test15.py0000644000231000000010000000236413211253757015226 0ustar chrisdaemonfrom __future__ import print_function import pytest import time #from math import exp, sin, cos def test_2(): try: from sympy import Symbol, exp, sin, cos except: print("You need sympy for this test") return x = Symbol('x') pi = 3.14 f = -3*x**7 - 2*x**3 + 2*exp(x**2) + x**12*(2*exp(2*x) - pi*sin(x)**((-1) + pi)*cos(x)) + 4*(pi**5 + x**5 + 5*pi*x**4 + 5*x*pi**4 + 10*pi**2*x**3 + 10*pi**3*x**2)*exp(123 + x - x**5 + 2*x**4) a = [] t0 = time.time() for i in range(0, 1000): xx = i/1000.0 y = f.subs(x, xx) a.append(y) t1 = time.time() print("Elapsed time with sympy", t1-t0) def test_3(): try: from sympy import Symbol, exp, sin, cos except: print("You need sympy for this test") return x = Symbol('x') pi = 3.14 f = lambda x : -3*x**7 - 2*x**3 + 2*exp(x**2) + x**12*(2*exp(2*x) - pi*sin(x)**((-1) + pi)*cos(x)) \ + 4*(pi**5 + x**5 + 5*pi*x**4 + 5*x*pi**4 + 10*pi**2*x**3 + 10*pi**3*x**2)*exp(123 + x - x**5 + 2*x**4) a = [] t0 = time.time() for i in range(0, 1000): xx = i/1000.0 y = f(xx) a.append(y) t1 = time.time() print("Elapsed time with lambda and math", t1-t0) instant-2017.2.0/test/test16.py0000644000231000000010000000217713211253757015231 0ustar chrisdaemonfrom __future__ import print_function import pytest import instant from instant import build_module, import_module def test_sum(): sig = "((instant unittest test16.py))" # Trying to import module module = import_module(sig, cache_dir="test_cache") if module is None: print("Defining code") c_code = """ class Sum { public: virtual double sum(double a, double b){ return a+b; } }; double use_Sum(Sum& sum, double a, double b) { return sum.sum(a,b); } """ print("Compiling code") module = build_module(code=c_code, signature=sig, cache_dir="test_cache") # Testing module Sum = module.Sum use_Sum = module.use_Sum sum = Sum() a = 3.7 b = 4.8 c = use_Sum(sum, a, b) print("The sum of %g and %g is %g"% (a, b, c)) class Sub(Sum): def __init__(self): Sum.__init__(self) def sum(self, a, b): print("sub") return a-b; sub = Sub() a = 3.7 b = 4.8 c = use_Sum(sub, a, b) print("The sub of %g and %g is %g"% (a, b, c)) instant-2017.2.0/test/test11.py0000644000231000000010000000151613211253757015220 0ustar chrisdaemonfrom __future__ import print_function import pytest import numpy import time import instant from instant import inline_with_numpy def test_numpy_inline(): c_code = """ double sum_of_some_func(int n1, double* array1){ double tmp = 0.0; for (int i=0; i double some_func(double a) { return cos(a) + sin(a); } instant-2017.2.0/test/test02.py0000644000231000000010000000133113211253757015213 0ustar chrisdaemonfrom __future__ import print_function import pytest import numpy import time from instant import inline_with_numpy c_code = """ double sum (int n1, double* array1){ double tmp = 0.0; for (int i=0; iSetFileName(filename); reader1->Update(); vtkUnstructuredGrid* grid; grid= reader1->GetOutput(); std::cout << "Number of cells "<GetNumberOfCells () <GetNumberOfCells () <GetNumberOfCells (); i++) { cell = grid->GetCell (i); std::cout <<"cell no. "<GetCellType () <GetPoints (); std::cout <<"points->GetNumberOfPoints() "<< points->GetNumberOfPoints() <GetNumberOfPoints(); d++){ points->GetPoint(d, x); std::cout <<" x " <GetPointIds(); for (int d=0; dGetNumberOfIds(); d++){ std::cout <<" ids " <GetId(d) < t2 # Try importing module in a separate python process python_interp = sys.executable cmd = python_interp + ' -c "import %s"' % modulename print(cmd) stat = os.system(cmd) assert stat == 0 # a # Build and rebuild with a valid filename as signature sig = "test19_signature_module" tic() module = build_module(code=c_code, signature=sig, cache_dir=cache_dir) assert module is not None t1 = toc("(1) With signature") tic() module = build_module(code=c_code, signature=sig, cache_dir=cache_dir) assert module is not None t2 = toc("(2) With signature") assert t1 > t2 tic() module = import_module(sig, cache_dir) assert module is not None t3 = toc("(3) import_module") assert t1 > t3 # Try importing module in a separate python process python_interp = sys.executable cmd = python_interp + ' -c "import instant; assert instant.import_module(\'%s\', \'%s\') is not None"' % (sig, cache_dir) print(cmd) stat = os.system(cmd) assert stat == 0 # b # Build and rebuild with generic signature string sig = "((test19_signature_module))" tic() module = build_module(code=c_code, signature=sig, cache_dir=cache_dir) assert module is not None t1 = toc("(1) With signature") tic() module = build_module(code=c_code, signature=sig, cache_dir=cache_dir) assert module is not None t2 = toc("(2) With signature") assert t1 > t2 tic() module = import_module(sig, cache_dir) assert module is not None t3 = toc("(3) import_module") assert t1 > t3 # Try importing module in a separate python process python_interp = sys.executable cmd = python_interp + ' -c "import instant; assert instant.import_module(\'%s\', \'%s\') is not None"' % (sig, cache_dir) print(cmd) stat = os.system(cmd) assert stat == 0 # c print("Skipping unit test, see https://bugs.launchpad.net/instant/+bug/518389") # Build and rebuild with generic signature object #sig = Sig("((test19_signature_module))") #tic() #module = build_module(code=c_code, signature=sig, cache_dir=cache_dir) #assert module is not None #t1 = toc("(1) With signature") #tic() #module = build_module(code=c_code, signature=sig, cache_dir=cache_dir) #assert module is not None #t2 = toc("(2) With signature") #assert t1 > t2 #tic() #module = import_module(sig, cache_dir) #assert module is not None #t3 = toc("(3) import_module") #assert t1 > t3 # Build and rebuild without modulename or signature tic() module = build_module(code=c_code, cache_dir=cache_dir) assert module is not None t1 = toc("(1) Without modulename or signature") tic() module = build_module(code=c_code, cache_dir=cache_dir) assert module is not None t2 = toc("(2) Without modulename or signature") assert t1 > t2 instant-2017.2.0/test/_test_omp.py0000755000231000000010000000313213211253757016067 0ustar chrisdaemonfrom __future__ import print_function from instant import inline_with_numpy from numpy import * import time import os c_code = r""" void compute(int n, double* x, int m, double*y) { if ( n != m ) { printf("n and m should be equal"); return; } #pragma omp parallel { int id; id = omp_get_thread_num(); printf("Thread %d\n", id); #pragma omp for for (int i=0; i