diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f267e5e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,61 @@
+### MOAB ###
+**/*.csv
+**/bot.json
+**/tags
+**/.ipynb_checkpoints/
+**/*.pem
+docker-compose.yml
+
+### C ###
+
+# Object files
+*.o
+*.a
+*.so
+*.so.*
+*.dylib
+
+
+### macOS ###
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+
+# Thumbnails
+._*
+
+
+### Python ###
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+.Python
+
+# pyenv
+.python-version
+
+# pipenv
+# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+# However, in case of collaboration, if having platform-specific dependencies or dependencies
+# having no cross-platform support, pipenv may install dependencies that don't work, or not
+# install all needed dependencies.
+#Pipfile.lock
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+pythonenv*
+
+# End of https://www.toptal.com/developers/gitignore/api/c,macos,python
+
diff --git a/NOTICE b/NOTICE
index bfbdae5..11615bf 100644
--- a/NOTICE
+++ b/NOTICE
@@ -5,684 +5,26 @@ listed below (Third Party IP). The original copyright notice and the license und
which Microsoft received such Third Party IP, are set forth below. Such licenses
and notices are provided for informational purposes only.
+miguelgrinberg/flask-video-streaming
+------------------------------------
-bcm2835 (v1.68)
----------------
+Copyright (c) 2014 Miguel Grinberg
-Copyright (c) 2018 Mike McCauley
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
- 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
-.
diff --git a/bin/_exercise.py b/bin/_exercise.py
deleted file mode 100755
index 298243e..0000000
--- a/bin/_exercise.py
+++ /dev/null
@@ -1,67 +0,0 @@
-#!runpy.sh
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from pymoab import *
-from time import sleep
-
-# This needs to be called before INIT
-# Also: do not call sync() on this (segfault)
-print("setting servo offset")
-setServoOffsets(-2, 1, 0)
-
-print("init()")
-init()
-sync()
-sleep(0.1)
-
-print("setting text and icon")
-setText(Text.INIT)
-setIcon(Icon.DOT)
-sync()
-sleep(0.1)
-
-
-print("activating plate")
-activatePlate()
-sync()
-sleep(0.1)
-
-## ^ swap v these two lines and I bet bad things happen
-## due to moab.c:90 and moab.c:91
-
-
-print("cycling angles")
-setText(Text.INFO)
-setIcon(Icon.PAUSE)
-sync()
-sleep(0.2)
-angles = [(0, 0), (0, 15), (15, 0), (0, -15), (-15, 0), (0, 0)]
-for angle in angles:
- setPlateAngles(angle[0], angle[1])
- sync()
- sleep(0.3)
-
-print("menu -> Success")
-setText(Text.CAL_COMPLETE)
-setIcon(Icon.DOT)
-sync()
-sleep(0.2)
-
-print("deactivating...")
-lowerPlate()
-sync()
-sleep(0.2)
-
-# Due to firmware 2.1 bug, disableServoPower sets icon=0 and text=0
-print("cutting servo power...")
-disableServoPower()
-sync()
-sleep(0.2)
-
-print("Menu -> Success (check)")
-setText(Text.CAL_COMPLETE)
-setIcon(Icon.CHECK)
-sync()
-sleep(0.2)
diff --git a/bin/_level.py b/bin/_level.py
deleted file mode 100755
index 7c0e893..0000000
--- a/bin/_level.py
+++ /dev/null
@@ -1,111 +0,0 @@
-#!runpy.sh
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from pymoab import *
-from time import sleep
-from signal import signal, SIGINT
-from sys import exit, argv
-import argparse
-
-
-def shutdown():
- print("deactivating...")
- lowerPlate()
- sync()
- sleep(0.5)
-
- # Due to firmware 2.1 bug, disableServoPower sets icon=0 and text=0
- print("cutting servo power")
- disableServoPower()
- sync()
- sleep(0.1)
-
-
-def setTextIcon(text, icon):
- setText(text)
- setIcon(icon)
- sync()
- sleep(0.1)
-
-
-def startup():
- # This needs to be called before INIT
- # Also: do not call sync() on this (segfault)
- # print("setting servo offset")
- # setServoOffsets(-2, 1, 0)
-
- print("initalizing")
- init()
- sync()
- sleep(0.1)
-
- setTextIcon(Text.INIT, Icon.DOT)
-
- #print("activating plate")
- #activatePlate()
- #sync()
- #sleep(0.1)
-
-
-def sigint(signal_received, frame):
- shutdown()
- exit(1)
-
-
-def main(args):
- startup()
-
- # min (0) all the way down = 160°
- # max (1) fully-extended = 90°
- # y = 160 - 16x/9
- # 1, 90
- # 0, 160
-
- x = clamp(args.height, 0, 1)
-
- y = -70 * x + 160
- print(f"Setting plate to {x:.2f} or {y:.2f}°")
-
- setServoPositions(y,y,y)
- sync()
- sleep(0.1)
- setTextIcon(Text.CAL_COMPLETE, Icon.DOT)
-
- print("press menu to quit...")
- sleep(0.1)
- while not getMenuBtn():
- sleep(0.01)
- sync()
-
- shutdown()
-
-
-def clamp(num, min_value, max_value):
- return max(min(num, max_value), min_value)
-
-def parseArgs():
- p = argparse.ArgumentParser(
- prog="zaxis",
- description="Set the height of the plate in the z-dimension"
- )
-
- p.add_argument(dest="height",
- type=float,
- help="height from 0 to 1")
-
- if len(argv) == 1:
- p.print_help()
- exit(1)
-
- args = p.parse_args()
- return args
-
-if __name__ == "__main__":
- args = parseArgs()
- print(vars(args), flush=True)
-
- signal(SIGINT, sigint)
- main(args)
-
diff --git a/bin/bot b/bin/bot
new file mode 100755
index 0000000..2ee135a
--- /dev/null
+++ b/bin/bot
@@ -0,0 +1,140 @@
+#!/usr/bin/env bash
+# vim:filetype=sh:
+
+# http://www.binaryphile.com/bash/2018/07/26/approach-bash-like-a-developer-part-1-intro.html
+# https://github.com/MatthewZito/sh/pull/1
+
+IFS=$'\n'
+set -o noglob
+shopt -s nocasematch expand_aliases
+alias args?='(( $# ))'
+alias args_include?='include? "$*"'
+alias fewer_args_than?='fewer_than? $#'
+
+this_script="$(basename "$0")"
+HERE=$(dirname "$BASH_SOURCE")
+
+die () {
+ local rc=$?
+
+ present? ${2:-} && rc=$2
+ present? "${1:-}" && echo "$1" >&2
+ exit $rc
+}
+
+define () { IFS=$'\n' read -r -d '' ${1} || true; }
+blank? () { [[ -z ${1:-} ]]; }
+fewer_than? () { (( $1 < $2 )); }
+include? () { [[ $IFS$1$IFS == *"$IFS$2$IFS"* ]]; }
+present? () { [[ -n ${1:-} ]]; }
+sourced? () { [[ ${FUNCNAME[1]} == source ]]; }
+
+split () {
+ local i
+
+ for (( i = 0; i < ${#1}; i++ )); do
+ echo ${1:i:1}
+ done
+}
+
+strict_mode () {
+ case $1 in
+ on ) set -euo pipefail;;
+ off ) set +euo pipefail;;
+ esac
+}
+
+define HELP <&2; exit "$ret"; }
+[[ $EUID -eq 0 ]] || die "$0 run as root. Try again with sudo"
+
+# Hat flashing procedure involves three GPIO pins: 20, 5, and 6
+# Hat enable pin 20
+# Boot mode pin 5
+# Hat reset 6
+
+# Using gpio readall
+# from v2.x flash.c code
+#define BOOT_EN RPI_BPLUS_GPIO_J8_29 BCM 5
+#define HAT_EN RPI_BPLUS_GPIO_J8_38 BCM 20
+#define HAT_RESET RPI_BPLUS_GPIO_J8_31 BCM 6
+
+# Enabling writing to these pins
+sudo raspi-gpio set 20 op
+sudo raspi-gpio set 5 op
+sudo raspi-gpio set 6 op
+
+# Putting firmware into upload mode...
+sudo raspi-gpio set 20 dh
+sudo raspi-gpio set 5 dh
+sudo raspi-gpio set 6 dh
+sleep 1
+sudo raspi-gpio set 6 dl
+
+FN=$1
+echo "Uploading $FN firmware now"
+mcumgr --conntype=serial --connstring=/dev/ttyAMA1,baud=115200 image upload $FN
+
+sudo raspi-gpio set 5 dl
+sudo raspi-gpio set 6 dh
+sleep 1
+sudo raspi-gpio set 6 dl
diff --git a/bin/fw-restart b/bin/fw-restart
deleted file mode 100755
index c19711d..0000000
--- a/bin/fw-restart
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/python3
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-import RPi.GPIO as gpio
-import time
-from signal import signal, SIGINT
-from sys import exit
-import os
-
-reset_pin = 6 # Reset the HAT controller https://pinout.xyz/pinout/pin31_gpio6
-
-
-def setupGPIO():
- gpio.setwarnings(False)
- gpio.setmode(gpio.BCM)
- gpio.setup(reset_pin, gpio.OUT)
-
-
-def main():
- setupGPIO()
-
- # set HIGH, then LOW to toggle firmware reset
- gpio.output(reset_pin, gpio.HIGH)
- time.sleep(0.1)
- gpio.output(reset_pin, gpio.LOW)
-
- gpio.cleanup()
-
-
-if __name__ == "__main__":
- main()
diff --git a/bin/fwversion b/bin/fwversion
new file mode 100755
index 0000000..7f00a4d
--- /dev/null
+++ b/bin/fwversion
@@ -0,0 +1,31 @@
+#!/usr/bin/python3
+
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+import serial # PySerial
+import time
+import sys
+
+# Interactive TTY shell with Moab Hat:
+# sudo minicom --device=/dev/ttyAMA1
+
+def main():
+ ser = serial.Serial('/dev/ttyAMA1', 115200, timeout = 0.5)
+
+ ser.write("version\n".encode())
+ out_a = ser.read_until(b'uart') # read until the "uart" prompt it seen
+
+ out_u = out_a.decode('ascii')
+
+ # 0: version\n
+ # 1: Moab version 3.0.1.04321
+ # 2: uart
+
+ if out_u != '':
+ print(out_u.splitlines()[1])
+ sys.exit(0)
+ else:
+ sys.exit(1)
+
+if __name__ == "__main__":
+ main()
diff --git a/bin/inside b/bin/inside
deleted file mode 100755
index f3817af..0000000
--- a/bin/inside
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env bash
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-docker run \
- --name inside \
- --volume=/home/pi/moab/config:/app/config \
- --privileged --rm -it \
- moab/control bash
diff --git a/bin/level b/bin/level
deleted file mode 100755
index 3d92abe..0000000
--- a/bin/level
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-# vim:ft=sh ts=4 sw=4 et
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-set -euo pipefail
-
-# change directories to the folder hosting this script
-readonly _D="$(dirname "$(readlink -f "$0")")" && cd "$_D"
-
-./_level.py "${1:-0.5}"
diff --git a/bin/restart b/bin/restart
index 46de28e..22d50ab 100755
--- a/bin/restart
+++ b/bin/restart
@@ -7,4 +7,5 @@
readonly _D="$(dirname "$(readlink -f "$0")")" && cd $_D
cd ..
-docker-compose restart || docker-compose up -d
+down
+up
diff --git a/bin/runpy.sh b/bin/runpy.sh
deleted file mode 100755
index 4ffaa7f..0000000
--- a/bin/runpy.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-pyfile="$1" # first argument is the python to run in docker
-rest="${@:2}" # remaining arguments $2 -> $n
-
-docker run \
- --name scriptrunner \
- --mount type=bind,source="$PWD",target=/app/scripts,readonly \
- --privileged --rm -it \
- moab/control python3 /app/scripts/"$pyfile" "$rest"
diff --git a/os/files/bin/splash b/bin/splash
similarity index 89%
rename from os/files/bin/splash
rename to bin/splash
index da34019..3b3cf94 100755
--- a/os/files/bin/splash
+++ b/bin/splash
@@ -42,7 +42,8 @@ gpu_t="$(vcgencmd measure_temp | cut -d '=' -f 2)"
cpu_t1k=$(cat /sys/class/thermal/thermal_zone0/temp)
cpu_t=$(printf %.1f "$((10**3 * $cpu_t1k / 1000))e-3")
temps="$cpu_t° C"
-moabian_version="${MOABIAN:-0.0}"
+moabian_version="${MOABIAN:-3.0.0}"
+fw_version="$([ -e ~/moab/bin/fwversion ] && ~/moab/bin/fwversion | awk '{print $NF}')"
# ☉
@@ -53,6 +54,7 @@ ${h2} · Kernel ${r}${kernel}
${h2} · Load ${r}${load}
${h2} · CPU ${r}${temps}
${h2} · URL ${r}https://aka.ms/moab
+${h2} · FW ${r}${fw_version}
${h1} ○ Moabian ${r}${moabian_version}
EOF
diff --git a/bin/status b/bin/status
new file mode 100755
index 0000000..17ea8cc
--- /dev/null
+++ b/bin/status
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+[[ $TERM == "alacritty" ]] && TERM=xterm-256color
+sudo systemctl status fan power nginx stream brain menu
diff --git a/bin/template.yml b/bin/template.yml
new file mode 100644
index 0000000..e04820a
--- /dev/null
+++ b/bin/template.yml
@@ -0,0 +1,38 @@
+version: "3"
+services:
+
+ brain:
+ image: moab/brain
+ container_name: brain1
+ stop_grace_period: 0s
+ ports: [ 5000:5000 ]
+
+ # custom1:
+ # image:
+ # container_name: custom1
+ # stop_grace_period: 0s
+ # ports: [ 5001:5000 ]
+
+ # custom2:
+ # image:
+ # container_name: custom2
+ # stop_grace_period: 0s
+ # ports: [ 5002:5000 ]
+
+# Add your trained Project Bonsai brains above.
+#
+# image: the URL from your "docker pull" to azuercr.io
+# container_name: optional name that appears in the Moab screen
+# stop_grace_period: allows brains to shut down quickly
+# ports: first number must be between 5001 and 6000, and unique
+#
+# Spacing matters in YAML so the custom brain below should line up
+# with the template show above.
+#
+# Example:
+
+# custom1:
+# image: scotstan.azurecr.io/a988a049-1111-ffff-eeee-ee55999a9723/my_balance1_test:1-linux-arm32v7
+# container_name: balance1
+# stop_grace_period: 0s
+# ports: [ 5001:5000 ]
diff --git a/bin/up b/bin/up
index 907b640..766383b 100755
--- a/bin/up
+++ b/bin/up
@@ -6,7 +6,13 @@
readonly _D="$(dirname "$(readlink -f "$0")")" && cd $_D
-fw-restart
-
cd ..
-docker-compose up -d
+
+missing-compose() {
+ echo "Using default docker-compose.yml"
+ cp $_D/template.yml docker-compose.yml
+}
+
+[[ -e docker-compose.yml ]] || missing-compose
+
+docker-compose up --remove-orphans -d
diff --git a/config/calibration.json b/config/calibration.json
deleted file mode 100644
index cebff66..0000000
--- a/config/calibration.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "ballHue": 22,
- "plateXOffset": 0,
- "plateYOffset": 0,
- "rotation": -30.0,
- "servoOffsets": [
- 0,
- 0,
- 0
- ]
-}
diff --git a/config/config.json b/config/config.json
deleted file mode 100644
index c745bfc..0000000
--- a/config/config.json
+++ /dev/null
@@ -1,182 +0,0 @@
-{
- "logging": {
- "version": 1,
- "formatters": {
- "single-line": {
- "class": "logging.Formatter",
- "style": "{",
- "datefmt": "%I:%M:%S",
- "format": "○ {levelname:8s} {asctime:s} {name:<15s} {message:s}"
- }
- },
- "handlers": {
- "socket": {
- "()": "logging.handlers.SocketHandler",
- "host": "localhost",
- "port": 9020
- },
- "console": {
- "class": "logging.StreamHandler",
- "formatter": "single-line",
- "stream": "ext://sys.stdout"
- }
- },
- "loggers": {
- "local": {
- "handlers": [
- "console"
- ],
- "level": "DEBUG"
- },
- "network": {
- "handlers": [
- "socket"
- ],
- "level": "DEBUG"
- },
- "performance": {
- "handlers": [
- "console"
- ],
- "level": "INFO"
- }
- },
- "root": {
- "handlers": [
- "console"
- ],
- "level": "INFO"
- }
- },
- "devices": {
- "menu": {
- "frequencyHz": 20,
- "controller": "control.controllers.MenuController"
- },
- "calibration": {
- "frequencyHz": 30,
- "debug": false,
- "debugDecorator": {
- "name": "control.debug.X11Decorator",
- "windowName": "frame"
- },
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": "control.detectors.HSVDetector"
- },
- "controller": "control.controllers.HueCalibrationController",
- "actuator": "control.actuators.ServoActuator"
- },
- "manual": {
- "controller": "control.controllers.JoystickController",
- "actuator": "control.actuators.ServoActuator"
- },
- "classic": {
- "frequencyHz": 30,
- "debug": false,
- "debugDecorator": {
- "name": "control.debug.X11Decorator",
- "windowName": "frame"
- },
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": {
- "debug": false,
- "name": "control.detectors.HSVDetector"
- }
- },
- "controller": {
- "name": "control.controllers.PIDController",
- "Kp": 0.15,
- "Ki": 0.001,
- "Kd": 0.090,
- "fc": 15
- },
- "actuator": "control.actuators.ServoActuator"
- },
- "brain": {
- "frequencyHz": 22,
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": "control.detectors.HSVDetector",
- "obstacle": {
- "name": "control.detectors.HSVDetector",
- "hue": 72
- }
- },
- "controller": {
- "name": "control.controllers.BrainController",
- "maxAngle": 22,
- "endPoint": "http://localhost:5000",
- "sensorSize": 256
- },
- "actuator": "control.actuators.ServoActuator"
- },
- "custom1": {
- "frequencyHz": 22,
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": "control.detectors.HSVDetector",
- "obstacle": {
- "name": "control.detectors.HSVDetector",
- "hue": 72
- }
- },
- "controller": {
- "name": "control.controllers.BrainController",
- "maxAngle": 22,
- "endPoint": "http://localhost:5001",
- "sensorSize": 256
- },
- "actuator": "control.actuators.ServoActuator"
- },
- "custom2": {
- "frequencyHz": 22,
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": "control.detectors.HSVDetector",
- "obstacle": {
- "name": "control.detectors.HSVDetector",
- "hue": 72
- }
- },
- "controller": {
- "name": "control.controllers.BrainController",
- "maxAngle": 22,
- "endPoint": "http://localhost:5002",
- "sensorSize": 256
- },
- "actuator": "control.actuators.ServoActuator"
- }
- }
-}
diff --git a/docker-compose.yml b/docker-compose.yml
deleted file mode 100644
index 6ef3a57..0000000
--- a/docker-compose.yml
+++ /dev/null
@@ -1,29 +0,0 @@
-version: "3"
-services:
- brain:
- image: moab/brain
- depends_on: [ "moab-control" ]
- container_name: brain1
- stop_grace_period: 0s
- ports: [ 5000:5000 ]
- custom1:
- image: moab/brain
- depends_on: [ "moab-control" ]
- container_name: custom1
- stop_grace_period: 0s
- ports: [ 5001:5000 ]
- custom2:
- image: moab/brain
- depends_on: [ "moab-control" ]
- container_name: custom2
- stop_grace_period: 0s
- ports: [ 5002:5000 ]
- moab-control:
- image: moab/control:latest
- container_name: control
- privileged: true
- network_mode: host
- working_dir: /app
- stop_grace_period: 1s
- volumes: [ "${PWD}/config:/app/config" ]
- command: python3 main.py -t 5
diff --git a/docs/images/DC1.png b/docs/images/DC1.png
new file mode 100644
index 0000000..7e94586
Binary files /dev/null and b/docs/images/DC1.png differ
diff --git a/docs/images/DC2.png b/docs/images/DC2.png
new file mode 100644
index 0000000..183a3df
Binary files /dev/null and b/docs/images/DC2.png differ
diff --git a/docs/images/DeployBrain1.png b/docs/images/DeployBrain1.png
new file mode 100644
index 0000000..8de0fc8
Binary files /dev/null and b/docs/images/DeployBrain1.png differ
diff --git a/docs/images/DeployBrain2.png b/docs/images/DeployBrain2.png
new file mode 100644
index 0000000..edaae51
Binary files /dev/null and b/docs/images/DeployBrain2.png differ
diff --git a/docs/images/DeployBrain3.png b/docs/images/DeployBrain3.png
new file mode 100644
index 0000000..674ac8e
Binary files /dev/null and b/docs/images/DeployBrain3.png differ
diff --git a/docs/images/DeployBrain4.png b/docs/images/DeployBrain4.png
new file mode 100644
index 0000000..aed2e29
Binary files /dev/null and b/docs/images/DeployBrain4.png differ
diff --git a/docs/images/DeployBrain5.png b/docs/images/DeployBrain5.png
new file mode 100644
index 0000000..6885b38
Binary files /dev/null and b/docs/images/DeployBrain5.png differ
diff --git a/docs/images/DockerCompose.png b/docs/images/DockerCompose.png
new file mode 100644
index 0000000..11651d3
Binary files /dev/null and b/docs/images/DockerCompose.png differ
diff --git a/docs/images/ExportBrain1.png b/docs/images/ExportBrain1.png
new file mode 100644
index 0000000..b97c637
Binary files /dev/null and b/docs/images/ExportBrain1.png differ
diff --git a/docs/images/ExportBrain2.png b/docs/images/ExportBrain2.png
new file mode 100644
index 0000000..8b48942
Binary files /dev/null and b/docs/images/ExportBrain2.png differ
diff --git a/docs/images/ExportBrain3.png b/docs/images/ExportBrain3.png
new file mode 100644
index 0000000..c6450d6
Binary files /dev/null and b/docs/images/ExportBrain3.png differ
diff --git a/docs/images/ExportBrain4.png b/docs/images/ExportBrain4.png
new file mode 100644
index 0000000..a558817
Binary files /dev/null and b/docs/images/ExportBrain4.png differ
diff --git a/docs/images/ExportBrain5.png b/docs/images/ExportBrain5.png
new file mode 100644
index 0000000..aa384db
Binary files /dev/null and b/docs/images/ExportBrain5.png differ
diff --git a/docs/images/ExportBrain6.png b/docs/images/ExportBrain6.png
new file mode 100644
index 0000000..c2256ed
Binary files /dev/null and b/docs/images/ExportBrain6.png differ
diff --git a/docs/images/ExportBrain7.png b/docs/images/ExportBrain7.png
new file mode 100644
index 0000000..466eace
Binary files /dev/null and b/docs/images/ExportBrain7.png differ
diff --git a/docs/images/ExportBrain8.png b/docs/images/ExportBrain8.png
new file mode 100644
index 0000000..1bb54d1
Binary files /dev/null and b/docs/images/ExportBrain8.png differ
diff --git a/docs/images/VSCode1.png b/docs/images/VSCode1.png
new file mode 100644
index 0000000..c88ff0c
Binary files /dev/null and b/docs/images/VSCode1.png differ
diff --git a/docs/images/VSCode2.png b/docs/images/VSCode2.png
new file mode 100644
index 0000000..cd6d341
Binary files /dev/null and b/docs/images/VSCode2.png differ
diff --git a/docs/images/VSCode3.png b/docs/images/VSCode3.png
new file mode 100644
index 0000000..c6bf50d
Binary files /dev/null and b/docs/images/VSCode3.png differ
diff --git a/docs/images/VSCode4.png b/docs/images/VSCode4.png
new file mode 100644
index 0000000..83fabf4
Binary files /dev/null and b/docs/images/VSCode4.png differ
diff --git a/docs/images/VSCodeOpen.png b/docs/images/VSCodeOpen.png
new file mode 100644
index 0000000..8d78bab
Binary files /dev/null and b/docs/images/VSCodeOpen.png differ
diff --git a/docs/images/VSCodeOpenMoab.png b/docs/images/VSCodeOpenMoab.png
new file mode 100644
index 0000000..22e4787
Binary files /dev/null and b/docs/images/VSCodeOpenMoab.png differ
diff --git a/docs/images/VSCodeTerminal.png b/docs/images/VSCodeTerminal.png
new file mode 100644
index 0000000..bbcf691
Binary files /dev/null and b/docs/images/VSCodeTerminal.png differ
diff --git a/docs/images/ssh.png b/docs/images/ssh.png
new file mode 100644
index 0000000..2991d0c
Binary files /dev/null and b/docs/images/ssh.png differ
diff --git a/docs/images/ssh_success.png b/docs/images/ssh_success.png
new file mode 100644
index 0000000..2991d0c
Binary files /dev/null and b/docs/images/ssh_success.png differ
diff --git a/docs/readme.md b/docs/readme.md
new file mode 100644
index 0000000..21dae3d
--- /dev/null
+++ b/docs/readme.md
@@ -0,0 +1,318 @@
+# Project Moab Manual
+
+## I. Getting Started
+
+### Power on
+
+Connect Moab to an electrical outlet using the provided power supply.
+The bot will automatically boot and display “PROJECT MOAB” when booting.
+This can take up to a minute if Moab is not connected to internet.
+
+### Balance a ball
+
+1. Manual Mode
+
+ Once Moab has booted, "MANUAL" mode will be displayed on the
+ screen. Press the joystick to select Manual mode. The plate will
+ rise up and now you can manually control the pitch and roll of the
+ plate using the joystick. Place the ping pong ball on the plate and
+ try balancing the ball manually!
+
+ To exit Manual mode, select the menu button next to the joystick.
+
+2. Classic Mode
+
+ This is classic PID (Proportional, Integral, Derivative) controller
+ that balance the ball at the center of the plate. This controller
+ works by minimizing the error between the actual ball position and
+ velocity, and the desired ball position and velocity. This type of
+ controller is the most commonly found in industrial control
+ applications.
+
+ Move the joystick down and select "CLASSIC" mode. Place the orange
+ ping pong ball on the plate and watch Moab automatically balance
+ the ball. Try disturbing the ball by poking it or blowing on it and
+ watch Moab return the ball to the center.
+
+ If Moab is unable to balance a ball or making erratic movements, go
+ on to step 4. Troubleshooting.
+
+ To exit Classic mode, select the menu button next to the joystick.
+
+3. **Brain Mode**
+
+ This is a brain that has been trained using the Bonsai platform. The
+ brain is a neural network that has been trained using two goals:
+ prevent the ball from falling off the plate, and balance the ball at
+ the center of the plate.
+
+ Move the joystick down and select "BRAIN" mode. Place the orange
+ ping pong ball on the plate and watch Moab automatically balance
+ the ball. Try disturbing the ball by poking it or blowing on it and
+ watch Moab return the ball to the center.
+
+4. **Troubleshooting**
+
+ If your Moab is not able to balance a ball in CLASSIC or BRAIN mode,
+ we recommend the following troubleshooting steps:
+
+ 1. Check your lighting situation. Are there any objects or lights in
+ the room that Moab could be mistaking for orange ping pong balls?
+ Look for circular lights on your ceiling. If this is the case try
+ moving Moab to another location, blocking the lights, or changing
+ the lighting situation.
+
+ 2. Calibrate the camera. Move the joystick down and select
+ "CALIBRATE". Follow the instructions on the screen to calibrate
+ the camera to recognize the color of the ball.
+
+ 3. If your Moab is still unable to balance a ball after following
+ the steps above, please contact us for a troubleshooting guide.
+
+## II. Connecting to Moab
+
+To deploy your own brain on Moab, you will need to connect to it on your
+local network. For the initial setup, we recommend using an ethernet
+cable to connect your Moab to your local network. If you are unable to
+connect to your network with an ethernet cable you can do so using WiFi.
+To configure the WiFi on your Moab, you will need an HDMI monitor and
+USB keyboard.
+
+### Option 1: Connecting with an ethernet cable
+
+Connect one end of an ethernet cable to your Moab and the other end to
+your router.
+
+### Option 2: Connecting with an HDMI monitor and USB keyboard
+
+1. Connect Moab to a monitor using an HDMI cable.
+
+2. Connect Moab to a USB keyboard.
+
+3. When prompted for the moab login, use "pi" and "raspberry":
+
+ login: pi
+ password: raspberry
+
+4. Follow the instructions in the next section to enable the WiFi.
+
+### Enable WiFi (required for Option 2)
+
+1. Type `sudo raspi-config`, and hit enter to open the Raspberry Pi
+Software Configuration Tool.
+
+ >sudo raspi-config
+
+2. If prompted, select your country from the list. You can type the
+first letter of your country as a short cut.
+
+3. Select **2 Network Options**.
+
+4. Select **N2 Wireless LAN**.
+
+5. Enter your WiFi network name.
+
+6. Enter your WiFi password.
+
+7. Select **Finish**.
+
+### SSH into Moab
+
+There are multiple methods to SSH into Moab. We provide instructions for
+using Visual Studio Code.
+
+#### SSH into Moab using Visual Studio Code
+
+1. Open Visual Studio Code. If you don't have it you can download it for
+free [here](https://code.visualstudio.com/).
+
+2. Add the extension **Remote - SSH**, if you don't already have it.
+Click on the Extensions icon on the left, and search "Remote - ssh" as
+shown in the following example. Click **Install**.
+
+ ![VSCode1](images/VSCode1.png)
+
+3. Add a new SSH host. Open the Command Palette through the **View**
+menu as shown in the following screenshot:
+
+ ![VSCode2](images/VSCode2.png)
+
+ Search for the command **Remote-SSH: Add New SSH Host...** as shown
+ in the following screenshot:
+
+ ![VSCode3](images/VSCode3.png)
+
+ Follow the prompts to create or update an SSH configuration file and
+ add a new SSH Host.
+
+ Use the user and host/IP `pi@moab.local` when prompted:
+
+ >pi@moab.local
+
+ Use the password `raspberry` when prompted.
+
+ >raspberry
+
+4. Connect to SSH Host. Search for and select the command **Remote-SSH:
+Connect to Host...**. Follow the prompts. When you have successfully
+connected, you will will see "**SSH: moab.local**" in the bottom left
+corner of the VS Code window as shown in the following screenshot:
+
+ ![VSCode4](images/VSCode4.png)
+
+## III. Train and Export a Brain
+
+### Train a brain
+
+If you have not trained a brain already, please follow [Project Moab
+tutorial](https://microsoft.github.io/moab/tutorials/) 1, 2 or 3 to
+train a brain.
+
+**Prerequisites**: To complete the tutorials, you must have a Bonsai
+workspace provisioned on Azure. If you do not have one, follow the
+[account setup
+guide](https://docs.microsoft.com/en-us/bonsai/guides/account-setup).
+
+### Export a brain for deployment
+
+1. In the Bonsai UI, Click on “**Export brain**” button in the Train tab
+for your trained brain, as in the following screenshot:
+
+ ![ExportBrain1](images/ExportBrain1.png)
+
+2. In the “**Export brain**” pop-up, under “**Processor architecture**”,
+select “Linux” and “**ARM32V7**”, as in the following screenshot:
+
+ ![ExportBrain2](images/ExportBrain2.png)
+
+3. Press the “**Export**” button, as in the following screenshot:
+
+ ![ExportBrain3](images/ExportBrain3.png)
+
+4. The brain version will appear in the **Exported Brains** list on the
+left-hand side of the UI with an “**Exporting brain…**” status, as in
+the following screenshot:
+
+ ![ExportBrain4](images/ExportBrain4.png)
+
+5. After your brain is exported, the “**Brain export complete!**” pop-up
+will appear, as in the following screenshot:
+
+ ![ExportBrain5](images/ExportBrain5.png)
+
+ If the “**Export brain**” pop-up doesn’t appear after the export
+ completes, click on the ellipsis (…) and click on “**View download
+ info**” , as in the following screenshot:
+
+ ![ExportBrain6](images/ExportBrain6.png)
+
+ The “**Download exported brain**” pop-up will appear. It has the
+ same download information.
+
+6. Copy the **docker pull** command (middle line) from the exported
+brain pop up, as in the following screenshot:
+
+ ![ExportBrain7](images/ExportBrain7.png)
+
+7. Open your favorite text editor and copy/paste the **docker pull**
+command.
+
+ ![ExportBrain8](images/ExportBrain8.png)
+
+ You’ll use it to pull down your exported brain into your Moab during
+ later steps.
+
+## IV. Deploy a Brain on Moab
+
+### Retrieve ACR credentials
+
+1. Copy/paste the following docker login statement into your text
+editor: *(You’ll paste your credentials from your Container Registry
+into it during later steps)*
+
+ > `docker login -u -p ' PASSWORD>' `
+
+ ![DeployBrain1](images/DeployBrain1.png)
+
+2. Login to [https://portal.azure.com](https://portal.azure.com)
+
+3. Go to your **Bonsai workspace**
+
+4. Click on **Registry** in upper right corner to go to the **Container
+Registry** page, as in the following screenshot:
+
+ ![DeployBrain2](images/DeployBrain2.png)
+
+5. On the **Container Registry** page, in the **Settings** section
+(left-hand menu), click the **Access Keys** page link, as in the
+following screenshot:
+
+ ![DeployBrain3](images/DeployBrain3.png)
+
+6. In the **Access Keys** page, copy/paste the **Login server** name,
+**Username**, and **Password** into a text editor, as in the following
+screenshot:
+
+ ![DeployBrain4](images/DeployBrain4.png)
+
+7. In your text editor, replace the `` in the docker login
+statement using the fields you copied (keep the single quotes around
+password), as in the following example:
+
+ ![DeployBrain5](images/DeployBrain5.png)
+
+### Login to ACR from Moab
+
+1. Open Visual Studio Code. If you have not yet already, SSH into Moab
+following the previous instructions.
+
+2. Open a new terminal window. You can do this by selecting "**New
+Terminal**" from the terminal window as shown in the screenshot below:
+
+ ![VSCodeTerminal](images/VSCodeTerminal.png)
+
+3. Copy/Paste or type the previously completed **docker login**
+statement in to the terminal and hit enter.
+
+3. Type `cd moab`, and hit enter, to go to the moab directory.
+
+4. Paste the **docker pull** command from your text editor and hit
+enter.
+
+5. After the docker pull completes, type `docker images` and hit the
+enter to see the exported brain image in the list.
+
+### Edit the docker-compose.yml file
+
+2. Select"**Open Folder**" as shown in the following screenshot.
+Alternatively, you can select **File** --> **Open**
+
+ ![VSCodeOpen](images/VSCodeOpen.png)
+
+ Select **moab** from the dropdown or type the file path
+ `/home/pi/moab/` and select **OK**.
+
+ ![VSCodeOpenMoab](images/VSCodeOpenMoab.png)
+
+1. Open the **docker-compose.yml** file by selecting in from the menu on
+the left.
+
+4. At line 10, delete `moab/brain` and copy/paste the container name of
+your exported brain (everything after the words `docker pull`) from the
+text editor, as in the following screenshots:
+
+ ![DC1](images/DC1.png)
+
+ ![DockerCompose](images/DockerCompose.png)
+
+
+### Restart your Moab and test your deployed brain
+
+1. In the terminal, type `down` and hit enter to terminate the Moab
+control service.
+
+2. Type `up` and hit enter to restart the Moab control service.
+
+3. Test your new exported brain on your Moab hardware by selecting
+“**Custom 1**” on your Moab menu (don’t forget your ping pong ball!).
diff --git a/fw/.gitignore b/fw/.gitignore
index 0e4b0ff..980a7fc 100644
--- a/fw/.gitignore
+++ b/fw/.gitignore
@@ -1,3 +1 @@
-hatflash
-mcumgr
flash
diff --git a/fw/Dockerfile b/fw/Dockerfile
deleted file mode 100644
index c14d6e9..0000000
--- a/fw/Dockerfile
+++ /dev/null
@@ -1,8 +0,0 @@
-FROM golang:alpine3.9
-
-RUN apk add git
-#RUN apk add gcc
-
-RUN go version
-RUN CGO_ENABLED=0 go get -v github.com/apache/mynewt-mcumgr-cli/mcumgr
-
diff --git a/fw/Makefile b/fw/Makefile
deleted file mode 100644
index 5fcd43d..0000000
--- a/fw/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-libs=-lbcm2835
-app=flash
-objs=flash.o
-
-$(app): $(objs)
- gcc $^ -o $@ $(libs)
-
-clean:
- @$(RM) *.o *~ $(app) mcumgr
diff --git a/fw/flash.c b/fw/flash.c
deleted file mode 100644
index 35d92e3..0000000
--- a/fw/flash.c
+++ /dev/null
@@ -1,94 +0,0 @@
-// vim: noai:ts=4:sw=4
-
-// Copyright (c) Microsoft Corporation.
-// Licensed under the MIT License.
-
-#include
-#include
-#include
-#include
-#include
-
-#define BOOT_EN RPI_BPLUS_GPIO_J8_29
-#define FAN_EN RPI_BPLUS_GPIO_J8_37
-#define HAT_EN RPI_BPLUS_GPIO_J8_38
-#define HAT_RESET RPI_BPLUS_GPIO_J8_31
-#define HAT_PWR_N RPI_BPLUS_GPIO_J8_05
-
-
-#define PIN_READ(pin) (bcm2835_gpio_lev(pin))
-#define SET_HIGH(pin) (bcm2835_gpio_set(pin))
-#define SET_LOW(pin) (bcm2835_gpio_clr(pin))
-
-int bootloader(char* binary_name)
-{
- // firmware upload command
- char command[256] = "mcumgr --conntype=serial --connstring=/dev/ttyAMA1,baud=115200 image upload ";
- int status;
-
- printf("Bootloader mode\n");
- SET_HIGH(HAT_EN);
- SET_HIGH(BOOT_EN);
- SET_HIGH(HAT_RESET);
- delay(250);
- SET_LOW(HAT_RESET);
-
- strcat(command, binary_name);
- printf("Running: %s\n", command);
-
- status = system(command);
-
- SET_LOW(BOOT_EN);
- SET_HIGH(HAT_RESET);
- delay(250);
- SET_LOW(HAT_RESET);
-
- return status;
-}
-
-
-int gpio_init()
-{
- if (!bcm2835_init()) return(0);
- if (!bcm2835_spi_begin()) return(0);
-
- bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default
- bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default
- bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default
- bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default
- bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // The default
-
- bcm2835_gpio_fsel(BOOT_EN, BCM2835_GPIO_FSEL_OUTP);
- bcm2835_gpio_fsel(HAT_EN, BCM2835_GPIO_FSEL_OUTP);
- bcm2835_gpio_fsel(HAT_RESET, BCM2835_GPIO_FSEL_OUTP);
- bcm2835_gpio_fsel(FAN_EN, BCM2835_GPIO_FSEL_OUTP);
- bcm2835_gpio_fsel(HAT_PWR_N, BCM2835_GPIO_FSEL_INPT);
- return(1);
-}
-
-
-int main(int argc, char *argv[])
-{
- int opt;
-
- // Requires one argument (the .bin filename)
- if (argc != 2) {
- printf("Usage: hatflash firmware.bin\n");
- return (-1);
- }
- char* path = argv[1];
-
- if (!gpio_init())
- {
- printf("bcm2835 initialize failed. Are you running as root?\n");
- return(-1);
- }
-
- int status = bootloader(path);
- if (status != 0)
- {
- printf("Firmware installed failed: %d\n", status);
- }
- return(0);
-}
-
diff --git a/fw/readme.md b/fw/readme.md
index 728bf44..d36b196 100644
--- a/fw/readme.md
+++ b/fw/readme.md
@@ -1,46 +1,103 @@
-## Upgrading Moab Firmware
+# PROJECT MOAB FIRMWARE
-> Note: this is for the Moab power distribution "hat"
-> The Raspberry Pi 4 takes care of upgrading it's EEPROM firmware.
+## Build 3.0 (May 2021)
+
+Binary built on Ubuntu 20
+
+## Zephyr dependencies:
```
-sudo ./install.sh [fw-version.bin]
+sudo apt install --no-install-recommends git cmake
+ build-essential curl ninja-build gperf \
+ ccache dfu-util device-tree-compiler wget \
+ python3-dev python3-pip python3-setuptools python3-tk python3-wheel \
+ xz-utils file make gcc gcc-multilib g++-multilib libsdl2-dev
```
-## Advanced
+## Clone Zephyr 2.1.0
-The firmware has an interactive shell where you can test the joystick,
-activate the plate and read the OTP calibration banks.
+Create a directory called "zephyrproject."
-For advanced use only. Interact with the firmware by making a connection
-to over the serial port as shown below.
+```
+cd ~
+mkdir zephyrproject
+cd zephyrproject
+git clone https://github.com/zephyrproject-rtos/zephyr.git
+cd zephyr/
+git checkout tags/v2.1.0
+```
-```bash
-sudo minicom --device /dev/ttyAMA1 # (interactive shell)
+## Install the "West" Zephyr helper toolchain
+
+```
+pip3 install --user west imgtool
```
-* Press "enter" or "tab" to get to the `uart>` prompt.
-* Exit with: ctrl-A Q
+Ensure `.local/bin` is on your PATH:
-Log monitoring with:
+For BASH:
+```
+echo 'export PATH=~/.local/bin:"$PATH"' >> ~/.bashrc
+source ~/.bashrc
+```
+
+Inform West where to find Zephyr v2.1.0
-```bash
-sudo minicom --device /dev/ttyAMA0 # (log)
+```
+cd ..
+west init -l zephyr/
+west update
```
-Troubleshooting firmware monitoring. Rpi4 might mask these external lines:
+Install a few Zephyr Python dependencies.
-> /boot/cmdline.txt
-remove the two console= lines
+```
+pip3 install --user -r zephyr/scripts/requirements.txt
+```
-> /boot/config.txt
-comment out dtoverlay=uart0
+Now get the Zephyr SDK (cross-compiler toolchains etc).
+> Install the 0.10.3 Version.
-To check camera capabilities:
+```
+wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.10.3/zephyr-sdk-0.10.3-setup.run
+chmod +x zephyr-sdk-0.10.3-setup.run
+./zephyr-sdk-0.10.3-setup.run -- -d ~/zephyr-sdk-0.10.3
+```
+
+
+For BASH users, Add a few environment variable settings (also add to your .bashrc):
+
+```
+cd ..
+export ZEPHYR_TOOLCHAIN_VARIANT=zephyr
+export ZEPHYR_SDK_INSTALL_DIR=~/zephyr-sdk-0.10.3/
+source zephyrproject/zephyr/zephyr-env.sh
+```
-```bash
-v4l2-ctl -d /dev/video0 --all
+For ZSH users, add this to the end of your .zshrc
+```zsh
+cat >> ~/.zshrc <&2; exit "$ret"; }
-
-FW_FILENAME=${1:-"firmware.bin"}
-
-[[ $EUID -eq 0 ]] || die "$0 needs to run as root. Try again with sudo."
-
-require wget
-require mcumgr
-
-readonly _D="$(dirname "$(readlink -f "$0")")" && cd "$_D"
-
-function warn {
- local color=$(tput smso)$(tput setaf 1) # inverse, red
- local reset=$(tput sgr0)
- printf '%s\n' "${color}$1${reset}" >&2
-}
-
-function info {
- local color=$(tput smso)$(tput setaf 2) # inverse, green
- local reset=$(tput sgr0)
- printf '%s\n' "${color}$1${reset}"
-}
-
-# bcm2835
-if [[ ! -e /usr/local/lib/libbcm2835.a ]]; then
- warn "Install the bcm2835 library first from ~/moab/sw/bin/bcm2835"
- exit 127
-fi
-
-info "making flash program"
-make
-
-info "flash $FW_FILENAME"
-./flash "$FW_FILENAME"
-
-# cleanup
-make clean
-
-info "finished"
diff --git a/fw/src/.gitignore b/fw/src/.gitignore
new file mode 100644
index 0000000..103474a
--- /dev/null
+++ b/fw/src/.gitignore
@@ -0,0 +1,3 @@
+binaries
+tags
+build
diff --git a/fw/src/CMakeLists.txt b/fw/src/CMakeLists.txt
new file mode 100644
index 0000000..3840421
--- /dev/null
+++ b/fw/src/CMakeLists.txt
@@ -0,0 +1,48 @@
+cmake_minimum_required(VERSION 3.13.1)
+
+# Board-specific files should get merged into the build as well.
+set(BOARD_ROOT ${CMAKE_CURRENT_LIST_DIR})
+set(BOARD moab_hat)
+set(DTS_ROOT ${CMAKE_CURRENT_LIST_DIR})
+
+# Add a common dts overlay necessary to ensure mcuboot is linked into,
+# and fits inside, the boot partition. (If the user specified a
+# DTC_OVERLAY_FILE on the CMake command line, we need to append onto
+# the list).
+if(DTC_OVERLAY_FILE)
+ set(DTC_OVERLAY_FILE
+ "${DTC_OVERLAY_FILE} ${CMAKE_CURRENT_LIST_DIR}/dts.overlay"
+ CACHE STRING "" FORCE
+ )
+else()
+ set(DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/dts.overlay)
+endif()
+
+add_compile_options(-Wall)
+
+include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
+
+project(app VERSION 3.0.0.0)
+
+set(SEMVER $ENV{SEMVER})
+set(MAJORMINORPATCH $ENV{MAJORMINORPATCH})
+message("Moab SEMVER=${SEMVER}")
+
+configure_file(app/app_version.h.in app_version.h)
+target_include_directories(app PUBLIC "${PROJECT_BINARY_DIR}")
+
+target_sources(app PRIVATE
+ app/display.c
+ app/font_din2014light_12.c
+ app/font_din2014_18.c
+ app/font_moabsym_30.c
+ app/font_iecsymbol_30.c
+ app/joystick.c
+ app/main.c
+ app/spi.c
+ app/plate.c
+ app/sh1106_spi.c
+ app/shell.c
+ app/state.c
+)
+
diff --git a/fw/src/app/app_version.h.in b/fw/src/app/app_version.h.in
new file mode 100644
index 0000000..acc9377
--- /dev/null
+++ b/fw/src/app/app_version.h.in
@@ -0,0 +1,11 @@
+#ifndef APP_VERSION_H
+#define APP_VERSION_H
+
+#define APP_VERSION_MAJOR @app_VERSION_MAJOR@
+#define APP_VERSION_MINOR @app_VERSION_MINOR@
+#define APP_VERSION_PATCH @app_VERSION_PATCH@
+
+#define APP_SEMVER "@SEMVER@"
+#define APP_MAJORMINORPATCH "@MAJORMINORPATCH@"
+
+#endif
diff --git a/fw/src/app/display.c b/fw/src/app/display.c
new file mode 100644
index 0000000..a59c7da
--- /dev/null
+++ b/fw/src/app/display.c
@@ -0,0 +1,235 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include "headers.h"
+#include "display.h"
+#include "app_version.h"
+
+LOG_MODULE_REGISTER(display);
+
+// Mutex to protect access from other threads
+struct k_mutex mutex1;
+
+// The SH1106 device handle
+static struct device *display_dev;
+
+// Three fonts used on the display
+LV_FONT_DECLARE(din2014_18)
+LV_FONT_DECLARE(din2014light_12)
+LV_FONT_DECLARE(moabsym_30)
+LV_FONT_DECLARE(iecsymbol_30)
+
+lv_obj_t* s1;
+lv_obj_t* s2;
+lv_obj_t* s3;
+lv_obj_t* s4;
+
+lv_obj_t* i1;
+lv_obj_t* i2;
+lv_obj_t* t1;
+lv_obj_t* t2;
+lv_obj_t* t3;
+lv_obj_t* t4;
+
+static lv_style_t i1_style; // moab_symbol
+static lv_style_t i2_style; // power_symbol
+static lv_style_t t1_style; // big, offset 32
+static lv_style_t t2_style; // big, centered
+static lv_style_t t3_style; // small, centered, scrolling
+static lv_style_t t4_style; // big, offset 32 power_symbol
+
+// For the display thread
+#define STACKSIZE 1024*4
+#define PRIORITY 9
+
+// Call once on startup
+int display_init()
+{
+ // Although the lvgl docs say to call lv_init()
+ // It's already by called by this point
+
+ display_dev = device_get_binding(CONFIG_LVGL_DISPLAY_DEV_NAME);
+ if (display_dev == NULL) {
+ LOG_ERR("display device not found");
+ return -1;
+ }
+
+ k_mutex_init(&mutex1);
+
+ LOG_INF("Display screen %s", log_strdup(CONFIG_LVGL_DISPLAY_DEV_NAME));
+
+ // SCREENS
+ s1 = lv_obj_create(NULL, NULL);
+ s2 = lv_obj_create(NULL, NULL);
+ s3 = lv_obj_create(NULL, NULL);
+ s4 = lv_obj_create(NULL, NULL);
+
+ // STYLES
+ lv_style_copy(&i1_style, &lv_style_plain);
+ lv_style_copy(&i2_style, &lv_style_plain);
+ lv_style_copy(&t1_style, &lv_style_plain);
+ lv_style_copy(&t2_style, &lv_style_plain);
+ lv_style_copy(&t3_style, &lv_style_plain);
+ lv_style_copy(&t4_style, &lv_style_plain);
+
+ i1_style.text.font = &moabsym_30;
+ i2_style.text.font = &iecsymbol_30;
+ t1_style.text.font = &din2014_18;
+ t2_style.text.font = &din2014_18;
+ t3_style.text.font = &din2014light_12;
+ t4_style.text.font = &din2014_18;
+
+ //
+ // SCREEN1
+ //
+ i1 = lv_label_create(s1, NULL);
+ lv_label_set_style(i1, LV_LABEL_STYLE_MAIN, &i1_style);
+ lv_obj_set_width(i1, 32);
+ lv_obj_align(i1, NULL, LV_ALIGN_IN_LEFT_MID, 2, 0);
+
+ t1 = lv_label_create(s1, NULL);
+ lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &t1_style);
+
+ lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK);
+ lv_label_set_align(t1, LV_LABEL_ALIGN_LEFT);
+ lv_label_set_text(t1, "TEXT1");
+ lv_obj_set_width(t1, 94);
+ lv_obj_align(t1, NULL, LV_ALIGN_IN_LEFT_MID, 36, 0);
+
+ //
+ // SCREEN2
+ //
+ t2 = lv_label_create(s2, NULL);
+ lv_label_set_style(t2, LV_LABEL_STYLE_MAIN, &t2_style);
+ lv_label_set_long_mode(t2, LV_LABEL_LONG_BREAK);
+ lv_label_set_align(t2, LV_LABEL_ALIGN_CENTER);
+ lv_obj_set_size(t2, 128, 32);
+ lv_obj_align(t2, NULL, LV_ALIGN_CENTER, 0, 0);
+
+ //
+ // SCREEN3 (Small Text)
+ //
+ t3 = lv_label_create(s3, NULL);
+ lv_label_set_style(t3, LV_LABEL_STYLE_MAIN, &t3_style);
+ lv_label_set_long_mode(t3, LV_LABEL_LONG_BREAK);
+ lv_label_set_align(t3, LV_LABEL_ALIGN_CENTER);
+ lv_obj_set_size(t3, 128, 32);
+ lv_obj_align(t3, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
+
+ //
+ // SCREEN4
+ //
+ i2 = lv_label_create(s4, NULL);
+ lv_label_set_style(i2, LV_LABEL_STYLE_MAIN, &i2_style);
+ lv_obj_set_width(i2, 32);
+ lv_obj_align(i2, NULL, LV_ALIGN_IN_LEFT_MID, 2, 0);
+
+ t4 = lv_label_create(s4, NULL);
+ lv_label_set_style(t4, LV_LABEL_STYLE_MAIN, &t4_style);
+
+ lv_label_set_long_mode(t4, LV_LABEL_LONG_BREAK);
+ lv_label_set_align(t4, LV_LABEL_ALIGN_LEFT);
+ lv_label_set_text(t4, "TEXT1");
+ lv_obj_set_width(t4, 94); //align text to label
+ lv_obj_align(t4, NULL, LV_ALIGN_IN_LEFT_MID, 36, 0);
+
+
+ //LOG_INF("Version %s", log_strdup(APP_SEMVER));
+ static char splash[30] = {0};
+ sprintf(splash, "PROJECT MOAB\n%s", APP_MAJORMINORPATCH);
+
+ display_small_text(splash);
+
+ lv_task_handler();
+ display_blanking_off(display_dev);
+
+ return 0;
+}
+
+
+// Four entry points, all called by main.c thread
+
+void display_power_symbol(const char *str, disp_power_icon_t i)
+{
+ // The icon is really a font, so convert number to a glyph
+ static char icon_str[4] = {0};
+ k_mutex_lock(&mutex1, K_FOREVER);
+
+ lv_label_set_text(t1, str);
+ sprintf(icon_str, "%d", (u8_t) i);
+ lv_label_set_text(i1, icon_str);
+ lv_scr_load(s1); // toggle IECSYMBOL
+
+ k_mutex_unlock(&mutex1);
+}
+
+
+
+void display_big_text(const char *str)
+{
+ k_mutex_lock(&mutex1, K_FOREVER);
+
+ lv_label_set_text(t2, str);
+ lv_scr_load(s2); // toggle IECSYMBOL
+
+ k_mutex_unlock(&mutex1);
+}
+
+void display_big_text_icon(const char *str, disp_icon_t i)
+{
+ // The icon is really a font, so convert number to a glyph
+ static char icon_str[4] = {0};
+
+ k_mutex_lock(&mutex1, K_FOREVER);
+
+ lv_label_set_text(t1, str);
+ sprintf(icon_str, "%d", (u8_t) i);
+ lv_label_set_text(i1, icon_str);
+ lv_scr_load(s1); // toggle MOABSYMBOL
+
+ k_mutex_unlock(&mutex1);
+}
+
+void display_small_text(const char *str)
+{
+ k_mutex_lock(&mutex1, K_FOREVER);
+
+ lv_label_set_text(t3, str);
+ lv_scr_load(s3); // toggle IECSYMBOL
+
+ k_mutex_unlock(&mutex1);
+}
+
+void display_big_text_power_icon(const char *str, disp_power_icon_t i)
+{
+ // The icon is really a font, so convert number to a glyph
+ static char icon_str[4] = {0};
+
+ k_mutex_lock(&mutex1, K_FOREVER);
+
+ lv_label_set_text(t4, str);
+ sprintf(icon_str, "%d", (u8_t) i);
+ lv_label_set_text(i2, icon_str);
+ lv_scr_load(s4); // toggle MOABSYMBOL
+
+ k_mutex_unlock(&mutex1);
+}
+
+static void disp_task(void)
+{
+ if (display_init()) {
+ LOG_ERR("Failed to initalize display");
+ return;
+ }
+
+ while(true)
+ {
+ k_mutex_lock(&mutex1, K_FOREVER);
+ lv_task_handler();
+ k_mutex_unlock(&mutex1);
+
+ lv_tick_inc(K_MSEC(5));
+ k_sleep(5);
+ }
+}
+
+K_THREAD_DEFINE(disp_task_id, STACKSIZE, disp_task, NULL, NULL, NULL, PRIORITY, 0, K_NO_WAIT);
diff --git a/fw/src/app/display.h b/fw/src/app/display.h
new file mode 100644
index 0000000..24e4e28
--- /dev/null
+++ b/fw/src/app/display.h
@@ -0,0 +1,46 @@
+#ifndef DISP_H_
+#define DISP_H_
+
+#include
+
+typedef enum
+{
+ MOABSYMBOL = 0,
+ IECSYMBOL,
+ DIN_18,
+ DIN_12,
+} our_fonts_t;
+
+// Glyphs for Moab Symbols
+typedef enum
+{
+ DISP_ICON_BLANK = 0,
+ DISP_ICON_UP_DOWN,
+ DISP_ICON_DOWN,
+ DISP_ICON_UP,
+ DISP_ICON_DOT,
+ DISP_ICON_PAUSE,
+ DISP_ICON_CHECK,
+ DISP_ICON_X,
+ DISP_ICON_EOL
+} disp_icon_t;
+
+// Glyphs for IEC Power Symbols
+// https://unicodepowersymbol.com/
+typedef enum
+{
+ IEC_ICON_POWER = 0, // ⏻
+ IEC_ICON_TOGGLE_POWER, // ⏼
+ IEC_ICON_POWER_ON, // ⏽
+ IEC_ICON_SLEEP_MODE, // ⏾
+ IEC_ICON_POWER_OFF, // ⭘
+ IEC_ICON_EOL // (sentinel)
+} disp_power_icon_t;
+
+void display_big_text_icon(const char *str, disp_icon_t i);
+void display_big_text(const char *str);
+void display_small_text(const char *str);
+//void display_power_symbol(const char *str, disp_power_icon_t i);
+void display_big_text_power_icon(const char *str, disp_power_icon_t i);
+
+#endif
diff --git a/fw/src/app/font_din2014_18.c b/fw/src/app/font_din2014_18.c
new file mode 100644
index 0000000..93cceda
--- /dev/null
+++ b/fw/src/app/font_din2014_18.c
@@ -0,0 +1,803 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include
+
+/*******************************************************************************
+ * Size: 18 px
+ * Bpp: 1
+ * Opts:
+ ******************************************************************************/
+
+#ifndef DIN2014_18
+#define DIN2014_18 1
+#endif
+
+#if DIN2014_18
+
+/*-----------------
+ * BITMAPS
+ *----------------*/
+
+/*Store the image of the glyphs*/
+static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = {
+ /* U+20 " " */
+
+ /* U+21 "!" */
+ 0x9f, 0xff, 0xff, 0xfa, 0x7e,
+
+ /* U+22 "\"" */
+ 0x1, 0xb6, 0xdb,
+
+ /* U+23 "#" */
+ 0x0, 0x3, 0xb8, 0x66, 0xc, 0xc7, 0xfe, 0xff,
+ 0xce, 0xe1, 0xdc, 0xff, 0xcf, 0xf8, 0xcc, 0x3b,
+ 0x87, 0x70,
+
+ /* U+24 "$" */
+ 0x8, 0x3, 0x0, 0xc0, 0xfc, 0x7f, 0x9b, 0x46,
+ 0xc1, 0xf0, 0x3f, 0x7, 0xe0, 0xf8, 0x36, 0x6f,
+ 0x9f, 0xe3, 0xf0, 0x30, 0xc, 0x0,
+
+ /* U+25 "%" */
+ 0x0, 0x1, 0xe1, 0x8e, 0xcc, 0x33, 0x70, 0xcd,
+ 0x81, 0xfe, 0x3, 0xb0, 0x1, 0xde, 0x6, 0xd8,
+ 0x33, 0x60, 0xcd, 0x86, 0x36, 0x38, 0x78, 0x0,
+ 0x0,
+
+ /* U+26 "&" */
+ 0x0, 0x3, 0xf0, 0x33, 0x3, 0x30, 0x3f, 0x3,
+ 0xe0, 0x3c, 0x7, 0xee, 0x67, 0xe6, 0x3c, 0x73,
+ 0xc7, 0xfc, 0x3f, 0xe0, 0x0,
+
+ /* U+27 "'" */
+ 0xd, 0xb0,
+
+ /* U+28 "(" */
+ 0x1, 0x9d, 0xce, 0x73, 0x9c, 0xe7, 0x39, 0xce,
+ 0x71, 0xce, 0x30,
+
+ /* U+29 ")" */
+ 0x3, 0x1c, 0x73, 0x9c, 0xe7, 0x39, 0xce, 0x73,
+ 0x9d, 0xce, 0x60,
+
+ /* U+2A "*" */
+ 0x0, 0x31, 0xf9, 0xe7, 0xeb, 0x84, 0x0,
+
+ /* U+2B "+" */
+ 0x10, 0x70, 0xe7, 0xff, 0xe7, 0xe, 0x0,
+
+ /* U+2C "," */
+ 0xdf, 0xfd, 0x0,
+
+ /* U+2D "-" */
+ 0x1, 0xe7, 0x80,
+
+ /* U+2E "." */
+ 0xff, 0x80,
+
+ /* U+2F "/" */
+ 0x0, 0x7, 0x6, 0x6, 0xc, 0xc, 0xc, 0x18,
+ 0x18, 0x18, 0x30, 0x30, 0x70, 0x60, 0x60, 0xe0,
+ 0xc0,
+
+ /* U+30 "0" */
+ 0x0, 0x1f, 0x9f, 0xee, 0x76, 0x3b, 0x1d, 0x8e,
+ 0xc7, 0x63, 0xb1, 0xdc, 0xef, 0xe3, 0xe0, 0x0,
+
+ /* U+31 "1" */
+ 0x3, 0xff, 0xf3, 0x9c, 0xe7, 0x39, 0xce, 0x73,
+ 0x80,
+
+ /* U+32 "2" */
+ 0x0, 0x7e, 0xfe, 0xc7, 0x7, 0x6, 0xe, 0x1c,
+ 0x38, 0x70, 0x70, 0xff, 0xff,
+
+ /* U+33 "3" */
+ 0x0, 0x1f, 0x9f, 0xcc, 0x70, 0x30, 0x38, 0x78,
+ 0x1e, 0x3, 0x81, 0xd8, 0xef, 0xe3, 0xe0, 0x0,
+
+ /* U+34 "4" */
+ 0x0, 0x3, 0x81, 0xc0, 0x70, 0x38, 0xe, 0x3,
+ 0xb1, 0xcc, 0x73, 0x3f, 0xef, 0xf8, 0xc, 0x3,
+ 0x0,
+
+ /* U+35 "5" */
+ 0x0, 0xff, 0xfe, 0xe0, 0xe8, 0xfe, 0xff, 0x47,
+ 0x7, 0x7, 0xe7, 0x7e, 0x3c, 0x0,
+
+ /* U+36 "6" */
+ 0x0, 0x7, 0x7, 0x3, 0x83, 0x81, 0xc1, 0xfc,
+ 0xff, 0x63, 0xb1, 0xdc, 0xef, 0xe3, 0xe0, 0x0,
+
+ /* U+37 "7" */
+ 0x0, 0xff, 0xff, 0xc6, 0xc6, 0xe, 0xc, 0xc,
+ 0x1c, 0x18, 0x38, 0x38, 0x30,
+
+ /* U+38 "8" */
+ 0x0, 0x1f, 0x9f, 0xee, 0x76, 0x3b, 0xb8, 0xfc,
+ 0xfe, 0x63, 0xb1, 0xdc, 0xef, 0xe3, 0xe0, 0x0,
+
+ /* U+39 "9" */
+ 0x0, 0x1f, 0x9f, 0xec, 0x76, 0x3b, 0x9d, 0xfe,
+ 0x7e, 0x7, 0x7, 0x3, 0x83, 0x81, 0xc0,
+
+ /* U+3A ":" */
+ 0xff, 0x0, 0x27, 0xe0,
+
+ /* U+3B ";" */
+ 0xff, 0x0, 0x27, 0xff, 0x40,
+
+ /* U+3C "<" */
+ 0x0, 0xc, 0x79, 0xe7, 0xf, 0xf, 0x87, 0x6,
+
+ /* U+3D "=" */
+ 0x0, 0xff, 0x7e, 0x0, 0xff, 0x7e,
+
+ /* U+3E ">" */
+ 0x3, 0xe, 0x1e, 0x3c, 0xff, 0xb8, 0x80,
+
+ /* U+3F "?" */
+ 0x0, 0x1f, 0x1f, 0xcc, 0x60, 0x30, 0x38, 0x38,
+ 0x38, 0x1c, 0x4, 0x4, 0x3, 0x81, 0xc0,
+
+ /* U+40 "@" */
+ 0x0, 0x0, 0x7, 0xf0, 0x1f, 0xf8, 0x38, 0x1c,
+ 0x73, 0xee, 0x67, 0xf6, 0x66, 0x77, 0x66, 0x77,
+ 0x66, 0x77, 0x66, 0x76, 0x67, 0xfe, 0x73, 0x9c,
+ 0x38, 0x0, 0x1f, 0xf8, 0xf, 0xf0, 0x0, 0x0,
+
+ /* U+41 "A" */
+ 0x0, 0x1, 0xc0, 0x38, 0xf, 0x81, 0xf0, 0x36,
+ 0xe, 0xe1, 0x8c, 0x7b, 0x8f, 0xf9, 0xff, 0x70,
+ 0x6e, 0xe,
+
+ /* U+42 "B" */
+ 0x0, 0x3f, 0xcf, 0xfb, 0x8e, 0xe3, 0xb9, 0xcf,
+ 0xf3, 0xfe, 0xe1, 0xb8, 0x6e, 0x3b, 0xfe, 0xfe,
+ 0x0,
+
+ /* U+43 "C" */
+ 0x0, 0x7, 0xf0, 0xff, 0x38, 0xe7, 0xc, 0xc0,
+ 0x18, 0x3, 0x0, 0x70, 0xe, 0x19, 0xc7, 0x1f,
+ 0xc1, 0xf0, 0x0, 0x0,
+
+ /* U+44 "D" */
+ 0x0, 0x3f, 0xcf, 0xfb, 0x8e, 0xe1, 0xb8, 0x6e,
+ 0x1f, 0x86, 0xe1, 0xb8, 0x6e, 0x3b, 0xfc, 0xfe,
+ 0x0,
+
+ /* U+45 "E" */
+ 0x0, 0xff, 0xff, 0xe0, 0xe0, 0xe0, 0xff, 0xfe,
+ 0xe0, 0xe0, 0xe0, 0xff, 0xff,
+
+ /* U+46 "F" */
+ 0x0, 0xff, 0xff, 0xe0, 0xe0, 0xe0, 0xff, 0xff,
+ 0xe0, 0xe0, 0xe0, 0xe0, 0xe0,
+
+ /* U+47 "G" */
+ 0x0, 0x3, 0xf0, 0xff, 0x38, 0xe7, 0xc, 0xc0,
+ 0x18, 0x3, 0x1e, 0x73, 0xce, 0x19, 0xc7, 0x1f,
+ 0xc1, 0xf0, 0x0, 0x0,
+
+ /* U+48 "H" */
+ 0x1, 0x38, 0x7e, 0x1f, 0x87, 0xe1, 0xf8, 0x7f,
+ 0xff, 0xff, 0xe1, 0xf8, 0x7e, 0x1f, 0x87, 0xe1,
+ 0xc0,
+
+ /* U+49 "I" */
+ 0x1f, 0xff, 0xff, 0xff, 0xfe,
+
+ /* U+4A "J" */
+ 0x0, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7,
+ 0x7, 0x7, 0x47, 0xfe, 0x7c, 0x0,
+
+ /* U+4B "K" */
+ 0x0, 0x1c, 0x73, 0x9c, 0x77, 0xe, 0xe1, 0xf8,
+ 0x3f, 0x7, 0xf0, 0xf7, 0x1c, 0xe3, 0x8e, 0x71,
+ 0xee, 0x1c,
+
+ /* U+4C "L" */
+ 0x0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0,
+ 0xe0, 0xe0, 0xe0, 0xff, 0xff,
+
+ /* U+4D "M" */
+ 0x0, 0xe, 0x7, 0xf0, 0xff, 0xf, 0xf9, 0xff,
+ 0x9f, 0xff, 0xfe, 0xf7, 0xef, 0x7e, 0x67, 0xe6,
+ 0x7e, 0x7, 0xe0, 0x70,
+
+ /* U+4E "N" */
+ 0x0, 0x38, 0x7f, 0x1f, 0xc7, 0xf9, 0xfe, 0x7f,
+ 0xdf, 0xbf, 0xe7, 0xf9, 0xfe, 0x3f, 0x8f, 0xe1,
+ 0xc0,
+
+ /* U+4F "O" */
+ 0x0, 0x7, 0xf0, 0xff, 0x38, 0xe7, 0xc, 0xc1,
+ 0x98, 0x3b, 0x6, 0x70, 0xce, 0x19, 0xc7, 0x1f,
+ 0xc1, 0xf0, 0x0, 0x0,
+
+ /* U+50 "P" */
+ 0x0, 0x3f, 0xcf, 0xfb, 0x8e, 0xe1, 0xb8, 0x6e,
+ 0x7b, 0xfc, 0xfc, 0x38, 0xe, 0x3, 0x80, 0xe0,
+ 0x0,
+
+ /* U+51 "Q" */
+ 0x0, 0x3, 0xf8, 0x3f, 0xc7, 0x1c, 0x70, 0xc6,
+ 0xc, 0x60, 0xe6, 0xc, 0x73, 0xc7, 0x3c, 0x73,
+ 0xc3, 0xfe, 0x1f, 0x60, 0x0,
+
+ /* U+52 "R" */
+ 0x0, 0x3f, 0xcf, 0xfb, 0x86, 0xe1, 0xb8, 0xef,
+ 0xfb, 0xfc, 0xe7, 0x39, 0xce, 0x3b, 0x8e, 0xe1,
+ 0xc0,
+
+ /* U+53 "S" */
+ 0x0, 0xf, 0xc7, 0xf9, 0xc4, 0x70, 0x1e, 0x3,
+ 0xf0, 0x3e, 0x3, 0xc0, 0x76, 0x1d, 0xfe, 0x3f,
+ 0x0, 0x0,
+
+ /* U+54 "T" */
+ 0x0, 0x3f, 0xff, 0xf8, 0x70, 0x1c, 0x7, 0x1,
+ 0xc0, 0x70, 0x1c, 0x7, 0x1, 0xc0, 0x70, 0x1c,
+ 0x0,
+
+ /* U+55 "U" */
+ 0x0, 0x38, 0x7e, 0x1f, 0x87, 0xe1, 0xf8, 0x7e,
+ 0x1f, 0x87, 0xe1, 0xf8, 0x77, 0x39, 0xfe, 0x3f,
+ 0x0, 0x0,
+
+ /* U+56 "V" */
+ 0x0, 0x1c, 0x1d, 0x83, 0x38, 0xe7, 0x1c, 0x63,
+ 0xe, 0xe1, 0xdc, 0x1f, 0x3, 0xe0, 0x3c, 0x7,
+ 0x0, 0xe0,
+
+ /* U+57 "W" */
+ 0x0, 0x0, 0xe1, 0x87, 0x63, 0xc6, 0x63, 0xc6,
+ 0x73, 0xce, 0x77, 0xee, 0x76, 0x6e, 0x36, 0x6c,
+ 0x3e, 0x7c, 0x3c, 0x3c, 0x3c, 0x3c, 0x1c, 0x38,
+ 0x1c, 0x38,
+
+ /* U+58 "X" */
+ 0x0, 0xe, 0x38, 0xce, 0x1d, 0xc1, 0xf0, 0x3e,
+ 0x3, 0x80, 0xf0, 0x1f, 0x7, 0x70, 0xce, 0x38,
+ 0xee, 0x1c,
+
+ /* U+59 "Y" */
+ 0x0, 0xe, 0x39, 0xce, 0x19, 0xc3, 0xb0, 0x3e,
+ 0x7, 0x80, 0x70, 0xe, 0x1, 0xc0, 0x38, 0x7,
+ 0x0, 0xe0,
+
+ /* U+5A "Z" */
+ 0x0, 0x7f, 0xdf, 0xe0, 0xe0, 0xe0, 0x70, 0x70,
+ 0x38, 0x38, 0x1c, 0x1c, 0xf, 0xff, 0xf8,
+
+ /* U+5B "[" */
+ 0x7, 0xfd, 0xce, 0x73, 0x9c, 0xe7, 0x39, 0xce,
+ 0x73, 0x9f, 0xf0,
+
+ /* U+5C "\\" */
+ 0x0, 0x30, 0x18, 0x6, 0x3, 0x1, 0x80, 0x60,
+ 0x30, 0x18, 0x6, 0x3, 0x1, 0xc0, 0x60, 0x30,
+ 0xc, 0x6, 0x3, 0x0,
+
+ /* U+5D "]" */
+ 0x7, 0xde, 0x73, 0x9c, 0xe7, 0x39, 0xce, 0x73,
+ 0x9c, 0xff, 0x78,
+
+ /* U+5E "^" */
+ 0x0, 0xf, 0xf, 0x86, 0xe7, 0x38, 0x0,
+
+ /* U+5F "_" */
+ 0xff, 0xbf, 0xe0, 0x0,
+
+ /* U+60 "`" */
+ 0xe6, 0x30,
+
+ /* U+61 "a" */
+ 0x0, 0x7e, 0x7f, 0x7, 0x7, 0x7f, 0x67, 0xe7,
+ 0x7f, 0x7f, 0x0,
+
+ /* U+62 "b" */
+ 0x80, 0xc0, 0xc0, 0xc0, 0xfc, 0xfe, 0xe6, 0xc7,
+ 0xc7, 0xc7, 0xe6, 0xfe, 0xfc, 0x0,
+
+ /* U+63 "c" */
+ 0x0, 0x3e, 0x7f, 0x60, 0x60, 0xe0, 0x60, 0x60,
+ 0x7f, 0x3e, 0x0,
+
+ /* U+64 "d" */
+ 0x2, 0x1, 0xc0, 0xe0, 0x73, 0xfb, 0xfd, 0x8e,
+ 0xc7, 0xe3, 0xb1, 0xd8, 0xef, 0xf3, 0xf8, 0x0,
+
+ /* U+65 "e" */
+ 0x0, 0x3c, 0x7e, 0x67, 0x67, 0xff, 0x60, 0x60,
+ 0x7f, 0x3e, 0x0,
+
+ /* U+66 "f" */
+ 0x0, 0xe7, 0x9c, 0xfb, 0xe7, 0x1c, 0x71, 0xc7,
+ 0x1c, 0x70,
+
+ /* U+67 "g" */
+ 0x0, 0x1f, 0xdf, 0xec, 0x76, 0x3f, 0x1d, 0x8e,
+ 0xc7, 0x7f, 0x9f, 0x80, 0xce, 0xe7, 0xe0, 0xc0,
+
+ /* U+68 "h" */
+ 0x80, 0xc0, 0xc0, 0xc0, 0xfc, 0xfe, 0xe6, 0xc7,
+ 0xc7, 0xc7, 0xc7, 0xc7, 0xc7,
+
+ /* U+69 "i" */
+ 0x9f, 0xf, 0xff, 0xff, 0xfe,
+
+ /* U+6A "j" */
+ 0x47, 0x60, 0x77, 0x77, 0x77, 0x77, 0x77, 0xee,
+ 0x0,
+
+ /* U+6B "k" */
+ 0x80, 0xc0, 0xc0, 0xc0, 0xce, 0xcc, 0xd8, 0xf8,
+ 0xf8, 0xfc, 0xdc, 0xce, 0xc7,
+
+ /* U+6C "l" */
+ 0x8c, 0xcc, 0xcc, 0xcc, 0xcc, 0xcf, 0x70,
+
+ /* U+6D "m" */
+ 0x0, 0x7, 0xef, 0x3f, 0xfd, 0xce, 0x6c, 0x63,
+ 0x63, 0x1f, 0x18, 0xf8, 0xc7, 0xc6, 0x3e, 0x31,
+ 0xc0,
+
+ /* U+6E "n" */
+ 0x0, 0xfc, 0xfe, 0xe6, 0xc7, 0xc7, 0xc7, 0xc7,
+ 0xc7, 0xc7,
+
+ /* U+6F "o" */
+ 0x0, 0x1f, 0x1f, 0xcc, 0x66, 0x37, 0x1d, 0x8c,
+ 0xc6, 0x7f, 0x1f, 0x0, 0x0,
+
+ /* U+70 "p" */
+ 0x0, 0xfc, 0xfe, 0xe7, 0xc7, 0xc7, 0xc7, 0xe7,
+ 0xfe, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0,
+
+ /* U+71 "q" */
+ 0x0, 0x1f, 0xdf, 0xec, 0x76, 0x3f, 0x1d, 0x8e,
+ 0xc7, 0x7f, 0x9f, 0xc0, 0xe0, 0x70, 0x38, 0x18,
+
+ /* U+72 "r" */
+ 0x1, 0xfb, 0xf7, 0xc, 0x18, 0x30, 0x60, 0xc1,
+ 0x80,
+
+ /* U+73 "s" */
+ 0x0, 0x3e, 0x7e, 0x60, 0x78, 0x3e, 0xf, 0x7,
+ 0x7e, 0x3e, 0x0,
+
+ /* U+74 "t" */
+ 0x71, 0xcf, 0xff, 0x71, 0xc7, 0x1c, 0x70, 0xf3,
+ 0xc0,
+
+ /* U+75 "u" */
+ 0xc7, 0xc7, 0xc7, 0xc7, 0xc7, 0xc7, 0xe7, 0xff,
+ 0x7f, 0x0,
+
+ /* U+76 "v" */
+ 0xe3, 0xb1, 0xd8, 0xce, 0xe3, 0x61, 0xf0, 0xf8,
+ 0x38, 0x1c, 0x0,
+
+ /* U+77 "w" */
+ 0xe6, 0x3f, 0x39, 0x99, 0xcc, 0xdf, 0x67, 0xdf,
+ 0x1e, 0xf0, 0xe3, 0x87, 0x1c, 0x38, 0xc0,
+
+ /* U+78 "x" */
+ 0x63, 0x3b, 0x8f, 0x87, 0x81, 0xc1, 0xe0, 0xf8,
+ 0xee, 0xe3, 0x0,
+
+ /* U+79 "y" */
+ 0xe3, 0x31, 0x98, 0xce, 0xc3, 0x61, 0xf0, 0xf0,
+ 0x38, 0x1c, 0xc, 0x1e, 0xe, 0x0, 0x0,
+
+ /* U+7A "z" */
+ 0xff, 0xfe, 0xe, 0x1c, 0x18, 0x38, 0x70, 0x7f,
+ 0xff,
+
+ /* U+7B "{" */
+ 0x0, 0xf3, 0x8c, 0x30, 0xc3, 0xc, 0xf1, 0xc3,
+ 0xc, 0x30, 0xc3, 0xf, 0x18,
+
+ /* U+7C "|" */
+ 0x4d, 0xb6, 0xdb, 0x6d, 0xb6, 0xdb, 0x60,
+
+ /* U+7D "}" */
+ 0x3, 0xc7, 0xc, 0x30, 0xc3, 0xc, 0x3c, 0xe3,
+ 0xc, 0x30, 0xc3, 0x3c, 0x60,
+
+ /* U+7E "~" */
+ 0x0, 0x1f, 0xe7, 0xf8, 0x0
+};
+
+
+/*---------------------
+ * GLYPH DESCRIPTION
+ *--------------------*/
+
+static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
+ {.bitmap_index = 0, .adv_w = 0, .box_h = 0, .box_w = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */,
+ {.bitmap_index = 0, .adv_w = 72, .box_h = 0, .box_w = 0, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 0, .adv_w = 72, .box_h = 13, .box_w = 3, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 5, .adv_w = 104, .box_h = 4, .box_w = 6, .ofs_x = 0, .ofs_y = 9},
+ {.bitmap_index = 8, .adv_w = 177, .box_h = 13, .box_w = 11, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 26, .adv_w = 156, .box_h = 17, .box_w = 10, .ofs_x = 0, .ofs_y = -2},
+ {.bitmap_index = 48, .adv_w = 219, .box_h = 14, .box_w = 14, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 73, .adv_w = 192, .box_h = 14, .box_w = 12, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 94, .adv_w = 58, .box_h = 4, .box_w = 3, .ofs_x = 0, .ofs_y = 9},
+ {.bitmap_index = 96, .adv_w = 91, .box_h = 17, .box_w = 5, .ofs_x = 1, .ofs_y = -2},
+ {.bitmap_index = 107, .adv_w = 91, .box_h = 17, .box_w = 5, .ofs_x = 0, .ofs_y = -2},
+ {.bitmap_index = 118, .adv_w = 122, .box_h = 7, .box_w = 7, .ofs_x = 0, .ofs_y = 6},
+ {.bitmap_index = 125, .adv_w = 156, .box_h = 8, .box_w = 7, .ofs_x = 1, .ofs_y = 2},
+ {.bitmap_index = 132, .adv_w = 74, .box_h = 6, .box_w = 3, .ofs_x = 1, .ofs_y = -3},
+ {.bitmap_index = 135, .adv_w = 92, .box_h = 3, .box_w = 6, .ofs_x = 0, .ofs_y = 4},
+ {.bitmap_index = 138, .adv_w = 79, .box_h = 3, .box_w = 3, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 140, .adv_w = 140, .box_h = 17, .box_w = 8, .ofs_x = 1, .ofs_y = -2},
+ {.bitmap_index = 157, .adv_w = 156, .box_h = 14, .box_w = 9, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 173, .adv_w = 156, .box_h = 13, .box_w = 5, .ofs_x = 2, .ofs_y = 0},
+ {.bitmap_index = 182, .adv_w = 156, .box_h = 13, .box_w = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 195, .adv_w = 156, .box_h = 14, .box_w = 9, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 211, .adv_w = 156, .box_h = 13, .box_w = 10, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 228, .adv_w = 156, .box_h = 14, .box_w = 8, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 242, .adv_w = 156, .box_h = 14, .box_w = 9, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 258, .adv_w = 156, .box_h = 13, .box_w = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 271, .adv_w = 156, .box_h = 14, .box_w = 9, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 287, .adv_w = 156, .box_h = 13, .box_w = 9, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 302, .adv_w = 71, .box_h = 9, .box_w = 3, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 306, .adv_w = 71, .box_h = 12, .box_w = 3, .ofs_x = 1, .ofs_y = -3},
+ {.bitmap_index = 311, .adv_w = 156, .box_h = 9, .box_w = 7, .ofs_x = 1, .ofs_y = 2},
+ {.bitmap_index = 319, .adv_w = 156, .box_h = 6, .box_w = 8, .ofs_x = 1, .ofs_y = 3},
+ {.bitmap_index = 325, .adv_w = 156, .box_h = 9, .box_w = 6, .ofs_x = 2, .ofs_y = 2},
+ {.bitmap_index = 332, .adv_w = 140, .box_h = 13, .box_w = 9, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 347, .adv_w = 259, .box_h = 16, .box_w = 16, .ofs_x = 0, .ofs_y = -3},
+ {.bitmap_index = 379, .adv_w = 175, .box_h = 13, .box_w = 11, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 397, .adv_w = 175, .box_h = 13, .box_w = 10, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 414, .adv_w = 171, .box_h = 14, .box_w = 11, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 434, .adv_w = 180, .box_h = 13, .box_w = 10, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 451, .adv_w = 152, .box_h = 13, .box_w = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 464, .adv_w = 150, .box_h = 13, .box_w = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 477, .adv_w = 176, .box_h = 14, .box_w = 11, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 497, .adv_w = 189, .box_h = 13, .box_w = 10, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 514, .adv_w = 85, .box_h = 13, .box_w = 3, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 519, .adv_w = 147, .box_h = 14, .box_w = 8, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 533, .adv_w = 186, .box_h = 13, .box_w = 11, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 551, .adv_w = 145, .box_h = 13, .box_w = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 564, .adv_w = 226, .box_h = 13, .box_w = 12, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 584, .adv_w = 189, .box_h = 13, .box_w = 10, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 601, .adv_w = 179, .box_h = 14, .box_w = 11, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 621, .adv_w = 170, .box_h = 13, .box_w = 10, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 638, .adv_w = 181, .box_h = 14, .box_w = 12, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 659, .adv_w = 178, .box_h = 13, .box_w = 10, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 676, .adv_w = 166, .box_h = 14, .box_w = 10, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 694, .adv_w = 154, .box_h = 13, .box_w = 10, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 711, .adv_w = 192, .box_h = 14, .box_w = 10, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 729, .adv_w = 177, .box_h = 13, .box_w = 11, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 747, .adv_w = 256, .box_h = 13, .box_w = 16, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 773, .adv_w = 170, .box_h = 13, .box_w = 11, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 791, .adv_w = 168, .box_h = 13, .box_w = 11, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 809, .adv_w = 149, .box_h = 13, .box_w = 9, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 824, .adv_w = 96, .box_h = 17, .box_w = 5, .ofs_x = 1, .ofs_y = -2},
+ {.bitmap_index = 835, .adv_w = 140, .box_h = 17, .box_w = 9, .ofs_x = 0, .ofs_y = -2},
+ {.bitmap_index = 855, .adv_w = 96, .box_h = 17, .box_w = 5, .ofs_x = 0, .ofs_y = -2},
+ {.bitmap_index = 866, .adv_w = 156, .box_h = 6, .box_w = 9, .ofs_x = 0, .ofs_y = 7},
+ {.bitmap_index = 873, .adv_w = 151, .box_h = 3, .box_w = 10, .ofs_x = 0, .ofs_y = -4},
+ {.bitmap_index = 877, .adv_w = 97, .box_h = 3, .box_w = 4, .ofs_x = 1, .ofs_y = 10},
+ {.bitmap_index = 879, .adv_w = 140, .box_h = 11, .box_w = 8, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 890, .adv_w = 147, .box_h = 14, .box_w = 8, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 904, .adv_w = 128, .box_h = 11, .box_w = 8, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 915, .adv_w = 149, .box_h = 14, .box_w = 9, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 931, .adv_w = 140, .box_h = 11, .box_w = 8, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 942, .adv_w = 87, .box_h = 13, .box_w = 6, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 952, .adv_w = 149, .box_h = 14, .box_w = 9, .ofs_x = 0, .ofs_y = -4},
+ {.bitmap_index = 968, .adv_w = 151, .box_h = 13, .box_w = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 981, .adv_w = 75, .box_h = 13, .box_w = 3, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 986, .adv_w = 72, .box_h = 17, .box_w = 4, .ofs_x = 0, .ofs_y = -4},
+ {.bitmap_index = 995, .adv_w = 145, .box_h = 13, .box_w = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 1008, .adv_w = 82, .box_h = 13, .box_w = 4, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 1015, .adv_w = 229, .box_h = 10, .box_w = 13, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 1032, .adv_w = 151, .box_h = 10, .box_w = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 1042, .adv_w = 144, .box_h = 11, .box_w = 9, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 1055, .adv_w = 149, .box_h = 14, .box_w = 8, .ofs_x = 1, .ofs_y = -4},
+ {.bitmap_index = 1069, .adv_w = 149, .box_h = 14, .box_w = 9, .ofs_x = 0, .ofs_y = -4},
+ {.bitmap_index = 1085, .adv_w = 118, .box_h = 10, .box_w = 7, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 1094, .adv_w = 134, .box_h = 11, .box_w = 8, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 1105, .adv_w = 95, .box_h = 11, .box_w = 6, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 1114, .adv_w = 151, .box_h = 10, .box_w = 8, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 1124, .adv_w = 145, .box_h = 9, .box_w = 9, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 1135, .adv_w = 206, .box_h = 9, .box_w = 13, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 1150, .adv_w = 141, .box_h = 9, .box_w = 9, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 1161, .adv_w = 138, .box_h = 13, .box_w = 9, .ofs_x = 0, .ofs_y = -4},
+ {.bitmap_index = 1176, .adv_w = 129, .box_h = 9, .box_w = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 1185, .adv_w = 94, .box_h = 17, .box_w = 6, .ofs_x = 0, .ofs_y = -2},
+ {.bitmap_index = 1198, .adv_w = 84, .box_h = 18, .box_w = 3, .ofs_x = 1, .ofs_y = -3},
+ {.bitmap_index = 1205, .adv_w = 91, .box_h = 17, .box_w = 6, .ofs_x = 0, .ofs_y = -2},
+ {.bitmap_index = 1218, .adv_w = 156, .box_h = 4, .box_w = 10, .ofs_x = 0, .ofs_y = 4}
+};
+
+/*---------------------
+ * CHARACTER MAPPING
+ *--------------------*/
+
+
+
+/*Collect the unicode lists and glyph_id offsets*/
+static const lv_font_fmt_txt_cmap_t cmaps[] =
+{
+ {
+ .range_start = 32, .range_length = 95, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY,
+ .glyph_id_start = 1, .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0
+ }
+};
+
+/*-----------------
+ * KERNING
+ *----------------*/
+
+
+/*Map glyph_ids to kern left classes*/
+static const uint8_t kern_left_class_mapping[] =
+{
+ 0, 0, 0, 1, 0, 0, 0, 0,
+ 1, 2, 0, 3, 0, 4, 5, 6,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 7, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 8, 0, 9, 10, 0, 11,
+ 12, 0, 0, 13, 14, 15, 0, 0,
+ 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 2, 0, 0, 0,
+ 0, 0, 28, 29, 30, 0, 31, 32,
+ 33, 34, 0, 0, 35, 36, 37, 38,
+ 39, 39, 40, 41, 42, 43, 44, 45,
+ 46, 47, 48, 49, 2, 0, 0, 0
+};
+
+/*Map glyph_ids to kern right classes*/
+static const uint8_t kern_right_class_mapping[] =
+{
+ 0, 0, 0, 1, 0, 0, 0, 0,
+ 1, 0, 2, 3, 0, 4, 5, 4,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 6, 0, 7, 0, 0, 0,
+ 8, 0, 0, 9, 0, 0, 0, 0,
+ 8, 0, 8, 0, 10, 11, 12, 13,
+ 14, 15, 16, 17, 0, 0, 2, 0,
+ 0, 0, 18, 0, 19, 20, 19, 0,
+ 20, 0, 0, 21, 0, 0, 22, 22,
+ 20, 22, 20, 22, 23, 24, 25, 26,
+ 27, 28, 29, 30, 0, 0, 2, 0
+};
+
+/*Kern values between classes*/
+static const uint8_t kern_class_values[] =
+{
+ 0, 0, 0, -9, -5, -11, -6, -6,
+ -20, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, -5, -5, 0, 0, 0, 0,
+ 0, 0, 0, -2, 0, -3, 0, 10,
+ 0, 0, -1, 6, 0, 0, 0, 0,
+ 4, 0, 6, 6, 6, 6, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 2, 0, 0, 0, 0, 0, -14,
+ 0, -13, 0, 0, -25, 0, 0, 0,
+ 0, 0, -3, 0, 0, 0, -2, -2,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, -9, 0, -14, 0, -7, 6,
+ -6, -6, -1, 0, -15, 0, -14, -8,
+ 0, -14, 0, 0, -3, -3, 0, 0,
+ 0, -6, 0, -8, -5, 0, -8, 0,
+ -5, -1, 0, -2, 0, -3, 0, 0,
+ -11, 0, -9, 0, -5, -3, -6, -9,
+ -4, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -3, 0, -1, -9, 0,
+ -14, 0, -7, 0, -6, -6, -1, 0,
+ -15, 0, -14, -8, 0, -14, 0, 0,
+ -3, -3, 0, 0, 0, -6, 0, -8,
+ -5, 0, -8, 0, 0, 0, 0, -18,
+ -9, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, -11, 6, -13, 0, -3, 6,
+ -6, -6, 4, 0, -11, -1, -13, -3,
+ 2, -15, 0, 0, -1, -1, 0, 0,
+ 0, -3, 0, -7, -3, 4, -7, -1,
+ -2, 0, 0, -3, 0, -2, -2, -2,
+ -3, 0, -4, 0, -4, -2, -7, -5,
+ -2, -3, 0, 0, 0, 0, 0, 0,
+ 0, -3, 0, -4, -3, -4, -6, 0,
+ 0, -6, 0, -6, 0, 0, -4, -2,
+ -2, 0, -5, 0, -5, -8, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, -3, -2, 0, 0, 0, 0, -10,
+ 0, -7, 0, 0, -19, 0, 0, 0,
+ -1, 0, -2, -1, -1, -5, -7, -7,
+ 0, 0, -2, 0, 0, -4, -3, -7,
+ -4, -5, 0, 0, 0, 0, 0, -5,
+ 0, 0, -5, 0, -2, 0, -4, 0,
+ -4, -7, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, -6, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, -1, 0, 0, 0,
+ 0, 0, 0, -1, -1, 0, -3, 0,
+ -6, 0, -9, 2, -9, -9, -4, -5,
+ -4, -3, -5, -2, 0, -5, 0, -7,
+ -9, -9, 0, 0, -3, -7, -5, -16,
+ -10, 0, -16, -3, -16, 0, -16, 0,
+ -6, 5, -7, -7, 5, 0, -15, 0,
+ -20, -12, 0, -24, 0, 0, 0, 0,
+ 0, 0, 0, -3, 0, -16, -8, 0,
+ -16, 0, -6, 0, 0, -6, 0, -6,
+ 0, 0, -6, -2, -2, 0, -5, 0,
+ -5, -8, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, -3, -2, 0,
+ 0, 0, 0, -19, 0, -14, 0, 0,
+ -30, 0, 0, 0, 0, 0, -10, -4,
+ -1, -5, -6, -6, -1, 0, 0, 0,
+ 0, 0, 1, -2, 0, -3, -6, 0,
+ 0, -6, 0, 4, 0, 0, 3, -2,
+ -2, 0, -5, 0, -3, -8, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, -3, -2, 0, 0, 0, 0, -2,
+ -1, 2, -1, -1, -1, 0, -3, 0,
+ -5, -1, 0, -8, -1, -2, -4, -4,
+ 0, 0, 0, 0, 0, -3, 0, 0,
+ -3, 0, 0, 0, 0, 0, 0, -3,
+ 0, 0, -1, 0, -1, 0, -1, 0,
+ -5, -2, 0, 0, 0, 0, -1, 0,
+ 0, 0, 0, -7, -5, -5, -7, 0,
+ 0, 0, 0, -15, -9, -11, -2, -2,
+ -23, 0, 1, 0, 0, 0, -4, 0,
+ 0, -12, -17, -17, -1, -6, -8, -5,
+ -6, -15, -13, -16, -15, -9, 0, 0,
+ 0, 0, 0, -1, 0, 0, -7, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, -2, 0, 0, 0,
+ 0, -2, -1, 0, 0, 2, 0, -14,
+ -5, -13, -5, -5, -21, -3, 0, 0,
+ 4, 4, -1, 4, 0, -8, -13, -13,
+ 0, -2, -5, -1, -2, -3, 0, -7,
+ -3, -6, 0, 2, 0, -8, -3, -3,
+ 0, 0, -12, 0, 0, 0, 4, 2,
+ 0, 4, 0, -4, -6, -6, 0, 0,
+ 0, 0, 0, 0, 0, -4, 0, -2,
+ 0, 2, -3, 0, -6, 2, -5, -5,
+ 0, 0, -4, 0, -1, 0, 0, -2,
+ 0, -3, -7, -7, 0, 0, -1, -4,
+ 0, -9, -5, 0, -9, -1, 0, 2,
+ 0, -14, -9, -15, -6, -6, -26, -5,
+ 0, 0, 4, 4, -2, 4, 0, -14,
+ -20, -20, 0, -8, -16, -3, -8, -9,
+ -8, -12, -9, -11, 0, 0, 0, 0,
+ -6, 0, -1, -1, 2, 0, 0, 0,
+ 0, 0, 0, 0, 0, -1, -1, -1,
+ 0, 0, 0, 0, 0, -4, -2, 0,
+ -4, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, -12, 0, -10, -5,
+ 0, -16, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -3, -3, 0, -4, 0,
+ -5, 0, -2, -3, 0, -1, 0, 0,
+ 0, 0, -17, 0, -13, -5, -5, -20,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, -4, -2, -7, -4, 0, -3, 0,
+ 0, -2, -3, 0, 0, 0, 2, 0,
+ -16, 0, -8, -4, 0, -14, 0, -1,
+ -2, -2, 0, 0, 0, 0, 0, 0,
+ 0, -2, 0, 0, -7, 0, -4, -2,
+ 0, 0, 0, 0, 0, 0, -17, 0,
+ -14, -5, 0, -19, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, -5, -2, -7,
+ -5, 0, 0, 0, 0, -5, -1, -1,
+ 0, 0, -5, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 1, 1, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, -4, 0, -3, 0, 0, -10,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, -5, 0,
+ -1, 0, 0, 0, 0, 0, 0, 0,
+ -16, 0, -14, -5, 0, -17, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, -4, 0, 0, 0, 0, 0,
+ 0, 4, -1, -2, 0, 0, -12, -2,
+ -10, -6, 0, -14, 0, 0, -2, -10,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ -2, 0, 0, 0, 0, 0, 0, 3,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, -15, 0, -14, -5, 0, -16,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ -15, 0, -14, -5, 0, -16, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, -3,
+ 0, 0, -4, 0, -5, 0, -2, -3,
+ 0, -1, 0, 0, 0, 0, -17, 0,
+ -13, -6, -5, -20, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, -4, -2, -7,
+ -4, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, -4, 0, -2, 0,
+ 0, -9, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -14, 0, -10, 0, 0,
+ -29, 0, -17, 0, -6, -2, 0, -14,
+ 0, -2, -2, -2, 0, 0, 0, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, -1, 0,
+ -20, 0, -15, -9, 0, -19, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, -2, 0, -2, 0, 0, 0,
+ 0, 0, 0, 0, 1, 0, -7, 0,
+ -3, 0, 0, -5, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, -7, 0, -2, 0,
+ 0, -9, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -8, 0, -7, 0, 0,
+ -17, 0, -16, 0, 0, 0, -9, -9,
+ 0, -1, -4, -4, 0, 0, 0, 2,
+ 0, 3, 3, 0, 3, -2, 0, 0,
+ 0, -5, 0, -3, 0, 0, -12, 0,
+ -15, 0, 0, 0, -5, -8, 0, 0,
+ -2, -2, 0, 0, 0, 0, 0, 2,
+ 2, 0, 2, 0, 0, 0, 0, 0,
+ -3, 0, -4, -4, 0, 0, -16, -3,
+ -6, -3, 0, -12, 0, -2, -7, -7,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, -8, 0, -7,
+ 0, 0, -17, 0, -16, 0, -1, 0,
+ -9, -9, 0, -1, -4, -4, 0, 0,
+ 0, 2, 0, 3, 3, 0, 3, -2,
+ -3, 0, 0, 0, -1, 0, 0, 0,
+ 0, 0, -12, 0, -7, -1, 0, -11,
+ 0, -1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0
+};
+
+
+/*Collect the kern class' data in one place*/
+static const lv_font_fmt_txt_kern_classes_t kern_classes =
+{
+ .class_pair_values = kern_class_values,
+ .left_class_mapping = kern_left_class_mapping,
+ .right_class_mapping = kern_right_class_mapping,
+ .left_class_cnt = 49,
+ .right_class_cnt = 30,
+};
+
+/*--------------------
+ * ALL CUSTOM DATA
+ *--------------------*/
+
+/*Store all the custom data of the font*/
+static lv_font_fmt_txt_dsc_t font_dsc = {
+ .glyph_bitmap = gylph_bitmap,
+ .glyph_dsc = glyph_dsc,
+ .cmaps = cmaps,
+ .cmap_num = 1,
+ .bpp = 1,
+
+ .kern_scale = 16,
+ .kern_dsc = &kern_classes,
+ .kern_classes = 1
+};
+
+
+/*-----------------
+ * PUBLIC FONT
+ *----------------*/
+
+/*Initialize a public general font descriptor*/
+lv_font_t din2014_18 = {
+ .dsc = &font_dsc, /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
+ .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/
+ .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/
+ .line_height = 19, /*The maximum line height required by the font*/
+ .base_line = 4, /*Baseline measured from the bottom of the line*/
+};
+
+#endif /*#if DIN2014_18*/
+
diff --git a/fw/src/app/font_din2014light_12.c b/fw/src/app/font_din2014light_12.c
new file mode 100644
index 0000000..9913ebe
--- /dev/null
+++ b/fw/src/app/font_din2014light_12.c
@@ -0,0 +1,450 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include
+
+/*******************************************************************************
+ * Size: 12 px
+ * Bpp: 1
+ * Opts:
+ ******************************************************************************/
+
+#ifndef DIN2014LIGHT_12
+#define DIN2014LIGHT_12 1
+#endif
+
+#if DIN2014LIGHT_12
+
+/*-----------------
+ * BITMAPS
+ *----------------*/
+
+/*Store the image of the glyphs*/
+static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = {
+ /* U+20 " " */
+ 0x0,
+
+ /* U+21 "!" */
+ 0xfd,
+
+ /* U+22 "\"" */
+ 0xf0,
+
+ /* U+23 "#" */
+ 0x24, 0x4b, 0xfa, 0x44, 0x9f, 0x92, 0x28,
+
+ /* U+24 "$" */
+ 0x21, 0x1d, 0x4a, 0x30, 0xe5, 0xaf, 0x88, 0x40,
+
+ /* U+25 "%" */
+ 0xf4, 0x98, 0x98, 0x68, 0x16, 0x19, 0x29, 0x2f,
+
+ /* U+26 "&" */
+ 0x70, 0xa1, 0x41, 0x6, 0x52, 0xa2, 0x3a,
+
+ /* U+27 "'" */
+ 0xc0,
+
+ /* U+28 "(" */
+ 0xa, 0x49, 0x24, 0x91, 0x0,
+
+ /* U+29 ")" */
+ 0x8, 0x92, 0x49, 0x25, 0x0,
+
+ /* U+2A "*" */
+ 0x23, 0x9c, 0x40,
+
+ /* U+2B "+" */
+ 0x27, 0xc8, 0x40,
+
+ /* U+2C "," */
+ 0xc0,
+
+ /* U+2D "-" */
+ 0xe0,
+
+ /* U+2E "." */
+ 0x80,
+
+ /* U+2F "/" */
+ 0x11, 0x22, 0x24, 0x48, 0x88, 0x80,
+
+ /* U+30 "0" */
+ 0x74, 0x63, 0x18, 0xc6, 0x2e,
+
+ /* U+31 "1" */
+ 0xd5, 0x55,
+
+ /* U+32 "2" */
+ 0x74, 0x42, 0x31, 0x11, 0x1f,
+
+ /* U+33 "3" */
+ 0x74, 0x42, 0x61, 0x86, 0x2e,
+
+ /* U+34 "4" */
+ 0x10, 0x82, 0x12, 0x49, 0x2f, 0xc2,
+
+ /* U+35 "5" */
+ 0xfc, 0x3d, 0x10, 0x86, 0x2e,
+
+ /* U+36 "6" */
+ 0x21, 0x10, 0xe8, 0xc6, 0x2e,
+
+ /* U+37 "7" */
+ 0xfc, 0x84, 0x22, 0x10, 0x88,
+
+ /* U+38 "8" */
+ 0x74, 0x62, 0xe8, 0xc6, 0x2e,
+
+ /* U+39 "9" */
+ 0x74, 0x63, 0x17, 0x8, 0x84,
+
+ /* U+3A ":" */
+ 0x84,
+
+ /* U+3B ";" */
+ 0x86,
+
+ /* U+3C "<" */
+ 0x3, 0xc4, 0x30,
+
+ /* U+3D "=" */
+ 0xf0, 0xf0,
+
+ /* U+3E ">" */
+ 0xc, 0x32, 0xc0,
+
+ /* U+3F "?" */
+ 0x74, 0x42, 0x33, 0x10, 0x4,
+
+ /* U+40 "@" */
+ 0x1e, 0x18, 0x65, 0xe6, 0x49, 0x92, 0x64, 0x98,
+ 0xd9, 0x0, 0x61, 0x7, 0x80,
+
+ /* U+41 "A" */
+ 0x10, 0xc2, 0x92, 0x49, 0xf8, 0x61,
+
+ /* U+42 "B" */
+ 0xf2, 0x28, 0xbc, 0x8e, 0x18, 0x7e,
+
+ /* U+43 "C" */
+ 0x7a, 0x18, 0x20, 0x82, 0x8, 0x5e,
+
+ /* U+44 "D" */
+ 0xfa, 0x18, 0x61, 0x86, 0x18, 0x7e,
+
+ /* U+45 "E" */
+ 0xfc, 0x21, 0xf8, 0x42, 0x1f,
+
+ /* U+46 "F" */
+ 0xfc, 0x21, 0xf8, 0x42, 0x10,
+
+ /* U+47 "G" */
+ 0x7a, 0x18, 0x60, 0x9e, 0x18, 0x5e,
+
+ /* U+48 "H" */
+ 0x86, 0x18, 0x7f, 0x86, 0x18, 0x61,
+
+ /* U+49 "I" */
+ 0xff,
+
+ /* U+4A "J" */
+ 0x8, 0x42, 0x10, 0x84, 0x3e,
+
+ /* U+4B "K" */
+ 0x85, 0x12, 0x45, 0xd, 0x11, 0x22, 0x42,
+
+ /* U+4C "L" */
+ 0x84, 0x21, 0x8, 0x42, 0x1f,
+
+ /* U+4D "M" */
+ 0x83, 0x8f, 0x1d, 0x5a, 0xb2, 0x60, 0xc1,
+
+ /* U+4E "N" */
+ 0x87, 0x1c, 0x69, 0x96, 0x58, 0xe1,
+
+ /* U+4F "O" */
+ 0x7a, 0x18, 0x61, 0x86, 0x18, 0x5e,
+
+ /* U+50 "P" */
+ 0xfa, 0x18, 0x61, 0xfa, 0x8, 0x20,
+
+ /* U+51 "Q" */
+ 0x79, 0xa, 0x14, 0x28, 0x52, 0xa2, 0x3e,
+
+ /* U+52 "R" */
+ 0xfa, 0x18, 0x61, 0xfa, 0x28, 0xa1,
+
+ /* U+53 "S" */
+ 0x7a, 0x8, 0x10, 0x38, 0x18, 0x5e,
+
+ /* U+54 "T" */
+ 0xfe, 0x20, 0x40, 0x81, 0x2, 0x4, 0x8,
+
+ /* U+55 "U" */
+ 0x86, 0x18, 0x61, 0x86, 0x18, 0x5e,
+
+ /* U+56 "V" */
+ 0x83, 0x9, 0x12, 0x42, 0x85, 0xc, 0x8,
+
+ /* U+57 "W" */
+ 0x88, 0x63, 0x28, 0xc9, 0x52, 0x52, 0x94, 0xc6,
+ 0x30, 0x84,
+
+ /* U+58 "X" */
+ 0x45, 0x22, 0x84, 0x30, 0xa4, 0xa1,
+
+ /* U+59 "Y" */
+ 0x84, 0x88, 0xa1, 0x41, 0x2, 0x4, 0x8,
+
+ /* U+5A "Z" */
+ 0xfc, 0x21, 0x4, 0x21, 0x4, 0x3f,
+
+ /* U+5B "[" */
+ 0xea, 0xaa, 0xb0,
+
+ /* U+5C "\\" */
+ 0x82, 0x10, 0x82, 0x10, 0x82, 0x10, 0x42,
+
+ /* U+5D "]" */
+ 0xd5, 0x55, 0x70,
+
+ /* U+5E "^" */
+ 0x22, 0xa2,
+
+ /* U+5F "_" */
+ 0xfc
+};
+
+
+/*---------------------
+ * GLYPH DESCRIPTION
+ *--------------------*/
+
+static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
+ {.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */,
+ {.bitmap_index = 0, .adv_w = 48, .box_w = 1, .box_h = 1, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 1, .adv_w = 40, .box_w = 1, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 2, .adv_w = 56, .box_w = 2, .box_h = 2, .ofs_x = 1, .ofs_y = 6},
+ {.bitmap_index = 3, .adv_w = 111, .box_w = 7, .box_h = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 10, .adv_w = 94, .box_w = 5, .box_h = 12, .ofs_x = 1, .ofs_y = -2},
+ {.bitmap_index = 18, .adv_w = 138, .box_w = 8, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 26, .adv_w = 125, .box_w = 7, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 33, .adv_w = 29, .box_w = 1, .box_h = 2, .ofs_x = 1, .ofs_y = 6},
+ {.bitmap_index = 34, .adv_w = 58, .box_w = 3, .box_h = 11, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 39, .adv_w = 58, .box_w = 3, .box_h = 11, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 44, .adv_w = 83, .box_w = 5, .box_h = 4, .ofs_x = 0, .ofs_y = 4},
+ {.bitmap_index = 47, .adv_w = 94, .box_w = 5, .box_h = 4, .ofs_x = 1, .ofs_y = 2},
+ {.bitmap_index = 50, .adv_w = 38, .box_w = 1, .box_h = 2, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 51, .adv_w = 59, .box_w = 3, .box_h = 1, .ofs_x = 0, .ofs_y = 3},
+ {.bitmap_index = 52, .adv_w = 41, .box_w = 1, .box_h = 1, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 53, .adv_w = 89, .box_w = 4, .box_h = 11, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 59, .adv_w = 94, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 64, .adv_w = 94, .box_w = 2, .box_h = 8, .ofs_x = 2, .ofs_y = 0},
+ {.bitmap_index = 66, .adv_w = 94, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 71, .adv_w = 94, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 76, .adv_w = 94, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 82, .adv_w = 94, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 87, .adv_w = 94, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 92, .adv_w = 94, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 97, .adv_w = 94, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 102, .adv_w = 94, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 107, .adv_w = 38, .box_w = 1, .box_h = 6, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 108, .adv_w = 38, .box_w = 1, .box_h = 7, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 109, .adv_w = 83, .box_w = 4, .box_h = 5, .ofs_x = 1, .ofs_y = 2},
+ {.bitmap_index = 112, .adv_w = 94, .box_w = 4, .box_h = 3, .ofs_x = 1, .ofs_y = 3},
+ {.bitmap_index = 114, .adv_w = 83, .box_w = 4, .box_h = 5, .ofs_x = 1, .ofs_y = 2},
+ {.bitmap_index = 117, .adv_w = 94, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 122, .adv_w = 172, .box_w = 10, .box_h = 10, .ofs_x = 1, .ofs_y = -2},
+ {.bitmap_index = 135, .adv_w = 106, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 141, .adv_w = 114, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 147, .adv_w = 111, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 153, .adv_w = 116, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 159, .adv_w = 104, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 164, .adv_w = 103, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 169, .adv_w = 116, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 175, .adv_w = 122, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 181, .adv_w = 50, .box_w = 1, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 182, .adv_w = 97, .box_w = 5, .box_h = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 187, .adv_w = 119, .box_w = 7, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 194, .adv_w = 96, .box_w = 5, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 199, .adv_w = 144, .box_w = 7, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 206, .adv_w = 122, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 212, .adv_w = 115, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 218, .adv_w = 113, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 224, .adv_w = 115, .box_w = 7, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 231, .adv_w = 116, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 237, .adv_w = 109, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 243, .adv_w = 99, .box_w = 7, .box_h = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 250, .adv_w = 129, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 256, .adv_w = 110, .box_w = 7, .box_h = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 263, .adv_w = 157, .box_w = 10, .box_h = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 273, .adv_w = 106, .box_w = 6, .box_h = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 279, .adv_w = 103, .box_w = 7, .box_h = 8, .ofs_x = 0, .ofs_y = 0},
+ {.bitmap_index = 286, .adv_w = 99, .box_w = 6, .box_h = 8, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 292, .adv_w = 59, .box_w = 2, .box_h = 10, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 295, .adv_w = 89, .box_w = 5, .box_h = 11, .ofs_x = 0, .ofs_y = -1},
+ {.bitmap_index = 302, .adv_w = 59, .box_w = 2, .box_h = 10, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 305, .adv_w = 87, .box_w = 5, .box_h = 3, .ofs_x = 0, .ofs_y = 5},
+ {.bitmap_index = 307, .adv_w = 101, .box_w = 6, .box_h = 1, .ofs_x = 0, .ofs_y = -2}
+};
+
+/*---------------------
+ * CHARACTER MAPPING
+ *--------------------*/
+
+
+
+/*Collect the unicode lists and glyph_id offsets*/
+static const lv_font_fmt_txt_cmap_t cmaps[] =
+{
+ {
+ .range_start = 32, .range_length = 64, .glyph_id_start = 1,
+ .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
+ }
+};
+
+/*-----------------
+ * KERNING
+ *----------------*/
+
+
+/*Map glyph_ids to kern left classes*/
+static const uint8_t kern_left_class_mapping[] =
+{
+ 0, 1, 0, 2, 0, 0, 0, 0,
+ 2, 3, 0, 4, 0, 5, 6, 5,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 7, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 8, 9, 10, 11, 0, 12,
+ 13, 0, 0, 14, 15, 16, 0, 0,
+ 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 3, 0, 0, 0,
+ 0
+};
+
+/*Map glyph_ids to kern right classes*/
+static const uint8_t kern_right_class_mapping[] =
+{
+ 0, 0, 0, 1, 0, 0, 0, 0,
+ 1, 0, 2, 3, 0, 4, 5, 4,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 6, 0, 7, 0, 0, 0,
+ 7, 0, 0, 8, 0, 0, 0, 0,
+ 7, 0, 9, 0, 10, 11, 12, 13,
+ 14, 15, 16, 17, 0, 0, 2, 0,
+ 0
+};
+
+/*Kern values between classes*/
+static const int8_t kern_class_values[] =
+{
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, -6, -3, -9, -4,
+ -10, -4, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 2, 0, 0, -2, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, -6, -1,
+ -7, 0, -12, 0, 0, 0, 0, 0,
+ 0, -2, 0, 0, -6, 0, -5, 0,
+ -5, 0, -4, -1, -4, 0, -11, 0,
+ -9, -4, 0, -9, 0, -3, -2, -1,
+ -4, 0, -2, 0, -8, 0, 0, -8,
+ 0, -3, -2, -4, -6, -2, 0, 0,
+ 0, -5, -3, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, -9,
+ 0, -7, 0, -2, 0, -1, 0, -1,
+ -1, -7, -2, -7, -1, 0, -9, 0,
+ 0, 0, 0, 0, 0, 0, 0, -2,
+ 0, 0, -2, 0, 0, 0, -1, 0,
+ 0, 0, 0, 0, -1, 0, -2, 0,
+ -3, 0, -1, -2, 0, -2, 0, -4,
+ -3, 0, -4, 0, 0, -4, 0, -1,
+ 0, -2, 0, 0, -2, 0, -2, 0,
+ -3, -5, -1, 0, 0, 0, -8, 0,
+ -8, -2, -19, -2, -3, -1, 0, -2,
+ -1, -7, -3, -3, 0, 0, 0, 0,
+ 0, -1, 0, -3, 0, 0, 0, 0,
+ -1, 0, -3, -3, -2, 0, 0, 0,
+ 0, 0, -4, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, -1, 0,
+ -4, 0, -5, 0, -2, 0, -2, -2,
+ -2, -1, -2, 0, 0, -3, 0, -9,
+ 0, -10, 0, -8, 1, -6, 0, -6,
+ -2, -10, 0, -12, -6, 0, -15, 0,
+ -4, 0, 0, -4, 0, -1, 0, -5,
+ 0, 0, -2, 0, -2, 0, -3, -5,
+ -1, -1, -1, 0, -11, -1, -11, -1,
+ -24, -1, -1, -1, 0, 0, 0, -6,
+ -4, -4, -4, 0, 0, -4, 0, 0,
+ 0, -1, 0, 0, -2, 0, -2, 0,
+ -3, -5, -1, -1, 0, 0, 0, -1,
+ 0, 0, -2, 0, 0, -2, 0, -2,
+ 0, 0, -4, 0, 0, 0, 0, 0,
+ 0, 0, 0, -2, 0, 0, -4, 0,
+ -2, 0, -2, -5, 0, 0, 0, 0,
+ -11, -6, -7, -2, -18, -2, -2, 1,
+ 0, 0, 0, -2, 0, 0, 0, 0,
+ 0, 0, 0, -2, 0, -5, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, -9, -3, -7, -2, -13, -2,
+ -1, 0, 0, 0, 0, -1, 0, 0,
+ 0, 0, 0, -4, -2, -1, 0, -8,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, -2, 0, -4, 0, -3,
+ -2, -3, 0, -2, 0, -1, 0, -1,
+ -2, 0, 0, 0, 0, -9, -6, -9,
+ -5, -18, -5, -3, 0, 0, 0, 0,
+ -2, 0, 0, 0, 0, 0, 0, -5,
+ 0, -3, -2, -3, 0, 0, 0, 0,
+ 0, -1, 0, 0
+};
+
+
+/*Collect the kern class' data in one place*/
+static const lv_font_fmt_txt_kern_classes_t kern_classes =
+{
+ .class_pair_values = kern_class_values,
+ .left_class_mapping = kern_left_class_mapping,
+ .right_class_mapping = kern_right_class_mapping,
+ .left_class_cnt = 28,
+ .right_class_cnt = 17,
+};
+
+/*--------------------
+ * ALL CUSTOM DATA
+ *--------------------*/
+
+/*Store all the custom data of the font*/
+static lv_font_fmt_txt_dsc_t font_dsc = {
+ .glyph_bitmap = gylph_bitmap,
+ .glyph_dsc = glyph_dsc,
+ .cmaps = cmaps,
+ .kern_dsc = &kern_classes,
+ .kern_scale = 16,
+ .cmap_num = 1,
+ .bpp = 1,
+ .kern_classes = 1,
+ .bitmap_format = 0
+};
+
+
+/*-----------------
+ * PUBLIC FONT
+ *----------------*/
+
+/*Initialize a public general font descriptor*/
+lv_font_t din2014light_12 = {
+ .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/
+ .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/
+ .line_height = 12, /*The maximum line height required by the font*/
+ .base_line = 2, /*Baseline measured from the bottom of the line*/
+#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0)
+ .subpx = LV_FONT_SUBPX_NONE,
+#endif
+ .dsc = &font_dsc /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
+};
+
+#endif /*#if DIN2014LIGHT_12*/
+
diff --git a/fw/src/app/font_iecsymbol_30.c b/fw/src/app/font_iecsymbol_30.c
new file mode 100644
index 0000000..eac7c32
--- /dev/null
+++ b/fw/src/app/font_iecsymbol_30.c
@@ -0,0 +1,156 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include
+
+/*******************************************************************************
+ * Size: 30 px
+ * Bpp: 1
+ * Opts:
+ ******************************************************************************/
+
+#ifndef IECSYMBOL_30
+#define IECSYMBOL_30 1
+#endif
+
+#if IECSYMBOL_30
+
+/*-----------------
+ * BITMAPS
+ *----------------*/
+
+/*Store the image of the glyphs*/
+static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = {
+ // "1" maps to this glyph
+ /* U+23FB "⏻" */
+ 0x0, 0x18, 0x0, 0x0, 0x1e, 0x0, 0x0, 0xf,
+ 0x0, 0x0, 0x7, 0x80, 0x0, 0x3, 0xc0, 0x0,
+ 0x1, 0xe0, 0x0, 0x0, 0xf0, 0x0, 0x38, 0x78,
+ 0x38, 0x3e, 0x3c, 0x3c, 0x1f, 0x1e, 0x1f, 0x1f,
+ 0xf, 0xf, 0xcf, 0x7, 0x83, 0xef, 0x83, 0xc0,
+ 0xf7, 0x81, 0xe0, 0x7f, 0xc0, 0xf0, 0x1f, 0xe0,
+ 0x78, 0xf, 0xf0, 0x3c, 0x7, 0xf8, 0xc, 0x3,
+ 0xfc, 0x0, 0x1, 0xff, 0x0, 0x1, 0xf7, 0x80,
+ 0x0, 0xf3, 0xe0, 0x0, 0xf8, 0xf0, 0x0, 0x78,
+ 0x7e, 0x0, 0xfc, 0x1f, 0xc1, 0xfc, 0x7, 0xff,
+ 0xfc, 0x1, 0xff, 0xfc, 0x0, 0x3f, 0xf8, 0x0,
+ 0x7, 0xf0, 0x0,
+
+ // "2"...
+ /* U+23FC "⏼" */
+ 0x0, 0x3f, 0x80, 0x0, 0x1f, 0xff, 0x0, 0x3,
+ 0xff, 0xfc, 0x0, 0x7f, 0xff, 0xe0, 0xf, 0xff,
+ 0xff, 0x1, 0xfe, 0x7, 0xf8, 0x3f, 0x80, 0x1f,
+ 0xc3, 0xf0, 0x0, 0xfc, 0x7e, 0xe, 0x7, 0xe7,
+ 0xc1, 0xf0, 0x3e, 0xfc, 0x1f, 0x3, 0xff, 0x81,
+ 0xf0, 0x1f, 0xf8, 0x1f, 0x1, 0xff, 0x81, 0xf0,
+ 0x1f, 0xf8, 0x1f, 0x1, 0xff, 0x81, 0xf0, 0x1f,
+ 0xf8, 0x1f, 0x1, 0xff, 0xc1, 0xf0, 0x3f, 0x7c,
+ 0x1f, 0x3, 0xe7, 0xe1, 0xf0, 0x7e, 0x3f, 0xe,
+ 0xf, 0xc3, 0xf8, 0x1, 0xfc, 0x1f, 0xe0, 0x7f,
+ 0x80, 0xff, 0xff, 0xf0, 0x7, 0xff, 0xfe, 0x0,
+ 0x3f, 0xff, 0xc0, 0x0, 0xff, 0xf0, 0x0, 0x3,
+ 0xfc, 0x0,
+
+ /* U+23FD "⏽" */
+ 0x77, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xfe, 0xe0,
+
+ /* U+23FE "⏾" */
+ 0x1, 0x0, 0x0, 0x60, 0x0, 0xe, 0x0, 0x1,
+ 0xe0, 0x0, 0x1c, 0x0, 0x3, 0xc0, 0x0, 0x7c,
+ 0x0, 0x7, 0xc0, 0x0, 0x7c, 0x0, 0xf, 0xc0,
+ 0x0, 0xfc, 0x0, 0xf, 0xc0, 0x0, 0xfe, 0x0,
+ 0xf, 0xe0, 0x0, 0xfe, 0x0, 0xf, 0xf0, 0x0,
+ 0xff, 0x0, 0x7, 0xf8, 0x0, 0x7f, 0x80, 0x3,
+ 0xfc, 0x0, 0x3f, 0xe0, 0x1, 0xff, 0x0, 0xf,
+ 0xf8, 0x0, 0x7f, 0xc0, 0x3, 0xff, 0x0, 0xf,
+ 0xfc, 0x0, 0x3f, 0xe0,
+
+ /* U+2B58 "⭘" */
+ 0x0, 0x3f, 0x80, 0x0, 0x3f, 0xfe, 0x0, 0xf,
+ 0xff, 0xe0, 0x7, 0xff, 0xff, 0x1, 0xfe, 0xf,
+ 0xf0, 0x3f, 0x0, 0x7e, 0xf, 0xc0, 0x7, 0xe3,
+ 0xf0, 0x0, 0x7e, 0x7c, 0x0, 0x7, 0xcf, 0x80,
+ 0x0, 0xfb, 0xe0, 0x0, 0xf, 0xfc, 0x0, 0x1,
+ 0xff, 0x80, 0x0, 0x3f, 0xf0, 0x0, 0x7, 0xfe,
+ 0x0, 0x0, 0xff, 0xc0, 0x0, 0x1f, 0xf8, 0x0,
+ 0x3, 0xef, 0x80, 0x0, 0xf9, 0xf0, 0x0, 0x1f,
+ 0x3f, 0x0, 0x7, 0xe3, 0xf0, 0x1, 0xf8, 0x3f,
+ 0x0, 0x7e, 0x7, 0xf8, 0x3f, 0xc0, 0x7f, 0xff,
+ 0xf0, 0x3, 0xff, 0xf8, 0x0, 0x3f, 0xfe, 0x0,
+ 0x0, 0xfe, 0x0, 0x0
+};
+
+
+/*---------------------
+ * GLYPH DESCRIPTION
+ *--------------------*/
+
+static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
+ {.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */,
+ {.bitmap_index = 0, .adv_w = 480, .box_w = 25, .box_h = 29, .ofs_x = 2, .ofs_y = 0},
+ {.bitmap_index = 91, .adv_w = 480, .box_w = 28, .box_h = 28, .ofs_x = 1, .ofs_y = 0},
+ {.bitmap_index = 189, .adv_w = 480, .box_w = 5, .box_h = 28, .ofs_x = 12, .ofs_y = 0},
+ {.bitmap_index = 207, .adv_w = 480, .box_w = 20, .box_h = 27, .ofs_x = 4, .ofs_y = 0},
+ {.bitmap_index = 275, .adv_w = 480, .box_w = 27, .box_h = 27, .ofs_x = 1, .ofs_y = 0}
+};
+
+/*---------------------
+ * CHARACTER MAPPING
+ *--------------------*/
+
+
+/*Collect the unicode lists and glyph_id offsets*/
+static const lv_font_fmt_txt_cmap_t cmaps[] =
+{
+ {
+ .range_start = 49, .range_length = 5, .glyph_id_start = 1,
+ .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
+ }
+};
+
+
+
+/*--------------------
+ * ALL CUSTOM DATA
+ *--------------------*/
+
+/*Store all the custom data of the font*/
+static lv_font_fmt_txt_dsc_t font_dsc = {
+ .glyph_bitmap = gylph_bitmap,
+ .glyph_dsc = glyph_dsc,
+ .cmaps = cmaps,
+ .kern_dsc = NULL,
+ .kern_scale = 0,
+ .cmap_num = 1,
+ .bpp = 1,
+ .kern_classes = 0,
+ .bitmap_format = 0
+};
+
+
+/*-----------------
+ * PUBLIC FONT
+ *----------------*/
+
+/*Initialize a public general font descriptor*/
+lv_font_t iecsymbol_30 = {
+ .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/
+ .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/
+ .line_height = 29, /*The maximum line height required by the font*/
+ .base_line = 0, /*Baseline measured from the bottom of the line*/
+#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0)
+ .subpx = LV_FONT_SUBPX_NONE,
+#endif
+#if LV_VERSION_CHECK(7, 4, 0)
+ .underline_position = 0,
+ .underline_thickness = 0,
+#endif
+ .dsc = &font_dsc /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
+};
+
+
+
+#endif /*#if IECSYMBOL_30*/
+
diff --git a/fw/src/app/font_moabsym_30.c b/fw/src/app/font_moabsym_30.c
new file mode 100644
index 0000000..80e0275
--- /dev/null
+++ b/fw/src/app/font_moabsym_30.c
@@ -0,0 +1,184 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include
+
+
+/*******************************************************************************
+ * Size: 30 px
+ * Bpp: 1
+ * Opts:
+ ******************************************************************************/
+
+#ifndef MOABSYM_30
+#define MOABSYM_30 1
+#endif
+
+#if MOABSYM_30
+
+/*-----------------
+ * BITMAPS
+ *----------------*/
+
+/*Store the image of the glyphs*/
+static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = {
+
+ /* U+31 "1" UP_DOWN */
+ 0x3, 0x0, 0x1e, 0x0, 0xfc, 0x7, 0x38, 0x38, // 0
+ 0x71, 0xc0, 0xee, 0x1, 0xd0, 0x2, 0x0, 0x0, // 8
+ 0x0, 0x0, 0x30, 0x1, 0xe0, 0x7, 0x80, 0x1e, // 16
+ 0x0, 0x70, 0x0, 0x0, 0x0, 0x1, 0x0, 0x2e, // 24
+ 0x1, 0xdc, 0xe, 0x38, 0x70, 0x73, 0x80, 0xfc, // 32
+ 0x1, 0xe0, 0x3, 0x0, // 40
+
+ /* U+32 "2" DOWN */
+ 0x3, 0x0, 0x1e, 0x0, 0x78, 0x1, 0xe0, 0x7, // 44
+ 0x0, 0x0, 0x0, 0x0, 0x10, 0x2, 0xe0, 0x1d, // 52
+ 0xc0, 0xe3, 0x87, 0x7, 0x38, 0xf, 0xc0, 0x1e, // 60
+ 0x0, 0x30, 0x0, // 68
+
+ /* U+33 "3" UP */
+ 0x3, 0x0, 0x1e, 0x0, 0xfc, 0x7, 0x38, 0x38, // 71
+ 0x71, 0xc0, 0xee, 0x1, 0xd0, 0x2, 0x0, 0x0, // 79
+ 0x0, 0x0, 0x30, 0x1, 0xe0, 0x7, 0x80, 0x1e, // 87
+ 0x0, 0x70, 0x0, // 95
+
+ /* U+34 "4" DOT */ // 0 1 2 3
+ 0x00, 0x00, 0x00, 0x00, // 0000000000000000000000000000 98
+ 0x07, 0xfc, 0x00, // 0000000001111111110000000000 102
+ 0x01, 0xe0, 0x78, 0x00, // 0000000111100000011110000000 105
+ 0x30, 0x00, 0xc0, // 0000001100000000000011000000 109
+ 0x06, 0x00, 0x06, 0x00, // 0000011000000000000001100000 112
+ 0x80, 0x00, 0x10, // 0000100000000000000000010000 116
+ 0x10, 0x00, 0x00, 0x83, // 0001000000000000000000001000 119
+ 0x00, 0x00, 0x0c, // 0011000000000000000000001100 123
+ 0x20, 0x0f, 0x00, 0x46, // 0010000000001111000000000100 126
+ 0x03, 0xfc, 0x06, // 0011000000111111110000000110 130
+ 0x40, 0x7f, 0xe0, 0x24, // 0100000001111111111000000010 133
+ 0x07, 0xfe, 0x02, // 0100000001111111111000000010 137
+ 0xc0, 0xff, 0xf0, 0x3c, // 1100000011111111111100000011 140
+ 0x0f, 0xff, 0x03, // 1100000011111111111100000011 144
+ 0x80, 0xff, 0xf0, 0x1c, // 1000000011111111111100000001 147
+ 0x0f, 0xff, 0x03, // 1100000011111111111100000011 151
+ 0xc0, 0xff, 0xf0, 0x34, // 1100000011111111111100000011 154
+ 0x07, 0xfe, 0x02, // 0100000001111111111000000010 158
+ 0x40, 0x7f, 0xe0, 0x26, // 0100000001111111111000000010 161
+ 0x03, 0xfc, 0x06, // 0110000000111111110000000110 165
+ 0x20, 0x0f, 0x00, 0x43, // 0010000000001111000000000100 168
+ 0x00, 0x00, 0x0c, // 0011000000000000000000001100 172
+ 0x10, 0x00, 0x00, 0x80, // 0001000000000000000000001000 175
+ 0x80, 0x00, 0x10, // 0000100000000000000000010000 179
+ 0x04, 0x00, 0x02, 0x00, // 0000010000000000000000100000 182
+ 0x30, 0x00, 0xc0, // 0000001100000000000011000000 186
+ 0x01, 0xe0, 0x78, 0x00, // 0000000111110000011110000000 189
+ 0x03, 0xfc, 0x00, // 0000000000111111110000000000 193
+ 0x00, 0x00, 0x00, 0x00, // 0000000000000000000000000000 196
+
+ /* U+35 "5" PAUSE */
+ // offset 200
+ 0x0, 0x7f, 0xc0, 0x0, 0x1e, 0x7, 0x80, 0x3,
+ 0x0, 0xc, 0x0, 0x60, 0x0, 0x60, 0x8, 0x0,
+ 0x1, 0x1, 0x0, 0x0, 0x8, 0x30, 0x0, 0x0,
+ 0xc2, 0x0, 0x0, 0x4, 0x60, 0x70, 0xe0, 0x64,
+ 0x7, 0xe, 0x2, 0x40, 0x70, 0xe0, 0x2c, 0x7,
+ 0xe, 0x3, 0xc0, 0x70, 0xe0, 0x38, 0x7, 0xe,
+ 0x1, 0xc0, 0x70, 0xe0, 0x3c, 0x7, 0xe, 0x3,
+ 0x40, 0x70, 0xe0, 0x24, 0x7, 0xe, 0x2, 0x60,
+ 0x70, 0xe0, 0x62, 0x0, 0x0, 0x4, 0x30, 0x0,
+ 0x0, 0xc1, 0x0, 0x0, 0x8, 0x8, 0x0, 0x1,
+ 0x0, 0x40, 0x0, 0x60, 0x3, 0x0, 0xc, 0x0,
+ 0x1e, 0x7, 0x80, 0x0, 0x3f, 0xc0, 0x0,
+
+ /* U+36 "6" CHECK */
+ 0x0, 0x7f, 0xc0, 0x0, 0x1e, 0x7, 0x80, 0x3,
+ 0x0, 0xc, 0x0, 0x60, 0x0, 0x60, 0x8, 0x0,
+ 0x1, 0x1, 0x0, 0x0, 0x8, 0x30, 0x0, 0x0,
+ 0xc2, 0x0, 0x0, 0x4, 0x60, 0x0, 0x10, 0x64,
+ 0x0, 0x3, 0x82, 0x40, 0x0, 0x70, 0x2c, 0x0,
+ 0xe, 0x3, 0xc3, 0x1, 0xc0, 0x38, 0x18, 0x38,
+ 0x1, 0xc1, 0xc7, 0x0, 0x3c, 0xe, 0xe0, 0x3,
+ 0x40, 0x7c, 0x0, 0x24, 0x3, 0x80, 0x2, 0x60,
+ 0x10, 0x0, 0x62, 0x0, 0x0, 0x4, 0x30, 0x0,
+ 0x0, 0xc1, 0x0, 0x0, 0x8, 0x8, 0x0, 0x1,
+ 0x0, 0x40, 0x0, 0x60, 0x3, 0x0, 0xc, 0x0,
+ 0x1e, 0x7, 0x80, 0x0, 0x3f, 0xc0, 0x0,
+
+ /* U+37 "7" X */
+ 0x0, 0x7f, 0xc0, 0x0, 0x1e, 0x7, 0x80, 0x3,
+ 0x0, 0xc, 0x0, 0x60, 0x0, 0x60, 0x8, 0x0,
+ 0x1, 0x1, 0x0, 0x0, 0x8, 0x30, 0x0, 0x0,
+ 0xc2, 0x0, 0x0, 0x4, 0x60, 0x40, 0x20, 0x64,
+ 0x6, 0x6, 0x2, 0x40, 0x30, 0xc0, 0x2c, 0x1,
+ 0x98, 0x3, 0xc0, 0xf, 0x0, 0x38, 0x0, 0x60,
+ 0x1, 0xc0, 0xf, 0x0, 0x3c, 0x1, 0x98, 0x3,
+ 0x40, 0x30, 0xc0, 0x24, 0x6, 0x6, 0x2, 0x60,
+ 0x40, 0x20, 0x62, 0x0, 0x0, 0x4, 0x30, 0x0,
+ 0x0, 0xc1, 0x0, 0x0, 0x8, 0x8, 0x0, 0x1,
+ 0x0, 0x40, 0x0, 0x60, 0x3, 0x0, 0xc, 0x0,
+ 0x1e, 0x7, 0x80, 0x0, 0x3f, 0xc0, 0x0
+
+};
+
+
+/*---------------------
+ * GLYPH DESCRIPTION
+ *--------------------*/
+
+static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
+ {.bitmap_index = 0, .adv_w = 0, .box_w = 0, .box_h = 0, .ofs_x = 0, .ofs_y = 0} /* id = 0 reserved */,
+ {.bitmap_index = 0, .adv_w = 480, .box_w = 14, .box_h = 25, .ofs_x = 8, .ofs_y = 0},
+ {.bitmap_index = 44, .adv_w = 480, .box_w = 14, .box_h = 15, .ofs_x = 8, .ofs_y = 0},
+ {.bitmap_index = 71, .adv_w = 480, .box_w = 14, .box_h = 15, .ofs_x = 8, .ofs_y = 10},
+ {.bitmap_index = 98, .adv_w = 480, .box_w = 28, .box_h = 29, .ofs_x = 1, .ofs_y = -2},
+ {.bitmap_index = 200, .adv_w = 480, .box_w = 28, .box_h = 27, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 295, .adv_w = 480, .box_w = 28, .box_h = 27, .ofs_x = 1, .ofs_y = -1},
+ {.bitmap_index = 390, .adv_w = 480, .box_w = 28, .box_h = 27, .ofs_x = 1, .ofs_y = -1},
+};
+
+/*---------------------
+ * CHARACTER MAPPING
+ *--------------------*/
+
+
+
+/*Collect the unicode lists and glyph_id offsets*/
+static const lv_font_fmt_txt_cmap_t cmaps[] =
+{
+ {
+ .range_start = 49, .range_length = 8, .glyph_id_start = 1,
+ .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
+ }
+};
+/*--------------------
+ * ALL CUSTOM DATA
+ *--------------------*/
+
+/*Store all the custom data of the font*/
+static lv_font_fmt_txt_dsc_t font_dsc = {
+ .glyph_bitmap = gylph_bitmap,
+ .glyph_dsc = glyph_dsc,
+ .cmaps = cmaps,
+ .cmap_num = 1,
+ .bpp = 1,
+
+ .kern_scale = 0,
+ .kern_dsc = NULL,
+ .kern_classes = 0,
+};
+
+/*-----------------
+ * PUBLIC FONT
+ *----------------*/
+
+/*Initialize a public general font descriptor*/
+lv_font_t moabsym_30 = {
+ .get_glyph_dsc = lv_font_get_glyph_dsc_fmt_txt, /*Function pointer to get glyph's data*/
+ .get_glyph_bitmap = lv_font_get_bitmap_fmt_txt, /*Function pointer to get glyph's bitmap*/
+ .line_height = 29, /*The maximum line height required by the font*/
+ .base_line = 1, /*Baseline measured from the bottom of the line*/
+#if !(LVGL_VERSION_MAJOR == 6 && LVGL_VERSION_MINOR == 0)
+ .subpx = LV_FONT_SUBPX_NONE,
+#endif
+ .dsc = &font_dsc /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
+};
+
+#endif /*#if ICONS_V3*/
diff --git a/fw/src/app/headers.h b/fw/src/app/headers.h
new file mode 100644
index 0000000..6ee0b68
--- /dev/null
+++ b/fw/src/app/headers.h
@@ -0,0 +1,26 @@
+#include
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
diff --git a/fw/src/app/joystick.c b/fw/src/app/joystick.c
new file mode 100644
index 0000000..34e13ae
--- /dev/null
+++ b/fw/src/app/joystick.c
@@ -0,0 +1,316 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include "headers.h"
+#include "state.h"
+#include "joystick.h"
+#include "spi.h"
+
+LOG_MODULE_REGISTER(joystick);
+
+#define ADC_RESOLUTION 12
+#define ADC_MAX 4095
+#define ADC_MAX_VOLT 3.3
+#define ADC_VOLT_BIT (ADC_MAX_VOLT / ADC_MAX)
+#define JOY_CENTER_VOLTS (ADC_MAX_VOLT / 2.0)
+#define JOY_X_CHANNEL 0
+#define JOY_Y_CHANNEL 1
+#define OTP_BASE_ADDR 0x1FFF7800
+#define OTP_BANK_SIZE 0x20
+#define OTP_LOCK_ADDR 0x1FFF7A00
+
+#define TYPICAL_90 1500
+#define TYPICAL_160 2250
+
+/* size of stack area used by the thread */
+#define STACKSIZE 1024
+
+/* scheduling priority used by the thread */
+#define PRIORITY 9
+
+
+static struct device *adc;
+static struct adc_channel_cfg ch_x_cfg;
+static struct adc_channel_cfg ch_y_cfg;
+static u16_t adc_buffer;
+joystick_cal_t calibration;
+
+static struct adc_sequence adc_table;
+
+static struct gpio_callback gpio_cb_joystick;
+static struct gpio_callback gpio_cb_menu;
+
+// https://devzone.nordicsemi.com/f/nordic-q-a/54146/blink-led-on-button-press-on-nrf9160dk
+// helped me on button up and down
+// trigger callback on pin rising *and* falling: GPIO_INT_DOUBLE_EDGE
+
+// 4 buttons, 4 leds
+// https://github.com/leonyoliveir/Embebbed-Systems/blob/fb797537b7818d7a6f15c9978d2152b2c3dafcc7/io_exercise/src/main.c
+
+#define EDGE (GPIO_INT | GPIO_INT_EDGE | GPIO_INT_DEBOUNCE)
+#define JOY_BTN_PORT DT_ALIAS_BUTTON_JOYSTICK_GPIOS_CONTROLLER
+#define JOY_BTN_PIN DT_ALIAS_BUTTON_JOYSTICK_GPIOS_PIN
+#define JOY_BTN_FLAGS (DT_ALIAS_BUTTON_JOYSTICK_GPIOS_FLAGS | EDGE | GPIO_PUD_PULL_UP)
+#define MENU_BTN_PORT DT_ALIAS_BUTTON_MENU_GPIOS_CONTROLLER
+#define MENU_BTN_PIN DT_ALIAS_BUTTON_MENU_GPIOS_PIN
+#define MENU_BTN_FLAGS (DT_ALIAS_BUTTON_MENU_GPIOS_FLAGS | EDGE | GPIO_PUD_PULL_UP)
+
+
+static void menu_button_pressed(struct device *gpio, struct gpio_callback *cb, u32_t pins)
+{
+ int state = 0;
+ gpio_pin_read(gpio, MENU_BTN_PIN, &state);
+ atomic_set(&g_btn_menu, state);
+}
+
+static void joy_button_pressed(struct device *gpio, struct gpio_callback *cb, u32_t pins)
+{
+ int state = 0;
+ gpio_pin_read(gpio, JOY_BTN_PIN, &state);
+ atomic_set(&g_btn_joy, state);
+}
+
+static int joy_button_init(struct device *gpio_dev)
+{
+ // Likely need gpio_int_double_edge
+ gpio_pin_configure(gpio_dev, JOY_BTN_PIN,
+ (GPIO_DIR_IN |
+ GPIO_INT_ACTIVE_HIGH | // from moab_hat.dts
+ GPIO_INT | GPIO_INT_EDGE | GPIO_INT_DEBOUNCE | // from EDGE
+ GPIO_INT_DOUBLE_EDGE |
+ GPIO_PUD_PULL_UP));
+
+ // gpio_pin_interrupt_configure is called here in the sample code
+ // https://github.com/zephyrproject-rtos/zephyr/blob/master/samples/basic/button/src/main.c
+ // why is it missing here?
+
+ gpio_init_callback(&gpio_cb_joystick, joy_button_pressed, BIT(JOY_BTN_PIN));
+ gpio_add_callback(gpio_dev, &gpio_cb_joystick);
+ gpio_pin_enable_callback(gpio_dev, JOY_BTN_PIN);
+
+ return 0;
+}
+
+static int menu_button_init(struct device *gpio_dev)
+{
+ gpio_pin_configure(gpio_dev, MENU_BTN_PIN,
+ (GPIO_DIR_IN |
+ GPIO_INT_ACTIVE_HIGH | // from moab_hat.dts
+ GPIO_INT | GPIO_INT_EDGE | GPIO_INT_DEBOUNCE | // from EDGE
+ GPIO_INT_DOUBLE_EDGE |
+ GPIO_PUD_PULL_UP));
+
+ gpio_init_callback(&gpio_cb_menu, menu_button_pressed, BIT(MENU_BTN_PIN));
+ gpio_add_callback(gpio_dev, &gpio_cb_menu);
+ gpio_pin_enable_callback(gpio_dev, MENU_BTN_PIN);
+
+ return 0;
+}
+
+
+int joystick_position(int8_t* x_percent, int8_t* y_percent, joystick_cal_t *cal)
+{
+ int err = 0;
+ u16_t analog_val_x, analog_val_y;
+ float xscale, yscale;
+
+ /* Configure ADC table structure */
+ adc_table.channels = BIT(JOY_X_CHANNEL);
+ adc_table.resolution = ADC_RESOLUTION;
+ adc_table.buffer = &adc_buffer;
+ adc_table.buffer_size = sizeof(adc_buffer);
+
+ if ((err = adc_read(adc, &adc_table)) != 0)
+ return err;
+
+ analog_val_x = adc_buffer;
+
+ /* Configure ADC table structure */
+ adc_table.channels = BIT(JOY_Y_CHANNEL);
+
+ if ((err = adc_read(adc, &adc_table)) != 0)
+ return err;
+
+ analog_val_y = adc_buffer;
+
+ if (cal)
+ {
+ analog_val_x -= (cal->x_error);
+ analog_val_y -= (cal->y_error);
+
+ }
+
+ float vx = analog_val_x * ADC_VOLT_BIT;
+ float vy = analog_val_y * ADC_VOLT_BIT;
+
+ xscale = 1.0;
+ yscale = 1.0;
+
+ if (cal)
+ {
+ if ((vx - JOY_CENTER_VOLTS) > 0) xscale = cal->xn_scale;
+ else xscale = cal->xp_scale;
+ if ((vy - JOY_CENTER_VOLTS) > 0) yscale = cal->yn_scale;
+ else yscale = cal->yp_scale;
+ }
+
+ // Remove the joystick's calibrated offset error
+ *x_percent = -(int8_t)(((vx - JOY_CENTER_VOLTS) * (100 / JOY_CENTER_VOLTS))/xscale);
+ *y_percent = -(int8_t)(((vy - JOY_CENTER_VOLTS) * (100 / JOY_CENTER_VOLTS))/yscale);
+
+ /* This operation removing the joystick's offset error can (and in the past
+ has) caused rollover errors by over- or underflowing. The next bit will
+ check for that and clamp the value to +100% or -100% as needed. */
+
+ // Check for int underflow (+offset)
+ if (analog_val_x > 10000) {
+ *x_percent = 100;
+ } else if (analog_val_x > ADC_MAX) { // also for overflow of the ADC's max value (-offset)
+ *x_percent = -100;
+ }
+
+ if (analog_val_y > 10000) {
+ *y_percent = 100;
+ } else if (analog_val_y > ADC_MAX) {
+ *y_percent = -100;
+ }
+
+ // Sanity check to clamp percent values to max. 100% in either direction
+ if (*x_percent > 100) {
+ *x_percent = 100;
+ }
+
+ if (*x_percent < -100) {
+ *x_percent = -100;
+ }
+
+ if (*y_percent > 100) {
+ *y_percent = 100;
+ }
+
+ if (*y_percent < -100) {
+ *y_percent = -100;
+ }
+
+ return err;
+}
+
+static int adc_init(void)
+{
+ int err = 0;
+
+ adc = device_get_binding(DT_ADC_1_NAME);
+
+ if (adc == NULL)
+ {
+ LOG_ERR("Failed to get ADC device.");
+ return -EINVAL;
+ }
+
+ /* Configure ADC channels */
+ ch_x_cfg.channel_id = JOY_X_CHANNEL;
+ ch_x_cfg.differential = false;
+ ch_x_cfg.gain = ADC_GAIN_1,
+ ch_x_cfg.reference = ADC_REF_INTERNAL;
+ ch_x_cfg.acquisition_time = ADC_ACQ_TIME_DEFAULT;
+
+ ch_y_cfg.channel_id = JOY_Y_CHANNEL;
+ ch_y_cfg.differential = false;
+ ch_y_cfg.gain = ADC_GAIN_1,
+ ch_y_cfg.reference = ADC_REF_INTERNAL;
+ ch_y_cfg.acquisition_time = ADC_ACQ_TIME_DEFAULT;
+
+ if ((err = adc_channel_setup(adc, &ch_x_cfg)) != 0)
+ return err;
+
+ err = adc_channel_setup(adc, &ch_y_cfg);
+
+ return err;
+}
+
+static void joy_task(void)
+{
+ struct device *joy_gpio_dev;
+ struct device *menu_gpio_dev;
+ int8_t joyx, joyy;
+ int err;
+ int bank = 14;
+ int i;
+ char cal[sizeof(joystick_cal_t)];
+ char c;
+ uint32_t address = (OTP_BASE_ADDR + (OTP_BANK_SIZE*bank));
+
+ /* Start searching for calibration data at bank 14 and work downwards. This
+ makes sure we're always looking at the most recent valid calibration. */
+ bank = 14;
+ for (bank = 14; bank >=0; bank -= 2)
+ {
+ c = *(unsigned char *)address;
+
+ // 0xCB is a magic value that indicates the beginning of calibration data
+ if (c == 0xCB)
+ {
+ break;
+ }
+
+ address = (OTP_BASE_ADDR + (OTP_BANK_SIZE * bank));
+ }
+
+ if (*(unsigned char *)address != 0xCB) {
+ LOG_ERR ("Joystick calibration not found");
+ /* These are default pre-calibration values for the joystick */
+ calibration.x_error = (0);
+ calibration.y_error = (0);
+ calibration.xp_scale = (0.5);
+ calibration.xn_scale = (0.5);
+ calibration.yp_scale = (0.5);
+ calibration.yn_scale = (0.5);
+ }
+ else
+ {
+ LOG_INF ("Found calibration data in bank: %i", bank);
+ address++; // skip over magic byte
+ for (i=0; i
+
+typedef struct joystick_cal
+{
+ int16_t x_error;
+ int16_t y_error;
+ float xp_scale;
+ float xn_scale;
+ float yp_scale;
+ float yn_scale;
+ } joystick_cal_t;
+
+
+int joystick_position(int8_t* x_percent, int8_t* y_percent, joystick_cal_t *cal);
+
+#endif
diff --git a/fw/src/app/main.c b/fw/src/app/main.c
new file mode 100644
index 0000000..ae93d78
--- /dev/null
+++ b/fw/src/app/main.c
@@ -0,0 +1,109 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include "headers.h"
+#include "app_version.h"
+#include "plate.h"
+#include "spi.h"
+#include "display.h"
+
+LOG_MODULE_REGISTER(main);
+
+void main(void)
+{
+ pi_to_hat_t rx;
+ u8_t last_control;
+
+ u8_t mb_idx = 0;
+ char message_buffer[255];
+
+ float servo1_pos, servo2_pos, servo3_pos;
+ u16_t servo1_pos_centi_deg, servo2_pos_centi_deg, servo3_pos_centi_deg;
+
+ LOG_INF("Version %s", log_strdup(APP_SEMVER));
+ LOG_INF("Word Size %d. pi_to_hat_t %d", sizeof(void *), sizeof(pi_to_hat_t));
+
+ plate_init();
+
+ while (true)
+ {
+ // process incoming SPI msgs
+ if (wait_for_pi_message(&rx, K_FOREVER) == 0)
+ {
+ last_control = rx.control;
+
+ switch (rx.control)
+ {
+ case COPY_STRING:
+ if (mb_idx == 0)
+ memset(message_buffer, 0, sizeof(message_buffer));
+ if (mb_idx < 240) {
+ memcpy(&message_buffer[mb_idx], rx.data.characters, 7);
+ mb_idx += 7;
+ }
+ else
+ LOG_ERR("String too long to display. Max length is 240 bytes.");
+ break;
+
+ case DISPLAY_BIG_TEXT_ICON:
+ message_buffer[mb_idx] = '\0'; // Add a termination char just in case
+ mb_idx = 0;
+ LOG_INF("0x%02x (%d) TEXT=%s", rx.control, (u8_t) rx.data.icon, log_strdup(message_buffer));
+ display_big_text_icon(message_buffer, (disp_icon_t) rx.data.icon);
+ break;
+
+ case DISPLAY_BIG_TEXT:
+ message_buffer[mb_idx] = '\0'; // Add a termination char just in case
+ mb_idx = 0;
+ LOG_INF("0x%02x TEXT=%s", rx.control, log_strdup(message_buffer));
+ display_big_text(message_buffer);
+ break;
+
+ case DISPLAY_SMALL_TEXT:
+ message_buffer[mb_idx] = '\0'; // Add a termination char just in case
+ mb_idx = 0;
+ LOG_INF("0x%02x text=%s", rx.control, log_strdup(message_buffer));
+ display_small_text(message_buffer);
+ break;
+
+ case DISPLAY_POWER_SYMBOL:
+ message_buffer[mb_idx] = '\0'; // Add a termination char just in case
+ mb_idx = 0;
+ LOG_INF("0x%02x (%d) TEXT=%s", rx.control, (u8_t) rx.data.icon, log_strdup(message_buffer));
+ display_big_text_power_icon(message_buffer, (disp_power_icon_t) rx.data.icon);
+ break;
+
+ case SERVO_ENABLE:
+ LOG_INF("0x%02x servos: on", rx.control);
+ plate_servo_enable(true);
+ break;
+
+ case SERVO_DISABLE:
+ LOG_INF("0x%02x servos: off", rx.control);
+ plate_servo_enable(false);
+ break;
+
+ case SET_SERVOS:
+ // Convert bytes to uint16
+ servo1_pos_centi_deg = ((rx.data.servo1_pos_centi_deg_high_byte << 8) + rx.data.servo1_pos_centi_deg_low_byte);
+ servo2_pos_centi_deg = ((rx.data.servo2_pos_centi_deg_high_byte << 8) + rx.data.servo2_pos_centi_deg_low_byte);
+ servo3_pos_centi_deg = ((rx.data.servo3_pos_centi_deg_high_byte << 8) + rx.data.servo3_pos_centi_deg_low_byte);
+ // Convert from hundredths of a degree to degrees
+ servo1_pos = ((float) servo1_pos_centi_deg) / 100.0;
+ servo2_pos = ((float) servo2_pos_centi_deg) / 100.0;
+ servo3_pos = ((float) servo3_pos_centi_deg) / 100.0;
+
+ plate_servo_update_position(0, servo1_pos);
+ plate_servo_update_position(1, servo2_pos);
+ plate_servo_update_position(2, servo3_pos);
+ break;
+
+ case NOOP:
+ break;
+
+ default:
+ LOG_ERR("Bad control byte: %0x2x. Prior was: %0x2x", rx.control, last_control);
+ break;
+ }
+ }
+ }
+}
diff --git a/fw/src/app/plate.c b/fw/src/app/plate.c
new file mode 100644
index 0000000..3637f43
--- /dev/null
+++ b/fw/src/app/plate.c
@@ -0,0 +1,267 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include
+
+#include "pwm/pwm_stm32.h"
+#include "stm32f4xx_hal_tim.h"
+
+
+/* ---- */
+#include
+#include
+#include
+#include
+
+#include
+LOG_MODULE_REGISTER(plate);
+
+
+#include "joystick.h"
+#include "plate.h"
+
+#define SERVO_EN_PORT DT_ALIAS_SERVO_ENABLE_GPIOS_CONTROLLER
+#define SERVO_EN_PIN DT_ALIAS_SERVO_ENABLE_GPIOS_PIN
+
+/* size of stack area used by this thread */
+#define STACKSIZE 1024
+
+/* scheduling priority used by this thread */
+#define PRIORITY 8
+
+/* Microsecond timing for the PWM module */
+#define PERIOD 3300
+#define MINPULSEWIDTH 375
+#define MAXPULSEWIDTH 2400
+#define SERVO_DEGREES 180
+#define SERVO_DEAD_WIDTH 4
+#define TYPICAL_MAX 2250
+#define TYPICAL_MID 1950
+#define TYPICAL_MIN 1450
+
+#define PW_PER_DEGREE (MAXPULSEWIDTH - MINPULSEWIDTH) / SERVO_DEGREES
+
+#define DT_ALIAS_PWM_3_LABEL DT_INST_0_ST_STM32_PWM_LABEL
+
+#define ARM_LENGTH 55.0
+#define PLATE_DIAMETER 197.3
+#define SIDE_LENGTH 170.87
+#define PIVOT_HEIGHT 80.0
+#define SQRT3 1.732050808
+#define ANGLE_MAX 160
+#define ANGLE_MIN 90
+#define ARM_TRAVEL 70.0
+
+#define PI 3.14159265358979323846
+
+#define OTP_BASE_ADDR 0x1FFF7800
+#define OTP_BANK_SIZE 0x20
+#define OTP_LOCK_ADDR 0x1FFF7A00
+
+#define DEV_DATA(dev) ((struct pwm_stm32_data * const)(dev)->driver_data)
+
+static struct device *plate_servo_en_dev;
+
+typedef struct
+{
+ struct device *dev;
+ u32_t pwm_channel;
+} servo_t;
+
+static servo_t plate_servos[3];
+static float servo_usec_degree[3];
+
+servo_cal_t servocal;
+
+static int plate_update_pw_stm32(struct device* dev, int channel, u32_t pulse_width)
+{
+ struct pwm_stm32_data *data = DEV_DATA(dev);
+ TIM_HandleTypeDef *TimerHandle = &data->hpwm;
+ static u64_t pulse_cycles = 0;
+ static u64_t cycles_per_sec = 0;
+ int err = 0;
+ uint32_t tim_chan = TIM_CHANNEL_1;
+
+ if (channel == 1)
+ tim_chan = TIM_CHANNEL_2;
+ else if (channel == 2)
+ tim_chan = TIM_CHANNEL_3;
+ else if (channel == 3)
+ tim_chan = TIM_CHANNEL_4;
+
+ if (pwm_get_cycles_per_sec(dev, channel, &cycles_per_sec) != 0)
+ {
+ return -EIO;
+ }
+
+ pulse_cycles = (pulse_width * cycles_per_sec) / USEC_PER_SEC;
+ if (pulse_cycles >= ((u64_t)1 << 32)) {
+ return -ENOTSUP;
+ }
+
+ __HAL_TIM_SET_COMPARE(TimerHandle, tim_chan, (u32_t)pulse_cycles);
+
+ return err;
+}
+
+static inline float plate_to_degrees(float radians)
+{
+ return radians * (180.0 / PI);
+}
+
+static inline float plate_to_radians(float degrees)
+{
+ return degrees * PI / 180.0;
+}
+
+static void plate_coerce_to_range(float* value, float low, float high)
+{
+ if (*value < low)
+ *value = low;
+ else if (*value > high)
+ *value = high;
+}
+
+
+static int plate_servo_set_position(u8_t id, float angle)
+{
+ int err = 0;
+ u32_t pulse_width;
+ servo_t servo;
+
+ plate_coerce_to_range(&angle, ANGLE_MIN, ANGLE_MAX);
+ //LOG_INF("channel %d @ %d degrees", id, (int)angle);
+
+ //pulse_width = (angle * servo_usec_degree[id]) + MINPULSEWIDTH;
+ pulse_width = ((angle - ANGLE_MIN) * servo_usec_degree[id]) + servocal.servo_min[id];
+ servo = plate_servos[id];
+
+ if ((err = pwm_pin_set_usec(servo.dev, servo.pwm_channel, PERIOD, pulse_width/*, PWM_POLARITY_NORMAL*/)) != 0)
+ {
+ LOG_ERR("pwm pin set fails");
+ }
+
+ return err;
+}
+
+int plate_servo_update_position(u8_t id, float angle)
+{
+ int err = 0;
+ u32_t pulse_width;
+ servo_t servo;
+
+ // Comment out this line, to remove servo limitations
+ plate_coerce_to_range(&angle, ANGLE_MIN, ANGLE_MAX);
+ //LOG_INF("channel %d @ %d degrees", id, (int)angle);
+
+ pulse_width = ((angle - ANGLE_MIN) * servo_usec_degree[id]) + servocal.servo_min[id];
+
+ servo = plate_servos[id];
+
+ if ((err = plate_update_pw_stm32(servo.dev, id, pulse_width)) != 0)
+ {
+ LOG_ERR("pwm update fails");
+ }
+
+ return err;
+}
+
+int plate_servo_enable(u8_t enable)
+{
+ return gpio_pin_write(plate_servo_en_dev, SERVO_EN_PIN, (u32_t)enable);
+}
+
+int plate_init(void)
+{
+ struct device *pwm_dev;
+ u32_t i;
+ char cal[sizeof(servo_cal_t)];
+ int bank = 1;
+ uint32_t address = (OTP_LOCK_ADDR + bank);
+ unsigned char c;
+ int cal_invalid = 0;
+
+ plate_servo_en_dev = device_get_binding(SERVO_EN_PORT);
+
+ if (!plate_servo_en_dev) {
+ LOG_ERR("Cannot find servo enable device!");
+ return -1;
+ }
+
+ gpio_pin_configure(plate_servo_en_dev, SERVO_EN_PIN, GPIO_DIR_OUT);
+
+ pwm_dev = device_get_binding(DT_ALIAS_PWM_3_LABEL);
+ if (!pwm_dev) {
+ LOG_ERR("Cannot find PWM device!");
+ return -1;
+ }
+
+ /* If there's no calibration data, we will leave these "default" values
+ as the calibration */
+ for (i=0; i<3; i++)
+ {
+ servocal.servo_max[i] = TYPICAL_MAX;
+ servocal.servo_133[i] = TYPICAL_MID;
+ servocal.servo_min[i] = TYPICAL_MIN;
+ }
+
+ bank = 15;
+ address = (OTP_BASE_ADDR + (OTP_BANK_SIZE * bank));
+ for (i=0; i<8; i++)
+ {
+ c = *(unsigned char *)address;
+ //LOG_INF ("0x%08X = %02X", address, c);
+ if (c == 0xFF) bank-=2;
+ else break;
+ address = (OTP_BASE_ADDR + (OTP_BANK_SIZE * bank));
+ }
+ /* Actual servo calibration values are in increments of 5 so we will never
+ see a value of 0xFF if the calibration data is present in OTP */
+ if (*(unsigned char *)address != 0xFF)
+ {
+ for (i=0; i MAXPULSEWIDTH) || (servocal.servo_max[i] < MINPULSEWIDTH)) cal_invalid = 1;
+ if ((servocal.servo_min[i] > MAXPULSEWIDTH) || (servocal.servo_min[i] < MINPULSEWIDTH)) cal_invalid = 1;
+ if ((servocal.servo_133[i] > MAXPULSEWIDTH) || (servocal.servo_133[i] < MINPULSEWIDTH)) cal_invalid = 1;
+ }
+ }
+
+ if (cal_invalid)
+ {
+ LOG_ERR("Servo calibration data is corrupt! Using defaults.");
+ for (i=0; i<3; i++)
+ {
+ servocal.servo_max[i] = TYPICAL_MAX;
+ servocal.servo_133[i] = TYPICAL_MID;
+ servocal.servo_min[i] = TYPICAL_MIN;
+ }
+ }
+
+ for (i=0; i<3; i++)
+ LOG_INF ("Bank: %i Servo %i: Max %i Mid %i Min %i", bank, i, servocal.servo_max[i], servocal.servo_133[i], servocal.servo_min[i]);
+
+ servo_usec_degree[0] = (servocal.servo_max[0] - servocal.servo_min[0])/ARM_TRAVEL;
+ servo_usec_degree[1] = (servocal.servo_max[1] - servocal.servo_min[1])/ARM_TRAVEL;
+ servo_usec_degree[2] = (servocal.servo_max[2] - servocal.servo_min[2])/ARM_TRAVEL;
+
+ plate_servos[0].dev = pwm_dev;
+ plate_servos[0].pwm_channel = 1;
+
+ plate_servos[1].dev = pwm_dev;
+ plate_servos[1].pwm_channel = 2;
+
+ plate_servos[2].dev = pwm_dev;
+ plate_servos[2].pwm_channel = 3;
+
+ // Need to start with some defaults. We tried removing
+ // but it's a load-bearing poster.
+ plate_servo_set_position(0, 150);
+ plate_servo_set_position(1, 150);
+ plate_servo_set_position(2, 150);
+
+ return 0;
+}
diff --git a/fw/src/app/plate.h b/fw/src/app/plate.h
new file mode 100644
index 0000000..0c80b7e
--- /dev/null
+++ b/fw/src/app/plate.h
@@ -0,0 +1,21 @@
+#ifndef SERVO_H_
+#define SERVO_H_
+
+#include
+
+typedef struct servo_cal
+{
+ u16_t servo_min[3];
+ u16_t servo_133[3];
+ u16_t servo_max[3];
+} servo_cal_t;
+
+int plate_init(void);
+int plate_servo_enable(u8_t enable);
+int plate_servo_update_position(u8_t id, float angle);
+int plate_set_angle(float theta_x, float theta_y);
+
+//int plate_sweep_sync_servos(float* target_servo_angles);
+//int plate_sync_angle(float theta_x, float theta_y);
+
+#endif
diff --git a/fw/src/app/sh1106_regs.h b/fw/src/app/sh1106_regs.h
new file mode 100644
index 0000000..4a02a54
--- /dev/null
+++ b/fw/src/app/sh1106_regs.h
@@ -0,0 +1,105 @@
+#ifndef __SH1106_REGS_H__
+#define __SH1106_REGS_H__
+
+#define SH1106_CONTROL_LAST_BYTE_CMD 0x00
+#define SH1106_CONTROL_LAST_BYTE_DATA 0x40
+#define SH1106_CONTROL_BYTE_CMD 0x80
+#define SH1106_CONTROL_BYTE_DATA 0xc0
+#define SH1106_READ_STATUS_MASK 0xc0
+#define SH1106_READ_STATUS_BUSY 0x80
+#define SH1106_READ_STATUS_ON 0x40
+
+/*
+ * Fundamental Command Table
+ */
+#define SH1106_SET_CONTRAST_CTRL 0x81 /* double byte command */
+
+#define SH1106_SET_ENTIRE_DISPLAY_OFF 0xa4
+#define SH1106_SET_ENTIRE_DISPLAY_ON 0xa5
+
+#define SH1106_SET_NORMAL_DISPLAY 0xa6
+#define SH1106_SET_REVERSE_DISPLAY 0xa7
+
+#define SH1106_DISPLAY_OFF 0xae
+#define SH1106_DISPLAY_ON 0xaf
+
+/*
+ * Addressing Setting Command Table
+ */
+#define SH1106_SET_LOWER_COL_ADDRESS 0x00
+#define SH1106_SET_LOWER_COL_ADDRESS_MASK 0x0f
+
+#define SH1106_SET_HIGHER_COL_ADDRESS 0x10
+#define SH1106_SET_HIGHER_COL_ADDRESS_MASK 0x0f
+
+#define SH1106_SET_MEM_ADDRESSING_MODE 0x20 /* double byte command */
+#define SH1106_SET_MEM_ADDRESSING_HORIZONTAL 0x00
+#define SH1106_SET_MEM_ADDRESSING_VERTICAL 0x01
+#define SH1106_SET_MEM_ADDRESSING_PAGE 0x02
+
+#define SH1106_SET_COLUMN_ADDRESS 0x21 /* triple byte command */
+
+#define SH1106_SET_PAGE_ADDRESS 0x22 /* triple byte command */
+
+#define SH1106_SET_PAGE_START_ADDRESS 0xb0
+#define SH1106_SET_PAGE_START_ADDRESS_MASK 0x07
+
+
+/*
+ * Hardware Configuration Command Table
+ */
+#define SH1106_SET_START_LINE 0x40
+#define SH1106_SET_START_LINE_MASK 0x3f
+
+#define SH1106_SET_SEGMENT_MAP_NORMAL 0xa0
+#define SH1106_SET_SEGMENT_MAP_REMAPED 0xa1
+
+#define SH1106_SET_MULTIPLEX_RATIO 0xa8 /* double byte command */
+
+#define SH1106_SET_COM_OUTPUT_SCAN_NORMAL 0xc0
+#define SH1106_SET_COM_OUTPUT_SCAN_FLIPPED 0xc8
+
+#define SH1106_SET_DISPLAY_OFFSET 0xd3 /* double byte command */
+
+#define SH1106_SET_PADS_HW_CONFIG 0xda /* double byte command */
+#define SH1106_SET_PADS_HW_SEQUENTIAL 0x02
+#define SH1106_SET_PADS_HW_ALTERNATIVE 0x12
+
+
+/*
+ * Timming and Driving Scheme Setting Command Table
+ */
+#define SH1106_SET_CLOCK_DIV_RATIO 0xd5 /* double byte command */
+
+#define SH1106_SET_CHARGE_PERIOD 0xd9 /* double byte command */
+
+#define SH1106_SET_VCOM_DESELECT_LEVEL 0xdb /* double byte command */
+
+#define SH1106_NOP 0xe3
+
+/*
+ * Charge Pump Command Table
+ */
+#define SH1106_SET_CHARGE_PUMP_ON 0x8d /* double byte command */
+#define SH1106_SET_CHARGE_PUMP_ON_DISABLED 0x10
+#define SH1106_SET_CHARGE_PUMP_ON_ENABLED 0x14
+
+#define SH1106_SET_DCDC_MODE 0xad /* double byte command */
+#define SH1106_SET_DCDC_DISABLED 0x8a
+#define SH1106_SET_DCDC_ENABLED 0x8b
+
+#define SH1106_SET_PUMP_VOLTAGE_64 0x30
+#define SH1106_SET_PUMP_VOLTAGE_74 0x31
+#define SH1106_SET_PUMP_VOLTAGE_80 0x32
+#define SH1106_SET_PUMP_VOLTAGE_90 0x33
+
+/*
+ * Read modify write
+ */
+#define SH1106_READ_MODIFY_WRITE_START 0xe0
+#define SH1106_READ_MODIFY_WRITE_END 0xee
+
+/* time constants in ms */
+#define SH1106_RESET_DELAY 100
+
+#endif // __SH1106_REGS_H__
diff --git a/fw/src/app/sh1106_spi.c b/fw/src/app/sh1106_spi.c
new file mode 100644
index 0000000..77b22e6
--- /dev/null
+++ b/fw/src/app/sh1106_spi.c
@@ -0,0 +1,514 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include
+LOG_MODULE_REGISTER(sh1106, CONFIG_DISPLAY_LOG_LEVEL);
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "sh1106_regs.h"
+
+#define SH1106_SPI_FREQ DT_INST_0_SINO_SH1106_SPI_MAX_FREQUENCY
+
+/* -- CS Pin -- */
+//#ifdef DT_INST_0_SINO_SH1106_CS_GPIOS_CONTROLLER
+#define SH1106_CS_CONTROLLER DT_INST_0_SINO_SH1106_CS_GPIOS_CONTROLLER
+#define SH1106_CS_PIN DT_INST_0_SINO_SH1106_CS_GPIOS_PIN
+#define SH1106_CS_FLAGS DT_INST_0_SINO_SH1106_CS_GPIOS_FLAGS
+//#endif
+
+/* -- Reset Pin -- */
+#define SH1106_RESET_CONTROLLER DT_INST_0_SINO_SH1106_RESET_GPIOS_CONTROLLER
+#define SH1106_RESET_PIN DT_INST_0_SINO_SH1106_RESET_GPIOS_PIN
+#define SH1106_RESET_FLAGS DT_INST_0_SINO_SH1106_RESET_GPIOS_FLAGS
+
+/* -- A0 Pin (4-wire mode) -- */
+//#ifdef DT_INST_0_SINO_SH1106_A0_GPIOS
+#define SH1106_4WIRE
+#define SH1106_A0_CONTROLLER DT_INST_0_SINO_SH1106_A0_GPIOS_CONTROLLER
+#define SH1106_A0_PIN DT_INST_0_SINO_SH1106_A0_GPIOS_PIN
+#define SH1106_A0_FLAGS DT_INST_0_SINO_SH1106_A0_GPIOS_FLAGS
+//#endif
+
+//#define CONFIG_SH1106_REVERSE_MODE
+
+#ifndef CONFIG_SH1106_DEFAULT_CONTRAST
+#define CONFIG_SH1106_DEFAULT_CONTRAST 0xAF
+#endif
+
+#if DT_INST_0_SINO_SH1106_SEGMENT_REMAP == 1
+#define SH1106_PANEL_SEGMENT_REMAP true
+#else
+#define SH1106_PANEL_SEGMENT_REMAP false
+#endif
+
+#if DT_INST_0_SINO_SH1106_COM_INVDIR == 1
+#define SH1106_PANEL_COM_INVDIR true
+#else
+#define SH1106_PANEL_COM_INVDIR false
+#endif
+
+#if DT_INST_0_SINO_SH1106_COM_SEQUENTIAL == 1
+#define SH1106_COM_PINS_HW_CONFIG SH1106_SET_PADS_HW_SEQUENTIAL
+#else
+#define SH1106_COM_PINS_HW_CONFIG SH1106_SET_PADS_HW_ALTERNATIVE
+#endif
+
+#define SH1106_PANEL_NUMOF_PAGES (DT_INST_0_SINO_SH1106_HEIGHT / 8)
+#define SH1106_CLOCK_DIV_RATIO 0x1
+#define SH1106_CLOCK_FREQUENCY 0x9
+#define SH1106_PANEL_VCOM_DESEL_LEVEL 0x25
+#define SH1106_PANEL_PUMP_VOLTAGE SH1106_SET_PUMP_VOLTAGE_90
+
+#define SH1106_BUF_SIZE (SH1106_PANEL_NUMOF_PAGES * )
+
+
+#define SH1106_PANEL_NUMOF_COLUMS 132
+
+
+#ifndef SH1106_ADDRESSING_MODE
+#define SH1106_ADDRESSING_MODE (SH1106_SET_MEM_ADDRESSING_HORIZONTAL)
+#endif
+
+struct sh1106_data {
+//#ifdef SH1106_4WIRE
+ struct device *a0;
+//#endif
+ struct device *cs;
+ struct spi_cs_control cs_ctrl;
+ struct device *reset;
+ struct device *spi;
+ struct spi_config spi_cfg;
+ u8_t contrast;
+ u8_t scan_mode;
+};
+
+static int sh1106_spi_write(const struct device *dev, const u8_t *data, size_t length)
+{
+ struct sh1106_data *driver = dev->driver_data;
+
+ const struct spi_buf buf[1] =
+ {
+ {
+ .buf = data,
+ .len = length
+ }
+ };
+
+ struct spi_buf_set tx =
+ {
+ .buffers = buf,
+ };
+
+ tx.count = 1;
+
+ return spi_write(driver->spi, &driver->spi_cfg, &tx);
+}
+
+static int sh1106_cmd_write(const struct device *dev, const u8_t *data, size_t length)
+{
+ struct sh1106_data *driver = dev->driver_data;
+
+ gpio_pin_write(driver->a0, SH1106_A0_PIN, 0);
+ return sh1106_spi_write(dev, data, length);
+}
+
+static int sh1106_data_write(const struct device *dev, const u8_t *data, size_t length)
+{
+ struct sh1106_data *driver = dev->driver_data;
+
+ gpio_pin_write(driver->a0, SH1106_A0_PIN, 1);
+ return sh1106_spi_write(dev, data, length);
+}
+
+static inline int sh1106_set_panel_orientation(const struct device *dev)
+{
+ u8_t cmd_buf[] = {
+ (SH1106_PANEL_SEGMENT_REMAP ?
+ SH1106_SET_SEGMENT_MAP_REMAPED :
+ SH1106_SET_SEGMENT_MAP_NORMAL),
+ (SH1106_PANEL_COM_INVDIR ?
+ SH1106_SET_COM_OUTPUT_SCAN_FLIPPED :
+ SH1106_SET_COM_OUTPUT_SCAN_NORMAL)
+ };
+
+ return sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf));
+}
+
+static inline int sh1106_set_timing_setting(const struct device *dev)
+{
+ u8_t cmd_buf[] = {
+ SH1106_SET_CLOCK_DIV_RATIO,
+ (SH1106_CLOCK_FREQUENCY << 4) | SH1106_CLOCK_DIV_RATIO,
+ SH1106_SET_CHARGE_PERIOD,
+ DT_INST_0_SINO_SH1106_PRECHARGEP,
+ SH1106_SET_VCOM_DESELECT_LEVEL,
+ SH1106_PANEL_VCOM_DESEL_LEVEL
+ };
+
+ return sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf));
+}
+
+static inline int sh1106_set_hardware_config(const struct device *dev)
+{
+ u8_t cmd_buf[] = {
+ SH1106_SET_START_LINE,
+ SH1106_SET_DISPLAY_OFFSET,
+ DT_INST_0_SINO_SH1106_DISPLAY_OFFSET,
+ SH1106_SET_PADS_HW_CONFIG,
+ SH1106_COM_PINS_HW_CONFIG,
+ SH1106_SET_MULTIPLEX_RATIO,
+ DT_INST_0_SINO_SH1106_MULTIPLEX_RATIO
+ };
+
+ return sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf));
+}
+
+static inline int sh1106_set_charge_pump(const struct device *dev)
+{
+ u8_t cmd_buf[] = {
+ SH1106_SET_CHARGE_PUMP_ON,
+ SH1106_SET_CHARGE_PUMP_ON_ENABLED,
+ SH1106_SET_DCDC_MODE,
+ SH1106_SET_DCDC_ENABLED,
+ SH1106_PANEL_PUMP_VOLTAGE,
+ };
+
+ return sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf));
+}
+
+int sh1106_resume(const struct device *dev)
+{
+ /* set display on */
+ u8_t cmd_buf[] = { SH1106_DISPLAY_ON };
+
+ return sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf));
+}
+
+int sh1106_suspend(const struct device *dev)
+{
+ /* set display off */
+ u8_t cmd_buf[] = { SH1106_DISPLAY_OFF };
+
+ return sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf));
+}
+
+int sh1106_set_pos(const struct device *dev, const u16_t x, const u16_t y)
+{
+ //struct sh1106_data *driver = dev->driver_data;
+
+ u16_t column = x;
+ u8_t page = y;
+
+ /* set posistion command */
+ u8_t cmd_buf[] =
+ {
+ SH1106_SET_PAGE_START_ADDRESS + page,
+ SH1106_SET_HIGHER_COL_ADDRESS_MASK & column,
+ SH1106_SET_HIGHER_COL_ADDRESS | (column >> 4)
+ };
+
+ return sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf));
+}
+
+int sh1106_write_page(const struct device *dev, u8_t page, void const *data, size_t length)
+{
+ u8_t cmd_buf[] =
+ {
+ SH1106_SET_LOWER_COL_ADDRESS | (DT_INST_0_SINO_SH1106_SEGMENT_OFFSET & SH1106_SET_LOWER_COL_ADDRESS_MASK),
+ SH1106_SET_HIGHER_COL_ADDRESS | ((DT_INST_0_SINO_SH1106_SEGMENT_OFFSET >> 4) & SH1106_SET_LOWER_COL_ADDRESS_MASK),
+ SH1106_SET_PAGE_START_ADDRESS | page
+ };
+
+ if (page >= SH1106_PANEL_NUMOF_PAGES) {
+ return -1;
+ }
+
+ if (length > SH1106_PANEL_NUMOF_COLUMS) {
+ return -1;
+ }
+
+ if (sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf)))
+ {
+ return -1;
+ }
+
+ return sh1106_data_write(dev, data, length);
+}
+
+static u8_t sh1106_reverseBits(u8_t num)
+{
+ unsigned int count = sizeof(num) * 8 - 1;
+ unsigned int reverse_num = num;
+
+ num >>= 1;
+ while(num)
+ {
+ reverse_num <<= 1;
+ reverse_num |= num & 1;
+ num >>= 1;
+ count--;
+ }
+ reverse_num <<= count;
+ return reverse_num;
+}
+
+
+static int sh1106_write(const struct device *dev, const u16_t x, const u16_t y, const struct display_buffer_descriptor *desc, const void *buf)
+{
+ if (desc->pitch < desc->width)
+ {
+ LOG_ERR("Pitch is smaller then width");
+ return -1;
+ }
+
+ if (buf == NULL || desc->buf_size == 0U)
+ {
+ LOG_ERR("Display buffer is not available");
+ return -1;
+ }
+
+ if (desc->pitch > desc->width)
+ {
+ LOG_ERR("Unsupported mode");
+ return -1;
+ }
+
+ u8_t row1 = y >> 3;
+ u8_t row2 = (y + desc->height) >> 3;
+ u16_t column1 = x;
+ u16_t column2 = x + desc->width - 1;
+ //const uint8_t *seg = (uint8_t*)buf;
+
+ // reverse display addresses
+ const u8_t* seg_end = &((uint8_t*)buf)[desc->buf_size - 1];
+
+ for (u8_t row = row1; row < row2; row ++)
+ {
+ if (sh1106_set_pos(dev, column1, row))
+ {
+ LOG_ERR("Unable to set pos: %d, %d", x, y);
+ return -1;
+ }
+
+ for (u16_t column = column1; column <= column2; column++)
+ {
+ // reverse data
+ u8_t reversed_bits = sh1106_reverseBits(*seg_end);
+ sh1106_data_write(dev, &reversed_bits, 1);
+ seg_end--;
+ }
+ }
+
+ return 0;
+}
+
+static int sh1106_read(const struct device *dev, const u16_t x, const u16_t y,
+ const struct display_buffer_descriptor *desc, void *buf)
+{
+ LOG_ERR("Unsupported");
+ return -ENOTSUP;
+}
+
+static void *sh1106_get_framebuffer(const struct device *dev)
+{
+ LOG_ERR("Unsupported");
+ return NULL;
+}
+
+static int sh1106_set_brightness(const struct device *dev, const u8_t brightness)
+{
+ LOG_WRN("Unsupported");
+ return -ENOTSUP;
+}
+
+int sh1106_set_contrast(const struct device *dev, const u8_t contrast)
+{
+ u8_t cmd_buf[] = {
+ SH1106_SET_CONTRAST_CTRL,
+ contrast,
+ };
+
+ return sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf));
+}
+
+static void sh1106_get_capabilities(const struct device *dev, struct display_capabilities *caps)
+{
+ memset(caps, 0, sizeof(struct display_capabilities));
+ caps->x_resolution = DT_INST_0_SINO_SH1106_WIDTH;
+ caps->y_resolution = DT_INST_0_SINO_SH1106_HEIGHT;
+ caps->supported_pixel_formats = PIXEL_FORMAT_MONO01;
+ caps->current_pixel_format = PIXEL_FORMAT_MONO01;
+ caps->screen_info = SCREEN_INFO_MONO_VTILED;
+}
+
+static int sh1106_set_orientation(const struct device *dev, const enum display_orientation orientation)
+{
+ LOG_ERR("Unsupported");
+ return -ENOTSUP;
+}
+
+static int sh1106_set_pixel_format(const struct device *dev, const enum display_pixel_format pf)
+{
+ if (pf == PIXEL_FORMAT_MONO01) {
+ return 0;
+ }
+ LOG_ERR("Unsupported");
+ return -ENOTSUP;
+}
+
+static int sh1106_clear(struct device *dev)
+{
+ u8_t page_data[DT_INST_0_SINO_SH1106_WIDTH];
+ memset(page_data, 0, sizeof(page_data));
+
+ for (size_t pidx = 0; pidx < SH1106_PANEL_NUMOF_PAGES; pidx++)
+ {
+ if (sh1106_write_page(dev, pidx, page_data, DT_INST_0_SINO_SH1106_WIDTH))
+ {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static int sh1106_init_device(struct device *dev)
+{
+ struct sh1106_data *driver = dev->driver_data;
+
+ u8_t cmd_buf[] = {
+ SH1106_SET_ENTIRE_DISPLAY_OFF,
+#ifdef CONFIG_SH1106_REVERSE_MODE
+ SH1106_SET_REVERSE_DISPLAY,
+#else
+ SH1106_SET_NORMAL_DISPLAY,
+#endif
+ };
+
+
+ /* -- Toggle Reset -- */
+ gpio_pin_write(driver->reset, SH1106_RESET_PIN, 1);
+ k_sleep(SH1106_RESET_DELAY);
+ gpio_pin_write(driver->reset, SH1106_RESET_PIN, 0);
+ k_sleep(SH1106_RESET_DELAY);
+ gpio_pin_write(driver->reset, SH1106_RESET_PIN, 1);
+
+
+ /* Turn display off */
+ if (sh1106_suspend(dev)) {
+ return -EIO;
+ }
+
+ if (sh1106_set_timing_setting(dev)) {
+ return -EIO;
+ }
+
+ if (sh1106_set_hardware_config(dev)) {
+ return -EIO;
+ }
+
+ if (sh1106_set_panel_orientation(dev)) {
+ return -EIO;
+ }
+
+ if (sh1106_set_charge_pump(dev)) {
+ return -EIO;
+ }
+
+ if (sh1106_cmd_write(dev, cmd_buf, sizeof(cmd_buf))) {
+ return -EIO;
+ }
+
+ if (sh1106_set_contrast(dev, CONFIG_SH1106_DEFAULT_CONTRAST)) {
+ return -EIO;
+ }
+
+ sh1106_resume(dev);
+
+ sh1106_clear(dev);
+
+ return 0;
+}
+
+static int sh1106_init(struct device *dev)
+{
+ struct sh1106_data *driver = dev->driver_data;
+
+ LOG_DBG("");
+
+ /* -- SPI Setup -- */
+ driver->spi = device_get_binding(DT_INST_0_SINO_SH1106_BUS_NAME);
+ if (!driver->spi) {
+ LOG_ERR("spi device not found: %s", DT_INST_0_SINO_SH1106_BUS_NAME);
+ return -EINVAL;
+ }
+ /* CPOL=0, CPHA=0 */
+ driver->spi_cfg.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB;
+ driver->spi_cfg.frequency = SH1106_SPI_FREQ;
+
+
+ /* -- SPI CS thru GPIO -- */
+ driver->cs = device_get_binding(SH1106_CS_CONTROLLER);
+ if (!driver->cs) {
+ LOG_ERR("Unable to get GPIO SPI CS device");
+ return -ENODEV;
+ }
+
+ driver->cs_ctrl.gpio_dev = driver->cs;
+ driver->cs_ctrl.gpio_pin = SH1106_CS_PIN;
+ driver->cs_ctrl.delay = 0U;
+
+ driver->spi_cfg.cs = &driver->cs_ctrl;
+
+ /* -- Reset Setup -- */
+ driver->reset = device_get_binding(SH1106_RESET_CONTROLLER);
+ if (!driver->reset) {
+ LOG_ERR("Unable to get GPIO Reset device");
+ return -ENODEV;
+ }
+
+ gpio_pin_configure(driver->reset, SH1106_RESET_PIN, GPIO_DIR_OUT);
+
+
+ /* -- A0 Setup -- */
+ driver->a0 = device_get_binding(SH1106_A0_CONTROLLER);
+ if (!driver->a0) {
+ LOG_ERR("Unable to get GPIO A0 device");
+ return -ENODEV;
+ }
+
+ if (gpio_pin_configure(driver->a0, SH1106_A0_PIN, GPIO_DIR_OUT))
+ {
+ LOG_ERR("Unable to get configure A0 device");
+ return -ENODEV;
+ }
+
+ gpio_pin_write(driver->a0, SH1106_A0_PIN, 0);
+
+ return sh1106_init_device(dev);
+}
+
+static struct sh1106_data sh1106_driver;
+
+static struct display_driver_api sh1106_driver_api = {
+ .blanking_on = sh1106_suspend,
+ .blanking_off = sh1106_resume,
+ .write = sh1106_write,
+ .read = sh1106_read,
+ .get_framebuffer = sh1106_get_framebuffer,
+ .set_brightness = sh1106_set_brightness,
+ .set_contrast = sh1106_set_contrast,
+ .get_capabilities = sh1106_get_capabilities,
+ .set_pixel_format = sh1106_set_pixel_format,
+ .set_orientation = sh1106_set_orientation,
+};
+
+DEVICE_AND_API_INIT(sh1106, DT_INST_0_SINO_SH1106_LABEL, sh1106_init,
+ &sh1106_driver, NULL,
+ POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY,
+ &sh1106_driver_api);
diff --git a/fw/src/app/shell.c b/fw/src/app/shell.c
new file mode 100644
index 0000000..287500e
--- /dev/null
+++ b/fw/src/app/shell.c
@@ -0,0 +1,431 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include "headers.h"
+#include "plate.h"
+#include "joystick.h"
+#include "display.h"
+#include "app_version.h"
+
+LOG_MODULE_REGISTER(shell);
+
+#define OTP_BASE_ADDR 0x1FFF7800
+#define OTP_BANK_SIZE 0x20
+#define OTP_LOCK_ADDR 0x1FFF7A00
+
+#define TYPICAL_MAX 2250
+#define TYPICAL_MID 1950
+#define TYPICAL_MIN 1450
+#define MINPULSEWIDTH 375
+#define MAXPULSEWIDTH 2400
+
+extern joystick_cal_t calibration;
+joystick_cal_t otp_cal;
+volatile uint32_t * flash_cr = (uint32_t *)0x40023C10;
+volatile uint32_t * flash_sr = (uint32_t *)0x40023C0C;
+
+// Plate commands
+
+static int cmd_plate_enable(const struct shell *shell)
+{
+ return plate_servo_enable(1);
+}
+
+static int cmd_plate_disable(const struct shell *shell)
+{
+ return plate_servo_enable(0);
+}
+
+static int cmd_plate_servo_angle(const struct shell *shell, size_t argc, char **argv)
+{
+ int err = 0;
+ u8_t id = 0;
+ float angle = 0.0;
+
+ if (argc < 3)
+ {
+ shell_error(shell, "Invalid number of arguments.");
+ return -EINVAL;
+ }
+
+ id = atoi(argv[1]);
+ angle = atoi(argv[2]);
+
+ if ((id < 0) | (id > 2))
+ {
+ shell_error(shell, "Invalid servo id (0-2).");
+ return -EINVAL;
+ }
+
+ if ((angle < 0) | (angle > 180))
+ {
+ shell_error(shell, "Invalid servo angle (0-180).");
+ return -EINVAL;
+ }
+
+ if ((err = plate_servo_update_position(id, angle)) != 0)
+ {
+ shell_error(shell, "Failed to set servo %d. Err = %d", id, err);
+ return -EINVAL;
+ }
+
+ return err;
+}
+
+SHELL_STATIC_SUBCMD_SET_CREATE(sub_plate,
+ SHELL_CMD(enable, NULL, "Enable servos.", cmd_plate_enable),
+ SHELL_CMD(enable, NULL, "Disable servos.", cmd_plate_disable),
+ SHELL_CMD(servo, NULL, "Set the angle of a servo. ", cmd_plate_servo_angle),
+ SHELL_SUBCMD_SET_END /* Array terminated. */
+);
+SHELL_CMD_REGISTER(plate, &sub_plate, "Plate control commands", NULL);
+
+
+// Joystick Commands
+
+static int cmd_joystick_position(const struct shell *shell, size_t argc, char **argv)
+{
+ int err = 0;
+ int8_t x, y;
+
+
+ if ((err = joystick_position(&x, &y, &calibration)) != 0)
+ {
+ shell_error(shell, "Failed to read joystick. Err = %d", err);
+ return err;
+ }
+
+ shell_print(shell, "x = %d, y = %d", (int)x, (int)y);
+
+ return err;
+}
+
+SHELL_CMD_REGISTER(joystick, NULL, "Read joystick position", cmd_joystick_position);
+
+
+// Kernel Commands
+
+static int cmd_version(const struct shell *shell, size_t argc, char **argv)
+{
+ ARG_UNUSED(argc);
+ ARG_UNUSED(argv);
+
+ shell_print(shell, "Moab version %s", APP_SEMVER);
+
+ return 0;
+}
+
+SHELL_CMD_ARG_REGISTER(version, NULL, "Show kernel version", cmd_version, 1, 0);
+
+
+// Non-volatile memory banks (OTP)
+
+void print_bank(const struct shell *sh, u8_t bank)
+{
+ uint32_t address = (OTP_BASE_ADDR + (bank * OTP_BANK_SIZE));
+ uint8_t otp[32];
+ memcpy(&otp, (const void *)address, sizeof(otp));
+
+ shell_print(sh, "Bank %i", bank);
+
+ shell_print(sh, "0x%08X: %02X %02X %02X %02X %02X %02X %02X %02X\r", address,
+ otp[0], otp[1], otp[2], otp[3], otp[4], otp[5], otp[6], otp[7]);
+
+ shell_print(sh, "0x%08X: %02X %02X %02X %02X %02X %02X %02X %02X\r", address+8,
+ otp[8], otp[9], otp[10], otp[11], otp[12], otp[13], otp[14], otp[15]);
+
+ shell_print(sh, "0x%08X: %02X %02X %02X %02X %02X %02X %02X %02X\r", address+16,
+ otp[16], otp[17], otp[18], otp[19], otp[20], otp[21], otp[22], otp[23]);
+
+ shell_print(sh, "0x%08X: %02X %02X %02X %02X %02X %02X %02X %02X\r\n", address+24,
+ otp[24], otp[25], otp[26], otp[27], otp[28], otp[29], otp[30], otp[31]);
+}
+
+/* "banks" will print the contents of the OTP flash. Simply calling it with no
+ arguments will output all 16 banks; with one argument will output one single
+ bank, and with two arguments will print from bank %1 to bank %2. */
+
+static int cmd_banks(const struct shell *sh, size_t argc, char **argv)
+{
+ // no arguments: show all banks
+ if (argc-1 == 0)
+ {
+ for (u8_t i = 0; i < 16; i++)
+ {
+ print_bank(sh, i);
+ }
+ }
+
+ // 1 arg: show one bank
+ if (argc-1 == 1)
+ {
+ uint8_t bank = atoi(argv[1]);
+ if ((bank < 0) | (bank > 15))
+ {
+ shell_error(sh, "Invalid bank (0-15): %d", bank);
+ return -EINVAL;
+ }
+ print_bank(sh, bank);
+
+ }
+
+ // 2 args: show range of banks
+ if (argc-1 == 2)
+ {
+ u8_t b1 = atoi(argv[1]);
+ u8_t b2 = atoi(argv[2]);
+
+ if ((b1 < 0) | (b1 > 15) | (b2 < 0) | (b2 > 15))
+ {
+ shell_error(sh, "Invalid bank range (0-15) (0-15): %d %d", b1, b2);
+ return -EINVAL;
+ }
+
+ if (b1 > b2)
+ {
+ shell_error(sh, "Bank %d must be less than %d", b1, b2);
+ return -EINVAL;
+ }
+
+ for (u8_t i = b1; i <= b2; i++)
+ {
+ print_bank(sh, i);
+ }
+
+ }
+
+ return 0;
+}
+
+SHELL_CMD_REGISTER(banks, NULL, "Print OTP banks [0-15]", cmd_banks);
+
+/* "calibjoy" searches OTP flash for the most recent joystick calibration and
+ outputs the values it finds (if any). Mostly useful for debugging. */
+
+static int cmd_calibjoy(const struct shell *sh, size_t argc, char **argv)
+{
+ joystick_cal_t pizza; // This variable name was Scott's idea, don't blame me
+
+ int bank = 14;
+ int i;
+ char cal[sizeof(joystick_cal_t)];
+ char c;
+ uint32_t address = (OTP_BASE_ADDR + (OTP_BANK_SIZE*bank));
+
+ shell_print(sh, "starting.");
+ bank = 14;
+ for (i=0; i<8; i++)
+ {
+ c = *(unsigned char *)address;
+ if (c == 0xCB)
+ {
+ break;
+ }
+ else
+ {
+ bank-=2;
+ }
+ address = (OTP_BASE_ADDR + (OTP_BANK_SIZE * bank));
+ }
+
+ if (*(unsigned char *)address != 0xCB) {
+ shell_print(sh, "Could not find calibration data");
+ pizza.x_error = (0);
+ pizza.y_error = (0);
+ pizza.xp_scale = (0.5);
+ pizza.xn_scale = (0.5);
+ pizza.yp_scale = (0.5);
+ pizza.yn_scale = (0.5);
+ }
+ else
+ {
+ shell_print(sh, "Found calibration data in bank %i", bank);
+ address++;
+ for (i=0; i MAXPULSEWIDTH) || (servocal.servo_max[i] < MINPULSEWIDTH)) cal_invalid = 1;
+ if ((servocal.servo_min[i] > MAXPULSEWIDTH) || (servocal.servo_min[i] < MINPULSEWIDTH)) cal_invalid = 1;
+ if ((servocal.servo_133[i] > MAXPULSEWIDTH) || (servocal.servo_133[i] < MINPULSEWIDTH)) cal_invalid = 1;
+ }
+ }
+
+ if (cal_invalid)
+ {
+ shell_error(sh, "Servo calibration data is corrupt! Setting to defaults");
+ for (i=0; i<3; i++)
+ {
+
+ servocal.servo_max[i] = TYPICAL_MAX;
+ servocal.servo_133[i] = TYPICAL_MID;
+ servocal.servo_min[i] = TYPICAL_MIN;
+ }
+ }
+
+ for (i=0; i<3; i++) shell_print(sh, "Servo %i: Max %i Mid %i Min %i", i, servocal.servo_max[i], servocal.servo_133[i], servocal.servo_min[i]);
+ return 0;
+}
+
+SHELL_CMD_REGISTER(calibservo, NULL, "Show servo calibration bank", cmd_calibservo);
+
+/* "resetservo" will write a set of default servo calibration values to the next available OTP bank.
+ This is useful in cases where the bot simply refuses to calibrate properly.
+
+ Since this is potentially destructive and, at present, not recoverable ex-
+ cept by performing another calibration, this command will not work unless
+ you feed it the right password, which is "shazam" at Scott's suggestion. */
+
+static int cmd_resetservo(const struct shell *sh, size_t argc, char **argv)
+{
+ servo_cal_t servocal;
+
+ int i;
+ char cal[sizeof(servo_cal_t)];
+ char c;
+ uint32_t address = (OTP_BASE_ADDR + (OTP_BANK_SIZE));
+
+ if (argc != 2)
+ {
+ shell_error(sh, "Syntax: resetservo password");
+ return -EINVAL;
+ }
+
+ if (strncmp(argv[1], "shazam", 6))
+ {
+ shell_error(sh, "Error: password incorrect");
+ return -EINVAL;
+ }
+
+ shell_print(sh, "Password accepted");
+
+ for (i=0; i<3; i++)
+ {
+
+ servocal.servo_max[i] = TYPICAL_MAX;
+ servocal.servo_133[i] = TYPICAL_MID;
+ servocal.servo_min[i] = TYPICAL_MIN;
+ }
+
+ // Addition: This seems to be a better default setting for S0
+ servocal.servo_min[0] -= 50;
+ servocal.servo_max[0] -= 50;
+ servocal.servo_133[0] -= 50;
+
+ for (i=0; i<8; i++)
+ {
+ c = *(unsigned char *)address;
+ if (c == 0xFF) break;
+ else address+=(OTP_BANK_SIZE*2);
+ }
+ shell_print(sh, "Writing OTP bank %i", (i*2)+1);
+ *flash_cr = 0x00000001;
+ memcpy(&cal, &servocal, sizeof(servo_cal_t));
+ for (i=0; imsg;
+ k_free(rx_data);
+ return 0;
+}
+
+void spi_task(void)
+{
+ struct device *spi;
+ struct spi_config spi_cfg;
+ struct spi_cs_control spi_cs;
+
+ spi = device_get_binding("SPI_1");
+ if (!spi)
+ {
+ LOG_ERR("Could not find SPI driver\n");
+ return;
+ }
+
+ spi_cfg.operation = SPI_WORD_SET(8) | SPI_OP_MODE_SLAVE;
+ spi_cfg.frequency = 25000000;
+
+ spi_cs.gpio_dev = device_get_binding(DT_INST_0_ST_STM32_SPI_CS_GPIOS_CONTROLLER);
+ spi_cs.gpio_pin = DT_INST_0_ST_STM32_SPI_CS_GPIOS_PIN;
+ spi_cs.delay = 0;
+ spi_cfg.cs = &spi_cs;
+
+ LOG_INF("SPI interface listening");
+
+ const struct spi_buf tx_buf = {
+ .buf = &hat_to_pi,
+ .len = sizeof(hat_to_pi)
+ };
+ const struct spi_buf rx_buf =
+ {
+ .buf = &pi_to_hat,
+ .len = sizeof(pi_to_hat)
+ };
+ const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1 };
+ const struct spi_buf_set rx = { .buffers = &rx_buf, .count = 1 };
+
+ while(true)
+ {
+ memset(&pi_to_hat, 0, sizeof(pi_to_hat)); // 8 bytes from Raspberry Pi (Tx)
+ memset(&hat_to_pi, 0, sizeof(hat_to_pi)); // 8 bytes to Raspberry Pi (Rx)
+
+ hat_to_pi.menu_button = atomic_get(&g_btn_menu);
+ hat_to_pi.joystick_button = atomic_get(&g_btn_joy);
+ hat_to_pi.joystick_x = (int) atomic_get(&g_joy_x);
+ hat_to_pi.joystick_y = (int) atomic_get(&g_joy_y);
+
+ // tx: outbound (button state and joystick positions)
+ // rx: incoming (command verbs)
+
+ if (spi_transceive(spi, &spi_cfg, &tx, &rx) > 0)
+ {
+ size_t size = sizeof(fifo_item_t);
+ fifo_item_t *ptr = (fifo_item_t *) k_malloc(size);
+ __ASSERT_NO_MSG(ptr != 0);
+
+ ptr->fifo_reserved = 0x0; // don't care
+ memcpy(&ptr->msg, &pi_to_hat, sizeof(pi_to_hat));
+
+ k_fifo_put(&my_fifo, ptr);
+ }
+ }
+}
+
+K_THREAD_DEFINE(spi_task_id, STACKSIZE, spi_task, NULL, NULL, NULL, PRIORITY, 0, K_NO_WAIT);
diff --git a/fw/src/app/spi.h b/fw/src/app/spi.h
new file mode 100644
index 0000000..181fa69
--- /dev/null
+++ b/fw/src/app/spi.h
@@ -0,0 +1,70 @@
+#ifndef PI_MSGR_H_
+#define PI_MSGR_H_
+
+#include
+#include
+
+
+// Messaging from the Pi to the hat --------------------------------------------
+#define NOOP 0x00
+#define SERVO_ENABLE 0x01 // The servos should be turned off
+#define SERVO_DISABLE 0x02 // The servos should be turned on
+#define CONTROL_INFO 0x03 // This packet contains control info
+#define SET_PLATE_ANGLES 0x04 // Set the plate angles (x and y angles)
+#define SET_SERVOS 0x05 // Set the servo positions manually
+
+#define COPY_STRING 0x80 // There is a arbitrary length string being transmitted (max len 240 bytes) and copy into the text buffer
+#define DISPLAY_BIG_TEXT_ICON 0x81 // Display what is currently in the buffer (large font) along with an icon sent in this message. Does not scroll.
+#define DISPLAY_BIG_TEXT 0x82 // Display only what is currently in the buffer (large font). Does not scroll.
+#define DISPLAY_SMALL_TEXT 0x83 // Display only what is currently in the buffer (small font). Scroll if required.
+#define DISPLAY_POWER_SYMBOL 0x84 // Display text (and icon) using one of the five IEC Power Symbols now in Unicode 9.0, as "0"..."5"
+
+
+typedef union
+{
+ struct
+ {
+ u8_t icon; // Selects 1 icon out of (currently) 8 options
+ };
+ struct
+ {
+ // Both are in hundredths of a degree
+ int8_t plate_angle1; // Plate X (pitch) angle
+ int8_t plate_angle2; // Plate Y (roll) angle
+ };
+ struct
+ {
+ // All are in hundredths of a degree
+ u8_t servo1_pos_centi_deg_high_byte; // Servo 1 angle (for direct servo control)
+ u8_t servo1_pos_centi_deg_low_byte;
+ u8_t servo2_pos_centi_deg_high_byte; // Servo 2 angle
+ u8_t servo2_pos_centi_deg_low_byte;
+ u8_t servo3_pos_centi_deg_high_byte; // Servo 3 angle
+ u8_t servo3_pos_centi_deg_low_byte;
+ };
+ struct
+ {
+ char characters[7];
+ };
+ u8_t raw[7];
+} pi_to_hat_data_t;
+
+// All CONTROL packets are 8 bytes long
+typedef struct
+{
+ u8_t control; // 1 byte: Control byte (always the same)
+ pi_to_hat_data_t data; // 7 bytes: Data (dependent on control byte)
+} pi_to_hat_t;
+
+typedef struct
+{
+ u8_t menu_button; // byte 0: 0 or 1
+ u8_t joystick_button; // byte 1: 0 or 1
+ int8_t joystick_x; // byte 2: Joystick X (-100 to +100)
+ int8_t joystick_y; // byte 3: Joystick Y (-100 to +100)
+ u8_t padding[4]; // byte 4-7: always 0
+} hat_to_pi_t;
+
+int wait_for_pi_message(pi_to_hat_t* msg, int32_t timeout);
+
+#endif
diff --git a/fw/src/app/state.c b/fw/src/app/state.c
new file mode 100644
index 0000000..7d1337b
--- /dev/null
+++ b/fw/src/app/state.c
@@ -0,0 +1,9 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+#include "headers.h"
+#include "state.h"
+
+atomic_t g_joy_x = ATOMIC_INIT(0);
+atomic_t g_joy_y = ATOMIC_INIT(0);
+atomic_t g_btn_joy = ATOMIC_INIT(0);
+atomic_t g_btn_menu = ATOMIC_INIT(0);
diff --git a/fw/src/app/state.h b/fw/src/app/state.h
new file mode 100644
index 0000000..f97d2ba
--- /dev/null
+++ b/fw/src/app/state.h
@@ -0,0 +1,10 @@
+#ifndef STATUS_H
+#define STATUS_H
+
+// 32-bit integers are the only atomic types
+extern atomic_t g_joy_x;
+extern atomic_t g_joy_y;
+extern atomic_t g_btn_menu;
+extern atomic_t g_btn_joy;
+
+#endif
diff --git a/fw/src/boards/arm/moab_hat/CMakeLists.txt b/fw/src/boards/arm/moab_hat/CMakeLists.txt
new file mode 100644
index 0000000..3b22ab6
--- /dev/null
+++ b/fw/src/boards/arm/moab_hat/CMakeLists.txt
@@ -0,0 +1,5 @@
+if(CONFIG_PINMUX)
+zephyr_library()
+zephyr_library_sources(pinmux.c)
+zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
+endif()
diff --git a/fw/src/boards/arm/moab_hat/Kconfig.board b/fw/src/boards/arm/moab_hat/Kconfig.board
new file mode 100644
index 0000000..f64bdb1
--- /dev/null
+++ b/fw/src/boards/arm/moab_hat/Kconfig.board
@@ -0,0 +1,6 @@
+# Kconfig - MOAB Hat with STM32F030CCT MCU
+#
+
+config BOARD_MOAB_HAT
+ bool "MOAB Hat Development Board"
+ depends on SOC_STM32F415XX
diff --git a/fw/src/boards/arm/moab_hat/Kconfig.defconfig b/fw/src/boards/arm/moab_hat/Kconfig.defconfig
new file mode 100644
index 0000000..3736698
--- /dev/null
+++ b/fw/src/boards/arm/moab_hat/Kconfig.defconfig
@@ -0,0 +1,61 @@
+# Kconfig - MOAB Hat with STM32F030CCT MCU
+#
+
+if BOARD_MOAB_HAT
+
+config BOARD
+ default "moab_hat"
+
+config USE_CODE_PARTITION
+ default y
+
+config UART_1
+ default y
+
+if SHELL
+config UART_3
+ default y
+endif # SHELL
+
+if I2C
+config I2C_2
+ default y
+
+config I2C_STM32_INTERRUPT
+ default y
+endif # I2C
+
+if PWM
+config PWM_STM32_3
+ default y
+endif # PWM
+
+if LVGL
+config LVGL_LOG_LEVEL
+ default 2
+
+config LVGL_DISPLAY_DEV_NAME
+ default "SH1106"
+
+config LVGL_HOR_RES
+ default 128
+
+config LVGL_VER_RES
+ default 32
+
+config LVGL_VDB_SIZE
+ default 100
+
+config LVGL_DPI
+ default 128
+
+config LVGL_BITS_PER_PIXEL
+ default 1
+
+choice LVGL_COLOR_DEPTH
+ default LVGL_COLOR_DEPTH_1
+endchoice
+endif
+
+
+endif # BOARD_MOAB_HAT
diff --git a/fw/src/boards/arm/moab_hat/board.cmake b/fw/src/boards/arm/moab_hat/board.cmake
new file mode 100644
index 0000000..4c57cdc
--- /dev/null
+++ b/fw/src/boards/arm/moab_hat/board.cmake
@@ -0,0 +1,4 @@
+board_runner_args(jlink "--device=STM32F415RG" "--speed=4000")
+
+#include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
+include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)
diff --git a/fw/src/boards/arm/moab_hat/moab_hat.dts b/fw/src/boards/arm/moab_hat/moab_hat.dts
new file mode 100644
index 0000000..9ffd5c6
--- /dev/null
+++ b/fw/src/boards/arm/moab_hat/moab_hat.dts
@@ -0,0 +1,148 @@
+/dts-v1/;
+#include
+
+/ {
+ model = "MOAB Hat board";
+ compatible = "st,stm32f415rg";
+
+ chosen {
+ zephyr,console = &usart1;
+ zephyr,shell-uart = &usart3;
+ zephyr,sram = &sram0;
+ zephyr,flash = &flash0;
+ zephyr,ccm = &ccm0;
+ zephyr,code-partition = &slot0_partition;
+ };
+
+ leds {
+ compatible = "gpio-leds";
+ red_led_1: led_1 {
+ gpios = <&gpioc 13 GPIO_INT_ACTIVE_HIGH>;
+ label = "User LD1";
+ };
+ servo_en_led: led_2 {
+ gpios = <&gpioa 12 GPIO_INT_ACTIVE_HIGH>;
+ label = "User LD2";
+ };
+ spi_msg_led: led_3 {
+ gpios = <&gpioc 4 GPIO_INT_ACTIVE_HIGH>;
+ label = "User LD3";
+ };
+ };
+
+
+ gpio_keys {
+ compatible = "gpio-keys";
+ user_button1: key1 {
+ label = "button1";
+ gpios = <&gpioc 0 GPIO_INT_ACTIVE_HIGH>;
+ };
+ user_button2: key2 {
+ label = "button2";
+ gpios = <&gpioc 1 GPIO_INT_ACTIVE_HIGH>;
+ };
+ };
+
+ aliases {
+ led-red = &red_led_1;
+ button-menu = &user_button1;
+ button-joystick = &user_button2;
+ servo-enable = &servo_en_led;
+ spi-msg-ready = &spi_msg_led;
+ };
+};
+
+
+
+&usart1 {
+ current-speed = <115200>;
+ //status = "okay";
+};
+
+&usart3 {
+ current-speed = <115200>;
+ //status = "okay";
+};
+
+&timers3 {
+ //status = "okay";
+
+ // pwm {
+ // st,prescaler = <100>;
+ // status = "okay";
+ // };
+};
+
+&i2c2 {
+ //status = "okay";
+ clock-frequency = ;
+
+ // lp5024@62 {
+ // compatible = "ti,lp50xx";
+ // reg = <0x62>;
+ // label = "LP5024";
+ // rgb-count = <8>;
+ // };
+};
+
+&spi1 {
+ //status = "okay";
+ cs-gpios = <&gpioa 4 GPIO_INT_ACTIVE_LOW>;
+};
+
+&spi2 {
+ //status = "okay";
+ cs-gpios = <&gpiob 12 GPIO_INT_ACTIVE_LOW>;
+ sh1106-spi@0 {
+ compatible = "sino,sh1106";
+ reg = <0x0>;
+ label = "SH1106";
+ width = <128>;
+ height = <32>;
+ segment-offset = <2>;
+ page-offset = <0>;
+ display-offset = <0x7>; // <0x7>;
+ multiplex-ratio = <0xA8>; // 63
+ segment-remap;
+ com-invdir;
+ //com-sequential;
+ prechargep = <0x1F>;
+ reset-gpios = <&gpioc 5 GPIO_INT_ACTIVE_LOW>;
+ a0-gpios = <&gpioc 9 GPIO_INT_ACTIVE_LOW>;
+ spi-max-frequency = <4000000>;
+ };
+};
+
+&adc1 {
+ //status = "okay";
+};
+
+&flash0 {
+ partitions {
+ compatible = "fixed-partitions";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ /* 128K */
+ boot_partition: partition@0 {
+ label = "mcuboot";
+ reg = <0x00000000 0x20000>;
+ #read-only;
+ };
+ /* 256K */
+ slot0_partition: partition@20000 {
+ label = "image-0";
+ reg = <0x00020000 0x40000>;
+ };
+ /* 256K */
+ slot1_partition: partition@60000 {
+ label = "image-1";
+ reg = <0x00060000 0x40000>;
+ };
+ /* 256K */
+ scratch_partition: partition@A0000 {
+ label = "image-scratch";
+ reg = <0x000A0000 0x40000>;
+ };
+ };
+};
diff --git a/fw/src/boards/arm/moab_hat/moab_hat.yaml b/fw/src/boards/arm/moab_hat/moab_hat.yaml
new file mode 100644
index 0000000..81ec752
--- /dev/null
+++ b/fw/src/boards/arm/moab_hat/moab_hat.yaml
@@ -0,0 +1,18 @@
+identifier: moab_hat
+name: MOAB_HAT
+type: mcu
+arch: arm
+toolchain:
+ - zephyr
+ - gnuarmemb
+ - xtools
+ram: 128
+flash: 1024
+supported:
+ - uart
+ - gpio
+ - i2c
+ - spi
+ - pwm
+ - usb
+
diff --git a/fw/src/boards/arm/moab_hat/moab_hat_defconfig b/fw/src/boards/arm/moab_hat/moab_hat_defconfig
new file mode 100644
index 0000000..cbe2eb6
--- /dev/null
+++ b/fw/src/boards/arm/moab_hat/moab_hat_defconfig
@@ -0,0 +1,35 @@
+# Zephyr Kernel Configuration
+CONFIG_ARM=y
+
+# Platform Configuration
+CONFIG_SOC_SERIES_STM32F4X=y
+CONFIG_SOC_STM32F415XX=y
+# 168MHz system clock
+CONFIG_CORTEX_M_SYSTICK=y
+CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=168000000
+
+# Enable MPU
+CONFIG_ARM_MPU=y
+
+# Pinmux Driver
+CONFIG_PINMUX=y
+
+# GPIO Controller
+CONFIG_GPIO=y
+
+# Clock configuration
+CONFIG_CLOCK_CONTROL=y
+
+# Clock configuration for Cube Clock control driver
+CONFIG_CLOCK_STM32_HSE_CLOCK=8000000
+CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
+# use HSE as PLL input
+CONFIG_CLOCK_STM32_PLL_SRC_HSE=y
+# produce 168MHz clock at PLL output
+CONFIG_CLOCK_STM32_PLL_M_DIVISOR=8
+CONFIG_CLOCK_STM32_PLL_N_MULTIPLIER=336
+CONFIG_CLOCK_STM32_PLL_P_DIVISOR=2
+CONFIG_CLOCK_STM32_PLL_Q_DIVISOR=7
+CONFIG_CLOCK_STM32_AHB_PRESCALER=1
+CONFIG_CLOCK_STM32_APB1_PRESCALER=4
+CONFIG_CLOCK_STM32_APB2_PRESCALER=2
diff --git a/fw/src/boards/arm/moab_hat/pinmux.c b/fw/src/boards/arm/moab_hat/pinmux.c
new file mode 100644
index 0000000..779ea12
--- /dev/null
+++ b/fw/src/boards/arm/moab_hat/pinmux.c
@@ -0,0 +1,88 @@
+#include
+#include
+#include
+#include
+#include
+#include "pinmux/pinmux.h"
+
+#include "pinmux/stm32/pinmux_stm32.h"
+
+#define STM32F4_PINMUX_FUNC_PB5_PWM3_CH2 \
+ (STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL)
+#define STM32F4_PINMUX_FUNC_PB0_PWM3_CH3 \
+ (STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL)
+#define STM32F4_PINMUX_FUNC_PB1_PWM3_CH4 \
+ (STM32_PINMUX_ALT_FUNC_2 | STM32_PUSHPULL_NOPULL)
+
+static const struct pin_config pinconf[] = {
+// UART1
+#ifdef CONFIG_UART_1
+ {STM32_PIN_PB6, STM32F4_PINMUX_FUNC_PB6_USART1_TX},
+ {STM32_PIN_PB7, STM32F4_PINMUX_FUNC_PB7_USART1_RX},
+#endif
+
+// UART3
+#ifdef CONFIG_UART_3
+ {STM32_PIN_PC10, STM32F4_PINMUX_FUNC_PC10_USART3_TX},
+ {STM32_PIN_PC11, STM32F4_PINMUX_FUNC_PC11_USART3_RX},
+#endif
+
+// PWM
+#ifdef CONFIG_PWM_STM32_3
+ {STM32_PIN_PB4, STM32F4_PINMUX_FUNC_PB4_PWM3_CH1},
+ {STM32_PIN_PB5, STM32F4_PINMUX_FUNC_PB5_PWM3_CH2},
+ {STM32_PIN_PB0, STM32F4_PINMUX_FUNC_PB0_PWM3_CH3},
+ {STM32_PIN_PB1, STM32F4_PINMUX_FUNC_PB1_PWM3_CH4},
+#endif
+
+// I2C2
+#ifdef CONFIG_I2C_2
+ {STM32_PIN_PB11, STM32F4_PINMUX_FUNC_PB11_I2C2_SDA},
+ {STM32_PIN_PB10, STM32F4_PINMUX_FUNC_PB10_I2C2_SCL},
+#endif
+
+// SPI1
+#ifdef CONFIG_SPI_1
+#ifdef CONFIG_SPI_STM32_USE_HW_SS
+ {STM32_PIN_PA4, STM32F4_PINMUX_FUNC_PA4_SPI1_NSS},
+#endif /* CONFIG_SPI_STM32_USE_HW_SS */
+ {STM32_PIN_PA5, STM32F4_PINMUX_FUNC_PA5_SPI1_SCK},
+ {STM32_PIN_PA6, STM32F4_PINMUX_FUNC_PA6_SPI1_MISO},
+ {STM32_PIN_PA7, STM32F4_PINMUX_FUNC_PA7_SPI1_MOSI},
+#endif
+
+// SPI2
+#ifdef CONFIG_SPI_2
+#ifdef CONFIG_SPI_STM32_USE_HW_SS
+ {STM32_PIN_PB12, STM32F4_PINMUX_FUNC_PB12_SPI2_NSS},
+#endif /* CONFIG_SPI_STM32_USE_HW_SS */
+ {STM32_PIN_PB13, STM32F4_PINMUX_FUNC_PB13_SPI2_SCK},
+ {STM32_PIN_PB14, STM32F4_PINMUX_FUNC_PB14_SPI2_MISO},
+ {STM32_PIN_PB15, STM32F4_PINMUX_FUNC_PB15_SPI2_MOSI},
+#endif
+
+// SPI3
+#ifdef CONFIG_SPI_3
+ {STM32_PIN_PB3, STM32F4_PINMUX_FUNC_PB3_SPI3_SCK},
+ {STM32_PIN_PC12, STM32F4_PINMUX_FUNC_PC12_SPI3_MOSI},
+#endif
+
+// ADC
+#ifdef CONFIG_ADC
+ {STM32_PIN_PA0, STM32F4_PINMUX_FUNC_PA0_ADC123_IN0},
+ {STM32_PIN_PA1, STM32F4_PINMUX_FUNC_PA1_ADC123_IN1},
+ //{STM32_PIN_PA2, STM32F4_PINMUX_FUNC_PA2_ADC123_IN2},
+ //{STM32_PIN_PA3, STM32F4_PINMUX_FUNC_PA3_ADC123_IN3},
+#endif
+};
+
+static int pinmux_stm32_init(struct device *port)
+{
+ ARG_UNUSED(port);
+
+ stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf));
+
+ return 0;
+}
+
+SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1, CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY);
diff --git a/fw/src/boards/arm/moab_hat/support/openocd.cfg b/fw/src/boards/arm/moab_hat/support/openocd.cfg
new file mode 100644
index 0000000..b97b1a0
--- /dev/null
+++ b/fw/src/boards/arm/moab_hat/support/openocd.cfg
@@ -0,0 +1,24 @@
+source [find interface/stlink.cfg]
+
+set WORKAREASIZE 0x30000
+
+transport select hla_swd
+
+source [find target/stm32f4x.cfg]
+
+adapter_khz 1000
+adapter_nsrst_delay 100
+jtag_ntrst_delay 100
+
+reset_config srst_only srst_nogate connect_assert_srst
+
+$_TARGETNAME configure -event gdb-attach {
+ echo "Debugger attaching: halting execution"
+ reset halt
+ gdb_breakpoint_override hard
+}
+
+$_TARGETNAME configure -event gdb-detach {
+ echo "Debugger detaching: resuming execution"
+ resume
+}
diff --git a/fw/src/doit b/fw/src/doit
new file mode 100755
index 0000000..f33d74f
--- /dev/null
+++ b/fw/src/doit
@@ -0,0 +1,95 @@
+#!/usr/bin/env bash
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+# vim:filetype=sh:
+
+set -euo pipefail
+trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
+
+require() { hash "$@" || exit 127; }
+
+require west
+
+## Log script output
+exec 1> >(tee "/tmp/stdout.log")
+exec 2> >(tee "/tmp/stderr.log")
+
+
+# Steps to build from scratch:
+# cd app
+# cmake -B build
+# cd build
+# make -j 12
+
+
+# Version Schema
+# major.minor.patch.timestamp
+# 3.0.4: atomic get/set of joystick/menu
+# 3.0.5: mutexes
+# 3.0.6: display calls handled by main.c loop w/timer instead of sleep
+# 3.0.7: restored display to it's own thread (due to main blocking on FIFO queue)
+# 3.0.8: unused
+# 3.0.10: always copy string from pi (instead of using text index)
+# 3.0.11: three display string/icon types
+# 3.0.12: add MOON icon
+# 3.0.13: add all IEC Power Symbols
+# 3.0.14: no changes, just bumping versions to match SW
+# 3.0.15: merge into moabian
+# 3.0.16: off-by-one icon errors
+# 3.0.17: Testing new MUTEX protected display.c code in MUTEX branch
+# 3.0.19: Arbitrary version bump to be in sync with the software stack
+# 3.0.20: Pitch/roll to servo 1/2/3 coordinate transform removed (now in hat.py)
+# 3.0.21: Tighten up the log info messages
+# 3.0.22: Trying to capture 3 Rx buffer overruns with WARN message
+# 3.0.23: Show FW version on boot; tighter FW logs
+
+VERSION="3.0.24"
+
+# YRDDDHR: 2103908. 2021, 39th day of the year, 08th hour (PDT)
+TIMESTAMP=$(TZ='America/Los_Angeles' date +"%j%H%M")
+export MAJORMINORPATCH=$VERSION
+export SEMVER=$VERSION.$TIMESTAMP
+
+# Lets you run this script from anywhere
+readonly _D="$(dirname "$(readlink -f "$0")")" && cd $_D
+
+# Dump firmware binaries here
+[[ -d binaries ]] || mkdir binaries
+DEST="$_D/binaries"
+
+# production "app" folder
+build () {
+ echo "Building Moab hat firmware with embedded version:" $SEMVER
+
+ west build -b moab_hat --pristine auto
+ west sign -d build -t imgtool -- --key ~/root-rsa-2048.pem
+
+ # SHA=$(git rev-parse HEAD | cut -b 1-4)
+ # DMY=$(date +"%Y%m%d-%H%M")
+ FN="$SEMVER.bin"
+ cp build/zephyr/zephyr.signed.bin "$DEST/$FN"
+}
+
+install() {
+ # "moab" must be setup for password-less ssh in ~/.ssh/config
+ if [[ $(ssh moab "hostname") ]]; then
+ # copy the last build to the pi
+ FN=$(ls -1 $DEST | tail -1)
+
+ echo "Installing $DEST/$FN on moab"
+ scp "$DEST/$FN" moab:$FN || echo "scp copy to moab failed"
+ ssh moab "sudo moab/bin/flash /home/pi/$FN"
+ fi
+}
+
+clean() {
+ echo "removing temporary folders"
+ rm -rf build
+ rm -rf binaries
+}
+
+cmd="${1:-build}"
+
+[[ "$cmd" == "build" ]] && build
+[[ "$cmd" == "clean" ]] && clean
+[[ "$cmd" == "install" ]] && install
diff --git a/fw/src/dts.overlay b/fw/src/dts.overlay
new file mode 100644
index 0000000..8fcc83a
--- /dev/null
+++ b/fw/src/dts.overlay
@@ -0,0 +1,32 @@
+&usart1 {
+ status = "okay";
+};
+
+&usart3 {
+ status = "okay";
+};
+
+&timers3 {
+ status = "okay";
+
+ pwm {
+ st,prescaler = <100>;
+ status = "okay";
+ };
+};
+
+&i2c2 {
+ status = "okay";
+};
+
+&spi1 {
+ status = "okay";
+};
+
+&spi2 {
+ status = "okay";
+};
+
+&adc1 {
+ status = "okay";
+};
diff --git a/fw/src/dts/bindings/sino,sh1106-spi.yaml b/fw/src/dts/bindings/sino,sh1106-spi.yaml
new file mode 100644
index 0000000..c76dde6
--- /dev/null
+++ b/fw/src/dts/bindings/sino,sh1106-spi.yaml
@@ -0,0 +1,70 @@
+title: SH1106 128x64 Dot Matrix Display Controller
+
+description: |
+ This is a representation of the SH1106 132x64 Dot Matrix Display Controller,
+ accessed through SPI bus
+
+compatible: "sino,sh1106"
+
+include: spi-device.yaml
+
+properties:
+ height:
+ type: int
+ required: true
+ description: Height in pixel of the panel driven by the controller
+
+ width:
+ type: int
+ required: true
+ description: Width in pixel of the panel driven by the controller
+
+ segment-offset:
+ type: int
+ required: true
+ description: 8-bit column start address for Page Addressing Mode
+
+ page-offset:
+ type: int
+ required: true
+ description: Start address for Page Addressing Mode
+
+ display-offset:
+ type: int
+ required: true
+ description: mapping of the display start line to one of COM0 .. COM63
+
+ multiplex-ratio:
+ type: int
+ required: true
+ description: Multiplex Ratio
+
+ segment-remap:
+ type: boolean
+ required: false
+ description: Last column address is mapped to first segment
+
+ com-invdir:
+ type: boolean
+ required: false
+ description: Scan direction is from last COM output to first COM output
+
+ com-sequential:
+ type: boolean
+ required: false
+ description: Sequential COM pin configuration
+
+ prechargep:
+ type: int
+ required: true
+ description: Duration of the pre-charge period
+
+ reset-gpios:
+ type: phandle-array
+ required: true
+ description: Reset pin
+
+ a0-gpios:
+ type: phandle-array
+ required: false
+ description: A0 pin (used in 4-wire mode)
diff --git a/fw/src/dts/bindings/ti,lp50xx.yaml b/fw/src/dts/bindings/ti,lp50xx.yaml
new file mode 100644
index 0000000..6bc98bd
--- /dev/null
+++ b/fw/src/dts/bindings/ti,lp50xx.yaml
@@ -0,0 +1,16 @@
+title: TI LP50xx LED Driver
+
+description: TI LP50xx LED binding
+
+compatible: "ti,lp50xx"
+
+include: i2c-device.yaml
+
+# Describes number of RGB LEDS supported by the specific chip
+# example: 5018 is 6, 5024 is 8, 5030 is 10, and 5036 is 12
+properties:
+ rgb-count:
+ type: int
+ required: true
+
+
diff --git a/fw/src/prj.conf b/fw/src/prj.conf
new file mode 100644
index 0000000..cbb6402
--- /dev/null
+++ b/fw/src/prj.conf
@@ -0,0 +1,76 @@
+CONFIG_BOOTLOADER_MCUBOOT=y
+CONFIG_DEBUG=y
+CONFIG_THREAD_MONITOR=y
+CONFIG_INIT_STACKS=y
+CONFIG_THREAD_NAME=y
+CONFIG_OBJECT_TRACING=y
+CONFIG_BOOT_BANNER=n
+CONFIG_NEWLIB_LIBC=y
+CONFIG_HEAP_MEM_POOL_SIZE=16384
+
+CONFIG_CONSOLE=y
+
+# Serial Drivers
+CONFIG_SERIAL=y
+CONFIG_UART_INTERRUPT_DRIVEN=y
+# enable console
+CONFIG_UART_CONSOLE=y
+CONFIG_UART_1=y
+CONFIG_UART_3=y
+
+# Log
+CONFIG_LOG=y
+CONFIG_LOG_BACKEND_UART=y
+CONFIG_LOG_BACKEND_SHOW_COLOR=y
+CONFIG_LOG_IMMEDIATE=y
+
+
+# Shell
+CONFIG_SHELL=y
+
+#CONFIG_KERNEL_SHELL=n
+CONFIG_ADC_SHELL=y
+CONFIG_SHELL_PRINTF_BUFF_SIZE=30
+CONFIG_SHELL_HISTORY=y
+CONFIG_SHELL_STACK_SIZE=1024
+CONFIG_SHELL_WILDCARD=n
+CONFIG_SHELL_ARGC_MAX=12
+CONFIG_SHELL_STATS=n
+CONFIG_SHELL_CMDS=y
+CONFIG_SHELL_CMD_BUFF_SIZE=128
+CONFIG_SHELL_BACKENDS=y
+CONFIG_SHELL_BACKEND_SERIAL=y
+CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL_NONE=y
+CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN=y
+CONFIG_SHELL_BACKEND_SERIAL_TX_RING_BUFFER_SIZE=8
+CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE=64
+
+# Display
+CONFIG_DISPLAY=y
+CONFIG_DISPLAY_LOG_LEVEL_ERR=y
+CONFIG_LVGL=y
+CONFIG_LVGL_BUFFER_ALLOC_STATIC=y
+CONFIG_LVGL_OBJ_LABEL=y
+CONFIG_LVGL_ANIMATION=y
+
+# Devices
+CONFIG_UART_CONSOLE=y
+#CONFIG_I2C=y
+CONFIG_SPI=y
+CONFIG_SPI_STM32=y
+CONFIG_SPI_SLAVE=y
+CONFIG_SPI_INIT_PRIORITY=70
+CONFIG_SPI_0=y
+CONFIG_SPI_0_OP_MODES=1
+CONFIG_SPI_1=y
+CONFIG_SPI_1_OP_MODES=1
+CONFIG_SPI_2=y
+CONFIG_SPI_2_OP_MODES=1
+CONFIG_SPI_STM32_INTERRUPT=y
+CONFIG_SPI_STM32_USE_HW_SS=y
+CONFIG_ADC=y
+CONFIG_ADC_STM32=y
+
+# PWM
+CONFIG_PWM=y
+CONFIG_PWM_3=y
diff --git a/fw/firmware.bin b/fw/v2.4.1.bin
similarity index 100%
rename from fw/firmware.bin
rename to fw/v2.4.1.bin
diff --git a/fw/v3.bin b/fw/v3.bin
new file mode 100644
index 0000000..91274e8
Binary files /dev/null and b/fw/v3.bin differ
diff --git a/os/files/bin/diagnose b/os/files/bin/diagnose
deleted file mode 100755
index 84a0d5e..0000000
--- a/os/files/bin/diagnose
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env bats
-
-@test "Year is at least 2020" {
- [[ `date +"%Y"` -ge 2020 ]]
-}
-
-@test "DNS working" {
- ping -c 1 github.com
-}
-
-@test "pymoab permissions nominal" {
- lib="/usr/local/lib/python3.7/dist-packages/pymoab-1.0.0.dist-info"
- if [ -e "$lib" ]; then
- [ $(stat -c "%a" "/usr/local/lib/python3.7/dist-packages/pymoab-1.0.0.dist-info") = "2755" ]
- fi
-}
-
-@test "libmoab permissions nominal" {
- [ -r /usr/local/lib/libmoab.so.1.0 ]
-}
-
-@test "Docker is running" {
- pgrep -l docker
-}
-
-@test 'Hostname is "moab"' {
- hostname | grep moab
-}
-
-@test 'Pi UART disabled' {
- grep -v 'console=serial0,115200 console=tty1' /boot/cmdline.txt
-}
-
-@test "Camera detected" {
- vcgencmd get_camera | grep 'detected=1'
-}
-
-@test "splash details on login is executable" {
- [[ -x /usr/local/bin/splash ]]
-}
-
-@test "power/fan/moab services started without GPIO error" {
- journalctl | grep -v gpio.setup
-}
-
-@test "fan and power services are running" {
- systemctl is-active fan.service
- systemctl is-active power.service
-}
-
-@test "/home/pi/moab/docker-compose.yml exists" {
- [[ -e /home/pi/moab/docker-compose.yml ]]
-}
-
-@test "docker-compose is installed and can launch" {
- docker-compose -v
-}
-
-@test "docker-compose has containers up" {
- pgrep -f main.py
- pgrep -f predict
-}
-
diff --git a/os/files/bin/oled b/os/files/bin/oled
deleted file mode 100755
index c69e78f..0000000
Binary files a/os/files/bin/oled and /dev/null differ
diff --git a/os/files/etc/environment b/os/files/etc/environment
index 97a222b..ab8c255 100644
--- a/os/files/etc/environment
+++ b/os/files/etc/environment
@@ -1 +1 @@
-MOABIAN=2.4.1
+MOABIAN=3.0.24
diff --git a/os/files/etc/profile b/os/files/etc/profile
deleted file mode 100644
index db3315a..0000000
--- a/os/files/etc/profile
+++ /dev/null
@@ -1,36 +0,0 @@
-# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
-# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
-
-if [ "`id -u`" -eq 0 ]; then
- PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-else
- PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"
-fi
-export PATH
-
-if [ "${PS1-}" ]; then
- if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
- # The file bash.bashrc already sets the default PS1.
- # PS1='\h:\w\$ '
- if [ -f /etc/bash.bashrc ]; then
- . /etc/bash.bashrc
- fi
- else
- if [ "`id -u`" -eq 0 ]; then
- PS1='# '
- else
- PS1='$ '
- fi
- fi
-fi
-
-if [ -d /etc/profile.d ]; then
- for i in /etc/profile.d/*.sh; do
- if [ -r $i ]; then
- . $i
- fi
- done
- unset i
-fi
-
-PATH="$HOME/moab/bin:$PATH:."; export PATH
diff --git a/os/files/home/bashrc b/os/files/home/bashrc
index 1082b11..aac4346 100644
--- a/os/files/home/bashrc
+++ b/os/files/home/bashrc
@@ -1,20 +1,19 @@
export CLICOLOR=1
export LANG="en_US.UTF-8"
export GOPATH=$HOME/.go
-export PATH=$HOME/.local/bin:$PATH:/usr/local/go/bin:$GOPATH/bin:.
+export PATH=$HOME/.local/bin:$PATH:$HOME/moab/bin:/usr/local/go/bin:$GOPATH/bin:.
export LESS="--quit-if-one-screen --no-init --ignore-case --RAW-CONTROL-CHARS --quiet --dumb --LONG-PROMPT"
export EDITOR="vim"
export BLOCK_SIZE="'1" # add commas to file size listings
-# Don't process the rest of the file for non-interactive shells
-# as indicated by a PS1 prompt
-[ -z "$PS1" ] && return
-
# Moab specific
alias logs="docker logs control -f"
alias t="tmux -2 new-session -A -s moabian"
alias dc="docker-compose"
+alias fwlog="sudo minicom --device=/dev/ttyAMA0"
+alias fwshell="sudo minicom --device=/dev/ttyAMA1"
+alias ports="sudo netstat -atlp"
# General aliases
lsflags="--color=auto --group-directories-first -F "
@@ -27,26 +26,32 @@ alias lls="ls ${lsflags} -l --sort=size --reverse" # sort by date
alias lle="ls ${lsflags} -l --sort=extension " # sort by extension
alias ,="cd .."
-alias m="less"
-alias h='history'
-alias hg="history | grep -i"
-alias @="printenv | grep -i"
-
+alias ga='git add'
+alias gb='git branch'
+alias gc='git commit -m'
+alias gco="git checkout"
alias gd='git diff'
-alias cp='cp --archive'
-alias df='df --human-readable'
-alias pd='pushd'
-alias gs="git status"
-alias gd="git diff"
-alias vi="vim -o"
+alias gf='git fetch'
+alias gk='git checkout'
+alias gp='git pull'
+alias gpush='git push'
+alias gs='git status'
+
+alias hg="history | grep -i"
+alias h='history'
+alias m="less"
alias path='echo $PATH | tr : "\n" | cat -n'
+alias p="python3"
+alias @="printenv | grep -i"
alias rg="rg --pretty --smart-case"
+alias vi="vim -o"
+alias vim="vim -o"
shopt -s checkwinsize # reset lines & cols after resize
shopt -s histappend # append rather than overwrite history
-export HISTCONTROL=ignoreboth
export HISTSIZE=1000 # save last 100k commands
export HISTFILESIZE=1000 # save last 100k commands
+export HISTCONTROL=ignoreboth
# auto cd to a folder by typing it's name
shopt -s autocd
@@ -59,3 +64,74 @@ function cd {
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi
+
+
+# Set prompt and title (for interactive shells only)
+if [ "$(expr $- : '.*i')" -ne 0 ]; then
+
+ # this works for sh and bash
+ if [ -z "$ZSH_VERSION" ]; then
+ # first get exit code of last command, and set colors
+ PS1="\$(\
+ EXIT=\"\$?\" ; \
+ BLUE=\"\[\e[38;5;39m\]\" ; \
+ RED=\"\[\e[31m\]\" ; \
+ ORANGE=\"\[\e[38;5;208m\]\" ; \
+ WHITE=\"\[\e[0m\]\" ; "
+ # endchar
+ # use # for root and $ for non-root users
+ # use white for default color, and red if last exit code is non-zero
+ # username
+ # use red for root blue(39) for non-root users
+ PS1+="\
+ endchar=\"\\$\${WHITE}\" ; \
+ username=\"\${BLUE}\u\${WHITE}\" ; \
+ if [ \"\$UID\" = \"0\" ]; then
+ username=\"\${RED}\u\${WHITE}\" ; \
+ fi ; \
+ if [ \"\$EXIT\" -eq 0 ]; then
+ endchar=\"\${WHITE}\$endchar\" ; \
+ else \
+ endchar=\"\${RED}\$endchar\"
+ fi ; "
+ # hostname in orange
+ PS1+="\
+ host=\"\${ORANGE}\H\${WHITE}\" ; "
+ # current directory in blue(39)
+ PS1+="\
+ dir=\"\${BLUE}\w\${WHITE}\" ; "
+ # set prompt, and additionally set window title for xterm
+ if [ "${TERM:0:5}" = "xterm" ]; then
+ PS1+="echo \"\[\e]2;\u@\H :: \w\a\]\${username}@\${host}\${dir} \${endchar} \" )"
+ else
+ PS1+="echo \"\${username}@\${host} \${dir} \${endchar} \" )"
+ fi
+
+ else
+ # this works for zsh
+ # endchar
+ # use red if last command has non-zero exit
+ # use # for root and $ for non-root users
+ local _root_endch="%(?.#.%F{red}#%f)"
+ local _other_endch="%(?.$.%F{red}$%f)"
+ local _endchar="%(#.${_root_endch}.${_other_endch})"
+ # use red for root and blue(39) for non-root users
+ local _username="%F{%(#.red.39)}%n%f"
+ # hostname in orange
+ local _host="%F{208}%m%f"
+ # current directory in blue(39)
+ local _dir="%F{39}%~%f"
+ # set prompt
+ PS1="${_username}@${_host} ${_dir} ${_endchar} "
+ # additionally set window title for xterm
+ __stateless_title () { # for xterm, set window title
+ if [ "${TERM:0:5}" = "xterm" ]; then
+ print -Pn "\e]2;%n\@%m :: %~\a"
+ fi
+ }
+ __stateless_title
+ autoload -Uz add-zsh-hook
+ add-zsh-hook chpwd __stateless_title
+ fi
+ export PS1
+fi
diff --git a/os/files/home/profile b/os/files/home/profile
new file mode 100644
index 0000000..ab8be84
--- /dev/null
+++ b/os/files/home/profile
@@ -0,0 +1,25 @@
+# ~/.profile: executed by the command interpreter for login shells.
+# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
+# exists.
+# see /usr/share/doc/bash/examples/startup-files for examples.
+# the files are located in the bash-doc package.
+
+# the default umask is set in /etc/profile; for setting the umask
+# for ssh logins, install and configure the libpam-umask package.
+#umask 022
+
+if [ -n "$BASH_VERSION" ]; then
+ # include .bashrc if it exists
+ if [ -f "$HOME/.bashrc" ]; then
+ . "$HOME/.bashrc"
+ fi
+fi
+
+if [[ $- == *i* ]]; then
+
+ # Bail if inside a TMUX session
+ # as the splash/motd has already been shown
+ [ -z $TMUX ] || return
+
+ [ -e ~/moab/bin/splash ] && ~/moab/bin/splash
+fi
diff --git a/os/files/home/tmux.conf b/os/files/home/tmux.conf
index b23324a..2b3ac54 100644
--- a/os/files/home/tmux.conf
+++ b/os/files/home/tmux.conf
@@ -12,6 +12,9 @@ set -g base-index 1
bind r source-file ~/.tmux.conf
+unbind q
+bind q kill-session
+
#####################
# random key bindings
#####################
diff --git a/os/files/lib/libmoab.so.1.0 b/os/files/lib/libmoab.so.1.0
deleted file mode 100644
index 1815f37..0000000
Binary files a/os/files/lib/libmoab.so.1.0 and /dev/null differ
diff --git a/os/files/profile.d/50-prompt.sh b/os/files/profile.d/50-prompt.sh
deleted file mode 100644
index f529aff..0000000
--- a/os/files/profile.d/50-prompt.sh
+++ /dev/null
@@ -1,72 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-# Set prompt and title (for interactive shells only)
-if [ "$(expr $- : '.*i')" -ne 0 ]; then
-
- # this works for sh and bash
- if [ -z "$ZSH_VERSION" ]; then
- # first get exit code of last command, and set colors
- PS1="\$(\
- EXIT=\"\$?\" ; \
- BLUE=\"\[\e[38;5;39m\]\" ; \
- RED=\"\[\e[31m\]\" ; \
- ORANGE=\"\[\e[38;5;208m\]\" ; \
- WHITE=\"\[\e[0m\]\" ; "
- # endchar
- # use # for root and $ for non-root users
- # use white for default color, and red if last exit code is non-zero
- # username
- # use red for root blue(39) for non-root users
- PS1+="\
- endchar=\"\\$\${WHITE}\" ; \
- username=\"\${BLUE}\u\${WHITE}\" ; \
- if [ \"\$UID\" = \"0\" ]; then
- username=\"\${RED}\u\${WHITE}\" ; \
- fi ; \
- if [ \"\$EXIT\" -eq 0 ]; then
- endchar=\"\${WHITE}\$endchar\" ; \
- else \
- endchar=\"\${RED}\$endchar\"
- fi ; "
- # hostname in orange
- PS1+="\
- host=\"\${ORANGE}\H\${WHITE}\" ; "
- # current directory in blue(39)
- PS1+="\
- dir=\"\${BLUE}\w\${WHITE}\" ; "
- # set prompt, and additionally set window title for xterm
- if [ "${TERM:0:5}" = "xterm" ]; then
- PS1+="echo \"\[\e]2;\u@\H :: \w\a\]\${username}@\${host}\${dir} \${endchar} \" )"
- else
- PS1+="echo \"\${username}@\${host} \${dir} \${endchar} \" )"
- fi
-
- else
- # this works for zsh
- # endchar
- # use red if last command has non-zero exit
- # use # for root and $ for non-root users
- local _root_endch="%(?.#.%F{red}#%f)"
- local _other_endch="%(?.$.%F{red}$%f)"
- local _endchar="%(#.${_root_endch}.${_other_endch})"
- # use red for root and blue(39) for non-root users
- local _username="%F{%(#.red.39)}%n%f"
- # hostname in orange
- local _host="%F{208}%m%f"
- # current directory in blue(39)
- local _dir="%F{39}%~%f"
- # set prompt
- PS1="${_username}@${_host} ${_dir} ${_endchar} "
- # additionally set window title for xterm
- __stateless_title () { # for xterm, set window title
- if [ "${TERM:0:5}" = "xterm" ]; then
- print -Pn "\e]2;%n\@%m :: %~\a"
- fi
- }
- __stateless_title
- autoload -Uz add-zsh-hook
- add-zsh-hook chpwd __stateless_title
- fi
- export PS1
-fi
diff --git a/os/files/profile.d/90-splash.sh b/os/files/profile.d/90-splash.sh
deleted file mode 100644
index cda22ef..0000000
--- a/os/files/profile.d/90-splash.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-
-# Show splash screen(for interactive shells only)
-
-# Bash shell sets special variable $- to include the letter "i"
-# to indicate an interactive shell.
-
-if [[ $- == *i* ]]; then
-
- # Bail if inside a TMUX session
- # as the splash/motd has already been shown
- [ -z $TMUX ] || return
-
-
- [ -e /usr/local/bin/splash ] && /usr/local/bin/splash
-fi
diff --git a/os/services/moab.service b/os/services/brain.service
similarity index 85%
rename from os/services/moab.service
rename to os/services/brain.service
index aca2e96..7eadec3 100644
--- a/os/services/moab.service
+++ b/os/services/brain.service
@@ -1,5 +1,5 @@
[Unit]
-Description=Moab Autostart Docker
+Description=Moab Brain
DefaultDependencies=false
After=docker.service
diff --git a/os/services/fan.py b/os/services/fan.py
index 60a58d2..d64be7c 100755
--- a/os/services/fan.py
+++ b/os/services/fan.py
@@ -58,11 +58,11 @@ def main(args):
temp = int(file.read()) / 1000.0
if temp >= args.temperature and fanIsRunning == False:
- print(f"{temp:.1f}º C; FAN: ON", flush=True)
+ print(f"{temp:.1f}° C; FAN: ON", flush=True)
turnOn()
if temp < (args.temperature - args.delta) and fanIsRunning == True:
- print(f"{temp:.1f}º C; FAN: OFF", flush=True)
+ print(f"{temp:.1f}° C; FAN: OFF", flush=True)
turnOff()
time.sleep(args.sec)
diff --git a/os/services/fan.service b/os/services/fan.service
index 072308d..e53674b 100644
--- a/os/services/fan.service
+++ b/os/services/fan.service
@@ -4,7 +4,7 @@ DefaultDependencies=false
After=basic.target
[Service]
-ExecStart=/usr/bin/python3 fan.py --temperature 60
+ExecStart=/usr/bin/python3 fan.py --temperature 63
WorkingDirectory=/home/pi/moab/os/services
User=pi
Restart=on-failure
diff --git a/os/services/install b/os/services/install
index 3911d66..37de2a6 100755
--- a/os/services/install
+++ b/os/services/install
@@ -9,15 +9,27 @@ readonly _D="$(dirname "$(readlink -f "$0")")" && cd "$_D"
function setup()
{
# next line failing in nominal on new systems
- sudo systemctl disable "$1" || true
+ sudo systemctl disable "$1" 2>/dev/null || true
sudo ln -sf "$PWD/$1" /etc/systemd/system/"$1"
sudo systemctl enable "$1"
sudo chmod 0644 "$1"
}
-setup moab.service
-setup power.service
-setup fan.service
+# v3 no longer needs version 2.4.1 moab.service
+systemctl disable moab 2>/dev/null || true
-sudo systemctl daemon-reload
+setup fan.service # 5 sec monitoring the /sys/cpu/temp
+setup power.service # Monitors power button: 2 seconds shuts down
+setup brain.service # 3 docker containers 5000 REST <--
+setup menu.service # menu.py
+setup stream.service # gunicorn(flask.py) <- reverse proxy nginx
+
+systemctl daemon-reload
+
+unlink /etc/nginx/sites-enabled/default
+cp stream.conf /etc/nginx/sites-enabled
+cp stream.conf /etc/nginx/sites-available
+
+echo "restarting nginx"
+service nginx reload
diff --git a/os/services/menu.service b/os/services/menu.service
new file mode 100644
index 0000000..7fbe018
--- /dev/null
+++ b/os/services/menu.service
@@ -0,0 +1,17 @@
+[Unit]
+Description=Moab Menu
+DefaultDependencies=false
+After=dhcpd.service
+
+[Service]
+Environment="MOABIAN=3.0.24"
+Environment="PYTHONUNBUFFERED=1"
+WorkingDirectory=/home/pi/moab/sw
+ExecStart=/usr/bin/python3 menu.py --debug --verbose --reset
+User=pi
+
+Restart=on-failure
+RestartSec=5s
+
+[Install]
+WantedBy=multi-user.target
diff --git a/os/services/oled.service b/os/services/oled.service
deleted file mode 100644
index f4444c0..0000000
--- a/os/services/oled.service
+++ /dev/null
@@ -1,11 +0,0 @@
-[Unit]
-Description=OLED Service
-DefaultDependencies=false
-
-[Service]
-ExecStart=/usr/local/bin/oled 0 1
-ExecStop=/usr/local/bin/oled 0 0
-User=root
-
-[Install]
-WantedBy=basic.target
diff --git a/os/services/power.py b/os/services/power.py
index b056522..3ae087c 100755
--- a/os/services/power.py
+++ b/os/services/power.py
@@ -16,7 +16,7 @@
power_pin = 3 # HAT puts button signal here https://pinout.xyz/pinout/pin5_gpio3
pressed = 0 # button is active low, so depressed is 0
-countdown = 0.5 # two seconds; it's longer than you think
+countdown = 3.0 # two seconds before power is cut
# countdown timer thread
T = None
@@ -36,10 +36,11 @@ def shutdown():
global too_late
too_late = True
- # Send SIGINT to moab/control container; when caught, Moab
+ # Send SIGTERM to moab/control container; when caught, Moab
# will drop the plate, kill the servo power and clear the screen
- os.system("docker kill --signal=2 control &> /dev/null")
+ cmd = "/bin/kill -s TERM $(cat /tmp/menu.pid) &> /dev/null"
+ os.system(cmd)
os.system("sudo shutdown now")
@@ -54,8 +55,9 @@ def power_button_event(pin):
else:
# kill the timer before it kills us
if T is not None and too_late is False:
- print("Countdown canceled", flush=True)
T.cancel()
+ print("Tapped. Restarting menu.", flush=True)
+ os.system("sudo systemctl restart menu")
def sigint(signal_received, frame):
@@ -67,7 +69,7 @@ def main():
setupGPIO()
while True:
- time.sleep(5)
+ time.sleep(1)
if __name__ == "__main__":
diff --git a/os/services/stream.conf b/os/services/stream.conf
new file mode 100644
index 0000000..d10ca3c
--- /dev/null
+++ b/os/services/stream.conf
@@ -0,0 +1,12 @@
+server {
+ listen 80;
+ server_name moab www.moab;
+
+ access_log /var/log/nginx/moab.access.log;
+ error_log /var/log/nginx/moab.error.log;
+
+ location / {
+ include proxy_params;
+ proxy_pass http://unix:/tmp/web.sock;
+ }
+}
diff --git a/os/services/stream.service b/os/services/stream.service
new file mode 100644
index 0000000..97c7a94
--- /dev/null
+++ b/os/services/stream.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Moab Web Service
+After=network.target
+
+[Service]
+Group=www-data
+User=pi
+WorkingDirectory=/home/pi/moab/sw/stream
+ExecStart=/home/pi/moab/sw/stream/launch.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/os/setup b/os/setup
index 86ac3b9..92d5bea 100755
--- a/os/setup
+++ b/os/setup
@@ -4,25 +4,33 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
-# add change et to noet if you need tabs in the TOHERE section
+# use :set noet when modifying EOF blocks
+# eventually fix with .editorconfig for VS Code <--
+
+## Moabian v3.0 OS Setup
+##
+## Pre-flight checklist for developer:
+##
+## 1) cd ~/moab/sw/huemask && make
+## 2) ensure correct v3.bin firwmare file is checked in to ~/moab/fw
set -euo pipefail # unofficial bash strict mode
-die() { ret=$?; printf '%s\n' "$@" >&2; exit "$ret"; }
require() { hash "$@" || exit 127; }
+println() { printf '%s\n' "$*"; }
+die() { ret=$?; printf "%s\n" "$@" >&2; exit "$ret"; }
-## This script needs to run as root
-[[ $EUID -eq 0 ]] || die "$0 needs to run as root. Try sudo $0"
+[[ $EUID -eq 0 ]] || die "$0 script needs to run as root. Try sudo $0"
## Log script output
exec 1> >(tee "/tmp/stdout.log")
exec 2> >(tee "/tmp/stderr.log")
## Set CWD to the location where this script is running
+## $_D -> full path to folder where script is
+## $_P -> parent path (usually /home/pi/moab)
readonly _D="$(dirname "$(readlink -f "$0")")" && cd "$_D"
-
-## Requirements before continuing
-[[ -d files ]] || die 'Need subfolder "files"'
+readonly _P=$(dirname $_D)
function layer-run-first
{
@@ -58,7 +66,7 @@ function layer-classic-moabian
tmux
vim
minicom
- libffi-dev
+ raspi-gpio
)
apt-get install --no-install-recommends -y ${packages[*]}
@@ -70,23 +78,8 @@ function layer-classic-moabian
systemctl disable apt-daily-upgrade
systemctl disable man-db
- ## Pre-compiled moab C library install for certain os/files/bin utilities
- install -pvm 644 files/lib/* /usr/local/lib
- ldconfig -v -n /usr/local/lib
- ln -fs /usr/local/lib/libmoab.so.1 /usr/local/lib/libmoab.so
- ldconfig
-
- ## Set a proper default bash prompt for all users
- ## and install a Moab specific message-of-the-day "splash" screen
- install -pvm 644 files/profile.d/* /etc/profile.d
rm -f /etc/motd
- ## This adds $HOME/moab/bin to the global path
- install -pvm 644 files/etc/* /etc
-
- ## /usr/local/bin
- install -pvm 755 files/bin/* /usr/local/bin
-
## /home/pi
for f in files/home/*; do
dst="/home/pi/.${f##*/}"
@@ -105,18 +98,17 @@ function layer-classic-moabian
## /home/pi/moab
chown -R pi:pi /home/pi/moab
-}
+ ## Remove files left over from v2.1
+ rm -f /usr/local/bin/{testmoab,ufetch,motd}
+ ## Remove files from v2.4
+ rm -f /usr/local/lib/libmoab*
+ ## Remove files from v2.5 (now in ~/moab/bin
+ rm -f /usr/local/lib/libbcm2835*
+ rm -f /usr/local/bin/{splash,diagnose,oled}
-function blah
-{
- sudo -u pi -s <<'EOF'
- dest="$HOME/.vim/pack/moabian/start"
- rm -rf $dest
- mkdir -p "$dest"
- git clone https://github.com/lifepillar/vim-solarized8 "$dest/solarized8"
- git clone https://github.com/scotstan/vim-polyglot "$dest/polyglot"
-EOF
+ ## /etc/environment file sets MOABIAN=3.x.x for all users
+ install -pvm 644 files/etc/* /etc
}
@@ -130,6 +122,8 @@ function layer-pip-docker
if ! command -v pip3 &> /dev/null; then
wget https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py
python3 /tmp/get-pip.py
+ else
+ python3 -m pip install --upgrade pip
fi
# Pointer for pip to download pre-compiled Raspberry Pi binary wheels
@@ -146,20 +140,27 @@ function layer-pip-docker
if ! command -v docker-compose &> /dev/null; then
pip3 install docker-compose
fi
+
+ # Setup a default docker-compose.yml
+ if ! [[ -e ../docker-compose.yml ]]; then
+ cp ../bin/template.yml ../docker-compose.yml
+ chown pi:pi ../docker-compose.yml
+ fi
}
function layer-moab-services
{
- require 'pip3'
- sudo -u pi pip3 install --user RPi.GPIO
- services/install 2&> /dev/null
+ sudo -u pi python3 -m pip install --user RPi.GPIO
+ services/install
}
function layer-rename {
- sed -i -e 's/raspberrypi/moab/' /etc/hosts /etc/hostname
- echo "raspberrypi.local renamed to moab.local"
- warn "Please reboot your Moab now by typing: sudo reboot now"
+ if grep raspberry /etc/hostname; then
+ sed -i -e 's/raspberrypi/moab/' /etc/hosts /etc/hostname
+ echo "raspberrypi.local renamed to moab.local"
+ warn "Please reboot your Moab now by typing: sudo reboot now"
+ fi
}
function touched { grep -qF "##moabian" "$1"; }
@@ -219,9 +220,22 @@ function touch-console-setup
EOF
}
-function layer-bcm2835
+function layer-baremetal
+{
+ # install APT packages as root
+ $_P/sw/setup/packages.sh
+
+ info "Installing python packages"
+ sudo -u pi -s <<-EOF
+ python3 -m pip install --upgrade pip
+ pip3 install --user -r $_P/sw/setup/requirements.txt
+ pip3 install --user $_P/sw/huemask
+ EOF
+}
+
+function layer-flash
{
- ../sw/bin/bcm2835
+ $_P/bin/flash $_P/fw/v3.bin
}
function layer-mcumgr
@@ -263,14 +277,16 @@ function info {
function main
{
- info "layer-run-first" && layer-run-first
- info "touch-files" && touch-files
- info "classic-moabian" && layer-classic-moabian
- info "pip-docker" && layer-pip-docker
- info "services setup" && layer-moab-services
- info "install bcm2835 library" && layer-bcm2835
- info "install go and mcumgr" && layer-mcumgr
- info "renaming to moab.local" && layer-rename
+ info "01/10: updating system packages" && layer-run-first
+ info "02/10: setting up boot files" && touch-files
+ info "03/10: moabian package install" && layer-classic-moabian
+ info "04/10: installing docker" && layer-pip-docker
+ info "05/10: firmware tooling" && layer-mcumgr
+ info "06/10: python packages for moab" && layer-baremetal
+ info "07/10: autorun services setup" && layer-moab-services
+ info "08/10: flashing Moab HAT to v3 firmware" && layer-flash
+ info "09/10: cleaning up" && sudo apt-get autoremove --yes
+ info "10/10: renaming bot to moab" && layer-rename
}
main
diff --git a/sw/.gitignore b/sw/.gitignore
new file mode 100644
index 0000000..61e1585
--- /dev/null
+++ b/sw/.gitignore
@@ -0,0 +1,2 @@
+.ipynb_checkpoints
+*.ipynb
diff --git a/sw/.ignore b/sw/.ignore
new file mode 100644
index 0000000..8b8b6cd
--- /dev/null
+++ b/sw/.ignore
@@ -0,0 +1,2 @@
+huemask/huemask.c
+tags
diff --git a/sw/Dockerfile b/sw/Dockerfile
deleted file mode 100644
index be79d91..0000000
--- a/sw/Dockerfile
+++ /dev/null
@@ -1,116 +0,0 @@
-FROM arm32v7/python:3.7-slim-buster
-# From https://hub.docker.com/r/arm32v7/python
-# Moabian uses python 3.7 Debian 10 (Buster) "slim", specifically:
-# https://github.com/docker-library/python/blob/35d8d9712c3ea4cbc4004a0e62ab61100b6fed99/3.7/buster/slim/Dockerfile
-
-ENV LC_ALL C.UTF-8
-ENV DEBIAN_FRONTEND noninteractive
-ENV UDEV off
-
-RUN apt-get update && apt-get install -y --no-install-recommends \
- ca-certificates \
- findutils \
- gnupg \
- dirmngr \
- inetutils-ping \
- netbase \
- curl \
- udev \
- procps \
- iproute2 \
-
- git \
- openssh-client \
- autoconf \
- build-essential \
- libbz2-dev \
- libcurl4-openssl-dev \
- libevent-dev \
- libffi-dev \
- libglib2.0-dev \
- libjpeg-dev \
- libncurses-dev \
- libpq-dev \
- libreadline-dev \
- libssl-dev \
- libxml2-dev \
- libxslt-dev \
- libyaml-dev \
- zlib1g-dev \
- && c_rehash
-
-
-# 01_nodoc
-RUN echo 'path-exclude /usr/share/doc/*\n\
-# we need to keep copyright files for legal reasons\n\
-path-include /usr/share/doc/*/copyright\n\
-path-exclude /usr/share/man/*\n\
-path-exclude /usr/share/info/*\n\
-path-exclude /usr/share/lintian/*\n\
-path-exclude /usr/share/locale/*\n\
-path-include /usr/share/locale/en*' > /etc/dpkg/dpkg.cfg.d/01_nodoc
-
-
-# 01_buildconfig
-RUN echo 'APT::Get::Assume-Yes "true";\n\
-APT::Install-Recommends "0";\n\
-APT::Install-Suggests "0";\n\
-quiet "true";' > /etc/apt/apt.conf.d/01_buildconfig
-
-RUN mkdir -p /usr/share/man/man1
-
-
-RUN echo "deb http://archive.raspbian.org/raspbian buster main contrib rpi" >> /etc/apt/sources.list \
- && apt-key adv --batch --keyserver ha.pool.sks-keyservers.net --recv-key 0x9165938D90FDDD2E \
- && echo "deb http://archive.raspberrypi.org/debian buster main ui" >> /etc/apt/sources.list.d/raspi.list \
- && apt-key adv --batch --keyserver ha.pool.sks-keyservers.net --recv-key 0x82B129927FA3303E
-
-
-RUN rm -rf /var/lib/apt/lists/*
-
-RUN find /usr/share/doc -depth -type f ! -name copyright | xargs rm || true \
- && find /usr/share/doc -empty | xargs rmdir || true \
- && find /usr/share/locale/* -depth -type d ! -name en* | xargs rm -rf || true \
- && rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/* \
- && rm -rf /usr/share/lintian/* /usr/share/linda/* /var/cache/man/*
-
-
-RUN apt-get update && apt-get install -y --no-install-recommends \
- less \
- kmod \
- nano \
- net-tools \
- ifupdown \
- iputils-ping \
- i2c-tools \
- usbutils \
- wget
-
-##
-## Moab specific install
-## Must use python3.7
-##
-
-WORKDIR /app
-COPY bin /app/bin
-
-RUN /app/bin/packages
-
-RUN apt-get -y autoremove && \
- rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*
-
-RUN /app/bin/bcm2835
-
-COPY requirements.txt /app
-RUN pip3 install -r /app/requirements.txt -i https://www.piwheels.org/simple
-
-COPY libs /app/libs
-RUN /app/bin/pymoab
-
-RUN apt-get autoremove build-essential cpp-8 gcc-8
-
-COPY control /app/control
-COPY config /app/config
-COPY main.py /app
-CMD python3 main.py -t 5
-
diff --git a/sw/bin/baremetal b/sw/bin/baremetal
deleted file mode 100755
index c9b4335..0000000
--- a/sw/bin/baremetal
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-set -euo pipefail
-
-die() { ret=$?; printf "%s\n", "$@" >&2; exit "$ret"; }
-# [[ $EUID -eq 0 ]] || die "Must run $0 as root"
-
-# change directories to the folder hosting this script
-readonly _D="$(dirname "$(readlink -f "$0")")" && cd "$_D"
-
-function info {
- if tput colors &> /dev/null; then
- local color=$(tput smso)$(tput setaf 2) # inverse, green
- local reset=$(tput sgr0)
- printf "${color}○ %s ${reset}\n" "$1"
- else
- printf '%s\n' "$1"
- fi
-}
-
-info "Installing apt-get packages"
-sudo ./packages
-
-info "Installing SPI/GPIO library"
-sudo ./bcm2835
-
-info "Installing libmoab and pymoab wrapper"
-sudo ./pymoab
-
-info "Installing Python3 packages"
-pip3 install -r ../requirements.txt
-
-info 'Finished. Run: "sudo moab/sw/bin/start" next'
diff --git a/sw/bin/bcm2835 b/sw/bin/bcm2835
deleted file mode 100755
index dc7b75f..0000000
--- a/sw/bin/bcm2835
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/bash
-# vim:ts=4 sw=4 et
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-##
-## Install the BCM2835 C library from source
-##
-
-set -euo pipefail # unofficial bash strict mode
-
-require() { hash "$@" || exit 127; }
-println() { printf '%s\n' "$*"; }
-die() { ret=$?; printf "%s\n" "$@" >&2; exit "$ret"; }
-
-# Only continue if we are running as sudo (for the make install)
-[[ $EUID -eq 0 ]] || die "$0 needs to run as root. Try again with sudo."
-
-# Test to see if library is already installed
-echo 'int main(){}' | gcc -o /dev/null -x c - -lbcm2835 2>/dev/null && die "lib already installed"
-
-# Create a temp folder to download and compile in to
-T=$(mktemp -d --suffix=.moab)
-trap 'rm -rf $T' EXIT
-cd "$T"
-
-ver="-1.64"
-wget --no-verbose http://www.airspayce.com/mikem/bcm2835/bcm2835"$ver".tar.gz
-tar xf bcm2835"$ver".tar.gz
-
-cd bcm2835"$ver"
-./configure > /dev/null
-make > /dev/null
-make install > /dev/null
-
-exit 0
diff --git a/sw/bin/pyclean b/sw/bin/pyclean
index cbf0220..d826947 100755
--- a/sw/bin/pyclean
+++ b/sw/bin/pyclean
@@ -5,6 +5,5 @@
set -euo pipefail
die() { ret=$?; printf "%s\n", "$@" >&2; exit "$ret"; }
-[[ $EUID -eq 0 ]] || die "$0 run as root"
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
diff --git a/sw/bin/pymoab b/sw/bin/pymoab
deleted file mode 100755
index 498a96c..0000000
--- a/sw/bin/pymoab
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-set -euo pipefail # unofficial bash strict mode
-trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
-
-require() { hash "$@" || exit 127; }
-die() { ret=$?; printf "%s\n" "$@" >&2; exit "$ret"; }
-
-# script requires sudo for shared pymoab library install
-[[ $EUID -eq 0 ]] || die "$0 needs to run as root. Try again with sudo."
-
-# change directories to the folder hosting this script
-readonly _D="$(dirname "$(readlink -f "$0")")" && cd "$_D"
-
-make -C ../libs/moab clean
-make -C ../libs/moab install
-
-make -C ../libs/pymoab clean
-make -C ../libs/pymoab install
diff --git a/sw/bin/start b/sw/bin/start
deleted file mode 100755
index 792906f..0000000
--- a/sw/bin/start
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-set -euo pipefail
-
-die() { ret=$?; printf "%s\n", "$@" >&2; exit "$ret"; }
-[[ $EUID -eq 0 ]] || die "Must run $0 as root"
-
-# change directories to the folder hosting this script
-readonly _D="$(dirname "$(readlink -f "$0")")" && cd "$_D"
-
-cd ..
-
-# Start a one-off brain for testing
-docker run -p 5000:5000 --detach --rm -it moab/brain:latest
-
-sudo python3 main.py $@
-
-# Kill the one we just started, on exit
-docker kill "$(docker ps --latest --quiet)"
diff --git a/sw/calibrate.py b/sw/calibrate.py
new file mode 100644
index 0000000..3aee905
--- /dev/null
+++ b/sw/calibrate.py
@@ -0,0 +1,402 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+"""
+Calibration Controller
+
+Performs calibration for hue, center of camera position, and servo offsets
+"""
+
+import os
+import cv2
+import time
+import json
+import argparse
+import datetime
+import numpy as np
+import logging as log
+
+from env import MoabEnv
+from typing import Tuple
+from common import Vector2
+from detector import hsv_detector
+from controllers import pid_controller
+from dataclasses import dataclass, astuple
+from hat import Hat, plate_angles_to_servo_positions
+
+
+@dataclass
+class CalibHue:
+ hue: int = 44 # Reasonable default
+ success: bool = False
+ early_quit: bool = False # If menu is pressed before the calibration is complete
+
+ def __iter__(self):
+ return iter(astuple(self))
+
+
+@dataclass
+class CalibPos:
+ position: Tuple[float, float] = (0.0, 0.0)
+ success: bool = False
+ early_quit: bool = False # If menu is pressed before the calibration is complete
+
+ def __iter__(self):
+ return iter(astuple(self))
+
+
+@dataclass
+class CalibServos:
+ servos: Tuple[float, float, float] = (0.0, 0.0, 0.0)
+ success: bool = False
+ early_quit: bool = False # If menu is pressed before the calibration is complete
+
+ def __iter__(self):
+ return iter(astuple(self))
+
+
+def ball_close_enough(x, y, radius, max_ball_dist=0.045, min_ball_dist=0.01):
+ # reject balls which are too far from the center and too small
+ return (
+ np.abs(x) < max_ball_dist
+ and np.abs(y) < max_ball_dist
+ and radius > min_ball_dist
+ )
+
+
+def calibrate_hue(camera_fn, detector_fn, is_menu_down_fn):
+ hue_low = 0
+ hue_high = 360
+ hue_steps = 41 # Is 41 instead of 40 so that the steps are even
+
+ img_frame, elapsed_time = camera_fn()
+ hue_options = list(np.linspace(hue_low, hue_high, hue_steps))
+
+ detected_hues = []
+ for hue in hue_options:
+ if is_menu_down_fn():
+ return CalibHue(early_quit=True)
+
+ img_frame, elapsed_time = camera_fn()
+ ball_detected, ((x, y), radius) = detector_fn(img_frame, hue=hue, debug=True)
+
+ # If we found a ball roughly in the center that is large enough
+ if ball_detected and ball_close_enough(x, y, radius):
+ log.info(
+ f"hue={hue:0.3f}, ball_detected={ball_detected}, "
+ f"(x, y)={x:0.3f} {y:0.3f}, radius={radius:0.3f}"
+ )
+ detected_hues.append(hue)
+
+ if len(detected_hues) > 0:
+ # https://en.wikipedia.org/wiki/Mean_of_circular_quantities
+ detected_hues_rad = np.radians(detected_hues)
+ sines, cosines = np.sin(detected_hues_rad), np.cos(detected_hues_rad)
+ sin_mean, cos_mean = np.mean(sines), np.mean(cosines)
+ avg_hue_rad = np.arctan2(sin_mean, cos_mean)
+ avg_hue = np.degrees(avg_hue_rad) % 360 # Convert back to [0, 360]
+
+ print(f"Hues are: {detected_hues}")
+ print(f"Hue calibrated: {avg_hue:0.2f}")
+ print(f"Avg hue: {avg_hue:0.2f}")
+ return CalibHue(hue=int(avg_hue), success=True)
+
+ else:
+ log.warning(f"Hue calibration failed.")
+ return CalibHue()
+
+
+def calibrate_pos(camera_fn, detector_fn, hue, is_menu_down_fn):
+ for i in range(10): # Try and detect for 10 frames before giving up
+ if is_menu_down_fn():
+ return CalibPos(early_quit=True)
+
+ img_frame, elapsed_time = camera_fn()
+ ball_detected, ((x, y), radius) = detector_fn(img_frame, hue=hue)
+
+ # If we found a ball roughly in the center that is large enough
+ if ball_detected and ball_close_enough(x, y, radius):
+ x_offset = round(x, 3)
+ y_offset = round(y, 3)
+
+ log.info(f"Offset calibrated: [{x_offset:.3f}, {y_offset:.3f}]")
+ return CalibPos(position=(x_offset, y_offset), success=True)
+
+ log.warning(f"Offset calibration failed.")
+ return CalibPos()
+
+
+def calibrate_servo_offsets(pid_fn, env, stationary_vel=0.005, time_limit=20):
+ start_time = time.time()
+ action = Vector2(0, 0)
+
+ # Initial high vel_history (to use the vel_hist[-100:] later)
+ vel_x_hist = [1.0 for _ in range(100)]
+ vel_y_hist = [1.0 for _ in range(100)]
+
+ # Run until the ball has stabilized or the time limit was reached
+ while time.time() < start_time + time_limit:
+ state = env.step(action)
+ action, info = pid_fn(state)
+
+ (x, y, vel_x, vel_y, sum_x, sum_y), ball_detected, buttons = state
+
+ # Quit on menu down
+ if buttons.menu_button:
+ return CalibServos(early_quit=True)
+
+ if ball_detected:
+ vel_x_hist.append(vel_x)
+ vel_y_hist.append(vel_y)
+ prev_100_x = np.mean(np.abs(vel_x_hist[-100:]))
+ prev_100_y = np.mean(np.abs(vel_y_hist[-100:]))
+ print("Prev 100: ", (prev_100_x, prev_100_y))
+
+ # If the average velocity for the last 100 timesteps is under the limit
+ if (prev_100_x < stationary_vel) and (prev_100_y < stationary_vel):
+
+ # Calculate offsets by calculating servo positions at the
+ # current stable position and subtracting the `default` zeroed
+ # position of the servos.
+ servos = np.array(plate_angles_to_servo_positions(*action))
+ servos_zeroed = np.array(plate_angles_to_servo_positions(0, 0))
+ servo_offsets = list(servos - servos_zeroed)
+
+ return CalibServos(servos=servo_offsets, success=True)
+
+ # If the plate could be stabilized in time_limit seconds, quit
+ log.warning(f"Servo calibration failed.")
+ return CalibServos()
+
+
+def write_calibration(calibration_dict, calibration_file="bot.json"):
+ log.info("Writing calibration.")
+
+ # write out stuff
+ with open(calibration_file, "w+") as outfile:
+ log.info(f"Creating calibration file {calibration_file}")
+ json.dump(calibration_dict, outfile, indent=4, sort_keys=True)
+
+
+def read_calibration(calibration_file="bot.json"):
+ log.info("Reading previous calibration.")
+
+ if os.path.isfile(calibration_file):
+ with open(calibration_file, "r") as f:
+ calibration_dict = json.load(f)
+ else: # Use defaults
+ calibration_dict = {
+ "ball_hue": 44,
+ "plate_offsets": (0.0, 0.0),
+ "servo_offsets": (0.0, 0.0, 0.0),
+ }
+ return calibration_dict
+
+
+def wait_for_joystick_or_menu(hat, sleep_time=1 / 30):
+ """Waits for either the joystick or the menu. Returns the buttons"""
+ while True:
+ hat.noop() # Force new transfer to have up to date button reading
+ buttons = hat.get_buttons()
+ if buttons.menu_button or buttons.joy_button:
+ return buttons
+ time.sleep(sleep_time)
+
+
+def wait_for_menu(hat, sleep_time=1 / 30):
+ while True:
+ hat.noop() # Force new transfer to have up to date button reading
+ menu_button, joy_button, joy_x, joy_y = hat.get_buttons()
+ time.sleep(sleep_time)
+ if menu_button:
+ return
+
+
+def run_calibration(env, pid_fn, calibration_file):
+ # Get some hidden things from env
+ hat = env.hat
+ camera_fn = env.camera
+ detector_fn = env.detector
+
+ def is_menu_down(hat=hat) -> bool:
+ hat.noop()
+ return hat.get_buttons().menu_button
+
+ # lift plate up first
+ hat.set_angles(0, 0)
+
+ # Display message and wait for joystick
+ hat.display_long_string(
+ "put ball on stand\nclick joystick"
+ # "Place ball in\ncenter using\nclear stand.\n\n" "Click joystick\nwhen ready."
+ )
+ buttons = wait_for_joystick_or_menu(hat)
+ if buttons.menu_button: # Early quit
+ hat.go_up()
+ return
+
+ hat.display_string("Calibrating...")
+ hue_calib = calibrate_hue(camera_fn, detector_fn, is_menu_down)
+ if hue_calib.early_quit:
+ hat.go_up()
+ return
+
+ # Calibrate position
+ pos_calib = calibrate_pos(camera_fn, detector_fn, hue_calib.hue, is_menu_down)
+ if pos_calib.early_quit:
+ hat.go_up()
+ return
+
+ # Save calibration
+ calibration_dict = read_calibration(calibration_file)
+ calibration_dict["ball_hue"] = hue_calib.hue
+ calibration_dict["plate_offsets"] = pos_calib.position
+ x_offset, y_offset = pos_calib.position
+ write_calibration(calibration_dict)
+
+ # Update the environment to use the new calibration
+ # Warning! This mutates the state!
+ env.reset_calibration(calibration_file=calibration_file)
+
+ if pos_calib.success and hue_calib.success: # and servo_calib.success:
+ hat.display_long_string(f"Ok! Ball hue={hue_calib.hue}\nClick menu...")
+ elif not (pos_calib.success or hue_calib.success): # or servo_calib.success):
+ hat.display_long_string("Calibration failed\nClick menu...")
+ else:
+ hue_str = (
+ f"Hue calib:\nsuccessful\nBall hue = {hue_calib.hue}\n\n"
+ if hue_calib.success
+ else "Hue calib:\nfailed\n\n"
+ )
+ pos_str = (
+ f"Position \ncalib:\nsuccessful\nPosition = \n({100*x_offset:.1f}, {100*y_offset:.1f})cm\n\n"
+ if hue_calib.success
+ else "(X, Y) calib:\nfailed\n\n"
+ )
+ hat.display_long_string(
+ "Calibration\npartially succeeded\n\n"
+ + hue_str
+ + pos_str
+ + "Click menu\nto return...\n"
+ )
+
+ # When the calibration is complete, save the image of what the moab camera
+ # sees (useful for debugging when the hue calibration fails)
+ # Have a nice filename with the time and whether it succeeded or failed
+
+ time_of_day = datetime.datetime.now().strftime("%H%M%S")
+ filename = "/tmp/hue"
+ if hue_calib.success:
+ filename += f".{hue_calib.hue}.{time_of_day}.jpg"
+ else:
+ filename += f".fail.{time_of_day}.jpg"
+
+ img_frame, _ = camera_fn()
+
+ # Huemask keeps an internal cache. By sending a new hue (hue + 1) invalidates
+ # the cache. TODO: added this while searching for a state bug
+ detector_fn(img_frame, hue=hue_calib.hue + 1, debug=True, filename=filename)
+
+ hat.go_up()
+
+
+def run_servo_calibration(env, pid_fn, calibration_file):
+ # Warning: servo calib works but doesn't currently give a good calibration
+ raise NotImplementedError
+
+ # Get some hidden things from env
+ hat = env.hat
+ camera_fn = env.camera
+ detector_fn = env.detector
+
+ # Start the calibration with uncalibrated servos
+ hat.set_servo_offsets(0, 0, 0)
+ # lift plate up fist
+ hat.set_angles(0, 0)
+
+ # Calibrate servo offsets
+ hat.display_long_string(
+ "Calibarating\nservos\n\n"
+ "Place ball in\ncenter without\n stand.\n\n"
+ "Click joystick\nto continue."
+ )
+ buttons = wait_for_joystick_or_menu(hat)
+ if buttons.menu_button: # Early quit
+ hat.go_up()
+ return
+
+ hat.display_long_string("Calibrating\nservos...")
+ servo_calib = calibrate_servo_offsets(pid_fn, env)
+
+ # Save calibration
+ calibration_dict = read_calibration(calibration_file)
+ calibration_dict["servo_offsets"] = servo_calib.servos
+ s1, s2, s3 = servo_calib.servos
+ write_calibration(calibration_dict)
+
+ # Update the environment to use the new calibration
+ # Warning! This mutates the state!
+ env.reset_calibration(calibration_file=calibration_file)
+
+ if servo_calib.success:
+ hat.display_long_string(
+ f"servo offsets =\n({s1:.2f}, {s2:.2f}, {s3:.2f})\n\n"
+ "Click menu\nto return...\n"
+ )
+ print(f"servo offsets =\n({s1:.2f}, {s2:.2f}, {s3:.2f})")
+ else:
+ hat.display_long_string("Calibration\nfailed\n\nClick menu\nto return...")
+
+ hat.go_up()
+
+
+def calibrate_controller(**kwargs):
+ run_calibration(
+ kwargs["env"],
+ kwargs["pid_fn"],
+ kwargs["calibration_file"],
+ )
+
+ def wait_for_menu_and_stream():
+ # Get some hidden things from env to be able to stream the calib results
+ env = kwargs["env"]
+ hat = env.hat
+ camera_fn = env.camera
+ detector_fn = env.detector
+
+ menu_button = False
+ while not menu_button:
+ img_frame, _ = camera_fn()
+ detector_fn(img_frame, debug=True) # Save to streaming
+
+ hat.noop()
+ menu, joy, _, _ = hat.get_buttons()
+ if menu or joy:
+ break
+ hat.go_up()
+
+ return wait_for_menu_and_stream
+
+
+def main(calibration_file, frequency=30, debug=True):
+ pid_fn = pid_controller(frequency=frequency)
+
+ with MoabEnv(frequency=frequency, debug=debug) as env:
+ env.step((0, 0))
+ time.sleep(0.2)
+ env.hat.enable_servos()
+ time.sleep(0.2)
+ env.hat.set_servos(133, 133, 133)
+
+ run_calibration(env, pid_fn, calibration_file)
+
+ env.hat.disable_servos()
+
+
+if __name__ == "__main__": # Parse command line args
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-d", "--debug", action="store_true")
+ parser.add_argument("-f", "--file", default="bot.json", type=str)
+
+ args, _ = parser.parse_known_args()
+ main(args.file, debug=args.debug)
diff --git a/sw/camera.py b/sw/camera.py
new file mode 100644
index 0000000..d2f8050
--- /dev/null
+++ b/sw/camera.py
@@ -0,0 +1,88 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+"""
+A sensor that uses OpenCV for capture
+"""
+
+import cv2
+import threading
+import numpy as np
+
+from time import time
+
+
+# Link to raspicam_cv implementation for mapping values
+# https://github.com/cedricve/raspicam/blob/651c56418a5a594fc12f1414eb14f2b899729cb1/src/raspicam_cv.h#L108
+class OpenCVCameraSensor:
+ def __init__(
+ self,
+ device_id=0,
+ rotation=0,
+ brightness=60,
+ contrast=100,
+ frequency=30,
+ x_offset_pixels=0.0,
+ y_offset_pixels=0.0,
+ ):
+ self.device_id = device_id
+ # self.width = width
+ # self.height = height
+ self.rotation = rotation
+ self.brightness = brightness
+ self.contrast = contrast
+ self.frequency = frequency
+ self.prev_time = 0.0
+ self.source = None
+ self.last_frame = None
+ self.x_offset_pixels = x_offset_pixels
+ self.y_offset_pixels = y_offset_pixels
+
+ def start(self):
+ self.source = cv2.VideoCapture(self.device_id)
+ if self.source:
+ self.source.set(cv2.CAP_PROP_FRAME_WIDTH, 384)
+ self.source.set(cv2.CAP_PROP_FRAME_HEIGHT, 288)
+ self.source.set(cv2.CAP_PROP_FPS, self.frequency)
+ self.source.set(cv2.CAP_PROP_MODE, 0) # Not meant to be configurable
+ self.source.set(cv2.CAP_PROP_BRIGHTNESS, self.brightness)
+ self.source.set(cv2.CAP_PROP_CONTRAST, self.contrast)
+ else:
+ raise Exception("Couldn't create camera.")
+
+ def stop(self):
+ if self.source:
+ self.source.release()
+ self.source = None
+
+ def __call__(self):
+ # safety check
+ if self.source is None:
+ raise Exception("Using camera before it has been started.")
+
+ # Calculate the time elapsed since the last sensor snapshot
+ curr_time = time()
+ elapsed_time = curr_time - self.prev_time
+ self.prev_time = curr_time
+
+ ret, frame = self.source.read()
+ if ret:
+ w, h = 384, 288
+ d = 256 # Our final "destination" rectangle is 256x256
+
+ # Ensure the offset crops are possible
+ x_offset_pixels = min(self.x_offset_pixels, (w / 2 - d / 2))
+ x_offset_pixels = max(self.x_offset_pixels, -(w / 2 - d / 2))
+ y_offset_pixels = min(self.y_offset_pixels, (h / 2 - d / 2))
+ y_offset_pixels = max(self.y_offset_pixels, -(h / 2 - d / 2))
+
+ # Calculate the starting point in x & y
+ x = int((w / 2 - d / 2) + x_offset_pixels)
+ y = int((h / 2 - d / 2) + y_offset_pixels)
+
+ frame = frame[y : y + d, x : x + d]
+ # frame = frame[:-24, 40:-80] # Crop so middle of plate is middle of image
+ # cv2.resize(frame, (256, 256)) # Crop off edges to make image (256, 256)
+ return frame, elapsed_time
+ else:
+ raise ValueError("Could not get the next frame")
diff --git a/sw/common.py b/sw/common.py
new file mode 100644
index 0000000..804e30e
--- /dev/null
+++ b/sw/common.py
@@ -0,0 +1,121 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+import math
+from dataclasses import dataclass
+
+
+def high_pass_filter(frequency, fc=50):
+ x_dot_cstate = 0
+
+ def hpf(x):
+ nonlocal x_dot_cstate # allow x_dot_cstate to be updated in inner scope
+ x_dot = -(fc ** 2) * x_dot_cstate + fc * x
+ x_dot_cstate += (-fc * x_dot_cstate + x) / frequency
+ return x_dot
+
+ return hpf
+
+
+def low_pass_filter(frequency, fc=50):
+ y_prev = 0.0
+ dt = 1 / frequency
+ tau = 1 / (2 * math.pi * fc)
+ alpha = dt / (tau + dt)
+
+ def lpf(x):
+ nonlocal y_prev # allow y_prev to be updated in inner scope
+ y = alpha * x + (1 - alpha) * y_prev
+ y_prev = y
+ return y
+
+ return lpf
+
+
+def derivative(frequency, fc=None):
+ prev_x = 0
+
+ def derivate(x):
+ nonlocal prev_x
+ x_dot = (x - prev_x) * frequency
+ prev_x = x
+ return x_dot
+
+ return derivate
+
+
+class Vector2:
+ def __init__(self, x: float, y: float):
+ self.x = float(x)
+ self.y = float(y)
+
+ def __str__(self):
+ return f"X: {self.x:2.3f}, Y: {self.y:2.3f}"
+
+ def __add__(self, o):
+ return Vector2(self.x + o.x, self.y + o.y)
+
+ def __sub__(self, o):
+ return Vector2(self.x - o.x, self.y - o.y)
+
+ def __truediv__(self, o):
+ return Vector2(self.x / o, self.y / o)
+
+ def __mul__(self, o):
+ return Vector2(self.x * o, self.y * o)
+
+ def length(self):
+ return math.sqrt(self.x ** 2 + self.y ** 2)
+
+ def normalized(self):
+ length = self.length()
+ if length != 0.0:
+ return Vector2(self.x / length, self.y / length)
+ else:
+ return Vector2(0, 0)
+
+ def dot(self, o):
+ return self.x * o.x + self.y * o.y
+
+ def angle(self, o):
+ return math.acos(self.dot(o) / self.length() * o.length())
+
+ def distance(self, o):
+ return (self - o).length()
+
+ def rotate(self, theta, o=None):
+ """ Return a point rotated `theta` radians around `o` """
+ if o is None:
+ o = Vector2(0, 0)
+ x = o.x + math.cos(theta) * (self.x - o.x) - math.sin(theta) * (self.y - o.y)
+ y = o.y + math.sin(theta) * (self.x - o.x) + math.cos(theta) * (self.y - o.y)
+ return Vector2(x, y)
+
+ def __iter__(self):
+ yield self.x
+ yield self.y
+
+ def to_int_tuple(self):
+ return (int(self.x), int(self.y))
+
+
+def polar(x, y, degrees=True):
+ r = math.sqrt(x * x + y * y)
+ theta = math.atan(y / x)
+ if degrees:
+ theta *= 180 / np.pi
+ return r, theta
+
+
+@dataclass
+class CircleFeature:
+ center: Vector2 = Vector2(0, 0)
+ radius = 0.0
+
+
+@dataclass
+class Calibration:
+ ball_hue = 22
+ plate_y_offset = 0.0 # -0.016
+ plate_x_offset = 0.0 # -0.092
+ rotation = -30.0
diff --git a/sw/config/calibration.json b/sw/config/calibration.json
deleted file mode 100644
index 28e4d35..0000000
--- a/sw/config/calibration.json
+++ /dev/null
@@ -1,11 +0,0 @@
-{
- "ballHue": 27,
- "plateXOffset": -0.092,
- "plateYOffset": -0.016,
- "rotation": -30.0,
- "servoOffsets": [
- 0,
- 0,
- 0
- ]
-}
\ No newline at end of file
diff --git a/sw/config/config.json b/sw/config/config.json
deleted file mode 100644
index 7cca39b..0000000
--- a/sw/config/config.json
+++ /dev/null
@@ -1,182 +0,0 @@
-{
- "logging": {
- "version": 1,
- "formatters": {
- "single-line": {
- "class": "logging.Formatter",
- "style": "{",
- "datefmt": "%I:%M:%S",
- "format": "{levelname:8s} {asctime:s} {name:<15s} {message:s}"
- }
- },
- "handlers": {
- "socket": {
- "()": "logging.handlers.SocketHandler",
- "host": "localhost",
- "port": 9020
- },
- "console": {
- "class": "logging.StreamHandler",
- "formatter": "single-line",
- "stream": "ext://sys.stdout"
- }
- },
- "loggers": {
- "local": {
- "handlers": [
- "console"
- ],
- "level": "DEBUG"
- },
- "network": {
- "handlers": [
- "socket"
- ],
- "level": "DEBUG"
- },
- "performance": {
- "handlers": [
- "console"
- ],
- "level": "INFO"
- }
- },
- "root": {
- "handlers": [
- "console"
- ],
- "level": "INFO"
- }
- },
- "devices": {
- "menu": {
- "frequencyHz": 20,
- "controller": "control.controllers.MenuController"
- },
- "calibration": {
- "frequencyHz": 30,
- "debug": false,
- "debugDecorator": {
- "name": "control.debug.X11Decorator",
- "windowName": "frame"
- },
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": "control.detectors.HSVDetector"
- },
- "controller": "control.controllers.HueCalibrationController",
- "actuator": "control.actuators.ServoActuator"
- },
- "manual": {
- "controller": "control.controllers.JoystickController",
- "actuator": "control.actuators.ServoActuator"
- },
- "classic": {
- "frequencyHz": 30,
- "debug": false,
- "debugDecorator": {
- "name": "control.debug.X11Decorator",
- "windowName": "frame"
- },
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": {
- "debug": false,
- "name": "control.detectors.HSVDetector"
- }
- },
- "controller": {
- "name": "control.controllers.PIDController",
- "Kp": 0.15,
- "Ki": 0.001,
- "Kd": 0.090,
- "fc": 15
- },
- "actuator": "control.actuators.ServoActuator"
- },
- "brain": {
- "frequencyHz": 22,
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": "control.detectors.HSVDetector",
- "obstacle": {
- "name": "control.detectors.HSVDetector",
- "hue": 72
- }
- },
- "controller": {
- "name": "control.controllers.BrainController",
- "maxAngle": 22,
- "endPoint": "http://localhost:5000",
- "sensorSize": 256
- },
- "actuator": "control.actuators.ServoActuator"
- },
- "custom1": {
- "frequencyHz": 22,
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": "control.detectors.HSVDetector",
- "obstacle": {
- "name": "control.detectors.HSVDetector",
- "hue": 72
- }
- },
- "controller": {
- "name": "control.controllers.BrainController",
- "maxAngle": 22,
- "endPoint": "http://localhost:5001",
- "sensorSize": 256
- },
- "actuator": "control.actuators.ServoActuator"
- },
- "custom2": {
- "frequencyHz": 22,
- "sensor": {
- "name": "control.sensors.OpenCVCameraSensor",
- "brightness": 60,
- "contrast": 50,
- "saturation": 50,
- "gain": 0
- },
- "detectors": {
- "ball": "control.detectors.HSVDetector",
- "obstacle": {
- "name": "control.detectors.HSVDetector",
- "hue": 72
- }
- },
- "controller": {
- "name": "control.controllers.BrainController",
- "maxAngle": 22,
- "endPoint": "http://localhost:5002",
- "sensorSize": 256
- },
- "actuator": "control.actuators.ServoActuator"
- }
- }
-}
diff --git a/sw/control/__init__.py b/sw/control/__init__.py
deleted file mode 100644
index be8064b..0000000
--- a/sw/control/__init__.py
+++ /dev/null
@@ -1,7 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from .debug import *
-from .device import *
-from .timers import *
-from .perfcounters import *
diff --git a/sw/control/actuators/__init__.py b/sw/control/actuators/__init__.py
deleted file mode 100644
index 0e4f92a..0000000
--- a/sw/control/actuators/__init__.py
+++ /dev/null
@@ -1,4 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from .servo_actuator import *
diff --git a/sw/control/actuators/servo_actuator.py b/sw/control/actuators/servo_actuator.py
deleted file mode 100644
index 43eb408..0000000
--- a/sw/control/actuators/servo_actuator.py
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Servo actuator
-"""
-
-import pymoab
-from numpy import int8
-
-from ..common import IActuator, IDevice, Vector2
-
-
-class ServoActuator(IActuator):
- def __init__(self, config: IActuator.Config, device: IDevice):
- super().__init__(config, device)
- self.config = config
- self.calibration = device.calibration
-
- pymoab.setServoOffsets(
- self.calibration.servoOffsets[0],
- self.calibration.servoOffsets[1],
- self.calibration.servoOffsets[2],
- )
- pymoab.activatePlate()
-
- self.setPlateAngles(device, Vector2(0, 0))
-
- def __del__(self):
- pymoab.hoverPlate()
-
- def setPlateAngles(self, sender: IDevice, plate_angles: Vector2):
- self.lastSetPlateAngles = plate_angles
- pymoab.setPlateAngles(int(plate_angles.x), int(plate_angles.y))
-
- def getLastSetPlateAngles(self) -> Vector2:
- return self.lastSetPlateAngles
diff --git a/sw/control/common/__init__.py b/sw/control/common/__init__.py
deleted file mode 100644
index 0166012..0000000
--- a/sw/control/common/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from .color import *
-from .event import *
-from .bounds import *
-from .common import *
-from .device import *
-from .sensor import *
-from .vector2 import *
-from .detector import *
-from .actuator import *
-from .controller import *
diff --git a/sw/control/common/actuator.py b/sw/control/common/actuator.py
deleted file mode 100644
index f64a7b7..0000000
--- a/sw/control/common/actuator.py
+++ /dev/null
@@ -1,26 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Actuator interface
-"""
-
-from dataclasses import dataclass
-
-from .device import IDevice
-from .vector2 import Vector2
-
-
-class IActuator:
- @dataclass
- class Config:
- pass
-
- def __init__(self, config: Config, device: IDevice):
- self.config = config
-
- def setPlateAngles(self, sender: IDevice, plate_angles: Vector2):
- pass
-
- def getLastSetPlateAngles(self) -> Vector2:
- return Vector2(0, 0)
diff --git a/sw/control/common/bounds.py b/sw/control/common/bounds.py
deleted file mode 100644
index 02061d0..0000000
--- a/sw/control/common/bounds.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Datclasses that contain bounds values
-"""
-
-from typing import Optional
-from dataclasses import dataclass, field
-
-from .color import HSVColor
-
-
-@dataclass
-class IntBounds:
- min: Optional[int] = 0
- max: Optional[int] = 0
-
-
-@dataclass
-class FloatBounds:
- min: Optional[float] = 0
- max: Optional[float] = 0
-
-
-@dataclass
-class HSVBounds:
- min: Optional[HSVColor] = field(default_factory=lambda: HSVColor((0, 0, 0)))
- max: Optional[HSVColor] = field(default_factory=lambda: HSVColor((0, 0, 0)))
diff --git a/sw/control/common/color.py b/sw/control/common/color.py
deleted file mode 100644
index efb6977..0000000
--- a/sw/control/common/color.py
+++ /dev/null
@@ -1,59 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Basic color classes
-"""
-
-from typing import Tuple
-from dataclasses import dataclass
-
-
-@dataclass
-class RGBColor:
- r: int
- g: int
- b: int
-
- def __init__(self, r: int = 0, g: int = 0, b: int = 0):
- self.r = r
- self.g = g
- self.b = b
-
- def __init__(self, rgb: Tuple[int, int, int]):
- self.r = rgb[0]
- self.g = rgb[1]
- self.b = rgb[2]
-
- def __str__(self):
- return f"R: {self.r}, G: {self.g}, B: {self.b}"
-
- def __iter__(self):
- yield self.r
- yield self.g
- yield self.b
-
-
-@dataclass
-class HSVColor:
- h: int
- s: int
- v: int
-
- def __init__(self, h: int = 0, s: int = 0, v: int = 0):
- self.h = h
- self.s = s
- self.v = v
-
- def __init__(self, hsv: Tuple[int, int, int]):
- self.h = hsv[0]
- self.s = hsv[1]
- self.v = hsv[2]
-
- def __str__(self):
- return f"H: {self.h:.4f}, S: {self.s:.4f}, V: {self.v:.4f}"
-
- def __iter__(self):
- yield self.h
- yield self.s
- yield self.v
diff --git a/sw/control/common/common.py b/sw/control/common/common.py
deleted file mode 100644
index 0274ca8..0000000
--- a/sw/control/common/common.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Shared interfaces
-"""
-
-from dataclasses import dataclass
-
-from .vector2 import Vector2
-
-
-@dataclass
-class CircleFeature:
- center: Vector2 = Vector2(0, 0)
- radius: float = 0.0
-
-
-class IDebugDecorator:
- def __init__(self, config: dict):
- self.config = config
-
- def __del__(self):
- pass
-
- def decorate(self, args):
- pass
diff --git a/sw/control/common/controller.py b/sw/control/common/controller.py
deleted file mode 100644
index bb89056..0000000
--- a/sw/control/common/controller.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Shared interfaces
-"""
-
-from typing import Dict
-from dataclasses import dataclass
-
-from .device import IDevice
-from .vector2 import Vector2
-from .common import CircleFeature
-from .event import IEventListener
-
-
-class IController(IEventListener):
- @dataclass
- class Config(IDevice):
- maxAngle: int = 15
-
- def __init__(self, config: Config, device: IDevice):
- self.config = config
-
- def getControlOutput(
- self,
- sender: IDevice,
- elapsedMs: float,
- detectorResults: Dict[str, CircleFeature],
- currPlateAngles: Vector2,
- ) -> Vector2:
- return Vector2(0, 0)
diff --git a/sw/control/common/detector.py b/sw/control/common/detector.py
deleted file mode 100644
index da157ae..0000000
--- a/sw/control/common/detector.py
+++ /dev/null
@@ -1,43 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Shared interfaces
-"""
-
-import math
-import numpy as np
-from dataclasses import dataclass
-
-
-from .device import IDevice
-from .vector2 import Vector2
-from .common import CircleFeature
-
-
-class IDetector:
- @dataclass
- class Config:
- pass
-
- def __init__(self, config: Config, device: IDevice):
- self.calibration = device.calibration
-
- def detect(
- self, sender: IDevice, img: np.ndarray, plate_angles: Vector2
- ) -> CircleFeature:
- """
- Your detection code goes here.
- """
- return CircleFeature()
-
- def post_detect(self, feature: CircleFeature) -> CircleFeature:
- """
- Do some post processing on the detected feature.
- You shouldn't need to overload this.
- """
- if feature:
- feature.center = feature.center.rotate(
- math.radians(self.calibration.rotation)
- )
- return feature
diff --git a/sw/control/common/device.py b/sw/control/common/device.py
deleted file mode 100644
index a5e7b9f..0000000
--- a/sw/control/common/device.py
+++ /dev/null
@@ -1,128 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Shared interfaces
-"""
-
-import logging as log
-from pydoc import locate
-from dacite import from_dict
-from dataclasses import dataclass, field
-from typing import List, Optional, Union, cast
-
-from .common import IDebugDecorator
-
-
-"""
-Component config is either a string of the name of component to load.
-Example:
- {
- "mycomponent" : "my.namespace.MyController",
- ...
- }
-
-Or it is a dictionary with a `name` field and parameter overrides for the defaults.
-Example:
- {
- "mycomponent": {
- "name": "my.namespace.MyController",
- "someParam": 42.0
- },
- ...
- }
-
-"""
-ComponentConfig = Union[dict, str]
-
-
-class IDevice:
- @dataclass
- class Calibration:
- servoOffsets: List[int] = field(default_factory=lambda: [0, 0, 0])
-
- # plate calibration as a percentage of frame size
- plateXOffset: float = 0.0
- plateYOffset: float = 0.0
-
- ballHue: int = 32 # orange/yellow
- rotation: float = -30.0 # the camera sits -30deg rotated from plate coords
-
- @dataclass
- class Config:
- frequencyHz: float = 30.0
- joystickThreshold: float = 0.8
- menu_idx: int = 0
- debug: bool = False
- debugDecorator: Optional[ComponentConfig] = None
- sensor: Optional[ComponentConfig] = None
- detectors: Optional[ComponentConfig] = None
- controller: Optional[ComponentConfig] = None
- actuator: Optional[ComponentConfig] = None
-
- def __init__(
- self,
- config: Config,
- calibration: Calibration,
- debug_decorator: Optional[IDebugDecorator],
- ):
- self.debug_decorator = debug_decorator
- self.config = config
-
- # shared per-machine calibration data
- self.calibration = calibration
- self.next_device: Optional[str] = None
- self.previous_menu: int = self.config.menu_idx
-
- def update(self):
- pass
-
- def run(self):
- pass
-
- def stop(self):
- pass
-
- def set_next_device(self, device_name: str):
- self.next_device = device_name
-
- def get_next_device(self) -> Optional[str]:
- return self.next_device
-
- def component_from_config(
- self, component_config: ComponentConfig
- ) -> Optional[object]:
- """
- Import classes with the following signature,
- and construct them with their config class.
-
- class Foo:
- @dataclass
- class Config:
- param1: type = default
- param2: type = default
- ...
- def __init__(self, config: Config):
- ...
- """
- class_name = ""
- config = {}
- try:
- # if we're just a string expand out into a dict with no config
- if type(component_config) is str:
- class_name = cast(str, component_config)
- elif type(component_config) is dict:
- class_name = cast(dict, component_config)["name"]
- config = component_config
-
- # locate class ref for module.name.Foo and module.name.Foo.Config
- class_ref = locate(class_name, forceload=False)
- config_ref = locate(class_name + ".Config", forceload=False)
-
- # unpack dict into dataclass
- config_inst = from_dict(config_ref, config)
- ref = class_ref(config_inst, self) # type: ignore
- except Exception as e:
- log.exception(f"Error creating class {class_name}\n{e}")
- return None
- return ref
diff --git a/sw/control/common/event.py b/sw/control/common/event.py
deleted file mode 100644
index 4909d90..0000000
--- a/sw/control/common/event.py
+++ /dev/null
@@ -1,151 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from enum import Enum
-from typing import List, Optional
-from dataclasses import dataclass
-
-from pymoab import getJoystickBtn, getJoystickX, getJoystickY, getMenuBtn
-
-
-@dataclass
-class Event:
- menu_btn: bool = False
- joy_btn: bool = False
- joy_x: float = 0.0
- joy_y: float = 0.0
-
-
-class IEventListener:
- """
- Mix-in class describing the callback event interface.
- """
-
- def __init__(self):
- pass
-
- def on_menu_down(self, sender: object):
- pass
-
- def on_joy_down(self, sender: object):
- pass
-
- # continuous
- def on_joy_moved(self, sender: object, x: float, y: float):
- pass
-
- # discrete navigation flicks
- def on_flick_up(self, sender: object):
- pass
-
- def on_flick_down(self, sender: object):
- pass
-
- def on_flick_return(self, sender: object):
- pass
-
-
-# constants for joystick flick direction
-class FlickDir(Enum):
- Unset = 0
- Center = 0
- Up = 1
- Down = 2
-
-
-class EventDispatcher:
- """
- Dispatches events to event to listeners
- in self.listeners.
-
- Call dispatch_event() in main loop.
- """
-
- def __init__(self):
- # ...are you listening?
- self.listeners: List[IEventListener] = []
-
- # previous event returned from get_next_event
- self.prev_event: Optional[Event] = None
-
- # last event scanned
- self._last_raw_event: Optional[Event] = None
-
- # tracked separately from the polled state
- self.flick_threshold = 0.8
- self.flick_dir = FlickDir.Unset
-
- def _raw_event(self) -> Event:
- return Event(getMenuBtn(), getJoystickBtn(), getJoystickX(), getJoystickY())
-
- def get_next_event(self) -> Optional[Event]:
- """
- Watch for changes between current state
- and previous state.
-
- Returns the next event or None
- """
- # poll the current state of the hardware
- curr_event = self._raw_event()
-
- # first scan will set previous
- event = None
- if self._last_raw_event is None:
- self.prev_event = curr_event
- self._last_raw_event = curr_event
-
- # ...not the first event
- elif self._last_raw_event != curr_event:
- self.prev_event = self._last_raw_event
- event = curr_event
-
- # cache for next time
- self._last_raw_event = curr_event
-
- return event
-
- def dispatch_event(self, sender: object, event: Event):
- """
- Watch for changes between current state
- and previous state.
-
- Dispatch events to all listeners.
- """
- for listener in self.listeners:
-
- # menu btn press/release
- if event.menu_btn != self.prev_event.menu_btn:
- listener.on_menu_down(sender)
-
- # joy btn press/release
- if event.joy_btn != self.prev_event.joy_btn:
- listener.on_joy_down(sender)
-
- # joy moved
- if (
- event.joy_x != self.prev_event.joy_x
- or event.joy_y != self.prev_event.joy_y
- ):
- listener.on_joy_moved(sender, event.joy_x, event.joy_y)
-
- # dispatch joy flicked
- # flick up
- if event.joy_y > self.flick_threshold:
- if self.flick_dir != FlickDir.Up:
- self.flick_dir = FlickDir.Up
- listener.on_flick_up(sender)
-
- # flick down
- if event.joy_y < -self.flick_threshold:
- if self.flick_dir != FlickDir.Down:
- self.flick_dir = FlickDir.Down
- listener.on_flick_down(sender)
-
- # return to center?
- if (
- event.joy_y > -self.flick_threshold
- and event.joy_y < self.flick_threshold
- ):
- if self.flick_dir != FlickDir.Center:
- self.flick_dir = FlickDir.Center
- listener.on_flick_return(sender)
diff --git a/sw/control/common/sensor.py b/sw/control/common/sensor.py
deleted file mode 100644
index e3a3e65..0000000
--- a/sw/control/common/sensor.py
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Shared interfaces
-"""
-
-import numpy as np
-from typing import Tuple
-from dataclasses import dataclass
-
-from .device import IDevice
-
-
-class ISensor:
- @dataclass
- class Config(IDevice):
- width: int = 256
- height: int = 256
-
- def __init__(self, config: Config, device: IDevice):
- self.config = config
-
- def start(self):
- pass
-
- def stop(self):
- pass
-
- def getNextInput(self, sender: IDevice) -> Tuple[float, np.ndarray]:
- return (0, [])
diff --git a/sw/control/common/vector2.py b/sw/control/common/vector2.py
deleted file mode 100644
index 19cda63..0000000
--- a/sw/control/common/vector2.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Basic 2D vector class
-"""
-
-import math
-from typing import Tuple, Optional
-
-
-class Vector2:
- x: float
- y: float
-
- def __init__(self, x: float, y: float):
- self.x = x
- self.y = y
-
- def __str__(self):
- return f"X: {self.x:2.3f}, Y: {self.y:2.3f}"
-
- def __add__(self, o: "Vector2"):
- return Vector2(self.x + o.x, self.y + o.y)
-
- def __sub__(self, o: "Vector2"):
- return Vector2(self.x - o.x, self.y - o.y)
-
- def __truediv__(self, o: float):
- return Vector2(self.x / o, self.y / o)
-
- def __mul__(self, o: float):
- return Vector2(self.x * o, self.y * o)
-
- def length(self) -> float:
- return math.sqrt(self.x ** 2 + self.y ** 2)
-
- def normalized(self):
- length = self.length()
- if length != 0.0:
- return Vector2(self.x / length, self.y / length)
- else:
- return Vector2(0, 0)
-
- def dot(self, o: "Vector2") -> float:
- return self.x * o.x + self.y * o.y
-
- def angle(self, o: "Vector2") -> float:
- return math.acos(self.dot(o) / self.length() * o.length())
-
- def distance(self, o: "Vector2") -> float:
- return (self - o).length()
-
- def rotate(self, theta: float, o: Optional["Vector2"] = None) -> "Vector2":
- """
- Return a point rotated `theta` radians around `o`
- """
- if o is None:
- o = Vector2(0, 0)
- x = o.x + math.cos(theta) * (self.x - o.x) - math.sin(theta) * (self.y - o.y)
- y = o.y + math.sin(theta) * (self.x - o.x) + math.cos(theta) * (self.y - o.y)
- return Vector2(x, y)
-
- def __iter__(self):
- yield self.x
- yield self.y
-
- def toIntTuple(self) -> Tuple[int, int]:
- return (int(self.x), int(self.y))
diff --git a/sw/control/config/__init__.py b/sw/control/config/__init__.py
deleted file mode 100644
index efc74da..0000000
--- a/sw/control/config/__init__.py
+++ /dev/null
@@ -1,12 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-import os
-
-# Both config.json and calibration.json live under "config/" relative to main.py.
-# This way, one can edit the host's config/calibration.json, then launch the container
-# overriding the container's version.
-
-config_path = os.path.abspath(f"{os.getcwd()}/config/config.json")
-moab_path = os.path.abspath(f"{os.getcwd()}/config")
-calibration_path = f"{moab_path}/calibration.json"
diff --git a/sw/control/config/orange-ball-color-map.png b/sw/control/config/orange-ball-color-map.png
deleted file mode 100644
index dc4f97b..0000000
Binary files a/sw/control/config/orange-ball-color-map.png and /dev/null differ
diff --git a/sw/control/controllers/__init__.py b/sw/control/controllers/__init__.py
deleted file mode 100644
index 88b3149..0000000
--- a/sw/control/controllers/__init__.py
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from .pid_controller import *
-from .menu_controller import *
-from .brain_controller import *
-from .huecal_controller import *
-from .joystick_controller import *
diff --git a/sw/control/controllers/brain_controller.py b/sw/control/controllers/brain_controller.py
deleted file mode 100644
index 82983fc..0000000
--- a/sw/control/controllers/brain_controller.py
+++ /dev/null
@@ -1,246 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Brain Controller
-
-Connect to a locally running brain server and
-ask for plate angles based on current hardware state.
-"""
-
-import math
-import time
-import pymoab
-import requests
-import numpy as np
-import logging as log
-from typing import Dict
-from dataclasses import dataclass
-
-from ..common import CircleFeature, IController, IDevice, Vector2
-
-
-# Some type aliases for clarity
-Plane = np.ndarray
-Ray = np.ndarray
-
-
-# Helper functions for linear algebra
-def rotation_about_x(theta):
- return np.array(
- [
- [1, 0, 0],
- [0, np.cos(theta), np.sin(theta)],
- [0, -np.sin(theta), np.cos(theta)],
- ]
- )
-
-
-def rotation_about_y(theta):
- return np.array(
- [
- [np.cos(theta), 0, -np.sin(theta)],
- [0, 1, 0],
- [np.sin(theta), 0, np.cos(theta)],
- ]
- )
-
-
-class BrainController(IController):
- """
- This class interfaces with an HTTP server running locally.
- It passes the current hardware state and gets new plate
- angles in return.
-
- The hardware state is unprojected from camera pixel space
- back to real space by using the calculated plate surface plane.
- """
-
- @dataclass
- class Config(IController.Config):
- endPoint: str = "localhost:5000"
- sensorSize: int = 256
-
- def __init__(self, config: Config, device: IDevice):
- super().__init__(config, device)
- self.config = config
-
- self.max_angle = self.config.maxAngle
- self.default_endpoint = self.config.endPoint
- self.prediction_url = f"{self.default_endpoint}/v1/prediction"
-
- self.velocity = Vector2(0, 0)
- self.prev_position = Vector2(0, 0)
- self.currPlateAngles = Vector2(0, 0)
-
- def _surface_plane(self) -> Plane:
- """
- Create a plane represent the surface of the plate
- in meters.
- """
- plate_theta_x = math.radians(self.currPlateAngles.x)
- plate_theta_y = math.radians(self.currPlateAngles.y)
-
- # get the plate normal
- x_rot = rotation_about_x(plate_theta_x)
- y_rot = rotation_about_y(plate_theta_y)
-
- # pitch then roll
- v = np.array([0.0, 0.0, 1.0]) @ x_rot @ y_rot
- plate_normal = v / np.linalg.norm(v)
-
- # create the plane
- PLATE_ORIGIN_Z = 0.020 # full range is 40mm of z-travel
- PLATE_ORIGIN_TO_SURFACE_OFFSET = 0.009 # 9mm above origin
- plate_surface = np.array(
- [0.0, 0.0, PLATE_ORIGIN_Z + PLATE_ORIGIN_TO_SURFACE_OFFSET]
- )
- return np.array([*plate_normal, np.sum(plate_normal * plate_surface)])
-
- def _detector_to_controller_units(self, pixels: CircleFeature) -> CircleFeature:
- """
- Convert a set of coordinates in pixels to meters
-
- The input is a 2D point in sensor image space.
- To get the location in meters, we need to unproject the camera
- back to the plate surface plane.
-
- We can derive the plate surface plane from the plate
- angles and distances.
- """
- # The plate is roughly 85% of the field of view
- PLATE_DIA_METERS = 0.225
- PLATE_DIA_PIXELS = self.config.sensorSize * 0.85
- scalar = PLATE_DIA_METERS / PLATE_DIA_PIXELS
-
- # basic linear transform
- meters = CircleFeature(
- Vector2(pixels.center.x * scalar, pixels.center.y * scalar),
- pixels.radius * scalar,
- )
- return meters
-
- @staticmethod
- def heading_to_point(start: Vector2, vel: Vector2, point: Vector2):
- """
- Return a heading, in 2D RH coordinate system.
- start: the current position of the object
- vel: the current velocity vector of motion for the object
- point: the destination point to head towards
-
- returns: offset angle in radians in the range [-pi .. pi]
- where:
- 0.0: object is moving directly towards the point
- [-pi .. <0]: object is moving to the "right" of the point
- [>0 .. -pi]: object is moving to the "left" of the point
- [-pi, pi]: object is moving directly away from the point
- """
- # vectors and lengths
- u = (point - start).normalized()
- v = vel.normalized()
-
- # no velocity? already on the target?
- angle = 0.0
- if (u.length() != 0.0) and (v.length() != 0.0):
- # signed angle
- cr = Vector2(-u.y, u.x)
- angle = math.atan2(cr.dot(v), u.dot(v))
- if math.isnan(angle):
- angle = 0.0
- return angle
-
- def _actions_for_state(
- self, elapsedSec: float, ball: CircleFeature, obstacle: CircleFeature
- ) -> Vector2:
- if elapsedSec > 0.0:
- self.velocity = (ball.center - self.prev_position) / elapsedSec
-
- obstacle_direction = BrainController.heading_to_point(
- ball.center, self.velocity, obstacle.center
- )
- obstacle_distance = obstacle.center.distance(ball.center) - (
- ball.radius + obstacle.radius
- )
-
- observables = {
- # BonsaiMoabSimV4
- "elapsed_time": elapsedSec,
- "plate_theta_x": math.radians(self.currPlateAngles.x),
- "plate_theta_y": math.radians(self.currPlateAngles.y),
- "ball_x": ball.center.x,
- "ball_y": ball.center.y,
- "ball_radius": ball.radius,
- "ball_vel_x": self.velocity.x,
- "ball_vel_y": self.velocity.y,
- "obstacle_x": obstacle.center.x,
- "obstacle_y": obstacle.center.y,
- "obstacle_radius": obstacle.radius,
- "obstacle_distance": obstacle_distance,
- "obstacle_direction": obstacle_direction,
- # BonsaiMoabSimV3 legacy names. delete soon
- "obstacle_pos_x": obstacle.center.x,
- "obstacle_pos_y": obstacle.center.y,
- "distance_to_obstacle": obstacle_distance,
- "direction_to_obstacle": obstacle_direction,
- }
-
- log.debug(
- f"b:{ball.center} r: {ball.radius:2.3f}, o:{obstacle.center} r: {obstacle.radius:2.3f} "
- f"do:{obstacle_distance:2.3f} hd:{math.degrees(obstacle_direction):2.1f}"
- )
-
- # Trap on GET failures so we can restart the brain without
- # bringing down this run loop. Plate will default to level
- # when it loses the connection.
- result = Vector2(0, 0)
- try:
- action = requests.get(self.prediction_url, json=observables).json()
-
- for key, _ in action.items():
- action[key] *= self.max_angle
- action[key] = np.clip(action[key], -self.max_angle, self.max_angle)
-
- self.prev_position = ball.center
- result = Vector2(action["input_pitch"], action["input_roll"])
- except Exception as e:
- log.exception(f"Exception calling predictor\n{e}")
- pass
-
- return result
-
- def on_menu_down(self, sender: IDevice):
- sender.stop()
-
- # Hover the plate and deactivate the servos
- pymoab.hoverPlate()
- pymoab.sync()
- time.sleep(0.5)
- pymoab.disableServoPower()
- pymoab.sync()
- time.sleep(0.5)
-
- def getControlOutput(
- self,
- sender: IDevice,
- elapsedSec: float,
- detectorResults: Dict[str, CircleFeature],
- currPlateAngles: Vector2,
- ) -> Vector2:
- # Calculate plate position using controller-specific factors
- self.currPlateAngles = currPlateAngles
-
- ball_real = CircleFeature(Vector2(0, 0), 0.0)
- detected = detectorResults.get("ball")
- if detected is not None:
- ball = CircleFeature(detected.center, detected.radius)
- ball_real = self._detector_to_controller_units(ball)
-
- # Unpack and convert the obstacle if present
- obstacle_real = CircleFeature(Vector2(0, 0.03), 0.020)
- detected = detectorResults.get("obstacle")
- if detected is not None:
- obstacle = CircleFeature(detected.center, detected.radius)
- obstacle_real = self._detector_to_controller_units(obstacle)
-
- plate_angles = self._actions_for_state(elapsedSec, ball_real, obstacle_real)
- return plate_angles
diff --git a/sw/control/controllers/huecal_controller.py b/sw/control/controllers/huecal_controller.py
deleted file mode 100644
index baa1691..0000000
--- a/sw/control/controllers/huecal_controller.py
+++ /dev/null
@@ -1,267 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Calibration Controller
-
-Use CalibrationDetector and perform calibration for plate and ball detection
-"""
-
-import json
-import os
-import pwd
-import math
-import logging as log
-from copy import copy
-from enum import Enum
-from time import sleep
-from dataclasses import asdict
-from typing import Dict, Optional, cast
-
-import pymoab
-
-from ..device import Device
-from ..detectors import HSVDetector
-from ..common.common import CircleFeature
-from ..config import calibration_path, moab_path
-from ..common import IController, IDevice, Vector2
-
-
-class CalibrationState(Enum):
- Start = 0
- WaitUser = 1
- CalibrateHue = 3
- CalibratePos = 4
- Cancel = 5
- Success = 6
- Failure = 7
-
-
-class HueCalibrationController(IController):
- def __init__(self, config: IController.Config, device: IDevice):
- super().__init__(config, device)
- self.config = config
-
- # plate must be level
- pymoab.setPlateAngles(0, 0)
-
- # initial state
- self.state = CalibrationState.Start
- self.found_ball = False
- self.hue_low = 180
- self.hue_high = 0
- self.hue_steps = 20
-
- # make a copy for the new settings
- self.calibration = device.calibration
- self.new_calibration = copy(device.calibration)
- self.ball_detector: Optional[HSVDetector] = None
-
- # cancel without calibrating
- def on_menu_down(self, sender: IDevice):
- self.state = CalibrationState.Cancel
- sender.stop()
-
- # Hover the plate and deactivate the servos
- pymoab.hoverPlate()
- pymoab.sync()
- sleep(0.5)
- pymoab.disableServoPower()
- pymoab.sync()
- sleep(0.5)
-
- def on_joy_down(self, sender: IDevice):
- if self.state == CalibrationState.WaitUser:
- self.state = CalibrationState.CalibrateHue
-
- def getControlOutput(
- self,
- sender: Device,
- elapsedSec: float,
- detectorResults: Dict[str, CircleFeature],
- currPlateAngles: Vector2,
- ) -> Vector2:
- """
- This state machine asks the user to place the ball in the center of the plate.
-
- - It then sweeps through the Hue spectrum looking for balls of different colors.
- - It takes the center average of the found balls by color and uses that as the
- ballHue.
- - It then uses that hue to find the center of the ball, which becomes the new plate center.
- """
- # init
- if self.ball_detector is None:
- self.ball_detector = cast(HSVDetector, sender.detectors["ball"])
-
- # make sure we don't use the last calibration settings
- # while trying to find the current calibration settings
- self.ball_detector.calibration.plateXOffset = 0.0
- self.ball_detector.calibration.plateYOffset = 0.0
-
- if self.state == CalibrationState.Start:
- self._start_calibration()
-
- # walk each hue and try and detect a ball
- if self.state == CalibrationState.CalibrateHue:
- result = detectorResults.get("ball", None)
- frameSize = sender.sensor.config.height
- self._calibrate_hue(result, frameSize)
-
- # once we've found a ball hue, find the center
- if self.state == CalibrationState.CalibratePos:
- result = detectorResults.get("ball", None)
- frameSize = sender.sensor.config.height
- self._calibrate_pos(result, frameSize)
-
- # user cancelled
- if self.state == CalibrationState.Cancel:
- pass
-
- # found a ball, write out hue
- if self.state == CalibrationState.Success:
- self._calibration_success(sender)
-
- # detect failed
- if self.state == CalibrationState.Failure:
- self._calibration_failure(sender)
-
- return Vector2(0, 0)
-
- def _start_calibration(self):
- if self.ball_detector:
- pymoab.setIcon(pymoab.Icon.BLANK)
- pymoab.setText(pymoab.Text.CAL_INSTR)
-
- # start search here
- self.found_ball = False
- self.hue_low = 180
- self.hue_high = 0
- self.hue_steps = 20
- self.count = 0
- self.ball_detector.config.hue = int(180 / self.hue_steps)
- self.state = CalibrationState.WaitUser
-
- def _ball_close_enough(self, feature: Optional[CircleFeature], frameSize: int):
- centerX = feature.center.x / frameSize
- centerY = feature.center.y / frameSize
- radius = feature.radius / frameSize
-
- # reject balls which are too far from the center and too small
- MAX_BALL_DIST = 0.2
- MIN_BALL_SIZE = 0.05
- return (
- math.fabs(centerX) < MAX_BALL_DIST
- and math.fabs(centerY) < MAX_BALL_DIST
- and radius > MIN_BALL_SIZE
- )
-
- def _calibrate_hue(self, result: Optional[CircleFeature], frameSize: int):
- # if we found a ball roughly in the center and large enough...
- if result and self._ball_close_enough(result, frameSize):
- self.found_ball = True
-
- self.hue_low = min(self.hue_low, self.ball_detector.config.hue)
- self.hue_high = max(self.hue_high, self.ball_detector.config.hue)
-
- # rotate through hues
- self.ball_detector.config.hue += int(180 / self.hue_steps)
-
- # after we've swept the whole hue range...
- if self.ball_detector.config.hue >= 180:
- log.info(f"Hue range: [{self.hue_low} .. {self.hue_high}]")
- if self.found_ball:
- # use the center of the detected ball hues
- self.new_calibration.ballHue = int((self.hue_low + self.hue_high) / 2)
- log.info(f"Hue calibrated: {self.new_calibration.ballHue}")
-
- # set up the hue for the position calibration
- self.ball_detector.config.hue = self.new_calibration.ballHue
- self.found_ball = False
- self.state = CalibrationState.CalibratePos
- else:
- log.warn(f"Hue calibrated failed.")
- self.state = CalibrationState.Failure
-
- def _calibrate_pos(self, result: Optional[CircleFeature], frameSize: int):
- if result:
- # if we found a ball roughly in the center and large enough...
- if self._ball_close_enough(result, frameSize):
- self.found_ball = True
-
- # center of plate is in range [-frameSize/2 .. frameSize/2]
- centerX = result.center.x / frameSize
- centerY = result.center.y / frameSize
-
- self.new_calibration.plateXOffset = round(centerX, 3)
- self.new_calibration.plateYOffset = round(centerY, 3)
- log.info(
- f"Offset calibrated: [{self.new_calibration.plateXOffset:.3f}, {self.new_calibration.plateYOffset:.3f}]"
- )
-
- self.state = CalibrationState.Success
-
- # try and detect for 20 frames before giving up
- elif self.count > 20:
- log.warn(f"Offset calibrated failed.")
- self.state = CalibrationState.Failure
-
- self.count += 1
-
- def _calibration_success(self, sender: Device):
- log.info("Calibration Success.")
- self._print_results()
- self._write_calibration(sender)
-
- pymoab.setIcon(pymoab.Icon.CHECK)
- pymoab.setText(pymoab.Text.CAL_COMPLETE)
- pymoab.sync()
- sleep(2)
-
- sender.stop()
-
- def _calibration_failure(self, sender: Device):
- log.warn("Failed to calibrate.")
- self._print_results()
-
- pymoab.setIcon(pymoab.Icon.BLANK)
- pymoab.setText(pymoab.Text.ERROR)
- pymoab.sync()
- sleep(2)
-
- sender.stop()
-
- def _print_results(self):
- log.info(
- f"center:[{self.new_calibration.plateXOffset}, {self.new_calibration.plateYOffset}] "
- f"hue: {self.new_calibration.ballHue}"
- )
-
- def _write_calibration(self, sender: Device):
- log.info("write_calibration")
- # move the values from new_calibration to calibration
- # gotta be careful not to move the *instance*, but the values
- self.calibration.plateXOffset = self.new_calibration.plateXOffset
- self.calibration.plateYOffset = self.new_calibration.plateYOffset
- self.calibration.ballHue = self.new_calibration.ballHue
-
- # Moab controller runs as root (simply for SPI access)
- # but we want to save confg as user so its editable by the "pi" user
- # Better solution is to get from Dockerfile ENV variable or infer
- # from existing folder permissions, but for now,
- # 1000:1000 is the well-known default "pi" user in Raspbian
- uid = 1000
- gid = 1000
-
- # create `.moab` if it doesn't exist
- if not os.path.exists(moab_path):
- os.makedirs(moab_path)
- log.info(f"Creating folder {moab_path}")
- os.chown(moab_path, uid, gid)
-
- # write out stuff
- with open(calibration_path, "w+") as outfile:
- log.info(f"Creating calibration file {calibration_path}")
- json.dump(asdict(self.calibration), outfile, indent=4, sort_keys=True)
-
- # set permisions so user can use
- os.chown(calibration_path, uid, gid)
diff --git a/sw/control/controllers/joystick_controller.py b/sw/control/controllers/joystick_controller.py
deleted file mode 100644
index ec4eb98..0000000
--- a/sw/control/controllers/joystick_controller.py
+++ /dev/null
@@ -1,52 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Joystick Controller
-
-Use joystick input to control the plate directly.
-"""
-
-from time import sleep
-from typing import Dict
-
-import time
-import pymoab
-
-from ..common import IController, IDevice, CircleFeature, Vector2
-
-
-class JoystickController(IController):
- def __init__(self, config: IController.Config, device: IDevice):
- super().__init__(config, device)
- self.config = config
- self.joystick = Vector2(0, 0)
-
- def on_menu_down(self, sender: IDevice):
- sender.stop()
-
- # Hover the plate and deactivate the servos
- pymoab.hoverPlate()
- pymoab.sync()
- sleep(0.5)
- pymoab.disableServoPower()
- pymoab.sync()
- sleep(0.5)
-
- def on_joy_moved(self, sender: object, x: float, y: float):
- self.joystick = Vector2(-y, x)
-
- def getControlOutput(
- self,
- sender: IDevice,
- elapsedSec: float,
- detectorResults: Dict[str, CircleFeature],
- currPlateAngles: Vector2,
- ) -> Vector2:
-
- # Without this sleep (for 90% of our update period), input polling
- # will return zeros intermittently and the actuator will twitch
- update_timestep = 1.0 / sender.config.frequencyHz
- sleep(update_timestep - 0.1 * update_timestep)
-
- return self.joystick * self.config.maxAngle
diff --git a/sw/control/controllers/menu_controller.py b/sw/control/controllers/menu_controller.py
deleted file mode 100644
index a7902a0..0000000
--- a/sw/control/controllers/menu_controller.py
+++ /dev/null
@@ -1,70 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Menu Controller
-
-Use joystick to navigate between other controllers.
-"""
-
-from typing import ClassVar, List
-from dataclasses import dataclass, field
-
-import pymoab
-
-from ..common import IController, IDevice
-
-
-@dataclass
-class MenuItem:
- icon: str = ""
- text: str = ""
- device: str = ""
- icon2: str = ""
-
-
-class MenuController(IController):
- @dataclass
- class Config(IController.Config):
- menuItems: List[MenuItem] = field(
- default_factory=lambda: [
- MenuItem("DOWN", "MANUAL", "manual", "DOT"),
- MenuItem("UP_DOWN", "CLASSIC", "classic", "DOT"),
- MenuItem("UP_DOWN", "BRAIN", "brain", "DOT"),
- MenuItem("UP_DOWN", "CUSTOM1", "custom1", "DOT"),
- MenuItem("UP_DOWN", "CUSTOM2", "custom2", "DOT"),
- MenuItem("UP", "CAL", "calibration", "BLANK"),
- ]
- )
-
- def __init__(self, config: Config, device: IDevice):
- super().__init__(config, device)
- self.config = config
-
- self.menu_items = self.config.menuItems
- self.menu_idx = device.previous_menu
-
- self.display_menu_item(self.menu_idx)
-
- def display_menu_item(self, idx: int):
- pymoab.setIcon(pymoab.Icon[self.menu_items[idx].icon])
- pymoab.setText(pymoab.Text[self.menu_items[idx].text])
-
- def on_flick_down(self, sender: IDevice):
- self.menu_idx = min(len(self.menu_items) - 1, self.menu_idx + 1)
- self.display_menu_item(self.menu_idx)
-
- def on_flick_up(self, sender: IDevice):
- self.menu_idx = max(0, self.menu_idx - 1)
- self.display_menu_item(self.menu_idx)
-
- def on_joy_down(self, sender: IDevice):
- menu_item = self.menu_items[self.menu_idx]
- sender.set_next_device(menu_item.device)
- pymoab.setIcon(pymoab.Icon[menu_item.icon2])
- pymoab.setText(pymoab.Text[menu_item.text])
-
- # save the menu item so we pop back up to this index when we return
- sender.previous_menu = self.menu_idx
-
- sender.stop()
diff --git a/sw/control/controllers/pid_controller.py b/sw/control/controllers/pid_controller.py
deleted file mode 100644
index 4227ea2..0000000
--- a/sw/control/controllers/pid_controller.py
+++ /dev/null
@@ -1,156 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-PID Controller
-
-proportional–integral–derivative feed-back algorithm to control
-the plate angles.
-"""
-
-import time
-import numpy as np
-from typing import Dict
-from enum import IntEnum
-from dataclasses import dataclass
-
-import pymoab
-
-from ..common import IController, IDevice, CircleFeature, Vector2
-
-
-class Axis(IntEnum):
- X = 0
- Y = 1
-
-
-class HighPassFilter(object):
- def __init__(self, frequency, fc=50):
- self.x_dot_cstate = 0
- self.frequency = frequency
- self.fc = fc
-
- def reset(self):
- self.x_dot_cstate = 0
-
- def __call__(self, x):
- x_dot = -(self.fc ** 2) * self.x_dot_cstate + self.fc * x
- self.x_dot_cstate += (-self.fc * self.x_dot_cstate + x) / self.frequency
- return x_dot
-
-
-class PIDController(IController):
- """PID controller class.
-
- This class handles the classic control calculations for ball balancing when
- in vision mode. In general, the following formulas are used for calculating
- appropriate values:
-
- # -----------------------------------------
- # Find velocity | velocity_x = (previous_x - current_x) / elapsedSec
- # Predict position | predicted_x = current_x + (velocity_x * time_step_future)
- # Find new error | error_prediction = set_point_x - predicted_x
- # Set previous error point | error_prediction_prev = error_prediction
- # Sum of errors | sum_error_prediction += error_prediction
- # -----------------------------------------
-
- """
-
- @dataclass
- class Config(IController.Config):
- Kp: float = 0.15
- Ki: float = 0.001
- Kd: float = 0.090
- conversionFactor: float = 2.375
- fc: float = 15 # Cutoff frequency of the high pass filter
- frequency: float = 30
-
- def __init__(self, config: Config, device: IDevice):
- super().__init__(config, device)
- self.config = config
-
- self.velocity = [0, 0]
- self.set_point = [0, 0]
- self.predicted = [0, 0]
- self.prev_position = [0, 0]
- self.error_prediction = [0, 0]
- self.sum_error_prediction = [0.0, 0.0]
- self.lastElapsedMs = 0
-
- # Use a high pass filter instead of a numerical derivative for stability
- filter_x = HighPassFilter(self.config.frequency, self.config.fc)
- filter_y = HighPassFilter(self.config.frequency, self.config.fc)
- self.filters = [filter_x, filter_y]
-
- def determine_theta(self, elapsedSec: float, position: float, axis: Axis) -> float:
- """Calculate desired angle of plate to balance ball.
-
- Args:
- position ([int, int]): The current x,y position of the ball.
- elapsedSec (float): The interval of time that has elapsed.
- axis (int): The axis in which to calulate (0 = x, 1 = y)
-
- Returns:
- Calculated angle to balance ball.
-
- """
- prod = np.clip(
- self.config.Kp * position, -self.config.maxAngle, self.config.maxAngle
- )
- inte = np.clip(
- self.config.Ki * self.sum_error_prediction[axis],
- -self.config.maxAngle,
- self.config.maxAngle,
- )
- # High pass filtered signal can be thought of as a derivative of a low
- # pass filtered signal: fc*s / (s + fc) = fc*s * 1 / (s + fc)
- # For more info: https://en.wikipedia.org/wiki/Differentiator
- # Or: https://www.youtube.com/user/ControlLectures/
- derv = np.clip(
- self.config.Kd * self.filters[axis](position),
- -self.config.maxAngle,
- self.config.maxAngle,
- )
- theta = prod + inte + derv
- theta_final = np.clip(theta, -self.config.maxAngle, self.config.maxAngle)
-
- self.sum_error_prediction[axis] += position
- return theta_final
-
- def detector_to_controller_units(self, ball_pos: Vector2) -> Vector2:
- return ball_pos / self.config.conversionFactor
-
- def on_menu_down(self, sender: IDevice):
- sender.stop()
-
- # Hover the plate and deactivate the servos
- pymoab.hoverPlate()
- pymoab.sync()
- time.sleep(0.5)
- pymoab.disableServoPower()
- pymoab.sync()
- time.sleep(0.5)
-
- def getControlOutput(
- self,
- sender: IDevice,
- elapsedSec: float,
- detectorResults: Dict[str, CircleFeature],
- currPlateAngles: Vector2,
- ) -> Vector2:
- """Calculate plate adjustment values based on current position to balance ball.
-
- Returns:
- Adjusted (theta) x,y values resulting from calculations.
- """
- ball = detectorResults.get("ball")
- if ball:
- # Calculate plate position using controller-specific factors
- ball_pos_real = self.detector_to_controller_units(ball.center)
-
- Tx = self.determine_theta(elapsedSec, ball_pos_real.y, Axis.Y)
- Ty = -self.determine_theta(elapsedSec, ball_pos_real.x, Axis.X)
-
- return Vector2(Tx, Ty)
- else:
- return Vector2(0, 0)
diff --git a/sw/control/debug.py b/sw/control/debug.py
deleted file mode 100644
index eeca913..0000000
--- a/sw/control/debug.py
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-import cv2
-
-from .common import IDebugDecorator
-
-
-SENSOR_IMG_ARG = "sensor_img"
-
-
-class CallbackDecorator(IDebugDecorator):
- def __init__(self, config: dict):
- super().__init__(config)
- self.callbacks = []
-
- def addCallback(self, fn):
- self.callbacks.append(fn)
-
- def decorate(self, args):
- for callback in self.callbacks:
- callback(args)
-
-
-class X11Decorator(CallbackDecorator):
- def __init__(self, config: dict):
- super().__init__(config)
-
- cv2.namedWindow(self.config["windowName"])
-
- def decorate(self, args):
- super().decorate(args)
-
- cv2.imshow(self.config["windowName"], args[SENSOR_IMG_ARG])
- cv2.waitKey(1) & 0xFF
-
- def __del__(self):
- cv2.destroyAllWindows()
diff --git a/sw/control/detectors/__init__.py b/sw/control/detectors/__init__.py
deleted file mode 100644
index 4292e60..0000000
--- a/sw/control/detectors/__init__.py
+++ /dev/null
@@ -1,4 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from .hsv_detector import *
diff --git a/sw/control/detectors/hsv_detector.py b/sw/control/detectors/hsv_detector.py
deleted file mode 100644
index 37b479f..0000000
--- a/sw/control/detectors/hsv_detector.py
+++ /dev/null
@@ -1,131 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-HSV filtering ball detector
-"""
-
-import math
-from typing import List, Optional
-from dataclasses import dataclass, field
-
-import cv2
-import numpy as np
-from pymoab import hue_mask
-
-from ..common import CircleFeature, IDetector, IDevice, Vector2
-from ..debug import *
-from ..device import Device
-from ..perfcounters import (
- FrequencyCounter,
- WindowedAverageCounter,
- PerformanceCounters as counter,
-)
-
-
-class HSVDetector(IDetector):
- @dataclass
- class Config(IDetector.Config):
- kernelSize: List[int] = field(default_factory=lambda: [5, 5])
- ballMin: float = 0.06
- ballMax: float = 0.22
- debug: bool = False
- hue: Optional[int] = None # hue [0..255]
- sigma: float = 0.05 # narrow: 0.01, wide: 0.1
- bandpassGain: float = 12.0
- maskGain: float = 4.0
-
- def __init__(self, config: Config, device: IDevice):
- super().__init__(config, device)
- self.config = config
- self.calibration = device.calibration
-
- # if we haven't been overridden, use ballHue from
- # the calibration settings.
- if self.config.hue is None:
- self.config.hue = self.calibration.ballHue
-
- self.kernel = cv2.getStructuringElement(
- cv2.MORPH_ELLIPSE, tuple(self.config.kernelSize)
- )
-
- if device.debug_decorator is not None:
- self.x_obs = 0
- self.y_obs = 0
- self.lastDetected = CircleFeature()
- device.debug_decorator.addCallback(self._debugDraw)
-
- def _debugDraw(self, args):
- img = args[SENSOR_IMG_ARG]
- f = self.lastDetected
- if f is not None:
- center = (int(self.x_obs), int(self.y_obs))
- cv2.circle(img, center, 2, (255, 0, 255), 2)
- cv2.circle(img, center, int(f.radius), (255, 0, 255), 2)
-
- def detect(
- self, sender: Device, img: np.ndarray, plate_angles: Vector2
- ) -> CircleFeature:
- if img is not None:
- # covert to HSV space
- color = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
-
- # 0 == red
- if self.config.hue is None:
- self.config.hue = 0
-
- # run through each triplet and perform our masking filter on it.
- # hue_mask coverts the hsv image into a grayscale image with a
- # bandpass applied centered around hue, with width sigma
- hue_mask(
- color,
- self.config.hue,
- self.config.sigma,
- self.config.bandpassGain,
- self.config.maskGain,
- )
-
- # convert to b&w mask from grayscale image
- mask = cv2.inRange(
- color, np.array((200, 200, 200)), np.array((255, 255, 255))
- )
-
- # expand b&w image with a dialation filter
- mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, self.kernel)
-
- contours = cv2.findContours(
- mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]
-
- if len(contours) > 0:
- contour_peak = max(contours, key=cv2.contourArea)
- ((self.x_obs, self.y_obs), radius) = cv2.minEnclosingCircle(
- contour_peak
- )
-
- # Determine if ball size is the appropriate size
- frameSize = sender.sensor.config.height
- norm_radius = radius / frameSize
- if self.config.ballMin < norm_radius < self.config.ballMax:
- counter.update("hit", 1, FrequencyCounter)
-
- # rotate the center coords into sensor coords
- # the ball detector uses rotate coordinates, so we must as well
- rot_center = Vector2(
- self.calibration.plateXOffset, self.calibration.plateYOffset
- ).rotate(math.radians(-self.calibration.rotation))
-
- x_center = (rot_center.x + 0.5) * frameSize
- y_center = (rot_center.y + 0.5) * frameSize
-
- # Convert from pixels to absolute with 0,0 as center of detected plate
- x = self.x_obs - x_center
- y = self.y_obs - y_center
- self.lastDetected = CircleFeature(Vector2(x, y), radius)
- return self.lastDetected
- else:
- counter.update("miss", 1, FrequencyCounter)
-
- counter.update("hit", 0, FrequencyCounter)
- counter.update("miss", 0, FrequencyCounter)
-
- return CircleFeature()
diff --git a/sw/control/device.py b/sw/control/device.py
deleted file mode 100644
index b24d8d6..0000000
--- a/sw/control/device.py
+++ /dev/null
@@ -1,177 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-import numpy as np
-from enum import Enum
-from pydoc import locate
-from typing import Any, Callable, Dict, Optional, cast
-
-import pymoab
-
-from .debug import *
-from .timers import BusyTimer
-from .common.event import EventDispatcher
-from .perfcounters import WindowedAverageCounter, PerformanceCounters as counter
-from .common import IActuator, IController, IDetector, IDevice, ISensor, Vector2
-
-InputHandler = Callable[[bool, bool, int, int], None]
-
-
-class JoystickYDir(Enum):
- Unset = 0
- Center = 0
- Up = 1
- Down = 2
-
-
-class Device(IDevice):
- def __init__(
- self,
- config: IDevice.Config,
- calibration: IDevice.Calibration,
- inputHandler: InputHandler = None,
- debugDecorator: Optional[IDebugDecorator] = None,
- ):
- super().__init__(config, calibration, debugDecorator)
- self.config = config
-
- self.inputHandler = inputHandler
-
- self.sensor: Optional[ISensor] = None
- self.detectors: Optional[Dict[str, IDetector]] = None
- self.controller: Optional[IController] = None
- self.actuator: Optional[IActuator] = None
-
- self.runloop = BusyTimer()
- self.running = False
-
- # listeners get added in createFromConfig...
- self.events = EventDispatcher()
-
- def update(self):
-
- # get input IO and dispatch it to listeners
- event = self.events.get_next_event()
- if event is not None:
- self.events.dispatch_event(self, event)
-
- # check if we should still run after processing events
- if self.runloop.running:
- # get sensor data
- elapsedSec: float = 0
- img: Optional[np.ndarray] = None
-
- if self.sensor:
- counter.start("sensor", WindowedAverageCounter)
- elapsedSec, img = self.sensor.getNextInput(self)
- counter.stop()
-
- # fetch previous plate angles if we have an actuator
- lastPlateAngles = Vector2(0, 0)
- if self.actuator:
- lastPlateAngles = self.actuator.getLastSetPlateAngles()
-
- # pass sensor output to various detectors
- detectorResults: Dict[str, Any] = {}
- if self.detectors and img is not None:
- for detectorName in self.detectors:
- detector = self.detectors[detectorName]
-
- counter.start(detectorName, WindowedAverageCounter)
- feature = detector.detect(self, img, lastPlateAngles)
- detectorResults[detectorName] = detector.post_detect(feature)
- counter.stop()
-
- # run the controller
- output = self.controller.getControlOutput(
- self, elapsedSec, detectorResults, lastPlateAngles
- )
-
- # actuate
- if self.actuator:
- self.actuator.setPlateAngles(self, output)
-
- # and execute debuging decorators
- if self.config.debug:
- if self.debug_decorator is not None:
- self.debug_decorator.decorate({SENSOR_IMG_ARG: img})
-
- # sync our desired state with servos and display
- pymoab.sync()
-
- def run(self):
- if self.sensor:
- self.sensor.start()
-
- # The control loop needs to run slightly faster than the camera capture rate.
- # The camera capture rate needs to be slightly slower than the controller execution time.
- #
- # If they run too close together the camera may give us stale frames and the controllers
- # will lose stability (positive feedback loop that causes the ball to drop).
- #
- # Suggest improvement to sync with the video capture buffer instead
- controlHz = self.config.frequencyHz + 5
- self.runloop.start(1.0 / (controlHz), self.update)
-
- def stop(self):
- self.runloop.stop()
- if self.sensor:
- self.sensor.stop()
-
- @staticmethod
- def createFromConfig(
- config: IDevice.Config,
- calibration: IDevice.Calibration,
- inputHandler: InputHandler = None,
- ) -> Optional[IDevice]:
-
- # optional debug decorator
- debug_decorator: Optional[IDebugDecorator] = None
- if config.debug and config.debugDecorator:
- debug_class = cast(dict, config.debugDecorator)["name"]
- decorator_ref = locate(debug_class, forceload=True)
- debug_decorator = decorator_ref(config.debugDecorator) # type: ignore
-
- # create device
- device = Device(config, calibration, inputHandler, debug_decorator)
-
- # sensor
- sensor: Optional[ISensor] = None
- if config.sensor:
- sensor = cast(ISensor, device.component_from_config(config.sensor),)
-
- # unpack the detectors
- detectors: Optional[Dict[str, IDetector]] = None
- if config.detectors:
- detectors = {}
- for name in cast(dict, config.detectors):
- detector_config = config.detectors[name]
- detector = cast(
- IDetector, device.component_from_config(detector_config)
- )
- detectors[name] = detector
-
- # controller
- controller: Optional[IController] = None
- if config.controller:
- controller = cast(
- IController, device.component_from_config(config.controller),
- )
-
- # register for events
- device.events.listeners.append(controller)
- else:
- raise Exception("You must specifiy a controller")
-
- # actuator
- actuator: Optional[IActuator] = None
- if config.actuator:
- actuator = cast(IActuator, device.component_from_config(config.actuator),)
-
- # set 'em
- device.sensor = sensor
- device.detectors = detectors
- device.controller = controller
- device.actuator = actuator
-
- return device
diff --git a/sw/control/perfcounters.py b/sw/control/perfcounters.py
deleted file mode 100644
index 7bd677d..0000000
--- a/sw/control/perfcounters.py
+++ /dev/null
@@ -1,161 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Performance counters
-"""
-
-import time
-import logging as log
-from enum import Enum
-from collections import deque
-from dataclasses import dataclass
-from typing import Deque, Optional
-
-
-class Evolution(Enum):
- Sample = 0
- CumulativeMovingAverage = 1
- WindowedAverage = 2
- FPSCounter = 3
-
-
-@dataclass
-class TimingContext:
- name: str
- startTime: float
- evolution: type
-
-
-class CounterBase:
- def update(self, value: float):
- pass
-
-
-class SamplingCounter(CounterBase):
- """
- Show the most recent value.
- """
-
- def __init__(self):
- self.value: float = 0.0
-
- def update(self, value: float):
- self.value = value
-
-
-class FrequencyCounter(CounterBase):
- """
- Do a frequency count.
-
- call counter.update(1) to add one.
- call counter.update(0) to add none.
- """
-
- def __init__(self):
- self.value: float = 0.0
- self.count: float = 0.0
- self.time_window = 1.0
- self.t_start = time.perf_counter()
-
- def update(self, value: float):
- t_now = time.perf_counter()
- if t_now - self.t_start > self.time_window:
- self.value = self.count
- self.count = 0.0
- self.t_start = t_now
-
- self.count += value
-
-
-class CumulativeMovingAverageCounter(CounterBase):
- """
- Do a moving average of the updated values.
- """
-
- def __init__(self):
- self.value: float = 0.0
- self.count: int = 0
-
- def update(self, value: float):
- if self.count is 0:
- self.value = value
- else:
- self.value = (value + self.count * self.value) / (self.count + 1)
- self.count += 1
-
-
-class WindowedAverageCounter(CounterBase):
- """
- Do windowed average of the updated values.
- """
-
- def __init__(self, window: int = 10):
- self.deque = deque(maxlen=window)
- self.value: float = 0.0
-
- def update(self, value: float):
- self.deque.append(value)
- self.value = sum(self.deque) / len(self.deque)
-
-
-class PerfCounters:
- _instance: Optional["PerfCounters"] = None
-
- # def __new__(cls, *args, **kwargs):
- # # Singleton pattern. Insure we only ever get one of these per module load.
- # if cls._instance is None:
- # cls._instance = super(PerfCounters, cls).__new__(cls)
- # return cls._instance
-
- def __init__(self):
- self.contextStack: Deque[TimingContext] = deque()
- self.counters = {}
-
- def start(self, context: str, evolution: type, **kwArgs):
- self.contextStack.append(TimingContext(context, time.perf_counter(), evolution))
-
- def stop(self):
- context = self.contextStack.pop()
- elapsedSec = time.perf_counter() - context.startTime
- counter = self.counters.get(context.name, None)
- if counter is None:
- counter = context.evolution()
- self.counters[context.name] = counter
-
- self.counters[context.name].update(elapsedSec)
-
- def update(self, context_name: str, value: float, context_evolution: type):
- """
- Do a single update. Useful for counters which don't start/stop
- """
- counter = self.counters.get(context_name, None)
- if counter is None:
- counter = context_evolution()
- self.counters[context_name] = counter
-
- self.counters[context_name].update(value)
-
- def logCounters(self, *names, level: int = log.INFO):
- global perf_logger
-
- message = ""
- for name in names:
- counter = self.counters.get(name, None)
- if counter is not None:
- message += f"{name}: {counter.value:.3f} "
- perf_logger.log(level, message)
-
- def logAllCounters(self, level: int = log.INFO):
- global perf_logger
-
- message = ""
- for name, counter in self.counters.items():
- if counter is not None:
- message += f"{name}: {counter.value:.3f} "
- perf_logger.log(level, message)
-
-
-perf_logger = log.getLogger("performance")
-perf_logger.propagate = False
-PerformanceCounters = PerfCounters()
diff --git a/sw/control/sensors/__init__.py b/sw/control/sensors/__init__.py
deleted file mode 100644
index 4a99c72..0000000
--- a/sw/control/sensors/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-from .opencv_sensor import *
-from .picamera_sensor import *
diff --git a/sw/control/sensors/opencv_sensor.py b/sw/control/sensors/opencv_sensor.py
deleted file mode 100644
index f5e9104..0000000
--- a/sw/control/sensors/opencv_sensor.py
+++ /dev/null
@@ -1,137 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-A sensor that uses OpenCV for capture
-"""
-
-from dataclasses import dataclass
-from ..common import ISensor, IDevice
-
-import cv2
-import threading
-import numpy as np
-
-from time import time
-from typing import Tuple, Optional
-
-
-# Link to raspicam_cv implementation for mapping values
-# https://github.com/cedricve/raspicam/blob/651c56418a5a594fc12f1414eb14f2b899729cb1/src/raspicam_cv.h#L108
-
-class OpenCVCameraSensor(ISensor):
- @dataclass
- class Config(ISensor.Config):
- deviceId: int = 0
- width: int = 256
- height: int = 256
- rotation: float = 0
- brightness: int = 50
- contrast: int = 100
- saturation: int = 100
- gain: int = 100
- fps: Optional[int] = None
-
- def __init__(self, config: Config, device: IDevice):
- super().__init__(config, device)
- self.config = config
- self.prevTime = 0.0
-
- # set the camera capture frequency to the control frequency
- if self.config.fps is None:
- self.fps = device.config.frequencyHz
- else:
- self.fps = self.config.fps
-
- self.source: Optional[cv2.VideoCapture] = None
- self.last_frame: Optional[np.ndarray] = None
-
- # move init_debug into X11 debug handler version only
- # self._init_debug(device)
-
- def start(self):
- self.source = cv2.VideoCapture(self.config.deviceId)
- if self.source:
- self.source.set(cv2.CAP_PROP_FRAME_WIDTH, self.config.width)
- self.source.set(cv2.CAP_PROP_FRAME_HEIGHT, self.config.height)
- self.source.set(cv2.CAP_PROP_FPS, self.fps)
-
- # Not meant to be configurable
- self.source.set(cv2.CAP_PROP_MODE, 0)
-
- # initial settings
- self.setBrightness(self.config.brightness)
- self.setContrast(self.config.contrast)
- self.setSaturation(self.config.saturation)
- self.setGain(self.config.gain)
- else:
- raise Exception("Couldn't create camera.")
-
- def stop(self):
- if self.source:
- self.source.release()
- self.source = None
-
- def getNextInput(self, sender: IDevice) -> Tuple[float, Optional[np.ndarray]]:
- # safety check
- if self.source is None:
- raise Exception("Using camera before it has been started.")
-
- # Calculate the time elapsed since the last sensor snapshot
- currTime = time()
- elapsedTime = currTime - self.prevTime
- self.prevTime = currTime
-
- ret, frame = self.source.read()
- if ret:
- return elapsedTime, frame
-
- return elapsedTime, None
-
- def setBrightness(self, b: int):
- self.config.brightness = b
- if self.source:
- self.source.set(cv2.CAP_PROP_BRIGHTNESS, self.config.brightness)
-
- def setContrast(self, c: int):
- self.config.contrast = c
- if self.source:
- self.source.set(cv2.CAP_PROP_CONTRAST, self.config.contrast)
-
- def setSaturation(self, s: int):
- self.config.saturation = s
- if self.source:
- self.source.set(cv2.CAP_PROP_CONTRAST, self.config.saturation)
-
- def setGain(self, g: int):
- self.config.gain = g
- if self.source:
- self.source.set(cv2.CAP_PROP_CONTRAST, self.config.gain)
-
- # debug stuff
- def _init_debug(self, device: IDevice):
- if device.config.debug and device.debug_decorator:
- cv2.createTrackbar(
- "brightness",
- "frame",
- self.config.brightness,
- 100,
- lambda b: self.setBrightness(b),
- )
- cv2.createTrackbar(
- "contrast",
- "frame",
- self.config.contrast,
- 100,
- lambda c: self.setContrast(c),
- )
- cv2.createTrackbar(
- "saturation",
- "frame",
- self.config.saturation,
- 100,
- lambda c: self.setSaturation(c),
- )
- cv2.createTrackbar(
- "gain", "frame", self.config.gain, 100, lambda c: self.setGain(c)
- )
diff --git a/sw/control/sensors/picamera_sensor.py b/sw/control/sensors/picamera_sensor.py
deleted file mode 100644
index cdf14ea..0000000
--- a/sw/control/sensors/picamera_sensor.py
+++ /dev/null
@@ -1,125 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-A sensor that use PiCamera for capture.
-"""
-
-import cv2
-import numpy as np
-from dataclasses import dataclass
-from time import time
-from threading import Event
-from picamera import PiCamera
-from typing import Optional, Tuple
-from picamera.array import PiRGBArray
-
-from ..common import ISensor, IDevice
-
-
-class PiCameraSensor(ISensor):
- @dataclass
- class Config(ISensor.Config):
- framerate: int = 30
- exposureMode: str = "off"
-
- brightness: int = 70
- contrast: int = 25
- rotated: bool = True
-
- ballOffsetX: int = 0
- ballOffsetY: int = 0
-
- def __init__(self, config: Config, device: IDevice):
- super().__init__(config, device)
- self.config = config
-
- self.camera = PiCamera()
-
- self.camera.resolution = [self.config.width, self.config.height]
- self.camera.framerate = self.config.framerate
-
- self.camera.exposure_mode = self.config.exposureMode
- self.camera.brightness = self.config.brightness
- self.camera.contrast = self.config.contrast
-
- self.frame_raw = None
-
- self.x_offset_left = 0
- self.x_offset_right = 0
- self.y_offset_bottom = 0
- self.y_offset_top = 0
-
- self.prevTime = 0.0
-
- def getNextInput(self, sender: IDevice) -> Tuple[float, Optional[np.ndarray]]:
-
- # Calculate the time elapsed since the last sensor snapshot
- currTime = time()
- elapsedTime = currTime - self.prevTime
- self.prevTime = currTime
-
- f = self.stream.__next__()
- self.frame_raw = f.array
- self.rawCapture.truncate(0)
-
- if self.frame_raw is not None:
- frame = self.frame_raw[
- self.x_offset_right : (self.config.width - self.x_offset_left),
- self.y_offset_bottom : (self.config.height - self.y_offset_top),
- ]
- if self.config.rotated:
- frame = self._rotate_image(frame, self.image_size)
-
- frame = cv2.flip(frame, 0)
-
- return (elapsedTime, frame)
- else:
- return (elapsedTime, None)
-
- def start(self):
- self._init_camera()
- self.kill = Event()
-
- def stop(self):
- self.stream.close()
- self.rawCapture.close()
-
- def _center_camera(self, ball_x, ball_y):
- if ball_x < 0:
- self.x_offset_right = abs(ball_x * 2)
-
- elif ball_x > 0:
- self.x_offset_left = abs(ball_x * 2)
-
- else:
- self.x_offset_left = 0
- self.x_offset_right = 0
-
- if ball_y < 0:
- self.y_offset_bottom = abs(ball_y * 2)
-
- elif ball_y > 0:
- self.y_offset_top = abs(ball_y * 2)
-
- else:
- self.y_offset_top = 0
- self.y_offset_bottom = 0
-
- def _rotate_image(self, frame, size, degrees=30):
- matrix = cv2.getRotationMatrix2D((size[0] / 2, size[1] / 2), degrees, 1.0)
- rotated = cv2.warpAffine(frame, matrix, (size[0], size[1]))
- return rotated
-
- def _init_camera(self):
- self._center_camera(self.config.ballOffsetX, self.config.ballOffsetY)
- self.image_size = (
- self.config.width - (self.x_offset_left + self.x_offset_right),
- self.config.height - (self.y_offset_top + self.y_offset_bottom),
- )
- self.rawCapture = PiRGBArray(
- self.camera, (self.config.width, self.config.height)
- )
- self.stream = self.camera.capture_continuous(
- self.rawCapture, format="bgr", use_video_port=True
- )
diff --git a/sw/control/tests/__init__.py b/sw/control/tests/__init__.py
deleted file mode 100644
index 59e481e..0000000
--- a/sw/control/tests/__init__.py
+++ /dev/null
@@ -1,2 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
diff --git a/sw/control/tests/context.py b/sw/control/tests/context.py
deleted file mode 100644
index 893982a..0000000
--- a/sw/control/tests/context.py
+++ /dev/null
@@ -1,7 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-import os
-import sys
-
-sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
diff --git a/sw/control/tests/test_heading.py b/sw/control/tests/test_heading.py
deleted file mode 100644
index f943941..0000000
--- a/sw/control/tests/test_heading.py
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Test cases
-"""
-
-# pyright: strict
-
-import math
-
-from ..controllers import BrainController
-from ..common import Vector2
-
-
-# basic test for heading
-def test_heading():
- zero = Vector2(0, 0)
- one = Vector2(1, 0)
- heading = BrainController.heading_to_point(zero, Vector2(1.0, 0.0), one)
- assert heading == 0.0, "Expected heading to be 0.0 while moving towards point"
-
- heading = BrainController.heading_to_point(zero, Vector2(-1.0, 0.0), one)
- assert (
- heading == math.pi
- ), "Expected heading to be math.pi while moving away from point"
-
- heading = BrainController.heading_to_point(zero, Vector2(0.0, -1.0), one)
- assert (
- heading == -math.pi / 2
- ), "Expected heading to be negative while moving to right of point"
-
- heading = BrainController.heading_to_point(zero, Vector2(0.0, 1.0), one)
- assert (
- heading == math.pi / 2
- ), "Expected heading to be positive while moving to left of point"
diff --git a/sw/control/timers.py b/sw/control/timers.py
deleted file mode 100644
index 80ca6d6..0000000
--- a/sw/control/timers.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# Copyright (c) Microsoft Corporation.
-# Licensed under the MIT License.
-
-"""
-Timer classes for profiling
-"""
-
-import time
-from threading import Thread
-
-from .perfcounters import WindowedAverageCounter
-from .perfcounters import PerformanceCounters as counter
-
-
-# A synchronous, low-drift timer using iterators
-# Use this timer for fixed time-step update loops
-# https://stackoverflow.com/a/28034554/802203
-class BusyTimer:
- def __init__(self):
- self.running = False
-
- def start(self, period, f, *args):
- def g_tick():
- t = time.perf_counter()
- count = 0
- while self.running:
- count += 1
- yield max(t + count * period - time.perf_counter(), 0)
-
- self.running = True
- g = g_tick()
- counter.start("loop", WindowedAverageCounter)
- while self.running:
- counter.stop()
- counter.start("loop", WindowedAverageCounter)
- time.sleep(next(g))
- f(*args)
- counter.stop()
-
- def stop(self):
- self.running = False
-
-
-# A threaded timer that yields the CPU
-# Use this for low frequency operations only
-# as it has a larger drift margin than BusyTimer
-class ThreadedTimer:
- def __init__(self):
- self.running = False
- self.thread = None
-
- def __threadCallback(self):
- while self.running:
- if self.callback is not None:
- self.callback(*self.args)
- time.sleep(self.period)
-
- def start(self, period, f, *args):
- if self.thread:
- raise Exception("Double start()")
-
- self.period = period
- self.callback = f
- self.args = args
-
- self.thread = Thread(target=self.__threadCallback)
- self.thread.daemon = True
- self.running = True
- self.thread.start()
-
- def stop(self):
- if self.thread is not None:
- self.running = False
- self.thread.join(timeout=self.period)
- self.thread = None
diff --git a/sw/controllers.py b/sw/controllers.py
new file mode 100644
index 0000000..17dc4ad
--- /dev/null
+++ b/sw/controllers.py
@@ -0,0 +1,123 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+import sys
+import time
+import requests
+import numpy as np
+import logging as log
+
+from env import MoabEnv
+from common import Vector2
+
+class BrainNotFound(Exception):
+ pass
+
+
+# Controllers ------------------------------------------------------------------
+def pid_controller(
+ Kp=75, # Proportional coefficient
+ Ki=0.5, # Integral coefficient
+ Kd=45, # Derivative coefficient
+ max_angle=22,
+ **kwargs,
+):
+ def next_action(state):
+ env_state, ball_detected, buttons = state
+ x, y, vel_x, vel_y, sum_x, sum_y = env_state
+
+ if ball_detected:
+ action_x = Kp * x + Ki * sum_x + Kd * vel_x
+ action_y = Kp * y + Ki * sum_y + Kd * vel_y
+ action_x = np.clip(action_x, -max_angle, max_angle)
+ action_y = np.clip(action_y, -max_angle, max_angle)
+
+ action = Vector2(action_x, action_y)
+
+ else:
+ # Move plate back to flat
+ action = Vector2(0, 0)
+
+ return action, {}
+
+ return next_action
+
+
+def joystick_controller(max_angle=16, **kwargs):
+ def next_action(state):
+ env_state, ball_detected, buttons = state
+ action = Vector2(-buttons.joy_x, -buttons.joy_y)
+ return action * max_angle, {}
+
+ return next_action
+
+
+def brain_controller(
+ max_angle=22,
+ port=5555,
+ alert_fn=lambda toggle: None,
+ **kwargs,
+):
+ """
+ This class interfaces with an HTTP server running locally.
+ It passes the current hardware state and gets new plate
+ angles in return.
+
+ The hardware state is unprojected from camera pixel space
+ back to real space by using the calculated plate surface plane.
+ """
+ prediction_url = f"http://localhost:{port}/v1/prediction"
+
+ def next_action(state):
+ env_state, ball_detected, buttons = state
+ x, y, vel_x, vel_y, sum_x, sum_y = env_state
+
+ observables = {
+ "ball_x": x,
+ "ball_y": y,
+ "ball_vel_x": vel_x,
+ "ball_vel_y": vel_y,
+ }
+
+ action = Vector2(0, 0) # Action is 0,0 if not detected or brain didn't work
+ info = {"status": 400, "resp": ""}
+ if ball_detected:
+
+ # Trap on GET failures so we can restart the brain without
+ # bringing down this run loop. Plate will default to level
+ # when it loses the connection.
+ try:
+ # Get action from brain
+ response = requests.get(prediction_url, json=observables)
+ info = {"status": response.status_code, "resp": response.json()}
+ action_json = response.json()
+
+ if response.ok:
+ if alert_fn is not None:
+ alert_fn(False)
+ action_json = requests.get(prediction_url, json=observables).json()
+ pitch = action_json["input_pitch"]
+ roll = action_json["input_roll"]
+
+ # Scale and clip
+ pitch = np.clip(pitch * max_angle, -max_angle, max_angle)
+ roll = np.clip(roll * max_angle, -max_angle, max_angle)
+
+ # To match how the old brain works (only integer plate angles)
+ pitch, roll = int(pitch), int(roll)
+
+ action = Vector2(-roll, pitch)
+ else:
+ if alert_fn is not None:
+ alert_fn(True)
+
+ except requests.exceptions.ConnectionError as e:
+ print(f"No brain listening on port: {port}", file=sys.stderr)
+ raise BrainNotFound
+
+ except Exception as e:
+ print(f"Brain exception: {e}")
+
+ return action, info
+
+ return next_action
diff --git a/sw/detector.py b/sw/detector.py
new file mode 100644
index 0000000..662ce9f
--- /dev/null
+++ b/sw/detector.py
@@ -0,0 +1,164 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+"""
+HSV filtering ball detector
+"""
+
+import cv2
+import math
+import numpy as np
+from hsv import hue_to_bgr
+from huemask import hue_mask
+from common import Vector2, CircleFeature, Calibration
+
+from typing import List, Optional
+
+
+def pixels_to_meters(vec, frame_size=256, field_of_view=1.05):
+ # The plate is default roughly 105% of the field of view
+ plate_diameter_meters = 0.225
+ plate_diameter_pixels = frame_size * field_of_view
+ conversion = plate_diameter_meters / plate_diameter_pixels
+ return np.asarray(vec) * conversion
+
+
+def meters_to_pixels(vec, frame_size=256, field_of_view=1.05):
+ # The plate is default roughly 105% of the field of view
+ plate_diameter_meters = 0.225
+ plate_diameter_pixels = frame_size * field_of_view
+ conversion = plate_diameter_meters / plate_diameter_pixels
+ return np.int_(np.asarray(vec) / conversion) # Note: pixels are only ever ints
+
+
+def pixel_to_meter_ratio(frame_size=256, field_of_view=1.05):
+ # The plate is default roughly 105% of the field of view
+ plate_diameter_meters = 0.225
+ plate_diameter_pixels = frame_size * field_of_view
+ conversion = plate_diameter_meters / plate_diameter_pixels
+ return conversion
+
+
+def draw_ball(img, center, radius, hue):
+ bgr = hue_to_bgr(hue)
+ # 45 -> hsl(45°, 75%, 50%)
+ cv2.circle(img, center, 2, bgr, 2)
+ cv2.circle(img, center, int(radius), bgr, 2)
+ return img
+
+
+def save_img(filepath, img, rotated=False, quality=80):
+ if rotated:
+ # Rotate the image -30 degrees so it looks normal
+ w, h = img.shape[:2]
+ center = (w / 2, h / 2)
+ M = cv2.getRotationMatrix2D(center, 30, 1.0)
+ img = cv2.warpAffine(img, M, (w, h))
+ img = img[::-1, :, :] # Mirror along x axis
+
+ cv2.imwrite(
+ filepath,
+ img,
+ [cv2.IMWRITE_JPEG_QUALITY, quality],
+ )
+
+
+def hsv_detector(
+ calibration=None,
+ frame_size=256,
+ kernel_size=[5, 5],
+ ball_min=0.06,
+ ball_max=0.22,
+ hue=None, # hue [0..255]
+ debug=False,
+):
+ if calibration is None:
+ calibration = Calibration()
+ # if we haven't been overridden, use ballHue from calibration
+ if hue is None:
+ hue = calibration.ball_hue
+ kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, tuple(kernel_size))
+
+ def detect_features(img, hue=hue, debug=debug, filename="/tmp/camera/frame.jpg"):
+ # covert to HSV space
+ img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
+
+ # The hue_mask function follows CV2 convention and hue is in the range
+ # [0, 180] instead of [0, 360]
+ # run through each triplet and perform our masking filter on it.
+ # hue_mask coverts the hsv image into a grayscale image with a
+ # bandpass applied centered around hue, with width sigma
+ hue_mask(img_hsv, hue / 2, 0.05, 12.0, 4.0)
+
+ # convert to b&w mask from grayscale image
+ mask = cv2.inRange(
+ img_hsv, np.array((200, 200, 200)), np.array((255, 255, 255))
+ )
+
+ # expand b&w image with a dialation filter
+ mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
+
+ contours = cv2.findContours(
+ mask,
+ cv2.RETR_EXTERNAL,
+ cv2.CHAIN_APPROX_SIMPLE,
+ )[-2]
+
+ if len(contours) > 0:
+ contour_peak = max(contours, key=cv2.contourArea)
+ ((x_obs, y_obs), radius) = cv2.minEnclosingCircle(contour_peak)
+
+ # Determine if ball size is the appropriate size
+ norm_radius = radius / frame_size
+ if ball_min < norm_radius < ball_max:
+ ball_detected = True
+
+ # Convert from pixels to absolute with 0,0 as center of detected plate
+ x = x_obs - frame_size // 2
+ y = y_obs - frame_size // 2
+
+ if debug:
+ ball_center_pixels = (int(x_obs), int(y_obs))
+ draw_ball(img, ball_center_pixels, radius, hue)
+ save_img(filename, img, rotated=False, quality=80)
+
+ # Rotate the x, y coordinates by -30 degrees
+ center = Vector2(x, y).rotate(np.radians(-30))
+ center = pixels_to_meters(center, frame_size)
+ return ball_detected, (center, radius)
+
+ # If there were no contours or no contours the size of the ball
+ ball_detected = False
+ if debug:
+ save_img(filename, img, rotated=False, quality=80)
+ return ball_detected, (Vector2(0, 0), 0.0)
+
+ return detect_features
+
+
+def circle_test_detector(hue=44, debug=False, *args, **kwargs):
+ angle = 0
+ time = 1
+ frequency = 30 # in Hz
+ scale = pixel_to_meter_ratio()
+ radius = 256 * 0.4
+ ball_radius_pixels = 256 * 0.1
+
+ def detect_features(img, hue=hue, debug=debug, filename="/tmp/camera/frame.jpg"):
+ nonlocal angle
+ angle += (1 / (time * frequency)) * (2 * np.pi)
+ x_pixels, y_pixels = (radius * np.sin(angle), radius * np.cos(angle))
+ x_pixels += 256 / 2
+ y_pixels += 256 / 2
+
+ if debug:
+ ball_center_pixels = (int(x_pixels), int(y_pixels))
+ print(ball_center_pixels)
+ draw_ball(img, ball_center_pixels, ball_radius_pixels, hue)
+ save_img(filename, img, rotated=False, quality=80)
+
+ x, y = x_pixels * scale, y_pixels * scale
+ ball_detected = True
+ return ball_detected, (Vector2(x, y), ball_radius_pixels * scale)
+
+ return detect_features
diff --git a/sw/env.py b/sw/env.py
new file mode 100644
index 0000000..3d63756
--- /dev/null
+++ b/sw/env.py
@@ -0,0 +1,145 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+import os
+import time
+import json
+
+from typing import Tuple
+from hat import Hat, Buttons, Icon, PowerIcon
+from camera import OpenCVCameraSensor
+from dataclasses import dataclass, astuple
+from detector import hsv_detector, meters_to_pixels
+from common import high_pass_filter, low_pass_filter, derivative
+
+
+@dataclass
+class EnvState:
+ x: float = 0.0
+ y: float = 0.0
+ vel_x: float = 0.0
+ vel_y: float = 0.0
+ sum_x: float = 0.0
+ sum_y: float = 0.0
+
+ def __iter__(self):
+ return iter(astuple(self))
+
+ def __repr__(self):
+ return self.__str__()
+
+ def __str__(self):
+ a = f"x,y ({self.x:.3f}, {self.y:.3f}) "
+ b = f"ẋ,ẏ ({self.vel_x:.3f}, {self.vel_y:.3f}) "
+ c = f"Δx,Δy {self.sum_x:.3f}, {self.sum_y:.3f})"
+ return a + b + c
+
+
+class MoabEnv:
+ def __init__(
+ self,
+ frequency=30,
+ debug=False,
+ verbose=0,
+ derivative_fn=derivative,
+ calibration_file="bot.json",
+ ):
+ self.debug = debug
+ self.verbose = verbose
+ self.frequency = frequency
+ self.derivative_fn = derivative
+ self.vel_x = self.derivative_fn(frequency)
+ self.vel_y = self.derivative_fn(frequency)
+ self.sum_x, self.sum_y = 0, 0
+
+ self.hat = Hat(debug=debug, verbose=verbose)
+ self.hat.open()
+ self.camera = OpenCVCameraSensor(frequency=frequency)
+ self.detector = hsv_detector(debug=debug)
+
+ self.calibration_file = calibration_file
+ self.reset_calibration()
+
+ def __enter__(self):
+ self.camera.start()
+ return self
+
+ def __exit__(self, type, value, traceback):
+ self.hat.go_down()
+ self.hat.disable_servos()
+ self.hat.display_power_symbol("TO WAKE", PowerIcon.POWER)
+ self.hat.close()
+ self.camera.stop()
+
+ def __repr__(self):
+ return self.__str__()
+
+ def __str__(self):
+ return f"hue: {self.hue}, offsets: {self.servo_offsets}"
+
+ def reset_calibration(self, calibration_file=None):
+ # Use default if not defined
+ calibration_file = calibration_file or self.calibration_file
+
+ # Get calibration settings
+ if os.path.isfile(calibration_file):
+ with open(calibration_file, "r") as f:
+ calib = json.load(f)
+ else: # Use defaults
+ calib = {
+ "ball_hue": 44,
+ "plate_offsets": (0.0, 0.0),
+ "servo_offsets": (0.0, 0.0, 0.0),
+ }
+
+ plate_offsets = calib["plate_offsets"]
+ self.plate_offsets_pixels = meters_to_pixels(plate_offsets)
+ self.servo_offsets = calib["servo_offsets"]
+ self.hue = calib["ball_hue"]
+
+ # Set the servo offsets (self.hue & self.plate_offsets_pixels are used in step)
+ self.hat.set_servo_offsets(*self.servo_offsets)
+ self.camera.x_offset_pixels = self.plate_offsets_pixels[0]
+ self.camera.y_offset_pixels = self.plate_offsets_pixels[1]
+
+ def reset(self, text=None, icon=None):
+ # Optionally display the controller active text
+ if icon and text:
+ self.hat.display_string_icon(text, icon)
+ elif text:
+ self.hat.display_string(text)
+
+ # Reset the derivative of the position
+ # Use a high pass filter instead of a numerical derivative for stability.
+ # A high pass filtered signal can be thought of as a derivative of a low
+ # pass filtered signal: fc*s / (s + fc) = fc*s * 1 / (s + fc)
+ # For more info: https://en.wikipedia.org/wiki/Differentiator
+ # Or: https://www.youtube.com/user/ControlLectures/
+ self.vel_x = self.derivative_fn(self.frequency)
+ self.vel_y = self.derivative_fn(self.frequency)
+ # Reset the integral of the position
+ self.sum_x, self.sum_y = 0, 0
+
+ # Return the state after a step with no motor actions
+ return self.step((0, 0))
+
+ def step(self, action) -> Tuple[EnvState, bool, Buttons]:
+ plate_x, plate_y = action
+ self.hat.set_angles(plate_x, plate_y)
+
+ frame, elapsed_time = self.camera()
+ ball_detected, cicle_feature = self.detector(frame, hue=self.hue)
+ ball_center, ball_radius = cicle_feature
+
+ x, y = ball_center
+
+ # Update derivate calulation
+ vel_x, vel_y = self.vel_x(x), self.vel_y(y)
+ # Update the summation (integral calculation)
+ self.sum_x += x
+ self.sum_y += y
+
+ buttons = self.hat.get_buttons()
+ state = EnvState(x, y, vel_x, vel_y, self.sum_x, self.sum_y)
+
+ return state, ball_detected, buttons
diff --git a/sw/hat.py b/sw/hat.py
new file mode 100644
index 0000000..7a07431
--- /dev/null
+++ b/sw/hat.py
@@ -0,0 +1,363 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+import os
+import time
+import signal
+
+import socket
+import spidev
+import numpy as np
+import logging as log
+import RPi.GPIO as gpio
+
+from hexyl import hexyl
+from enum import IntEnum
+from typing import Union, List, Tuple
+from dataclasses import dataclass, astuple
+
+# fmt: off
+# Define which bytes represent which commands
+
+# Messaging from the Pi to the hat
+class SendCommand(IntEnum):
+ NOOP = 0x00 # Import for polling the state of the buttons and joystick
+ SERVO_ENABLE = 0x01 # The servos should be turned off
+ SERVO_DISABLE = 0x02 # The servos should be turned on
+ SET_SERVOS = 0x05 # Set the servo positions manually (s1, s2, s3)
+ COPY_STRING = 0x80 # Pass a variable length string (max 240 bytes). Requires DISPLAY_ after.
+ DISPLAY_BIG_TEXT_ICON = 0x81 # Display buffer (large font) with icon. Does not scroll.
+ DISPLAY_BIG_TEXT = 0x82 # Display the 0x80 buffer (in large font). Does not scroll.
+ DISPLAY_SMALL_TEXT = 0x83 # Display the 0x80 buffer (in small font). Scroll if required.
+ DISPLAY_POWER_SYMBOL = 0x84 # Display buffer (large font) with icon. Does not scroll.
+
+# Icon index
+class Icon(IntEnum):
+ BLANK = 0
+ UP_DOWN = 1
+ DOWN = 2
+ UP = 3
+ DOT = 4
+ PAUSE = 5
+ CHECK = 6
+ X = 7
+
+# ⏻ ⏼ ⏽ ⭘ ⏾
+class PowerIcon(IntEnum):
+ POWER = 1
+ TOGGLE_POWER = 2
+ POWER_ON = 3
+ SLEEP_MODE = 4
+ POWER_OFF = 5
+
+
+@dataclass
+class Buttons:
+ menu_button: bool
+ joy_button: bool
+ joy_x: float
+ joy_y: float
+
+ def __iter__(self):
+ return iter(astuple(self))
+
+
+# GPIO pins
+class GpioPin(IntEnum):
+ HAT_EN = 20 # Bcm 20 - RPi pin 38 - RPI_BPLUS_GPIO_J8_38
+ HAT_RESET = 6 # Bcm 6 - RPi pin 31 - RPI_BPLUS_GPIO_J8_31
+# fmt: on
+
+
+# Helper functions -------------------------------------------------------------
+def _uint8_to_int8(b: int) -> int:
+ """
+ Converts a byte to a signed int (int8) instead of unsigned int (uint8).
+ """
+ return np.int8(b)
+
+
+def _int8_to_uint8(b: int) -> int:
+ """
+ Converts a byte to a signed int (int8) instead of unsigned int (uint8).
+ """
+ return np.uint8(b)
+
+
+def _xy_offsets(
+ x: float,
+ y: float,
+ servo_offsets: Tuple[float, float, float],
+ x_tilt_servo1: float = -0.5,
+ y_tilt_servo2: float = 0.866,
+ y_tilt_servo3: float = -0.866,
+) -> Tuple[float, float]:
+ so_1, so_2, so_3 = servo_offsets
+ x_offset = x + so_1 + x_tilt_servo1 * so_2 + x_tilt_servo1 * so_3
+ y_offset = y + y_tilt_servo2 * so_2 + y_tilt_servo3 * so_3
+ return x_offset, y_offset
+
+
+def plate_angles_to_servo_positions(
+ pitch: float,
+ roll: float,
+ arm_len: float = 55.0,
+ side_len: float = 170.87,
+ pivot_height: float = 80.0,
+ angle_max: float = 160,
+ angle_min: float = 90,
+) -> Tuple[float, float, float]:
+ servo_angles = [0.0, 0.0, 0.0]
+
+ z1 = pivot_height + np.sin(np.radians(roll)) * (side_len / np.sqrt(3))
+ r = pivot_height - np.sin(np.radians(roll)) * (side_len / (2 * np.sqrt(3)))
+ z2 = r + np.sin(np.radians(-pitch)) * (side_len / 2)
+ z3 = r - np.sin(np.radians(-pitch)) * (side_len / 2)
+
+ if z1 > 2 * arm_len:
+ z1 = 2 * arm_len
+ if z2 > 2 * arm_len:
+ z2 = 2 * arm_len
+ if z3 > 2 * arm_len:
+ z3 = 2 * arm_len
+
+ servo_angles[0] = 180 - (np.degrees(np.arcsin(z1 / (2 * arm_len))))
+ servo_angles[1] = 180 - (np.degrees(np.arcsin(z2 / (2 * arm_len))))
+ servo_angles[2] = 180 - (np.degrees(np.arcsin(z3 / (2 * arm_len))))
+
+ servo_angles = np.clip(servo_angles, angle_min, angle_max)
+ return servo_angles
+
+
+# Return an exact 8 byte numpy array
+def pad(*args, **kwargs):
+ data = [*args][:8]
+ pads = (8 - len(data)) * [0]
+ dtype = kwargs.pop("dtype", np.int8)
+ return np.array(data + pads, dtype)
+
+
+class Hat:
+ def __init__(
+ self,
+ servo_offsets: Tuple[float, float, float] = (0, 0, 0),
+ debug=False,
+ verbose=0,
+ ):
+ self.servo_offsets: Tuple[float, float, float] = servo_offsets
+ self.buttons = Buttons(False, False, 0.0, 0.0)
+
+ self.debug = debug
+ self.verbose = verbose
+ if debug:
+ self.hex_printer = hexyl()
+
+ self.spi = None
+
+ def open(self):
+ # Attempt to open the spidev bus
+ try:
+ self.spi = spidev.SpiDev()
+ self.spi.open(0, 0)
+ self.spi.max_speed_hz = 100000
+ except Exception as e:
+ # possible that ctrl-C was caught here
+ raise IOError(f"Could not open `/dev/spidev{spi_bus}.{spi_device}`.")
+
+ # Attempt to setup the GPIO pins
+ try:
+ gpio.setwarnings(False)
+ gpio.setmode(gpio.BCM)
+ # Setting pin direction, in our case, reboots Moab!
+ gpio.setup(
+ [GpioPin.HAT_EN, GpioPin.HAT_RESET],
+ gpio.OUT,
+ )
+ time.sleep(0.1)
+ except KeyboardInterrupt:
+ raise
+ except:
+ raise IOError(f"Could not setup GPIO pins")
+
+ def close(self):
+ if self.spi is not None:
+ self.spi.close()
+
+ def __enter__(self):
+ self.open()
+ return self
+
+ def __exit__(self, type, value, traceback):
+ self.close()
+
+ def transceive(self, packet: np.ndarray):
+ """
+ Send and receive 8 bytes from hat.
+ """
+ assert self.spi is not None # did you call hat.open() first ?
+ assert len(packet) == 8
+
+ hat_to_pi = self.spi.xfer(packet.tolist())
+ time.sleep(0.005)
+
+ if self.debug:
+ self.hex_printer(packet.tolist(), hat_to_pi, self.verbose)
+
+ # Check if buttons are pressed
+ self.buttons.menu_button = hat_to_pi[0] == 1
+ self.buttons.joy_button = hat_to_pi[1] == 1
+
+ # Get x & y coordinates of joystick normalized to [-1, +1]
+ self.buttons.joy_x = _uint8_to_int8(hat_to_pi[2]) / 100
+ self.buttons.joy_y = _uint8_to_int8(hat_to_pi[3]) / 100
+
+ def get_buttons(self) -> Buttons:
+ """
+ Check whether buttons are pressed and the joystick x & y values in the
+ response.
+
+ Return:
+ Buttons
+ Which is a dataclass with:
+ - menu_button: bool
+ - joy_button : bool
+ - joy_x : float normalized from -1 to +1
+ - joy_y : float normalized from -1 to +1
+ """
+ return self.buttons
+
+ def noop(self):
+ """Send a NOOP. Useful for if you just want to read buttons."""
+ self.transceive(pad(SendCommand.NOOP))
+
+ def enable_servos(self):
+ """ Set the plate to track plate angles. """
+ self.transceive(pad(SendCommand.SERVO_ENABLE))
+
+ def disable_servos(self):
+ """ Disables the power to the servos. """
+ self.transceive(pad(SendCommand.SERVO_DISABLE))
+
+ def set_angles(self, pitch: float, roll: float):
+ s1, s2, s3 = plate_angles_to_servo_positions(pitch, roll)
+ self.set_servos(s1, s2, s3)
+
+ def set_servos(self, servo1: float, servo2: float, servo3: float):
+ # Note the off by 1 for indexing
+ servo1 += self.servo_offsets[0]
+ servo2 += self.servo_offsets[1]
+ servo3 += self.servo_offsets[2]
+
+ # Use fixed point 16-bit numbers, with precision of hundredths
+ servo1_centi_degrees = np.int16(servo1 * 100)
+ servo2_centi_degrees = np.int16(servo2 * 100)
+ servo3_centi_degrees = np.int16(servo3 * 100)
+
+ # Get the first 8 bits and last 8 bits of every 16-bit integer
+ # (To send it as indivdual bytes)
+ servo1_centi_degrees_high_byte = servo1_centi_degrees >> 8
+ servo1_centi_degrees_low_byte = servo1_centi_degrees & 0x00FF
+ servo2_centi_degrees_high_byte = servo2_centi_degrees >> 8
+ servo2_centi_degrees_low_byte = servo2_centi_degrees & 0x00FF
+ servo3_centi_degrees_high_byte = servo3_centi_degrees >> 8
+ servo3_centi_degrees_low_byte = servo3_centi_degrees & 0x00FF
+
+ self.transceive(
+ pad(
+ SendCommand.SET_SERVOS,
+ servo3_centi_degrees_high_byte,
+ servo3_centi_degrees_low_byte,
+ servo1_centi_degrees_high_byte,
+ servo1_centi_degrees_low_byte,
+ servo2_centi_degrees_high_byte,
+ servo2_centi_degrees_low_byte,
+ )
+ )
+
+ def set_servo_offsets(self, servo1: int, servo2: int, servo3: int):
+ """
+ Set post-factory calibration offsets for each servo.
+ Normally this call should not be needed.
+ """
+ self.servo_offsets = (servo1, servo2, servo3)
+
+ def go_up(self):
+ """
+ Set the plate to its hover position.
+ This was experimentally found to be 150 (down but still leaving some
+ space at the bottom).
+ """
+ self.set_servos(150, 150, 150)
+ # Give enough time for the action to be taken
+ time.sleep(0.200) # Make sure this action gets taken before turning off servos
+
+ def go_down(self):
+ """
+ Set the plate to its lower position (usually powered-off state).
+ This was experimentally found to be 155 (lowest possible position).
+ """
+ self.set_servos(155, 155, 155)
+ # Give enough time for the action to be taken
+ time.sleep(0.200) # Make sure this action gets taken before turning off servos
+
+ def _copy_buffer(self, s: str):
+ s = s.upper() # The firware currently only has uppercase fonts
+
+ s = bytes(s, "utf-8")
+ s += b"\0" # Ensure a trailing termination character
+ assert len(s) <= 240, "String too long to send to hat."
+
+ # Calculate the number of messages required to send the text
+ num_msgs = int(np.ceil(len(s) / 7))
+
+ # Pad the message with trailing termination chars to so we always
+ # send in 8 bytes increments (1 byte control, 7 bytes data)
+ s += (num_msgs * 7 - len(s)) * b"\0"
+
+ for msg_idx in range(num_msgs):
+ # Combine into one list to send
+ msg = [SendCommand.COPY_STRING] + list(s[7 * msg_idx : 7 * msg_idx + 7])
+ self.transceive(np.array(msg, dtype=np.int8))
+ time.sleep(0.010)
+
+ def display_power_symbol(self, text: str, icon_idx: PowerIcon):
+ assert len(text) <= 12, "String is too long to display with icon"
+
+ # Copy the text into a buffer in the firmware
+ self._copy_buffer(text)
+
+ # After sending copying to the fw buffer, display the buffer as a short string
+ self.transceive(pad(SendCommand.DISPLAY_POWER_SYMBOL, icon_idx))
+
+ def display_string_icon(self, text: str, icon_idx: Icon):
+ # assert len(text) <= 12, "String is too long to display with icon"
+
+ # Copy the text into a buffer in the firmware
+ self._copy_buffer(text)
+
+ # After sending copying to the fw buffer, display the buffer as a short string
+ self.transceive(pad(SendCommand.DISPLAY_BIG_TEXT_ICON, icon_idx))
+
+ def update_icon(self, icon_idx: Icon):
+ # Don't needlessly update display if icon hasn't changed or if last text
+ # didn't have an icon (ie last called send text was display_string or
+ # display_long_string)
+
+ # Display the buffer as a long string
+ self.transceive(pad(SendCommand.DISPLAY_BIG_TEXT_ICON, icon_idx))
+
+ def display_string(self, text: str):
+ assert len(text) <= 15, "String is too long to display without scrolling."
+
+ # Copy the text into a buffer in the firmware
+ self._copy_buffer(text)
+
+ # After sending copying to the fw buffer, display the buffer as a short string
+ self.transceive(pad(SendCommand.DISPLAY_BIG_TEXT))
+
+ def display_long_string(self, text: str):
+ # Copy the text into a buffer in the firmware
+ self._copy_buffer(text)
+
+ # After sending copying to the fw buffer, display the buffer as a long string
+ self.transceive(pad(SendCommand.DISPLAY_SMALL_TEXT))
diff --git a/sw/hexyl.py b/sw/hexyl.py
new file mode 100644
index 0000000..49ffaf7
--- /dev/null
+++ b/sw/hexyl.py
@@ -0,0 +1,192 @@
+#!/usr/bin/env python3
+
+import time
+import numpy as np
+import itertools
+from operator import add
+from typing import Union, List, Tuple, Dict
+
+
+class color:
+ green = "\033[38;5;40m"
+ cyan = "\033[38;5;111m"
+ red = "\033[31m"
+ yellow = "\033[38;5;40m"
+ string = "\033[38;5;40m"
+ string_cmd = "\033[38;5;34m"
+ gray = "\033[38;5;242m"
+ darkgray = "\033[38;5;238m"
+ danger = "\033[38;5;196m"
+ servos = "\033[38;5;19m"
+ end = "\033[0m"
+
+
+def hexyl():
+ tick = 0
+
+ def wrapstr(c: Union[str, None], s):
+ if c is None:
+ return s
+ else:
+ return c + s + color.end
+
+ def wrap_tx(c: Union[str, None], s):
+ # first byte like 31 to string 0x1F
+ byte = f"{np.uint8(s):02x}"
+ if byte == "00":
+ c = color.darkgray
+ if c is None:
+ return byte
+ else:
+ return c + byte + color.end
+
+ def enum_bytes_tx(bytelist, c: Dict):
+ for i, v in enumerate(bytelist):
+ yield wrap_tx(c.get(i), v)
+
+ def wrap_rx(clr: Union[str, None], the_byte, position):
+ # first byte like 31 to string 0x1F
+ byte_str = f"{np.uint8(the_byte):02x}"
+
+ # first two bytes are buttons
+ # second two bytes are joystick
+ # last four bytes should always be zero
+
+ # unused bytes
+ if position > 3:
+ if byte_str == "00": # nominal
+ clr = color.darkgray
+ else:
+ clr = color.danger
+
+ if position <= 1:
+ if byte_str == "00": # nominal
+ clr = color.darkgray
+
+ if clr is None:
+ clr = color.darkgray
+
+ return clr + byte_str + color.end
+
+ def enum_bytes_rx(bytelist, c: Dict):
+ for i, v in enumerate(bytelist):
+ yield wrap_rx(c.get(i), v, i)
+
+ def tx_list(l):
+ if np.uint8(l[0]) == 0x80:
+ c = {0: color.green}
+ c.update({k: color.yellow for k in range(1, 9)})
+ else:
+ c = {0: color.red}
+
+ return " ".join(enum_bytes_tx(l, c))
+
+ def printable(c):
+ if c > 0x1F & c < 0x7F:
+ return chr(c)
+ if c == 0x0A:
+ return "¶"
+ else:
+ return "·"
+
+ def tx_to_english(l):
+ b1 = np.uint8(l[0])
+ if b1 == 0x80:
+ remainder = l[1:]
+ return " ┊ " + color.string + "".join(map(printable, remainder)) + color.end
+ elif b1 == 0x01:
+ return " ┊ " + wrapstr(color.red, "servos: on")
+ elif b1 == 0x02:
+ return " ┊ " + wrapstr(color.red, "servos: off")
+ elif b1 == 0x05:
+ s1 = ((l[1] << 8) + l[2]) / 100
+ s2 = ((l[3] << 8) + l[4]) / 100
+ s3 = ((l[5] << 8) + l[6]) / 100
+
+ s = f"{s1:6.2f}, {s2:6.2f}, {s3:6.2f}"
+ return " ┊ " + wrapstr(color.servos, s)
+ elif b1 == 0x06:
+ return " ┊ " + wrapstr(color.green, "text/icon")
+ elif b1 >= 0x81 and b1 <= 0x85:
+ return " ┊ " + wrapstr(color.string_cmd, "◊")
+ else:
+ return ""
+
+ def rx_list(l):
+ c = {0: color.green, 1: color.green, 2: color.cyan, 3: color.cyan}
+ return " ".join(enum_bytes_rx(l, c))
+
+ def canary(l):
+ if (
+ np.uint8(l[0]) > 0x01
+ or np.uint(l[1]) > 0x01
+ or sum(np.uint(l[4:8])) > 0
+ or abs(np.int8(l[2])) > 100
+ or abs(np.int8(l[3]) > 100)
+ ):
+ return wrapstr(color.red, " FATAL")
+ else:
+ return ""
+
+ # verbosity spi debug
+ # 0: nothing
+ # 1: mode changes
+ # 2: include servo settings (0x05)
+ # 3: include noops (0x00) (useful to show menu/joystick state)
+
+ def hfn(tx, rx, verbose=0):
+ nonlocal tick
+ tick = tick + 1
+
+ if verbose == 0:
+ return
+
+ if np.uint8(tx[0]) == 0x05 and verbose < 2:
+ return
+
+ if np.uint8(tx[0]) == 0x00 and verbose < 3:
+ return
+
+ # Print a 5-digit tick that updates every 30 Hz
+ print(f"{color.gray}{tick:05d}{color.end}", end="")
+ print(" ┊ ", end="")
+
+ # Tx 8 bytes: transmit to Hat
+ print(tx_list(tx), end="")
+ print(" ┊ ", end="")
+
+ # Rx 8 bytes: receive bytes back from Hat
+ print(rx_list(rx), end="")
+
+ # Translate some of the bytes
+ print(tx_to_english(tx), end="")
+
+ # Scan for unusual bytes
+ print(canary(rx))
+
+ return hfn
+
+
+def main():
+ tx1 = [0x05, 0x32, 0x5F, 0x2C, 0x64, 0x35, 0x62, 0x00]
+
+ rx0 = [0x00, 0x00, 0x5F, 0x2C, 0x00, 0x00, 0x00, 0x00] # good
+ rx1 = [0x01, 0x01, 0x3F, 0x2C, 0x00, 0x00, 0x00, 0x00] # rest are bad
+ rx2 = [0x05, 0x00, 0x3F, 0x2C, 0x01, 0x01, 0x00, 0x00] # badd 4-byte range
+ rx3 = [0x05, 0x00, 0x3F, 0x2C, 0x00, 0x00, 0x00, 0x00] # bad button down
+ rx4 = [0x00, 0x00, 0x3F, 0x2C, 0x00, 0x99, 0x00, 0x00] # bad 4-byte
+ rx5 = [0x00, 0x00, 0x6F, 0x5C, 0x00, 0x00, 0x00, 0x00] # bad joy stick (x)
+ rx6 = [0x00, 0x00, 0x5F, 0x6F, 0x00, 0x00, 0x00, 0x00] # bad joy stick (y)
+
+ t = hexyl()
+ t(tx1, rx0, verbose=4)
+ t(tx1, rx1, verbose=4)
+ t(tx1, rx2, verbose=4)
+ t(tx1, rx3, verbose=4)
+ t(tx1, rx4, verbose=4)
+ t(tx1, rx5, verbose=4)
+ t(tx1, rx6, verbose=4)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/sw/hsv.py b/sw/hsv.py
new file mode 100644
index 0000000..9ff9179
--- /dev/null
+++ b/sw/hsv.py
@@ -0,0 +1,76 @@
+import colorsys
+
+
+def hsv_to_rgb(h, s, v):
+ if s == 0.0:
+ return (v, v, v)
+ i = int(h * 6.0) # XXX assume int() truncates!
+ f = (h * 6.0) - i
+ p, q, t = v * (1.0 - s), v * (1.0 - s * f), v * (1.0 - s * (1.0 - f))
+ i %= 6
+ if i == 0:
+ return (v, t, p)
+ if i == 1:
+ return (q, v, p)
+ if i == 2:
+ return (p, v, t)
+ if i == 3:
+ return (p, q, v)
+ if i == 4:
+ return (t, p, v)
+ if i == 5:
+ return (v, p, q)
+
+
+def rgb_to_bgr(rgb):
+ return rgb[::-1]
+
+
+def hue_to_bgr(hue, s=0.75, v=0.75):
+ assert hue >= 0 and hue <= 360
+
+ rgb = hsv_to_rgb(hue / 360.0, s, v)
+ rgb = [int(c * 255) for c in rgb]
+ return rgb_to_bgr(rgb)
+
+
+def hsv_normalized_to_bgr(h, s, v):
+ assert 0 <= h <= 1.0
+ assert 0 <= s <= 1.0
+ assert 0 <= v <= 1.0
+
+ def h2r(h, s, v):
+ return tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h, s, v))
+
+ return rgb_to_bgr(h2r(h, s, v))
+
+
+# HSV was invented by Alvy Ray Smith (cool!)
+
+
+def test_code(t, e):
+ v = hsv_to_rgb(*t)
+ y = [int(s * 255) for s in v]
+ print(f"f({t}) = {y} ~= expected: {e}")
+ return y == e
+
+
+if __name__ == "__main__":
+
+ # 45 = orange
+ test_code((45 / 360.0, 1.0, 0.5), [128, 96, 0])
+
+ # 45 = orange
+ test_code((45 / 360.0, 0.75, 0.5), [218, 165, 32])
+
+ # 157 = green
+ test_code((45 / 360.0, 1.0, 0.5), [128, 96, 0])
+
+ # 211 = blue
+ test_code((211 / 360.0, 1.0, 0.5), [0, 61, 128])
+
+ # 0, 100%, 100% = red
+ test_code((1, 1.0, 1.0), [255, 4, 0])
+ test_code((0 / 360.0, 1.0, 1.0), [255, 0, 0])
+
+ print(hue_to_bgr(45))
diff --git a/sw/huemask/Makefile b/sw/huemask/Makefile
new file mode 100644
index 0000000..b018f04
--- /dev/null
+++ b/sw/huemask/Makefile
@@ -0,0 +1,11 @@
+# https://gist.github.com/ctokheim/6c34dc1d672afca0676a
+
+.PHONY: install
+
+all: huemask.c
+
+huemask.c: huemask.pyx
+ cython -3 huemask.pyx
+
+install:
+ @pip3 install .
diff --git a/sw/libs/pymoab/moab.c b/sw/huemask/huemask.c
similarity index 86%
rename from sw/libs/pymoab/moab.c
rename to sw/huemask/huemask.c
index 4daf168..8075419 100644
--- a/sw/libs/pymoab/moab.c
+++ b/sw/huemask/huemask.c
@@ -1,30 +1,5 @@
/* Generated by Cython 0.29.21 */
-/* BEGIN: Cython Metadata
-{
- "distutils": {
- "depends": [
- "/usr/local/include/moab.h"
- ],
- "include_dirs": [
- "/usr/local/include"
- ],
- "libraries": [
- "moab",
- "bcm2835"
- ],
- "library_dirs": [
- "/usr/local/lib"
- ],
- "name": "pymoab",
- "sources": [
- "moab.pyx"
- ]
- },
- "module_name": "pymoab"
-}
-END: Cython Metadata */
-
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
@@ -627,10 +602,9 @@ static CYTHON_INLINE float __PYX_NAN() {
#endif
#endif
-#define __PYX_HAVE__pymoab
-#define __PYX_HAVE_API__pymoab
+#define __PYX_HAVE__huemask
+#define __PYX_HAVE_API__huemask
/* Early includes */
-#include "moab.h"
#include "pythread.h"
#include
#include
@@ -844,7 +818,7 @@ static const char *__pyx_filename;
static const char *__pyx_f[] = {
- "moab.pyx",
+ "huemask.pyx",
"stringsource",
};
/* MemviewSliceStruct.proto */
@@ -956,33 +930,6 @@ typedef struct {
} __Pyx_BufFmt_Context;
-/* "moab.pyx":9
- * from typing import Tuple
- *
- * ctypedef char bool # <<<<<<<<<<<<<<
- * ctypedef signed char int8_t
- * ctypedef unsigned char uint8_t
- */
-typedef char __pyx_t_6pymoab_bool;
-
-/* "moab.pyx":10
- *
- * ctypedef char bool
- * ctypedef signed char int8_t # <<<<<<<<<<<<<<
- * ctypedef unsigned char uint8_t
- *
- */
-typedef signed char __pyx_t_6pymoab_int8_t;
-
-/* "moab.pyx":11
- * ctypedef char bool
- * ctypedef signed char int8_t
- * ctypedef unsigned char uint8_t # <<<<<<<<<<<<<<
- *
- * cdef extern from "moab.h":
- */
-typedef unsigned char __pyx_t_6pymoab_uint8_t;
-
/*--- Type declarations ---*/
struct __pyx_array_obj;
struct __pyx_MemviewEnum_obj;
@@ -1188,6 +1135,42 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject
/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);
+/* RaiseArgTupleInvalid.proto */
+static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
+ Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
+
+/* RaiseDoubleKeywords.proto */
+static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
+
+/* ParseKeywords.proto */
+static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
+ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
+ const char* function_name);
+
+/* PyFloatBinop.proto */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyFloat_TrueDivideObjC(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check);
+#else
+#define __Pyx_PyFloat_TrueDivideObjC(op1, op2, floatval, inplace, zerodivision_check)\
+ (inplace ? PyNumber_InPlaceTrueDivide(op1, op2) : PyNumber_TrueDivide(op1, op2))
+#endif
+
+/* PyFloatBinop.proto */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyFloat_SubtractObjC(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check);
+#else
+#define __Pyx_PyFloat_SubtractObjC(op1, op2, floatval, inplace, zerodivision_check)\
+ (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
+#endif
+
+/* PyFloatBinop.proto */
+#if !CYTHON_COMPILING_IN_PYPY
+static PyObject* __Pyx_PyFloat_AddObjC(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check);
+#else
+#define __Pyx_PyFloat_AddObjC(op1, op2, floatval, inplace, zerodivision_check)\
+ (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
+#endif
+
/* PyDictVersioning.proto */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1)
@@ -1283,42 +1266,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject
/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
-/* RaiseArgTupleInvalid.proto */
-static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
- Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
-
-/* RaiseDoubleKeywords.proto */
-static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
-
-/* ParseKeywords.proto */
-static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
- PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
- const char* function_name);
-
-/* PyFloatBinop.proto */
-#if !CYTHON_COMPILING_IN_PYPY
-static PyObject* __Pyx_PyFloat_TrueDivideObjC(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check);
-#else
-#define __Pyx_PyFloat_TrueDivideObjC(op1, op2, floatval, inplace, zerodivision_check)\
- (inplace ? PyNumber_InPlaceTrueDivide(op1, op2) : PyNumber_TrueDivide(op1, op2))
-#endif
-
-/* PyFloatBinop.proto */
-#if !CYTHON_COMPILING_IN_PYPY
-static PyObject* __Pyx_PyFloat_SubtractObjC(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check);
-#else
-#define __Pyx_PyFloat_SubtractObjC(op1, op2, floatval, inplace, zerodivision_check)\
- (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
-#endif
-
-/* PyFloatBinop.proto */
-#if !CYTHON_COMPILING_IN_PYPY
-static PyObject* __Pyx_PyFloat_AddObjC(PyObject *op1, PyObject *op2, double floatval, int inplace, int zerodivision_check);
-#else
-#define __Pyx_PyFloat_AddObjC(op1, op2, floatval, inplace, zerodivision_check)\
- (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
-#endif
-
/* MemviewSliceInit.proto */
#define __Pyx_BUF_MAX_NDIMS %(BUF_MAX_NDIMS)d
#define __Pyx_MEMVIEW_DIRECT 1
@@ -1629,26 +1576,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, P
/* SetupReduce.proto */
static int __Pyx_setup_reduce(PyObject* type_obj);
-/* CalculateMetaclass.proto */
-static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);
-
-/* SetNameInClass.proto */
-#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
-#define __Pyx_SetNameInClass(ns, name, value)\
- (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value))
-#elif CYTHON_COMPILING_IN_CPYTHON
-#define __Pyx_SetNameInClass(ns, name, value)\
- (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value))
-#else
-#define __Pyx_SetNameInClass(ns, name, value) PyObject_SetItem(ns, name, value)
-#endif
-
-/* Py3ClassCreate.proto */
-static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
- PyObject *mkw, PyObject *modname, PyObject *doc);
-static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
- PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass);
-
/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
@@ -1736,10 +1663,10 @@ static int __Pyx_ValidateAndInit_memviewslice(
static CYTHON_INLINE __Pyx_memviewslice __Pyx_PyObject_to_MemoryviewSlice_dsdsds_unsigned_char(PyObject *, int writable_flag);
/* CIntToPy.proto */
-static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_char(unsigned char value);
/* CIntToPy.proto */
-static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_char(unsigned char value);
+static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
/* MemviewDtypeToObject.proto */
static CYTHON_INLINE PyObject *__pyx_memview_get_unsigned_char(const char *itemp);
@@ -1755,21 +1682,18 @@ __pyx_memoryview_copy_new_contig(const __Pyx_memviewslice *from_mvs,
size_t sizeof_dtype, int contig_flag,
int dtype_is_object);
-/* CIntFromPy.proto */
-static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *);
-
/* CIntFromPy.proto */
static CYTHON_INLINE unsigned char __Pyx_PyInt_As_unsigned_char(PyObject *);
-/* CIntFromPy.proto */
-static CYTHON_INLINE signed char __Pyx_PyInt_As_signed__char(PyObject *);
-
/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
+/* CIntFromPy.proto */
+static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *);
+
/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);
@@ -1791,15 +1715,15 @@ static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memo
/* Module declarations from 'cython' */
-/* Module declarations from 'pymoab' */
+/* Module declarations from 'huemask' */
static PyTypeObject *__pyx_array_type = 0;
static PyTypeObject *__pyx_MemviewEnum_type = 0;
static PyTypeObject *__pyx_memoryview_type = 0;
static PyTypeObject *__pyx_memoryviewslice_type = 0;
-static float __pyx_v_6pymoab__bandpass_lookup[0x100];
-static float __pyx_v_6pymoab__last_sigma;
-static float __pyx_v_6pymoab__last_gain;
-static unsigned char __pyx_v_6pymoab__last_center;
+static float __pyx_v_7huemask__bandpass_lookup[0x100];
+static float __pyx_v_7huemask__last_sigma;
+static float __pyx_v_7huemask__last_gain;
+static unsigned char __pyx_v_7huemask__last_center;
static PyObject *generic = 0;
static PyObject *strided = 0;
static PyObject *indirect = 0;
@@ -1841,11 +1765,11 @@ static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *, int, size
static void __pyx_memoryview__slice_assign_scalar(char *, Py_ssize_t *, Py_ssize_t *, int, size_t, void *); /*proto*/
static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *, PyObject *); /*proto*/
static __Pyx_TypeInfo __Pyx_TypeInfo_unsigned_char = { "unsigned char", NULL, sizeof(unsigned char), { 0 }, 0, IS_UNSIGNED(unsigned char) ? 'U' : 'I', IS_UNSIGNED(unsigned char), 0 };
-#define __Pyx_MODULE_NAME "pymoab"
-extern int __pyx_module_is_main_pymoab;
-int __pyx_module_is_main_pymoab = 0;
+#define __Pyx_MODULE_NAME "huemask"
+extern int __pyx_module_is_main_huemask;
+int __pyx_module_is_main_huemask = 0;
-/* Implementation of 'pymoab' */
+/* Implementation of 'huemask' */
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_MemoryError;
@@ -1855,7 +1779,6 @@ static PyObject *__pyx_builtin_Ellipsis;
static PyObject *__pyx_builtin_id;
static PyObject *__pyx_builtin_IndexError;
static const char __pyx_k_O[] = "O";
-static const char __pyx_k_X[] = "X";
static const char __pyx_k_c[] = "c";
static const char __pyx_k_f[] = "f";
static const char __pyx_k_h[] = "h";
@@ -1864,27 +1787,15 @@ static const char __pyx_k_s[] = "s";
static const char __pyx_k_v[] = "v";
static const char __pyx_k_x[] = "x";
static const char __pyx_k_y[] = "y";
-static const char __pyx_k_OK[] = "OK";
-static const char __pyx_k_UP[] = "UP";
static const char __pyx_k_id[] = "id";
static const char __pyx_k_ih[] = "ih";
static const char __pyx_k_mu[] = "mu";
-static const char __pyx_k_CAL[] = "CAL";
-static const char __pyx_k_DOT[] = "DOT";
-static const char __pyx_k_doc[] = "__doc__";
static const char __pyx_k_exp[] = "exp";
static const char __pyx_k_new[] = "__new__";
static const char __pyx_k_obj[] = "obj";
-static const char __pyx_k_DOWN[] = "DOWN";
-static const char __pyx_k_INFO[] = "INFO";
-static const char __pyx_k_INIT[] = "INIT";
-static const char __pyx_k_Icon[] = "Icon";
-static const char __pyx_k_Text[] = "Text";
static const char __pyx_k_base[] = "base";
static const char __pyx_k_dict[] = "__dict__";
-static const char __pyx_k_enum[] = "enum";
static const char __pyx_k_gain[] = "gain";
-static const char __pyx_k_init[] = "init";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_mask[] = "mask";
static const char __pyx_k_math[] = "math";
@@ -1895,15 +1806,8 @@ static const char __pyx_k_pack[] = "pack";
static const char __pyx_k_size[] = "size";
static const char __pyx_k_step[] = "step";
static const char __pyx_k_stop[] = "stop";
-static const char __pyx_k_sync[] = "sync";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_ASCII[] = "ASCII";
-static const char __pyx_k_BLANK[] = "BLANK";
-static const char __pyx_k_BRAIN[] = "BRAIN";
-static const char __pyx_k_CHECK[] = "CHECK";
-static const char __pyx_k_ERROR[] = "ERROR";
-static const char __pyx_k_PAUSE[] = "PAUSE";
-static const char __pyx_k_Tuple[] = "Tuple";
static const char __pyx_k_class[] = "__class__";
static const char __pyx_k_error[] = "error";
static const char __pyx_k_flags[] = "flags";
@@ -1913,98 +1817,48 @@ static const char __pyx_k_shape[] = "shape";
static const char __pyx_k_sigma[] = "sigma";
static const char __pyx_k_start[] = "start";
static const char __pyx_k_width[] = "width";
-static const char __pyx_k_MANUAL[] = "MANUAL";
-static const char __pyx_k_Result[] = "Result";
static const char __pyx_k_center[] = "center";
static const char __pyx_k_encode[] = "encode";
static const char __pyx_k_format[] = "format";
static const char __pyx_k_height[] = "height";
static const char __pyx_k_import[] = "__import__";
-static const char __pyx_k_module[] = "__module__";
static const char __pyx_k_name_2[] = "__name__";
static const char __pyx_k_pickle[] = "pickle";
-static const char __pyx_k_pymoab[] = "pymoab";
static const char __pyx_k_reduce[] = "__reduce__";
static const char __pyx_k_struct[] = "struct";
-static const char __pyx_k_typing[] = "typing";
static const char __pyx_k_unpack[] = "unpack";
static const char __pyx_k_update[] = "update";
-static const char __pyx_k_CLASSIC[] = "CLASSIC";
-static const char __pyx_k_CUSTOM1[] = "CUSTOM1";
-static const char __pyx_k_CUSTOM2[] = "CUSTOM2";
-static const char __pyx_k_IntEnum[] = "IntEnum";
-static const char __pyx_k_UP_DOWN[] = "UP_DOWN";
-static const char __pyx_k_enabled[] = "enabled";
static const char __pyx_k_fortran[] = "fortran";
+static const char __pyx_k_huemask[] = "huemask";
static const char __pyx_k_memview[] = "memview";
-static const char __pyx_k_prepare[] = "__prepare__";
-static const char __pyx_k_setIcon[] = "setIcon";
-static const char __pyx_k_setText[] = "setText";
static const char __pyx_k_Ellipsis[] = "Ellipsis";
static const char __pyx_k_getstate[] = "__getstate__";
static const char __pyx_k_hue_mask[] = "hue_mask";
-static const char __pyx_k_icon_idx[] = "icon_idx";
static const char __pyx_k_itemsize[] = "itemsize";
-static const char __pyx_k_moab_pyx[] = "moab.pyx";
-static const char __pyx_k_pollTemp[] = "pollTemp";
static const char __pyx_k_pyx_type[] = "__pyx_type";
-static const char __pyx_k_qualname[] = "__qualname__";
static const char __pyx_k_setstate[] = "__setstate__";
-static const char __pyx_k_text_idx[] = "text_idx";
-static const char __pyx_k_CAL_INSTR[] = "CAL_INSTR";
-static const char __pyx_k_POWER_OFF[] = "POWER_OFF";
static const char __pyx_k_TypeError[] = "TypeError";
-static const char __pyx_k_enableFan[] = "enableFan";
-static const char __pyx_k_enableHat[] = "enableHat";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_mask_gain[] = "mask_gain";
-static const char __pyx_k_metaclass[] = "__metaclass__";
static const char __pyx_k_pyx_state[] = "__pyx_state";
static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
-static const char __pyx_k_CAL_FAILED[] = "CAL_FAILED";
static const char __pyx_k_IndexError[] = "IndexError";
-static const char __pyx_k_VERS_IP_SN[] = "VERS_IP_SN";
static const char __pyx_k_ValueError[] = "ValueError";
-static const char __pyx_k_getMenuBtn[] = "getMenuBtn";
-static const char __pyx_k_hoverPlate[] = "hoverPlate";
-static const char __pyx_k_lowerPlate[] = "lowerPlate";
static const char __pyx_k_pyx_result[] = "__pyx_result";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
-static const char __pyx_k_servo1_pos[] = "servo1_pos";
-static const char __pyx_k_servo2_pos[] = "servo2_pos";
-static const char __pyx_k_servo3_pos[] = "servo3_pos";
-static const char __pyx_k_INVALID_ARG[] = "INVALID_ARG";
static const char __pyx_k_MemoryError[] = "MemoryError";
static const char __pyx_k_PickleError[] = "PickleError";
-static const char __pyx_k_plate_x_deg[] = "plate_x_deg";
-static const char __pyx_k_plate_y_deg[] = "plate_y_deg";
-static const char __pyx_k_CAL_CANCELED[] = "CAL_CANCELED";
-static const char __pyx_k_CAL_COMPLETE[] = "CAL_COMPLETE";
-static const char __pyx_k_UPDATE_BRAIN[] = "UPDATE_BRAIN";
-static const char __pyx_k_getJoystickX[] = "getJoystickX";
-static const char __pyx_k_getJoystickY[] = "getJoystickY";
-static const char __pyx_k_pollPowerBtn[] = "pollPowerBtn";
+static const char __pyx_k_huemask_pyx[] = "huemask.pyx";
static const char __pyx_k_pyx_checksum[] = "__pyx_checksum";
static const char __pyx_k_stringsource[] = "stringsource";
-static const char __pyx_k_UNKNOWN_ERROR[] = "UNKNOWN_ERROR";
-static const char __pyx_k_UPDATE_SYSTEM[] = "UPDATE_SYSTEM";
-static const char __pyx_k_activatePlate[] = "activatePlate";
static const char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer";
static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
-static const char __pyx_k_servo1_offset[] = "servo1_offset";
-static const char __pyx_k_servo2_offset[] = "servo2_offset";
-static const char __pyx_k_servo3_offset[] = "servo3_offset";
-static const char __pyx_k_getJoystickBtn[] = "getJoystickBtn";
-static const char __pyx_k_setPlateAngles[] = "setPlateAngles";
static const char __pyx_k_View_MemoryView[] = "View.MemoryView";
static const char __pyx_k_allocate_buffer[] = "allocate_buffer";
static const char __pyx_k_dtype_is_object[] = "dtype_is_object";
static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError";
-static const char __pyx_k_setServoOffsets[] = "setServoOffsets";
static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
-static const char __pyx_k_disableServoPower[] = "disableServoPower";
static const char __pyx_k_pyx_unpickle_Enum[] = "__pyx_unpickle_Enum";
-static const char __pyx_k_setServoPositions[] = "setServoPositions";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_strided_and_direct[] = "";
static const char __pyx_k_strided_and_indirect[] = "";
@@ -2032,62 +1886,28 @@ static const char __pyx_k_got_differing_extents_in_dimensi[] = "got differing ex
static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__";
static const char __pyx_k_unable_to_allocate_shape_and_str[] = "unable to allocate shape and strides.";
static PyObject *__pyx_n_s_ASCII;
-static PyObject *__pyx_n_s_BLANK;
-static PyObject *__pyx_n_s_BRAIN;
static PyObject *__pyx_kp_s_Buffer_view_does_not_expose_stri;
-static PyObject *__pyx_n_s_CAL;
-static PyObject *__pyx_n_s_CAL_CANCELED;
-static PyObject *__pyx_n_s_CAL_COMPLETE;
-static PyObject *__pyx_n_s_CAL_FAILED;
-static PyObject *__pyx_n_s_CAL_INSTR;
-static PyObject *__pyx_n_s_CHECK;
-static PyObject *__pyx_n_s_CLASSIC;
-static PyObject *__pyx_n_s_CUSTOM1;
-static PyObject *__pyx_n_s_CUSTOM2;
static PyObject *__pyx_kp_s_Can_only_create_a_buffer_that_is;
static PyObject *__pyx_kp_s_Cannot_assign_to_read_only_memor;
static PyObject *__pyx_kp_s_Cannot_create_writable_memory_vi;
static PyObject *__pyx_kp_s_Cannot_index_with_type_s;
-static PyObject *__pyx_n_s_DOT;
-static PyObject *__pyx_n_s_DOWN;
-static PyObject *__pyx_n_s_ERROR;
static PyObject *__pyx_n_s_Ellipsis;
static PyObject *__pyx_kp_s_Empty_shape_tuple_for_cython_arr;
-static PyObject *__pyx_n_s_INFO;
-static PyObject *__pyx_n_s_INIT;
-static PyObject *__pyx_n_s_INVALID_ARG;
-static PyObject *__pyx_n_s_Icon;
static PyObject *__pyx_kp_s_Incompatible_checksums_s_vs_0xb0;
static PyObject *__pyx_n_s_IndexError;
static PyObject *__pyx_kp_s_Indirect_dimensions_not_supporte;
-static PyObject *__pyx_n_s_IntEnum;
static PyObject *__pyx_kp_s_Invalid_mode_expected_c_or_fortr;
static PyObject *__pyx_kp_s_Invalid_shape_in_axis_d_d;
-static PyObject *__pyx_n_s_MANUAL;
static PyObject *__pyx_n_s_MemoryError;
static PyObject *__pyx_kp_s_MemoryView_of_r_at_0x_x;
static PyObject *__pyx_kp_s_MemoryView_of_r_object;
static PyObject *__pyx_n_b_O;
-static PyObject *__pyx_n_s_OK;
static PyObject *__pyx_kp_s_Out_of_bounds_on_buffer_access_a;
-static PyObject *__pyx_n_s_PAUSE;
-static PyObject *__pyx_n_s_POWER_OFF;
static PyObject *__pyx_n_s_PickleError;
-static PyObject *__pyx_n_s_Result;
-static PyObject *__pyx_n_s_Text;
-static PyObject *__pyx_n_s_Tuple;
static PyObject *__pyx_n_s_TypeError;
-static PyObject *__pyx_n_s_UNKNOWN_ERROR;
-static PyObject *__pyx_n_s_UP;
-static PyObject *__pyx_n_s_UPDATE_BRAIN;
-static PyObject *__pyx_n_s_UPDATE_SYSTEM;
-static PyObject *__pyx_n_s_UP_DOWN;
static PyObject *__pyx_kp_s_Unable_to_convert_item_to_object;
-static PyObject *__pyx_n_s_VERS_IP_SN;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_s_View_MemoryView;
-static PyObject *__pyx_n_s_X;
-static PyObject *__pyx_n_s_activatePlate;
static PyObject *__pyx_n_s_allocate_buffer;
static PyObject *__pyx_n_s_base;
static PyObject *__pyx_n_s_c;
@@ -2098,14 +1918,8 @@ static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_kp_s_contiguous_and_direct;
static PyObject *__pyx_kp_s_contiguous_and_indirect;
static PyObject *__pyx_n_s_dict;
-static PyObject *__pyx_n_s_disableServoPower;
-static PyObject *__pyx_n_s_doc;
static PyObject *__pyx_n_s_dtype_is_object;
-static PyObject *__pyx_n_s_enableFan;
-static PyObject *__pyx_n_s_enableHat;
-static PyObject *__pyx_n_s_enabled;
static PyObject *__pyx_n_s_encode;
-static PyObject *__pyx_n_s_enum;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_error;
static PyObject *__pyx_n_s_exp;
@@ -2115,34 +1929,25 @@ static PyObject *__pyx_n_s_format;
static PyObject *__pyx_n_s_fortran;
static PyObject *__pyx_n_u_fortran;
static PyObject *__pyx_n_s_gain;
-static PyObject *__pyx_n_s_getJoystickBtn;
-static PyObject *__pyx_n_s_getJoystickX;
-static PyObject *__pyx_n_s_getJoystickY;
-static PyObject *__pyx_n_s_getMenuBtn;
static PyObject *__pyx_n_s_getstate;
static PyObject *__pyx_kp_s_got_differing_extents_in_dimensi;
static PyObject *__pyx_n_s_h;
static PyObject *__pyx_n_s_height;
-static PyObject *__pyx_n_s_hoverPlate;
static PyObject *__pyx_n_s_hue_mask;
-static PyObject *__pyx_n_s_icon_idx;
+static PyObject *__pyx_n_s_huemask;
+static PyObject *__pyx_kp_s_huemask_pyx;
static PyObject *__pyx_n_s_id;
static PyObject *__pyx_n_s_ih;
static PyObject *__pyx_n_s_image;
static PyObject *__pyx_n_s_import;
-static PyObject *__pyx_n_s_init;
static PyObject *__pyx_n_s_itemsize;
static PyObject *__pyx_kp_s_itemsize_0_for_cython_array;
-static PyObject *__pyx_n_s_lowerPlate;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_mask;
static PyObject *__pyx_n_s_mask_gain;
static PyObject *__pyx_n_s_math;
static PyObject *__pyx_n_s_memview;
-static PyObject *__pyx_n_s_metaclass;
-static PyObject *__pyx_kp_s_moab_pyx;
static PyObject *__pyx_n_s_mode;
-static PyObject *__pyx_n_s_module;
static PyObject *__pyx_n_s_mu;
static PyObject *__pyx_n_s_n;
static PyObject *__pyx_n_s_name;
@@ -2153,12 +1958,6 @@ static PyObject *__pyx_kp_s_no_default___reduce___due_to_non;
static PyObject *__pyx_n_s_obj;
static PyObject *__pyx_n_s_pack;
static PyObject *__pyx_n_s_pickle;
-static PyObject *__pyx_n_s_plate_x_deg;
-static PyObject *__pyx_n_s_plate_y_deg;
-static PyObject *__pyx_n_s_pollPowerBtn;
-static PyObject *__pyx_n_s_pollTemp;
-static PyObject *__pyx_n_s_prepare;
-static PyObject *__pyx_n_s_pymoab;
static PyObject *__pyx_n_s_pyx_PickleError;
static PyObject *__pyx_n_s_pyx_checksum;
static PyObject *__pyx_n_s_pyx_getbuffer;
@@ -2167,23 +1966,11 @@ static PyObject *__pyx_n_s_pyx_state;
static PyObject *__pyx_n_s_pyx_type;
static PyObject *__pyx_n_s_pyx_unpickle_Enum;
static PyObject *__pyx_n_s_pyx_vtable;
-static PyObject *__pyx_n_s_qualname;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_reduce;
static PyObject *__pyx_n_s_reduce_cython;
static PyObject *__pyx_n_s_reduce_ex;
static PyObject *__pyx_n_s_s;
-static PyObject *__pyx_n_s_servo1_offset;
-static PyObject *__pyx_n_s_servo1_pos;
-static PyObject *__pyx_n_s_servo2_offset;
-static PyObject *__pyx_n_s_servo2_pos;
-static PyObject *__pyx_n_s_servo3_offset;
-static PyObject *__pyx_n_s_servo3_pos;
-static PyObject *__pyx_n_s_setIcon;
-static PyObject *__pyx_n_s_setPlateAngles;
-static PyObject *__pyx_n_s_setServoOffsets;
-static PyObject *__pyx_n_s_setServoPositions;
-static PyObject *__pyx_n_s_setText;
static PyObject *__pyx_n_s_setstate;
static PyObject *__pyx_n_s_setstate_cython;
static PyObject *__pyx_n_s_shape;
@@ -2197,10 +1984,7 @@ static PyObject *__pyx_kp_s_strided_and_direct_or_indirect;
static PyObject *__pyx_kp_s_strided_and_indirect;
static PyObject *__pyx_kp_s_stringsource;
static PyObject *__pyx_n_s_struct;
-static PyObject *__pyx_n_s_sync;
static PyObject *__pyx_n_s_test;
-static PyObject *__pyx_n_s_text_idx;
-static PyObject *__pyx_n_s_typing;
static PyObject *__pyx_kp_s_unable_to_allocate_array_data;
static PyObject *__pyx_kp_s_unable_to_allocate_shape_and_str;
static PyObject *__pyx_n_s_unpack;
@@ -2210,27 +1994,8 @@ static PyObject *__pyx_n_s_v;
static PyObject *__pyx_n_s_width;
static PyObject *__pyx_n_s_x;
static PyObject *__pyx_n_s_y;
-static PyObject *__pyx_pf_6pymoab_init(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_2activatePlate(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_4hoverPlate(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_6lowerPlate(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_8disableServoPower(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_10setPlateAngles(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_plate_x_deg, PyObject *__pyx_v_plate_y_deg); /* proto */
-static PyObject *__pyx_pf_6pymoab_12setServoPositions(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_servo1_pos, PyObject *__pyx_v_servo2_pos, PyObject *__pyx_v_servo3_pos); /* proto */
-static PyObject *__pyx_pf_6pymoab_14setServoOffsets(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_servo1_offset, PyObject *__pyx_v_servo2_offset, PyObject *__pyx_v_servo3_offset); /* proto */
-static PyObject *__pyx_pf_6pymoab_16setIcon(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_icon_idx); /* proto */
-static PyObject *__pyx_pf_6pymoab_18setText(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_text_idx); /* proto */
-static PyObject *__pyx_pf_6pymoab_20sync(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_22getMenuBtn(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_24getJoystickBtn(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_26getJoystickX(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_28getJoystickY(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_30enableFan(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_6pymoab_bool __pyx_v_enabled); /* proto */
-static PyObject *__pyx_pf_6pymoab_32enableHat(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_6pymoab_bool __pyx_v_enabled); /* proto */
-static PyObject *__pyx_pf_6pymoab_34pollTemp(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_36pollPowerBtn(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
-static PyObject *__pyx_pf_6pymoab_38_update_bandpass_lookup(CYTHON_UNUSED PyObject *__pyx_self, unsigned char __pyx_v_center, float __pyx_v_sigma, float __pyx_v_gain); /* proto */
-static PyObject *__pyx_pf_6pymoab_40hue_mask(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_image, unsigned char __pyx_v_center, float __pyx_v_sigma, float __pyx_v_gain, float __pyx_v_mask_gain); /* proto */
+static PyObject *__pyx_pf_7huemask__update_bandpass_lookup(CYTHON_UNUSED PyObject *__pyx_self, unsigned char __pyx_v_center, float __pyx_v_sigma, float __pyx_v_gain); /* proto */
+static PyObject *__pyx_pf_7huemask_2hue_mask(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_image, unsigned char __pyx_v_center, float __pyx_v_sigma, float __pyx_v_gain, float __pyx_v_mask_gain); /* proto */
static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer); /* proto */
static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self); /* proto */
@@ -2283,21 +2048,6 @@ static PyObject *__pyx_float_255_0;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
-static PyObject *__pyx_int_3;
-static PyObject *__pyx_int_4;
-static PyObject *__pyx_int_5;
-static PyObject *__pyx_int_6;
-static PyObject *__pyx_int_7;
-static PyObject *__pyx_int_8;
-static PyObject *__pyx_int_9;
-static PyObject *__pyx_int_10;
-static PyObject *__pyx_int_11;
-static PyObject *__pyx_int_12;
-static PyObject *__pyx_int_13;
-static PyObject *__pyx_int_14;
-static PyObject *__pyx_int_15;
-static PyObject *__pyx_int_16;
-static PyObject *__pyx_int_17;
static PyObject *__pyx_int_184977713;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_tuple_;
@@ -2318,369 +2068,436 @@ static PyObject *__pyx_tuple__14;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__17;
static PyObject *__pyx_tuple__18;
+static PyObject *__pyx_tuple__19;
+static PyObject *__pyx_tuple__21;
+static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
+static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__26;
+static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__28;
-static PyObject *__pyx_tuple__30;
-static PyObject *__pyx_tuple__32;
-static PyObject *__pyx_tuple__39;
-static PyObject *__pyx_tuple__41;
-static PyObject *__pyx_tuple__45;
-static PyObject *__pyx_tuple__47;
-static PyObject *__pyx_tuple__49;
-static PyObject *__pyx_tuple__50;
-static PyObject *__pyx_tuple__51;
-static PyObject *__pyx_tuple__52;
-static PyObject *__pyx_tuple__53;
-static PyObject *__pyx_tuple__54;
-static PyObject *__pyx_codeobj__19;
static PyObject *__pyx_codeobj__20;
-static PyObject *__pyx_codeobj__21;
static PyObject *__pyx_codeobj__22;
-static PyObject *__pyx_codeobj__23;
-static PyObject *__pyx_codeobj__25;
-static PyObject *__pyx_codeobj__27;
static PyObject *__pyx_codeobj__29;
-static PyObject *__pyx_codeobj__31;
-static PyObject *__pyx_codeobj__33;
-static PyObject *__pyx_codeobj__34;
-static PyObject *__pyx_codeobj__35;
-static PyObject *__pyx_codeobj__36;
-static PyObject *__pyx_codeobj__37;
-static PyObject *__pyx_codeobj__38;
-static PyObject *__pyx_codeobj__40;
-static PyObject *__pyx_codeobj__42;
-static PyObject *__pyx_codeobj__43;
-static PyObject *__pyx_codeobj__44;
-static PyObject *__pyx_codeobj__46;
-static PyObject *__pyx_codeobj__48;
-static PyObject *__pyx_codeobj__55;
/* Late includes */
-/* "moab.pyx":71
- * UPDATE_SYSTEM = 17
- *
- * def init() -> Result: # <<<<<<<<<<<<<<
- * """
- * Initializes the library.
+/* "huemask.pyx":14
+ * @cython.boundscheck(False)
+ * @cython.wraparound(False)
+ * def _update_bandpass_lookup(unsigned char center, float sigma, float gain): # <<<<<<<<<<<<<<
+ * global _bandpass_lookup
+ * global _last_center
*/
/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_1init(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static char __pyx_doc_6pymoab_init[] = "\n Initializes the library.\n Call once at startup.\n\n return OK on success.\n ";
-static PyMethodDef __pyx_mdef_6pymoab_1init = {"init", (PyCFunction)__pyx_pw_6pymoab_1init, METH_NOARGS, __pyx_doc_6pymoab_init};
-static PyObject *__pyx_pw_6pymoab_1init(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
+static PyObject *__pyx_pw_7huemask_1_update_bandpass_lookup(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7huemask_1_update_bandpass_lookup = {"_update_bandpass_lookup", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7huemask_1_update_bandpass_lookup, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_7huemask_1_update_bandpass_lookup(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ unsigned char __pyx_v_center;
+ float __pyx_v_sigma;
+ float __pyx_v_gain;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("init (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_init(__pyx_self);
+ __Pyx_RefNannySetupContext("_update_bandpass_lookup (wrapper)", 0);
+ {
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_center,&__pyx_n_s_sigma,&__pyx_n_s_gain,0};
+ PyObject* values[3] = {0,0,0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+ switch (pos_args) {
+ case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+ CYTHON_FALLTHROUGH;
+ case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ CYTHON_FALLTHROUGH;
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ CYTHON_FALLTHROUGH;
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (pos_args) {
+ case 0:
+ if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_center)) != 0)) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ CYTHON_FALLTHROUGH;
+ case 1:
+ if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sigma)) != 0)) kw_args--;
+ else {
+ __Pyx_RaiseArgtupleInvalid("_update_bandpass_lookup", 1, 3, 3, 1); __PYX_ERR(0, 14, __pyx_L3_error)
+ }
+ CYTHON_FALLTHROUGH;
+ case 2:
+ if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gain)) != 0)) kw_args--;
+ else {
+ __Pyx_RaiseArgtupleInvalid("_update_bandpass_lookup", 1, 3, 3, 2); __PYX_ERR(0, 14, __pyx_L3_error)
+ }
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_update_bandpass_lookup") < 0)) __PYX_ERR(0, 14, __pyx_L3_error)
+ }
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
+ goto __pyx_L5_argtuple_error;
+ } else {
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+ }
+ __pyx_v_center = __Pyx_PyInt_As_unsigned_char(values[0]); if (unlikely((__pyx_v_center == (unsigned char)-1) && PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error)
+ __pyx_v_sigma = __pyx_PyFloat_AsFloat(values[1]); if (unlikely((__pyx_v_sigma == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error)
+ __pyx_v_gain = __pyx_PyFloat_AsFloat(values[2]); if (unlikely((__pyx_v_gain == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error)
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("_update_bandpass_lookup", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 14, __pyx_L3_error)
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("huemask._update_bandpass_lookup", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return NULL;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_pf_7huemask__update_bandpass_lookup(__pyx_self, __pyx_v_center, __pyx_v_sigma, __pyx_v_gain);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_6pymoab_init(CYTHON_UNUSED PyObject *__pyx_self) {
+static PyObject *__pyx_pf_7huemask__update_bandpass_lookup(CYTHON_UNUSED PyObject *__pyx_self, unsigned char __pyx_v_center, float __pyx_v_sigma, float __pyx_v_gain) {
+ double __pyx_v_mu;
+ PyObject *__pyx_v_n = NULL;
+ PyObject *__pyx_v_h = NULL;
+ PyObject *__pyx_v_f = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
+ long __pyx_t_1;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
- PyObject *__pyx_t_4 = NULL;
+ int __pyx_t_4;
+ PyObject *__pyx_t_5 = NULL;
+ PyObject *__pyx_t_6 = NULL;
+ PyObject *__pyx_t_7 = NULL;
+ float __pyx_t_8;
+ Py_ssize_t __pyx_t_9;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("init", 0);
+ __Pyx_RefNannySetupContext("_update_bandpass_lookup", 0);
- /* "moab.pyx":78
- * return OK on success.
- * """
- * return Result(moab_init()) # <<<<<<<<<<<<<<
+ /* "huemask.pyx":20
+ * global _last_sigma
*
- * def activatePlate():
+ * _last_center = center # <<<<<<<<<<<<<<
+ * _last_sigma = sigma
+ * _last_gain = gain
*/
- __Pyx_XDECREF(__pyx_r);
- __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = __Pyx_PyInt_From_int(moab_init()); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 78, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = NULL;
- if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
- __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
- if (likely(__pyx_t_4)) {
- PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
- __Pyx_INCREF(__pyx_t_4);
- __Pyx_INCREF(function);
- __Pyx_DECREF_SET(__pyx_t_2, function);
- }
- }
- __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
- __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
+ __pyx_v_7huemask__last_center = __pyx_v_center;
- /* "moab.pyx":71
- * UPDATE_SYSTEM = 17
+ /* "huemask.pyx":21
*
- * def init() -> Result: # <<<<<<<<<<<<<<
- * """
- * Initializes the library.
- */
-
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_4);
- __Pyx_AddTraceback("pymoab.init", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":80
- * return Result(moab_init())
+ * _last_center = center
+ * _last_sigma = sigma # <<<<<<<<<<<<<<
+ * _last_gain = gain
*
- * def activatePlate(): # <<<<<<<<<<<<<<
- * """ Set the plate to track plate angles. """
- * moab_activatePlate()
*/
+ __pyx_v_7huemask__last_sigma = __pyx_v_sigma;
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_3activatePlate(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static char __pyx_doc_6pymoab_2activatePlate[] = " Set the plate to track plate angles. ";
-static PyMethodDef __pyx_mdef_6pymoab_3activatePlate = {"activatePlate", (PyCFunction)__pyx_pw_6pymoab_3activatePlate, METH_NOARGS, __pyx_doc_6pymoab_2activatePlate};
-static PyObject *__pyx_pw_6pymoab_3activatePlate(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("activatePlate (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_2activatePlate(__pyx_self);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_2activatePlate(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("activatePlate", 0);
-
- /* "moab.pyx":82
- * def activatePlate():
- * """ Set the plate to track plate angles. """
- * moab_activatePlate() # <<<<<<<<<<<<<<
+ /* "huemask.pyx":22
+ * _last_center = center
+ * _last_sigma = sigma
+ * _last_gain = gain # <<<<<<<<<<<<<<
*
- * def hoverPlate():
+ * mu = 0.5
*/
- moab_activatePlate();
+ __pyx_v_7huemask__last_gain = __pyx_v_gain;
- /* "moab.pyx":80
- * return Result(moab_init())
+ /* "huemask.pyx":24
+ * _last_gain = gain
*
- * def activatePlate(): # <<<<<<<<<<<<<<
- * """ Set the plate to track plate angles. """
- * moab_activatePlate()
+ * mu = 0.5 # <<<<<<<<<<<<<<
+ * for n in range(256):
+ * h = n / 255.0
*/
+ __pyx_v_mu = 0.5;
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":84
- * moab_activatePlate()
+ /* "huemask.pyx":25
+ *
+ * mu = 0.5
+ * for n in range(256): # <<<<<<<<<<<<<<
+ * h = n / 255.0
*
- * def hoverPlate(): # <<<<<<<<<<<<<<
- * """
- * Set the plate to its hover position.
*/
+ for (__pyx_t_1 = 0; __pyx_t_1 < 0x100; __pyx_t_1+=1) {
+ __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_2);
+ __pyx_t_2 = 0;
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_5hoverPlate(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static char __pyx_doc_6pymoab_4hoverPlate[] = "\n Set the plate to its hover position. \n This was experimentally found to be 150 (down but still leaving some \n space at the bottom).\n ";
-static PyMethodDef __pyx_mdef_6pymoab_5hoverPlate = {"hoverPlate", (PyCFunction)__pyx_pw_6pymoab_5hoverPlate, METH_NOARGS, __pyx_doc_6pymoab_4hoverPlate};
-static PyObject *__pyx_pw_6pymoab_5hoverPlate(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("hoverPlate (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_4hoverPlate(__pyx_self);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_4hoverPlate(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("hoverPlate", 0);
-
- /* "moab.pyx":90
- * space at the bottom).
- * """
- * moab_setServoPositions(150, 150, 150) # <<<<<<<<<<<<<<
+ /* "huemask.pyx":26
+ * mu = 0.5
+ * for n in range(256):
+ * h = n / 255.0 # <<<<<<<<<<<<<<
*
- * def lowerPlate():
+ * # rotate the hue phase so that `center` is at 0.5
*/
- moab_setServoPositions(0x96, 0x96, 0x96);
+ __pyx_t_2 = __Pyx_PyFloat_TrueDivideObjC(__pyx_v_n, __pyx_float_255_0, 255.0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_XDECREF_SET(__pyx_v_h, __pyx_t_2);
+ __pyx_t_2 = 0;
- /* "moab.pyx":84
- * moab_activatePlate()
+ /* "huemask.pyx":29
*
- * def hoverPlate(): # <<<<<<<<<<<<<<
- * """
- * Set the plate to its hover position.
+ * # rotate the hue phase so that `center` is at 0.5
+ * h = h + (0.5 - (center / 255.0)) # <<<<<<<<<<<<<<
+ * if (h > 1.0):
+ * h = h - 1.0
*/
+ __pyx_t_2 = PyFloat_FromDouble((0.5 - (((double)__pyx_v_center) / 255.0))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyNumber_Add(__pyx_v_h, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 29, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF_SET(__pyx_v_h, __pyx_t_3);
+ __pyx_t_3 = 0;
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":92
- * moab_setServoPositions(150, 150, 150)
- *
- * def lowerPlate(): # <<<<<<<<<<<<<<
- * """
- * Set the plate to its lower position (usually powered-off state).
+ /* "huemask.pyx":30
+ * # rotate the hue phase so that `center` is at 0.5
+ * h = h + (0.5 - (center / 255.0))
+ * if (h > 1.0): # <<<<<<<<<<<<<<
+ * h = h - 1.0
+ * if (h < 0.0):
*/
+ __pyx_t_3 = PyObject_RichCompare(__pyx_v_h, __pyx_float_1_0, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L1_error)
+ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 30, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ if (__pyx_t_4) {
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_7lowerPlate(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static char __pyx_doc_6pymoab_6lowerPlate[] = "\n Set the plate to its lower position (usually powered-off state). \n This was experimentally found to be 155 (lowest possible position).\n ";
-static PyMethodDef __pyx_mdef_6pymoab_7lowerPlate = {"lowerPlate", (PyCFunction)__pyx_pw_6pymoab_7lowerPlate, METH_NOARGS, __pyx_doc_6pymoab_6lowerPlate};
-static PyObject *__pyx_pw_6pymoab_7lowerPlate(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("lowerPlate (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_6lowerPlate(__pyx_self);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "huemask.pyx":31
+ * h = h + (0.5 - (center / 255.0))
+ * if (h > 1.0):
+ * h = h - 1.0 # <<<<<<<<<<<<<<
+ * if (h < 0.0):
+ * h = h + 1.0
+ */
+ __pyx_t_3 = __Pyx_PyFloat_SubtractObjC(__pyx_v_h, __pyx_float_1_0, 1.0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF_SET(__pyx_v_h, __pyx_t_3);
+ __pyx_t_3 = 0;
-static PyObject *__pyx_pf_6pymoab_6lowerPlate(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("lowerPlate", 0);
+ /* "huemask.pyx":30
+ * # rotate the hue phase so that `center` is at 0.5
+ * h = h + (0.5 - (center / 255.0))
+ * if (h > 1.0): # <<<<<<<<<<<<<<
+ * h = h - 1.0
+ * if (h < 0.0):
+ */
+ }
- /* "moab.pyx":97
- * This was experimentally found to be 155 (lowest possible position).
- * """
- * moab_setServoPositions(155, 155, 155) # <<<<<<<<<<<<<<
+ /* "huemask.pyx":32
+ * if (h > 1.0):
+ * h = h - 1.0
+ * if (h < 0.0): # <<<<<<<<<<<<<<
+ * h = h + 1.0
*
- * def disableServoPower():
*/
- moab_setServoPositions(0x9B, 0x9B, 0x9B);
+ __pyx_t_3 = PyObject_RichCompare(__pyx_v_h, __pyx_float_0_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error)
+ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 32, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ if (__pyx_t_4) {
- /* "moab.pyx":92
- * moab_setServoPositions(150, 150, 150)
+ /* "huemask.pyx":33
+ * h = h - 1.0
+ * if (h < 0.0):
+ * h = h + 1.0 # <<<<<<<<<<<<<<
*
- * def lowerPlate(): # <<<<<<<<<<<<<<
- * """
- * Set the plate to its lower position (usually powered-off state).
+ * # gaussian bandpass filter
*/
+ __pyx_t_3 = __Pyx_PyFloat_AddObjC(__pyx_v_h, __pyx_float_1_0, 1.0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 33, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF_SET(__pyx_v_h, __pyx_t_3);
+ __pyx_t_3 = 0;
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "huemask.pyx":32
+ * if (h > 1.0):
+ * h = h - 1.0
+ * if (h < 0.0): # <<<<<<<<<<<<<<
+ * h = h + 1.0
+ *
+ */
+ }
-/* "moab.pyx":99
- * moab_setServoPositions(155, 155, 155)
+ /* "huemask.pyx":36
+ *
+ * # gaussian bandpass filter
+ * f = math.exp(-( (h - mu)**2 / ( 2.0 * sigma**2 ) ) ) # <<<<<<<<<<<<<<
*
- * def disableServoPower(): # <<<<<<<<<<<<<<
- * """ Disables the power to the servos. """
- * moab_disableServoPower()
+ * # pre-gain around center
*/
+ __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_math); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_exp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 36, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_6 = PyNumber_Subtract(__pyx_v_h, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 36, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyNumber_Power(__pyx_t_6, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __pyx_t_6 = PyFloat_FromDouble((2.0 * powf(__pyx_v_sigma, 2.0))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 36, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 36, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_7);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __pyx_t_6 = PyNumber_Negative(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 36, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+ __pyx_t_7 = NULL;
+ if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
+ __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
+ if (likely(__pyx_t_7)) {
+ PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+ __Pyx_INCREF(__pyx_t_7);
+ __Pyx_INCREF(function);
+ __Pyx_DECREF_SET(__pyx_t_5, function);
+ }
+ }
+ __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
+ __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 36, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_XDECREF_SET(__pyx_v_f, __pyx_t_3);
+ __pyx_t_3 = 0;
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_9disableServoPower(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static char __pyx_doc_6pymoab_8disableServoPower[] = " Disables the power to the servos. ";
-static PyMethodDef __pyx_mdef_6pymoab_9disableServoPower = {"disableServoPower", (PyCFunction)__pyx_pw_6pymoab_9disableServoPower, METH_NOARGS, __pyx_doc_6pymoab_8disableServoPower};
-static PyObject *__pyx_pw_6pymoab_9disableServoPower(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("disableServoPower (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_8disableServoPower(__pyx_self);
+ /* "huemask.pyx":39
+ *
+ * # pre-gain around center
+ * f = f * gain # <<<<<<<<<<<<<<
+ * if f > 1.0:
+ * f = 1.0
+ */
+ __pyx_t_3 = PyFloat_FromDouble(__pyx_v_gain); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 39, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_5 = PyNumber_Multiply(__pyx_v_f, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 39, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_DECREF_SET(__pyx_v_f, __pyx_t_5);
+ __pyx_t_5 = 0;
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "huemask.pyx":40
+ * # pre-gain around center
+ * f = f * gain
+ * if f > 1.0: # <<<<<<<<<<<<<<
+ * f = 1.0
+ *
+ */
+ __pyx_t_5 = PyObject_RichCompare(__pyx_v_f, __pyx_float_1_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 40, __pyx_L1_error)
+ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 40, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ if (__pyx_t_4) {
-static PyObject *__pyx_pf_6pymoab_8disableServoPower(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("disableServoPower", 0);
+ /* "huemask.pyx":41
+ * f = f * gain
+ * if f > 1.0:
+ * f = 1.0 # <<<<<<<<<<<<<<
+ *
+ * _bandpass_lookup[n] = f
+ */
+ __Pyx_INCREF(__pyx_float_1_0);
+ __Pyx_DECREF_SET(__pyx_v_f, __pyx_float_1_0);
- /* "moab.pyx":101
- * def disableServoPower():
- * """ Disables the power to the servos. """
- * moab_disableServoPower() # <<<<<<<<<<<<<<
+ /* "huemask.pyx":40
+ * # pre-gain around center
+ * f = f * gain
+ * if f > 1.0: # <<<<<<<<<<<<<<
+ * f = 1.0
*
- * def setPlateAngles(plate_x_deg: int, plate_y_deg: int):
*/
- moab_disableServoPower();
+ }
- /* "moab.pyx":99
- * moab_setServoPositions(155, 155, 155)
+ /* "huemask.pyx":43
+ * f = 1.0
+ *
+ * _bandpass_lookup[n] = f # <<<<<<<<<<<<<<
+ *
*
- * def disableServoPower(): # <<<<<<<<<<<<<<
- * """ Disables the power to the servos. """
- * moab_disableServoPower()
+ */
+ __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_v_f); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 43, __pyx_L1_error)
+ __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_v_n); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 43, __pyx_L1_error)
+ (__pyx_v_7huemask__bandpass_lookup[__pyx_t_9]) = __pyx_t_8;
+ }
+
+ /* "huemask.pyx":14
+ * @cython.boundscheck(False)
+ * @cython.wraparound(False)
+ * def _update_bandpass_lookup(unsigned char center, float sigma, float gain): # <<<<<<<<<<<<<<
+ * global _bandpass_lookup
+ * global _last_center
*/
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_XDECREF(__pyx_t_7);
+ __Pyx_AddTraceback("huemask._update_bandpass_lookup", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_n);
+ __Pyx_XDECREF(__pyx_v_h);
+ __Pyx_XDECREF(__pyx_v_f);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "moab.pyx":103
- * moab_disableServoPower()
- *
- * def setPlateAngles(plate_x_deg: int, plate_y_deg: int): # <<<<<<<<<<<<<<
- * moab_setPlateAngles(plate_x_deg, plate_y_deg)
+/* "huemask.pyx":48
+ * @cython.boundscheck(False)
+ * @cython.wraparound(False)
+ * def hue_mask(unsigned char [:, :, :] image, unsigned char center, float sigma, float gain, float mask_gain): # <<<<<<<<<<<<<<
+ * global _bandpass_lookup
*
*/
/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_11setPlateAngles(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_11setPlateAngles = {"setPlateAngles", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pymoab_11setPlateAngles, METH_VARARGS|METH_KEYWORDS, 0};
-static PyObject *__pyx_pw_6pymoab_11setPlateAngles(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- PyObject *__pyx_v_plate_x_deg = 0;
- PyObject *__pyx_v_plate_y_deg = 0;
+static PyObject *__pyx_pw_7huemask_3hue_mask(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static PyMethodDef __pyx_mdef_7huemask_3hue_mask = {"hue_mask", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7huemask_3hue_mask, METH_VARARGS|METH_KEYWORDS, 0};
+static PyObject *__pyx_pw_7huemask_3hue_mask(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ __Pyx_memviewslice __pyx_v_image = { 0, 0, { 0 }, { 0 }, { 0 } };
+ unsigned char __pyx_v_center;
+ float __pyx_v_sigma;
+ float __pyx_v_gain;
+ float __pyx_v_mask_gain;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("setPlateAngles (wrapper)", 0);
+ __Pyx_RefNannySetupContext("hue_mask (wrapper)", 0);
{
- static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_plate_x_deg,&__pyx_n_s_plate_y_deg,0};
- PyObject* values[2] = {0,0};
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_image,&__pyx_n_s_center,&__pyx_n_s_sigma,&__pyx_n_s_gain,&__pyx_n_s_mask_gain,0};
+ PyObject* values[5] = {0,0,0,0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
+ case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+ CYTHON_FALLTHROUGH;
+ case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+ CYTHON_FALLTHROUGH;
+ case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+ CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
@@ -2691,239 +2508,449 @@ static PyObject *__pyx_pw_6pymoab_11setPlateAngles(PyObject *__pyx_self, PyObjec
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
- if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_plate_x_deg)) != 0)) kw_args--;
+ if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_image)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
- if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_plate_y_deg)) != 0)) kw_args--;
+ if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_center)) != 0)) kw_args--;
+ else {
+ __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, 1); __PYX_ERR(0, 48, __pyx_L3_error)
+ }
+ CYTHON_FALLTHROUGH;
+ case 2:
+ if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sigma)) != 0)) kw_args--;
+ else {
+ __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, 2); __PYX_ERR(0, 48, __pyx_L3_error)
+ }
+ CYTHON_FALLTHROUGH;
+ case 3:
+ if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gain)) != 0)) kw_args--;
+ else {
+ __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, 3); __PYX_ERR(0, 48, __pyx_L3_error)
+ }
+ CYTHON_FALLTHROUGH;
+ case 4:
+ if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mask_gain)) != 0)) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("setPlateAngles", 1, 2, 2, 1); __PYX_ERR(0, 103, __pyx_L3_error)
+ __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, 4); __PYX_ERR(0, 48, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setPlateAngles") < 0)) __PYX_ERR(0, 103, __pyx_L3_error)
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "hue_mask") < 0)) __PYX_ERR(0, 48, __pyx_L3_error)
}
- } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+ values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+ values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
}
- __pyx_v_plate_x_deg = values[0];
- __pyx_v_plate_y_deg = values[1];
+ __pyx_v_image = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_unsigned_char(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_image.memview)) __PYX_ERR(0, 48, __pyx_L3_error)
+ __pyx_v_center = __Pyx_PyInt_As_unsigned_char(values[1]); if (unlikely((__pyx_v_center == (unsigned char)-1) && PyErr_Occurred())) __PYX_ERR(0, 48, __pyx_L3_error)
+ __pyx_v_sigma = __pyx_PyFloat_AsFloat(values[2]); if (unlikely((__pyx_v_sigma == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 48, __pyx_L3_error)
+ __pyx_v_gain = __pyx_PyFloat_AsFloat(values[3]); if (unlikely((__pyx_v_gain == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 48, __pyx_L3_error)
+ __pyx_v_mask_gain = __pyx_PyFloat_AsFloat(values[4]); if (unlikely((__pyx_v_mask_gain == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 48, __pyx_L3_error)
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("setPlateAngles", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 103, __pyx_L3_error)
+ __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 48, __pyx_L3_error)
__pyx_L3_error:;
- __Pyx_AddTraceback("pymoab.setPlateAngles", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_AddTraceback("huemask.hue_mask", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_pf_6pymoab_10setPlateAngles(__pyx_self, __pyx_v_plate_x_deg, __pyx_v_plate_y_deg);
+ __pyx_r = __pyx_pf_7huemask_2hue_mask(__pyx_self, __pyx_v_image, __pyx_v_center, __pyx_v_sigma, __pyx_v_gain, __pyx_v_mask_gain);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_6pymoab_10setPlateAngles(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_plate_x_deg, PyObject *__pyx_v_plate_y_deg) {
+static PyObject *__pyx_pf_7huemask_2hue_mask(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_image, unsigned char __pyx_v_center, float __pyx_v_sigma, float __pyx_v_gain, float __pyx_v_mask_gain) {
+ int __pyx_v_x;
+ int __pyx_v_y;
+ int __pyx_v_width;
+ int __pyx_v_height;
+ float __pyx_v_h;
+ float __pyx_v_s;
+ float __pyx_v_v;
+ float __pyx_v_f;
+ unsigned char __pyx_v_mask;
+ unsigned char __pyx_v_ih;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- __pyx_t_6pymoab_int8_t __pyx_t_1;
- __pyx_t_6pymoab_int8_t __pyx_t_2;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("setPlateAngles", 0);
-
- /* "moab.pyx":104
+ int __pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ PyObject *__pyx_t_6 = NULL;
+ PyObject *__pyx_t_7 = NULL;
+ PyObject *__pyx_t_8 = NULL;
+ int __pyx_t_9;
+ PyObject *__pyx_t_10 = NULL;
+ int __pyx_t_11;
+ int __pyx_t_12;
+ int __pyx_t_13;
+ int __pyx_t_14;
+ int __pyx_t_15;
+ Py_ssize_t __pyx_t_16;
+ Py_ssize_t __pyx_t_17;
+ Py_ssize_t __pyx_t_18;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("hue_mask", 0);
+
+ /* "huemask.pyx":57
*
- * def setPlateAngles(plate_x_deg: int, plate_y_deg: int):
- * moab_setPlateAngles(plate_x_deg, plate_y_deg) # <<<<<<<<<<<<<<
+ * # grab the image dimensions
+ * height = image.shape[0] # <<<<<<<<<<<<<<
+ * width = image.shape[1]
*
- * def setServoPositions(servo1_pos: int, servo2_pos: int, servo3_pos: int):
*/
- __pyx_t_1 = __Pyx_PyInt_As_signed__char(__pyx_v_plate_x_deg); if (unlikely((__pyx_t_1 == (signed char)-1) && PyErr_Occurred())) __PYX_ERR(0, 104, __pyx_L1_error)
- __pyx_t_2 = __Pyx_PyInt_As_signed__char(__pyx_v_plate_y_deg); if (unlikely((__pyx_t_2 == (signed char)-1) && PyErr_Occurred())) __PYX_ERR(0, 104, __pyx_L1_error)
- moab_setPlateAngles(__pyx_t_1, __pyx_t_2);
+ __pyx_v_height = (__pyx_v_image.shape[0]);
- /* "moab.pyx":103
- * moab_disableServoPower()
- *
- * def setPlateAngles(plate_x_deg: int, plate_y_deg: int): # <<<<<<<<<<<<<<
- * moab_setPlateAngles(plate_x_deg, plate_y_deg)
+ /* "huemask.pyx":58
+ * # grab the image dimensions
+ * height = image.shape[0]
+ * width = image.shape[1] # <<<<<<<<<<<<<<
*
+ * # generate a lookup table for center, sigma & gain
*/
+ __pyx_v_width = (__pyx_v_image.shape[1]);
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_AddTraceback("pymoab.setPlateAngles", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":106
- * moab_setPlateAngles(plate_x_deg, plate_y_deg)
+ /* "huemask.pyx":61
*
- * def setServoPositions(servo1_pos: int, servo2_pos: int, servo3_pos: int): # <<<<<<<<<<<<<<
- * moab_setServoPositions(servo1_pos, servo2_pos, servo3_pos)
+ * # generate a lookup table for center, sigma & gain
+ * if (center != _last_center or sigma != _last_sigma or gain != _last_gain): # <<<<<<<<<<<<<<
+ * _update_bandpass_lookup(center, sigma, gain)
*
*/
+ __pyx_t_2 = ((__pyx_v_center != __pyx_v_7huemask__last_center) != 0);
+ if (!__pyx_t_2) {
+ } else {
+ __pyx_t_1 = __pyx_t_2;
+ goto __pyx_L4_bool_binop_done;
+ }
+ __pyx_t_2 = ((__pyx_v_sigma != __pyx_v_7huemask__last_sigma) != 0);
+ if (!__pyx_t_2) {
+ } else {
+ __pyx_t_1 = __pyx_t_2;
+ goto __pyx_L4_bool_binop_done;
+ }
+ __pyx_t_2 = ((__pyx_v_gain != __pyx_v_7huemask__last_gain) != 0);
+ __pyx_t_1 = __pyx_t_2;
+ __pyx_L4_bool_binop_done:;
+ if (__pyx_t_1) {
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_13setServoPositions(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_13setServoPositions = {"setServoPositions", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pymoab_13setServoPositions, METH_VARARGS|METH_KEYWORDS, 0};
-static PyObject *__pyx_pw_6pymoab_13setServoPositions(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- PyObject *__pyx_v_servo1_pos = 0;
- PyObject *__pyx_v_servo2_pos = 0;
- PyObject *__pyx_v_servo3_pos = 0;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("setServoPositions (wrapper)", 0);
- {
- static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_servo1_pos,&__pyx_n_s_servo2_pos,&__pyx_n_s_servo3_pos,0};
- PyObject* values[3] = {0,0,0};
- if (unlikely(__pyx_kwds)) {
- Py_ssize_t kw_args;
- const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
- switch (pos_args) {
- case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
- CYTHON_FALLTHROUGH;
- case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- CYTHON_FALLTHROUGH;
- case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- CYTHON_FALLTHROUGH;
- case 0: break;
- default: goto __pyx_L5_argtuple_error;
- }
- kw_args = PyDict_Size(__pyx_kwds);
- switch (pos_args) {
- case 0:
- if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_servo1_pos)) != 0)) kw_args--;
- else goto __pyx_L5_argtuple_error;
- CYTHON_FALLTHROUGH;
- case 1:
- if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_servo2_pos)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("setServoPositions", 1, 3, 3, 1); __PYX_ERR(0, 106, __pyx_L3_error)
- }
- CYTHON_FALLTHROUGH;
- case 2:
- if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_servo3_pos)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("setServoPositions", 1, 3, 3, 2); __PYX_ERR(0, 106, __pyx_L3_error)
- }
+ /* "huemask.pyx":62
+ * # generate a lookup table for center, sigma & gain
+ * if (center != _last_center or sigma != _last_sigma or gain != _last_gain):
+ * _update_bandpass_lookup(center, sigma, gain) # <<<<<<<<<<<<<<
+ *
+ * for y in range(0, height):
+ */
+ __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_update_bandpass_lookup); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 62, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = __Pyx_PyInt_From_unsigned_char(__pyx_v_center); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 62, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_6 = PyFloat_FromDouble(__pyx_v_sigma); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 62, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_7 = PyFloat_FromDouble(__pyx_v_gain); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 62, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_7);
+ __pyx_t_8 = NULL;
+ __pyx_t_9 = 0;
+ if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
+ __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4);
+ if (likely(__pyx_t_8)) {
+ PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
+ __Pyx_INCREF(__pyx_t_8);
+ __Pyx_INCREF(function);
+ __Pyx_DECREF_SET(__pyx_t_4, function);
+ __pyx_t_9 = 1;
}
- if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setServoPositions") < 0)) __PYX_ERR(0, 106, __pyx_L3_error)
+ }
+ #if CYTHON_FAST_PYCALL
+ if (PyFunction_Check(__pyx_t_4)) {
+ PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_t_5, __pyx_t_6, __pyx_t_7};
+ __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 62, __pyx_L1_error)
+ __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+ } else
+ #endif
+ #if CYTHON_FAST_PYCCALL
+ if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
+ PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_t_5, __pyx_t_6, __pyx_t_7};
+ __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 62, __pyx_L1_error)
+ __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+ } else
+ #endif
+ {
+ __pyx_t_10 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 62, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_10);
+ if (__pyx_t_8) {
+ __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
}
- } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
- goto __pyx_L5_argtuple_error;
- } else {
- values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+ __Pyx_GIVEREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_5);
+ __Pyx_GIVEREF(__pyx_t_6);
+ PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_6);
+ __Pyx_GIVEREF(__pyx_t_7);
+ PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_t_7);
+ __pyx_t_5 = 0;
+ __pyx_t_6 = 0;
+ __pyx_t_7 = 0;
+ __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 62, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
}
- __pyx_v_servo1_pos = values[0];
- __pyx_v_servo2_pos = values[1];
- __pyx_v_servo3_pos = values[2];
- }
- goto __pyx_L4_argument_unpacking_done;
- __pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("setServoPositions", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 106, __pyx_L3_error)
- __pyx_L3_error:;
- __Pyx_AddTraceback("pymoab.setServoPositions", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __Pyx_RefNannyFinishContext();
- return NULL;
- __pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_pf_6pymoab_12setServoPositions(__pyx_self, __pyx_v_servo1_pos, __pyx_v_servo2_pos, __pyx_v_servo3_pos);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-static PyObject *__pyx_pf_6pymoab_12setServoPositions(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_servo1_pos, PyObject *__pyx_v_servo2_pos, PyObject *__pyx_v_servo3_pos) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __pyx_t_6pymoab_uint8_t __pyx_t_1;
- __pyx_t_6pymoab_uint8_t __pyx_t_2;
- __pyx_t_6pymoab_uint8_t __pyx_t_3;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("setServoPositions", 0);
+ /* "huemask.pyx":61
+ *
+ * # generate a lookup table for center, sigma & gain
+ * if (center != _last_center or sigma != _last_sigma or gain != _last_gain): # <<<<<<<<<<<<<<
+ * _update_bandpass_lookup(center, sigma, gain)
+ *
+ */
+ }
- /* "moab.pyx":107
+ /* "huemask.pyx":64
+ * _update_bandpass_lookup(center, sigma, gain)
*
- * def setServoPositions(servo1_pos: int, servo2_pos: int, servo3_pos: int):
- * moab_setServoPositions(servo1_pos, servo2_pos, servo3_pos) # <<<<<<<<<<<<<<
+ * for y in range(0, height): # <<<<<<<<<<<<<<
+ * for x in range(0, width):
+ * # pull each component out as a float [0..1]
+ */
+ __pyx_t_9 = __pyx_v_height;
+ __pyx_t_11 = __pyx_t_9;
+ for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
+ __pyx_v_y = __pyx_t_12;
+
+ /* "huemask.pyx":65
*
- * def setServoOffsets(servo1_offset: int, servo2_offset: int, servo3_offset: int):
+ * for y in range(0, height):
+ * for x in range(0, width): # <<<<<<<<<<<<<<
+ * # pull each component out as a float [0..1]
+ * ih = image[y, x, 0]
+ */
+ __pyx_t_13 = __pyx_v_width;
+ __pyx_t_14 = __pyx_t_13;
+ for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
+ __pyx_v_x = __pyx_t_15;
+
+ /* "huemask.pyx":67
+ * for x in range(0, width):
+ * # pull each component out as a float [0..1]
+ * ih = image[y, x, 0] # <<<<<<<<<<<<<<
+ * s = image[y, x, 1] / 255.0
+ * v = image[y, x, 2] / 255.0
*/
- __pyx_t_1 = __Pyx_PyInt_As_unsigned_char(__pyx_v_servo1_pos); if (unlikely((__pyx_t_1 == (unsigned char)-1) && PyErr_Occurred())) __PYX_ERR(0, 107, __pyx_L1_error)
- __pyx_t_2 = __Pyx_PyInt_As_unsigned_char(__pyx_v_servo2_pos); if (unlikely((__pyx_t_2 == (unsigned char)-1) && PyErr_Occurred())) __PYX_ERR(0, 107, __pyx_L1_error)
- __pyx_t_3 = __Pyx_PyInt_As_unsigned_char(__pyx_v_servo3_pos); if (unlikely((__pyx_t_3 == (unsigned char)-1) && PyErr_Occurred())) __PYX_ERR(0, 107, __pyx_L1_error)
- moab_setServoPositions(__pyx_t_1, __pyx_t_2, __pyx_t_3);
+ __pyx_t_16 = __pyx_v_y;
+ __pyx_t_17 = __pyx_v_x;
+ __pyx_t_18 = 0;
+ __pyx_v_ih = (*((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_16 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_18 * __pyx_v_image.strides[2]) )));
- /* "moab.pyx":106
- * moab_setPlateAngles(plate_x_deg, plate_y_deg)
+ /* "huemask.pyx":68
+ * # pull each component out as a float [0..1]
+ * ih = image[y, x, 0]
+ * s = image[y, x, 1] / 255.0 # <<<<<<<<<<<<<<
+ * v = image[y, x, 2] / 255.0
*
- * def setServoPositions(servo1_pos: int, servo2_pos: int, servo3_pos: int): # <<<<<<<<<<<<<<
- * moab_setServoPositions(servo1_pos, servo2_pos, servo3_pos)
+ */
+ __pyx_t_18 = __pyx_v_y;
+ __pyx_t_17 = __pyx_v_x;
+ __pyx_t_16 = 1;
+ __pyx_v_s = (((double)(*((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_18 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_16 * __pyx_v_image.strides[2]) )))) / 255.0);
+
+ /* "huemask.pyx":69
+ * ih = image[y, x, 0]
+ * s = image[y, x, 1] / 255.0
+ * v = image[y, x, 2] / 255.0 # <<<<<<<<<<<<<<
*
+ * # map from [0..255] -> [0..1] through lookup table
*/
+ __pyx_t_16 = __pyx_v_y;
+ __pyx_t_17 = __pyx_v_x;
+ __pyx_t_18 = 2;
+ __pyx_v_v = (((double)(*((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_16 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_18 * __pyx_v_image.strides[2]) )))) / 255.0);
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_AddTraceback("pymoab.setServoPositions", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "huemask.pyx":73
+ * # map from [0..255] -> [0..1] through lookup table
+ * # this applies the bandpass filter on hue
+ * h = _bandpass_lookup[ih] # <<<<<<<<<<<<<<
+ *
+ * # mask the hue with sat, val and apply another gain filter
+ */
+ __pyx_v_h = (__pyx_v_7huemask__bandpass_lookup[__pyx_v_ih]);
-/* "moab.pyx":109
- * moab_setServoPositions(servo1_pos, servo2_pos, servo3_pos)
+ /* "huemask.pyx":76
*
- * def setServoOffsets(servo1_offset: int, servo2_offset: int, servo3_offset: int): # <<<<<<<<<<<<<<
- * """
- * Set post-factory calibration offsets for each servo.
+ * # mask the hue with sat, val and apply another gain filter
+ * f = (h * s * v) * mask_gain # <<<<<<<<<<<<<<
+ * if f > 1.0:
+ * f = 1.0
*/
+ __pyx_v_f = (((__pyx_v_h * __pyx_v_s) * __pyx_v_v) * __pyx_v_mask_gain);
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_15setServoOffsets(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_6pymoab_14setServoOffsets[] = "\n Set post-factory calibration offsets for each servo.\n Can be called before init().\n\n Normally this call should not be needed.\n ";
-static PyMethodDef __pyx_mdef_6pymoab_15setServoOffsets = {"setServoOffsets", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pymoab_15setServoOffsets, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6pymoab_14setServoOffsets};
-static PyObject *__pyx_pw_6pymoab_15setServoOffsets(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- PyObject *__pyx_v_servo1_offset = 0;
- PyObject *__pyx_v_servo2_offset = 0;
- PyObject *__pyx_v_servo3_offset = 0;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- PyObject *__pyx_r = 0;
+ /* "huemask.pyx":77
+ * # mask the hue with sat, val and apply another gain filter
+ * f = (h * s * v) * mask_gain
+ * if f > 1.0: # <<<<<<<<<<<<<<
+ * f = 1.0
+ *
+ */
+ __pyx_t_1 = ((__pyx_v_f > 1.0) != 0);
+ if (__pyx_t_1) {
+
+ /* "huemask.pyx":78
+ * f = (h * s * v) * mask_gain
+ * if f > 1.0:
+ * f = 1.0 # <<<<<<<<<<<<<<
+ *
+ * # covert back to char space
+ */
+ __pyx_v_f = 1.0;
+
+ /* "huemask.pyx":77
+ * # mask the hue with sat, val and apply another gain filter
+ * f = (h * s * v) * mask_gain
+ * if f > 1.0: # <<<<<<<<<<<<<<
+ * f = 1.0
+ *
+ */
+ }
+
+ /* "huemask.pyx":81
+ *
+ * # covert back to char space
+ * mask = (f * 255) # <<<<<<<<<<<<<<
+ * image[y, x, 0] = mask
+ * image[y, x, 1] = mask
+ */
+ __pyx_v_mask = ((unsigned char)(__pyx_v_f * 255.0));
+
+ /* "huemask.pyx":82
+ * # covert back to char space
+ * mask = (f * 255)
+ * image[y, x, 0] = mask # <<<<<<<<<<<<<<
+ * image[y, x, 1] = mask
+ * image[y, x, 2] = mask
+ */
+ __pyx_t_18 = __pyx_v_y;
+ __pyx_t_17 = __pyx_v_x;
+ __pyx_t_16 = 0;
+ *((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_18 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_16 * __pyx_v_image.strides[2]) )) = __pyx_v_mask;
+
+ /* "huemask.pyx":83
+ * mask = (f * 255)
+ * image[y, x, 0] = mask
+ * image[y, x, 1] = mask # <<<<<<<<<<<<<<
+ * image[y, x, 2] = mask
+ *
+ */
+ __pyx_t_16 = __pyx_v_y;
+ __pyx_t_17 = __pyx_v_x;
+ __pyx_t_18 = 1;
+ *((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_16 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_18 * __pyx_v_image.strides[2]) )) = __pyx_v_mask;
+
+ /* "huemask.pyx":84
+ * image[y, x, 0] = mask
+ * image[y, x, 1] = mask
+ * image[y, x, 2] = mask # <<<<<<<<<<<<<<
+ *
+ * # return the thresholded image
+ */
+ __pyx_t_18 = __pyx_v_y;
+ __pyx_t_17 = __pyx_v_x;
+ __pyx_t_16 = 2;
+ *((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_18 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_16 * __pyx_v_image.strides[2]) )) = __pyx_v_mask;
+ }
+ }
+
+ /* "huemask.pyx":87
+ *
+ * # return the thresholded image
+ * return image # <<<<<<<<<<<<<<
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_image, 3, (PyObject *(*)(char *)) __pyx_memview_get_unsigned_char, (int (*)(char *, PyObject *)) __pyx_memview_set_unsigned_char, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 87, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+
+ /* "huemask.pyx":48
+ * @cython.boundscheck(False)
+ * @cython.wraparound(False)
+ * def hue_mask(unsigned char [:, :, :] image, unsigned char center, float sigma, float gain, float mask_gain): # <<<<<<<<<<<<<<
+ * global _bandpass_lookup
+ *
+ */
+
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_XDECREF(__pyx_t_7);
+ __Pyx_XDECREF(__pyx_t_8);
+ __Pyx_XDECREF(__pyx_t_10);
+ __Pyx_AddTraceback("huemask.hue_mask", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __PYX_XDEC_MEMVIEW(&__pyx_v_image, 1);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":122
+ * cdef bint dtype_is_object
+ *
+ * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<<
+ * mode="c", bint allocate_buffer=True):
+ *
+ */
+
+/* Python wrapper */
+static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_shape = 0;
+ Py_ssize_t __pyx_v_itemsize;
+ PyObject *__pyx_v_format = 0;
+ PyObject *__pyx_v_mode = 0;
+ int __pyx_v_allocate_buffer;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ int __pyx_r;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("setServoOffsets (wrapper)", 0);
+ __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
{
- static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_servo1_offset,&__pyx_n_s_servo2_offset,&__pyx_n_s_servo3_offset,0};
- PyObject* values[3] = {0,0,0};
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_shape,&__pyx_n_s_itemsize,&__pyx_n_s_format,&__pyx_n_s_mode,&__pyx_n_s_allocate_buffer,0};
+ PyObject* values[5] = {0,0,0,0,0};
+ values[3] = ((PyObject *)__pyx_n_s_c);
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
+ case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+ CYTHON_FALLTHROUGH;
+ case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+ CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
@@ -2936,6925 +2963,6148 @@ static PyObject *__pyx_pw_6pymoab_15setServoOffsets(PyObject *__pyx_self, PyObje
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
- if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_servo1_offset)) != 0)) kw_args--;
+ if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_shape)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
- if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_servo2_offset)) != 0)) kw_args--;
+ if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_itemsize)) != 0)) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("setServoOffsets", 1, 3, 3, 1); __PYX_ERR(0, 109, __pyx_L3_error)
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); __PYX_ERR(1, 122, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
- if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_servo3_offset)) != 0)) kw_args--;
+ if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--;
else {
- __Pyx_RaiseArgtupleInvalid("setServoOffsets", 1, 3, 3, 2); __PYX_ERR(0, 109, __pyx_L3_error)
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); __PYX_ERR(1, 122, __pyx_L3_error)
+ }
+ CYTHON_FALLTHROUGH;
+ case 3:
+ if (kw_args > 0) {
+ PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
+ if (value) { values[3] = value; kw_args--; }
+ }
+ CYTHON_FALLTHROUGH;
+ case 4:
+ if (kw_args > 0) {
+ PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_allocate_buffer);
+ if (value) { values[4] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setServoOffsets") < 0)) __PYX_ERR(0, 109, __pyx_L3_error)
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 122, __pyx_L3_error)
}
- } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
- goto __pyx_L5_argtuple_error;
} else {
- values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
+ CYTHON_FALLTHROUGH;
+ case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
+ CYTHON_FALLTHROUGH;
+ case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+ values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ }
+ __pyx_v_shape = ((PyObject*)values[0]);
+ __pyx_v_itemsize = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_itemsize == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 122, __pyx_L3_error)
+ __pyx_v_format = values[2];
+ __pyx_v_mode = values[3];
+ if (values[4]) {
+ __pyx_v_allocate_buffer = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_allocate_buffer == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 123, __pyx_L3_error)
+ } else {
+
+ /* "View.MemoryView":123
+ *
+ * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,
+ * mode="c", bint allocate_buffer=True): # <<<<<<<<<<<<<<
+ *
+ * cdef int idx
+ */
+ __pyx_v_allocate_buffer = ((int)1);
}
- __pyx_v_servo1_offset = values[0];
- __pyx_v_servo2_offset = values[1];
- __pyx_v_servo3_offset = values[2];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("setServoOffsets", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 109, __pyx_L3_error)
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 122, __pyx_L3_error)
__pyx_L3_error:;
- __Pyx_AddTraceback("pymoab.setServoOffsets", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
- return NULL;
+ return -1;
__pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_pf_6pymoab_14setServoOffsets(__pyx_self, __pyx_v_servo1_offset, __pyx_v_servo2_offset, __pyx_v_servo3_offset);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_14setServoOffsets(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_servo1_offset, PyObject *__pyx_v_servo2_offset, PyObject *__pyx_v_servo3_offset) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __pyx_t_6pymoab_int8_t __pyx_t_1;
- __pyx_t_6pymoab_int8_t __pyx_t_2;
- __pyx_t_6pymoab_int8_t __pyx_t_3;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("setServoOffsets", 0);
+ if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shape), (&PyTuple_Type), 1, "shape", 1))) __PYX_ERR(1, 122, __pyx_L1_error)
+ if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) {
+ PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "format"); __PYX_ERR(1, 122, __pyx_L1_error)
+ }
+ __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(((struct __pyx_array_obj *)__pyx_v_self), __pyx_v_shape, __pyx_v_itemsize, __pyx_v_format, __pyx_v_mode, __pyx_v_allocate_buffer);
- /* "moab.pyx":116
- * Normally this call should not be needed.
- * """
- * moab_setServoOffsets(servo1_offset, servo2_offset, servo3_offset) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":122
+ * cdef bint dtype_is_object
*
- * def setIcon(icon_idx: Icon):
- */
- __pyx_t_1 = __Pyx_PyInt_As_signed__char(__pyx_v_servo1_offset); if (unlikely((__pyx_t_1 == (signed char)-1) && PyErr_Occurred())) __PYX_ERR(0, 116, __pyx_L1_error)
- __pyx_t_2 = __Pyx_PyInt_As_signed__char(__pyx_v_servo2_offset); if (unlikely((__pyx_t_2 == (signed char)-1) && PyErr_Occurred())) __PYX_ERR(0, 116, __pyx_L1_error)
- __pyx_t_3 = __Pyx_PyInt_As_signed__char(__pyx_v_servo3_offset); if (unlikely((__pyx_t_3 == (signed char)-1) && PyErr_Occurred())) __PYX_ERR(0, 116, __pyx_L1_error)
- moab_setServoOffsets(__pyx_t_1, __pyx_t_2, __pyx_t_3);
-
- /* "moab.pyx":109
- * moab_setServoPositions(servo1_pos, servo2_pos, servo3_pos)
+ * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<<
+ * mode="c", bint allocate_buffer=True):
*
- * def setServoOffsets(servo1_offset: int, servo2_offset: int, servo3_offset: int): # <<<<<<<<<<<<<<
- * """
- * Set post-factory calibration offsets for each servo.
*/
/* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_AddTraceback("pymoab.setServoOffsets", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
+ __pyx_r = -1;
__pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":118
- * moab_setServoOffsets(servo1_offset, servo2_offset, servo3_offset)
- *
- * def setIcon(icon_idx: Icon): # <<<<<<<<<<<<<<
- * moab_setIcon(icon_idx)
- *
- */
-
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_17setIcon(PyObject *__pyx_self, PyObject *__pyx_v_icon_idx); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_17setIcon = {"setIcon", (PyCFunction)__pyx_pw_6pymoab_17setIcon, METH_O, 0};
-static PyObject *__pyx_pw_6pymoab_17setIcon(PyObject *__pyx_self, PyObject *__pyx_v_icon_idx) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("setIcon (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_16setIcon(__pyx_self, ((PyObject *)__pyx_v_icon_idx));
-
- /* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_6pymoab_16setIcon(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_icon_idx) {
- PyObject *__pyx_r = NULL;
+static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer) {
+ int __pyx_v_idx;
+ Py_ssize_t __pyx_v_i;
+ Py_ssize_t __pyx_v_dim;
+ PyObject **__pyx_v_p;
+ char __pyx_v_order;
+ int __pyx_r;
__Pyx_RefNannyDeclarations
- int __pyx_t_1;
+ Py_ssize_t __pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_t_4;
+ PyObject *__pyx_t_5 = NULL;
+ PyObject *__pyx_t_6 = NULL;
+ char *__pyx_t_7;
+ int __pyx_t_8;
+ Py_ssize_t __pyx_t_9;
+ PyObject *__pyx_t_10 = NULL;
+ Py_ssize_t __pyx_t_11;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("setIcon", 0);
+ __Pyx_RefNannySetupContext("__cinit__", 0);
+ __Pyx_INCREF(__pyx_v_format);
- /* "moab.pyx":119
+ /* "View.MemoryView":129
+ * cdef PyObject **p
*
- * def setIcon(icon_idx: Icon):
- * moab_setIcon(icon_idx) # <<<<<<<<<<<<<<
+ * self.ndim = len(shape) # <<<<<<<<<<<<<<
+ * self.itemsize = itemsize
*
- * def setText(text_idx: Text):
*/
- __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_icon_idx); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 119, __pyx_L1_error)
- moab_setIcon(__pyx_t_1);
-
- /* "moab.pyx":118
- * moab_setServoOffsets(servo1_offset, servo2_offset, servo3_offset)
- *
- * def setIcon(icon_idx: Icon): # <<<<<<<<<<<<<<
- * moab_setIcon(icon_idx)
- *
- */
-
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_AddTraceback("pymoab.setIcon", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ if (unlikely(__pyx_v_shape == Py_None)) {
+ PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
+ __PYX_ERR(1, 129, __pyx_L1_error)
+ }
+ __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_shape); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(1, 129, __pyx_L1_error)
+ __pyx_v_self->ndim = ((int)__pyx_t_1);
-/* "moab.pyx":121
- * moab_setIcon(icon_idx)
+ /* "View.MemoryView":130
*
- * def setText(text_idx: Text): # <<<<<<<<<<<<<<
- * moab_setText(text_idx)
+ * self.ndim = len(shape)
+ * self.itemsize = itemsize # <<<<<<<<<<<<<<
*
+ * if not self.ndim:
*/
+ __pyx_v_self->itemsize = __pyx_v_itemsize;
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_19setText(PyObject *__pyx_self, PyObject *__pyx_v_text_idx); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_19setText = {"setText", (PyCFunction)__pyx_pw_6pymoab_19setText, METH_O, 0};
-static PyObject *__pyx_pw_6pymoab_19setText(PyObject *__pyx_self, PyObject *__pyx_v_text_idx) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("setText (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_18setText(__pyx_self, ((PyObject *)__pyx_v_text_idx));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_18setText(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_text_idx) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- int __pyx_t_1;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("setText", 0);
-
- /* "moab.pyx":122
+ /* "View.MemoryView":132
+ * self.itemsize = itemsize
*
- * def setText(text_idx: Text):
- * moab_setText(text_idx) # <<<<<<<<<<<<<<
+ * if not self.ndim: # <<<<<<<<<<<<<<
+ * raise ValueError("Empty shape tuple for cython.array")
*
- * def sync() -> Result:
*/
- __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_text_idx); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 122, __pyx_L1_error)
- moab_setText(__pyx_t_1);
+ __pyx_t_2 = ((!(__pyx_v_self->ndim != 0)) != 0);
+ if (unlikely(__pyx_t_2)) {
- /* "moab.pyx":121
- * moab_setIcon(icon_idx)
+ /* "View.MemoryView":133
*
- * def setText(text_idx: Text): # <<<<<<<<<<<<<<
- * moab_setText(text_idx)
+ * if not self.ndim:
+ * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<<
*
+ * if itemsize <= 0:
*/
+ __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 133, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __PYX_ERR(1, 133, __pyx_L1_error)
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_AddTraceback("pymoab.setText", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":124
- * moab_setText(text_idx)
+ /* "View.MemoryView":132
+ * self.itemsize = itemsize
*
- * def sync() -> Result: # <<<<<<<<<<<<<<
- * """
- * Sets the current state on the hardware and polls
- */
-
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_21sync(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static char __pyx_doc_6pymoab_20sync[] = "\n Sets the current state on the hardware and polls\n the current control states.\n\n return OK on success.\n ";
-static PyMethodDef __pyx_mdef_6pymoab_21sync = {"sync", (PyCFunction)__pyx_pw_6pymoab_21sync, METH_NOARGS, __pyx_doc_6pymoab_20sync};
-static PyObject *__pyx_pw_6pymoab_21sync(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("sync (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_20sync(__pyx_self);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_20sync(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- PyObject *__pyx_t_2 = NULL;
- PyObject *__pyx_t_3 = NULL;
- PyObject *__pyx_t_4 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("sync", 0);
-
- /* "moab.pyx":131
- * return OK on success.
- * """
- * return Result(moab_sync()) # <<<<<<<<<<<<<<
+ * if not self.ndim: # <<<<<<<<<<<<<<
+ * raise ValueError("Empty shape tuple for cython.array")
*
- * def getMenuBtn() -> bool:
*/
- __Pyx_XDECREF(__pyx_r);
- __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Result); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = __Pyx_PyInt_From_int(moab_sync()); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 131, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = NULL;
- if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
- __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
- if (likely(__pyx_t_4)) {
- PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
- __Pyx_INCREF(__pyx_t_4);
- __Pyx_INCREF(function);
- __Pyx_DECREF_SET(__pyx_t_2, function);
- }
}
- __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
- __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
- /* "moab.pyx":124
- * moab_setText(text_idx)
+ /* "View.MemoryView":135
+ * raise ValueError("Empty shape tuple for cython.array")
+ *
+ * if itemsize <= 0: # <<<<<<<<<<<<<<
+ * raise ValueError("itemsize <= 0 for cython.array")
*
- * def sync() -> Result: # <<<<<<<<<<<<<<
- * """
- * Sets the current state on the hardware and polls
*/
+ __pyx_t_2 = ((__pyx_v_itemsize <= 0) != 0);
+ if (unlikely(__pyx_t_2)) {
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_4);
- __Pyx_AddTraceback("pymoab.sync", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":133
- * return Result(moab_sync())
+ /* "View.MemoryView":136
*
- * def getMenuBtn() -> bool: # <<<<<<<<<<<<<<
- * return True if moab_getMenuBtn() else False
+ * if itemsize <= 0:
+ * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<<
*
+ * if not isinstance(format, bytes):
*/
+ __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 136, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __PYX_ERR(1, 136, __pyx_L1_error)
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_23getMenuBtn(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_23getMenuBtn = {"getMenuBtn", (PyCFunction)__pyx_pw_6pymoab_23getMenuBtn, METH_NOARGS, 0};
-static PyObject *__pyx_pw_6pymoab_23getMenuBtn(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("getMenuBtn (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_22getMenuBtn(__pyx_self);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_22getMenuBtn(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- __Pyx_RefNannySetupContext("getMenuBtn", 0);
-
- /* "moab.pyx":134
+ /* "View.MemoryView":135
+ * raise ValueError("Empty shape tuple for cython.array")
*
- * def getMenuBtn() -> bool:
- * return True if moab_getMenuBtn() else False # <<<<<<<<<<<<<<
+ * if itemsize <= 0: # <<<<<<<<<<<<<<
+ * raise ValueError("itemsize <= 0 for cython.array")
*
- * def getJoystickBtn() -> bool:
*/
- __Pyx_XDECREF(__pyx_r);
- if ((moab_getMenuBtn() != 0)) {
- __Pyx_INCREF(Py_True);
- __pyx_t_1 = Py_True;
- } else {
- __Pyx_INCREF(Py_False);
- __pyx_t_1 = Py_False;
}
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
- /* "moab.pyx":133
- * return Result(moab_sync())
- *
- * def getMenuBtn() -> bool: # <<<<<<<<<<<<<<
- * return True if moab_getMenuBtn() else False
+ /* "View.MemoryView":138
+ * raise ValueError("itemsize <= 0 for cython.array")
*
+ * if not isinstance(format, bytes): # <<<<<<<<<<<<<<
+ * format = format.encode('ASCII')
+ * self._format = format # keep a reference to the byte string
*/
+ __pyx_t_2 = PyBytes_Check(__pyx_v_format);
+ __pyx_t_4 = ((!(__pyx_t_2 != 0)) != 0);
+ if (__pyx_t_4) {
- /* function exit code */
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":136
- * return True if moab_getMenuBtn() else False
- *
- * def getJoystickBtn() -> bool: # <<<<<<<<<<<<<<
- * return True if moab_getJoystickBtn() else False
+ /* "View.MemoryView":139
*
+ * if not isinstance(format, bytes):
+ * format = format.encode('ASCII') # <<<<<<<<<<<<<<
+ * self._format = format # keep a reference to the byte string
+ * self.format = self._format
*/
+ __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_format, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 139, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_6 = NULL;
+ if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+ __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
+ if (likely(__pyx_t_6)) {
+ PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+ __Pyx_INCREF(__pyx_t_6);
+ __Pyx_INCREF(function);
+ __Pyx_DECREF_SET(__pyx_t_5, function);
+ }
+ }
+ __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_n_s_ASCII) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_n_s_ASCII);
+ __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+ if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 139, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_DECREF_SET(__pyx_v_format, __pyx_t_3);
+ __pyx_t_3 = 0;
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_25getJoystickBtn(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_25getJoystickBtn = {"getJoystickBtn", (PyCFunction)__pyx_pw_6pymoab_25getJoystickBtn, METH_NOARGS, 0};
-static PyObject *__pyx_pw_6pymoab_25getJoystickBtn(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("getJoystickBtn (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_24getJoystickBtn(__pyx_self);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":138
+ * raise ValueError("itemsize <= 0 for cython.array")
+ *
+ * if not isinstance(format, bytes): # <<<<<<<<<<<<<<
+ * format = format.encode('ASCII')
+ * self._format = format # keep a reference to the byte string
+ */
+ }
-static PyObject *__pyx_pf_6pymoab_24getJoystickBtn(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- __Pyx_RefNannySetupContext("getJoystickBtn", 0);
+ /* "View.MemoryView":140
+ * if not isinstance(format, bytes):
+ * format = format.encode('ASCII')
+ * self._format = format # keep a reference to the byte string # <<<<<<<<<<<<<<
+ * self.format = self._format
+ *
+ */
+ if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_format)->tp_name), 0))) __PYX_ERR(1, 140, __pyx_L1_error)
+ __pyx_t_3 = __pyx_v_format;
+ __Pyx_INCREF(__pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_3);
+ __Pyx_GOTREF(__pyx_v_self->_format);
+ __Pyx_DECREF(__pyx_v_self->_format);
+ __pyx_v_self->_format = ((PyObject*)__pyx_t_3);
+ __pyx_t_3 = 0;
- /* "moab.pyx":137
+ /* "View.MemoryView":141
+ * format = format.encode('ASCII')
+ * self._format = format # keep a reference to the byte string
+ * self.format = self._format # <<<<<<<<<<<<<<
*
- * def getJoystickBtn() -> bool:
- * return True if moab_getJoystickBtn() else False # <<<<<<<<<<<<<<
*
- * def getJoystickX() -> float:
*/
- __Pyx_XDECREF(__pyx_r);
- if ((moab_getJoystickBtn() != 0)) {
- __Pyx_INCREF(Py_True);
- __pyx_t_1 = Py_True;
- } else {
- __Pyx_INCREF(Py_False);
- __pyx_t_1 = Py_False;
+ if (unlikely(__pyx_v_self->_format == Py_None)) {
+ PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
+ __PYX_ERR(1, 141, __pyx_L1_error)
}
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
+ __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_self->_format); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(1, 141, __pyx_L1_error)
+ __pyx_v_self->format = __pyx_t_7;
- /* "moab.pyx":136
- * return True if moab_getMenuBtn() else False
+ /* "View.MemoryView":144
*
- * def getJoystickBtn() -> bool: # <<<<<<<<<<<<<<
- * return True if moab_getJoystickBtn() else False
+ *
+ * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) # <<<<<<<<<<<<<<
+ * self._strides = self._shape + self.ndim
*
*/
+ __pyx_v_self->_shape = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * __pyx_v_self->ndim) * 2)));
- /* function exit code */
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":139
- * return True if moab_getJoystickBtn() else False
+ /* "View.MemoryView":145
*
- * def getJoystickX() -> float: # <<<<<<<<<<<<<<
- * return moab_getJoystickX() / 100.0
+ * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2)
+ * self._strides = self._shape + self.ndim # <<<<<<<<<<<<<<
*
+ * if not self._shape:
*/
+ __pyx_v_self->_strides = (__pyx_v_self->_shape + __pyx_v_self->ndim);
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_27getJoystickX(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_27getJoystickX = {"getJoystickX", (PyCFunction)__pyx_pw_6pymoab_27getJoystickX, METH_NOARGS, 0};
-static PyObject *__pyx_pw_6pymoab_27getJoystickX(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("getJoystickX (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_26getJoystickX(__pyx_self);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_26getJoystickX(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("getJoystickX", 0);
-
- /* "moab.pyx":140
+ /* "View.MemoryView":147
+ * self._strides = self._shape + self.ndim
*
- * def getJoystickX() -> float:
- * return moab_getJoystickX() / 100.0 # <<<<<<<<<<<<<<
+ * if not self._shape: # <<<<<<<<<<<<<<
+ * raise MemoryError("unable to allocate shape and strides.")
*
- * def getJoystickY() -> float:
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyFloat_FromDouble((((double)moab_getJoystickX()) / 100.0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
+ __pyx_t_4 = ((!(__pyx_v_self->_shape != 0)) != 0);
+ if (unlikely(__pyx_t_4)) {
- /* "moab.pyx":139
- * return True if moab_getJoystickBtn() else False
+ /* "View.MemoryView":148
+ *
+ * if not self._shape:
+ * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<<
*
- * def getJoystickX() -> float: # <<<<<<<<<<<<<<
- * return moab_getJoystickX() / 100.0
*
*/
+ __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 148, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __PYX_ERR(1, 148, __pyx_L1_error)
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("pymoab.getJoystickX", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":142
- * return moab_getJoystickX() / 100.0
+ /* "View.MemoryView":147
+ * self._strides = self._shape + self.ndim
*
- * def getJoystickY() -> float: # <<<<<<<<<<<<<<
- * return moab_getJoystickY() / 100.0
+ * if not self._shape: # <<<<<<<<<<<<<<
+ * raise MemoryError("unable to allocate shape and strides.")
*
*/
+ }
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_29getJoystickY(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_29getJoystickY = {"getJoystickY", (PyCFunction)__pyx_pw_6pymoab_29getJoystickY, METH_NOARGS, 0};
-static PyObject *__pyx_pw_6pymoab_29getJoystickY(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("getJoystickY (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_28getJoystickY(__pyx_self);
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_28getJoystickY(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("getJoystickY", 0);
-
- /* "moab.pyx":143
+ /* "View.MemoryView":151
*
- * def getJoystickY() -> float:
- * return moab_getJoystickY() / 100.0 # <<<<<<<<<<<<<<
*
- * def enableFan(enabled: bool):
+ * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<<
+ * if dim <= 0:
+ * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyFloat_FromDouble((((double)moab_getJoystickY()) / 100.0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
+ __pyx_t_8 = 0;
+ __pyx_t_3 = __pyx_v_shape; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
+ for (;;) {
+ if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+ __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(1, 151, __pyx_L1_error)
+ #else
+ __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 151, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ #endif
+ __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 151, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_v_dim = __pyx_t_9;
+ __pyx_v_idx = __pyx_t_8;
+ __pyx_t_8 = (__pyx_t_8 + 1);
- /* "moab.pyx":142
- * return moab_getJoystickX() / 100.0
- *
- * def getJoystickY() -> float: # <<<<<<<<<<<<<<
- * return moab_getJoystickY() / 100.0
+ /* "View.MemoryView":152
*
+ * for idx, dim in enumerate(shape):
+ * if dim <= 0: # <<<<<<<<<<<<<<
+ * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
+ * self._shape[idx] = dim
*/
+ __pyx_t_4 = ((__pyx_v_dim <= 0) != 0);
+ if (unlikely(__pyx_t_4)) {
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("pymoab.getJoystickY", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":145
- * return moab_getJoystickY() / 100.0
- *
- * def enableFan(enabled: bool): # <<<<<<<<<<<<<<
- * moab_enableFan(enabled)
+ /* "View.MemoryView":153
+ * for idx, dim in enumerate(shape):
+ * if dim <= 0:
+ * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) # <<<<<<<<<<<<<<
+ * self._shape[idx] = dim
*
*/
+ __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 153, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 153, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 153, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_10);
+ __Pyx_GIVEREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5);
+ __Pyx_GIVEREF(__pyx_t_6);
+ PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6);
+ __pyx_t_5 = 0;
+ __pyx_t_6 = 0;
+ __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 153, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+ __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 153, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_10);
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __Pyx_Raise(__pyx_t_10, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+ __PYX_ERR(1, 153, __pyx_L1_error)
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_31enableFan(PyObject *__pyx_self, PyObject *__pyx_arg_enabled); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_31enableFan = {"enableFan", (PyCFunction)__pyx_pw_6pymoab_31enableFan, METH_O, 0};
-static PyObject *__pyx_pw_6pymoab_31enableFan(PyObject *__pyx_self, PyObject *__pyx_arg_enabled) {
- __pyx_t_6pymoab_bool __pyx_v_enabled;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("enableFan (wrapper)", 0);
- assert(__pyx_arg_enabled); {
- __pyx_v_enabled = __Pyx_PyInt_As_char(__pyx_arg_enabled); if (unlikely((__pyx_v_enabled == (char)-1) && PyErr_Occurred())) __PYX_ERR(0, 145, __pyx_L3_error)
- }
- goto __pyx_L4_argument_unpacking_done;
- __pyx_L3_error:;
- __Pyx_AddTraceback("pymoab.enableFan", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __Pyx_RefNannyFinishContext();
- return NULL;
- __pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_pf_6pymoab_30enableFan(__pyx_self, ((__pyx_t_6pymoab_bool)__pyx_v_enabled));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_30enableFan(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_6pymoab_bool __pyx_v_enabled) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("enableFan", 0);
-
- /* "moab.pyx":146
- *
- * def enableFan(enabled: bool):
- * moab_enableFan(enabled) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":152
*
- * def enableHat(enabled: bool):
+ * for idx, dim in enumerate(shape):
+ * if dim <= 0: # <<<<<<<<<<<<<<
+ * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
+ * self._shape[idx] = dim
*/
- moab_enableFan(__pyx_v_enabled);
+ }
- /* "moab.pyx":145
- * return moab_getJoystickY() / 100.0
- *
- * def enableFan(enabled: bool): # <<<<<<<<<<<<<<
- * moab_enableFan(enabled)
+ /* "View.MemoryView":154
+ * if dim <= 0:
+ * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
+ * self._shape[idx] = dim # <<<<<<<<<<<<<<
*
+ * cdef char order
*/
+ (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_v_dim;
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "moab.pyx":148
- * moab_enableFan(enabled)
+ /* "View.MemoryView":151
*
- * def enableHat(enabled: bool): # <<<<<<<<<<<<<<
- * moab_enableHat(enabled)
*
+ * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<<
+ * if dim <= 0:
+ * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
*/
-
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_33enableHat(PyObject *__pyx_self, PyObject *__pyx_arg_enabled); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_33enableHat = {"enableHat", (PyCFunction)__pyx_pw_6pymoab_33enableHat, METH_O, 0};
-static PyObject *__pyx_pw_6pymoab_33enableHat(PyObject *__pyx_self, PyObject *__pyx_arg_enabled) {
- __pyx_t_6pymoab_bool __pyx_v_enabled;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("enableHat (wrapper)", 0);
- assert(__pyx_arg_enabled); {
- __pyx_v_enabled = __Pyx_PyInt_As_char(__pyx_arg_enabled); if (unlikely((__pyx_v_enabled == (char)-1) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L3_error)
}
- goto __pyx_L4_argument_unpacking_done;
- __pyx_L3_error:;
- __Pyx_AddTraceback("pymoab.enableHat", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __Pyx_RefNannyFinishContext();
- return NULL;
- __pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_pf_6pymoab_32enableHat(__pyx_self, ((__pyx_t_6pymoab_bool)__pyx_v_enabled));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_6pymoab_32enableHat(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_6pymoab_bool __pyx_v_enabled) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("enableHat", 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "moab.pyx":149
- *
- * def enableHat(enabled: bool):
- * moab_enableHat(enabled) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":157
*
- * def pollTemp() -> float:
+ * cdef char order
+ * if mode == 'fortran': # <<<<<<<<<<<<<<
+ * order = b'F'
+ * self.mode = u'fortran'
*/
- moab_enableHat(__pyx_v_enabled);
+ __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_fortran, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 157, __pyx_L1_error)
+ if (__pyx_t_4) {
- /* "moab.pyx":148
- * moab_enableFan(enabled)
- *
- * def enableHat(enabled: bool): # <<<<<<<<<<<<<<
- * moab_enableHat(enabled)
- *
+ /* "View.MemoryView":158
+ * cdef char order
+ * if mode == 'fortran':
+ * order = b'F' # <<<<<<<<<<<<<<
+ * self.mode = u'fortran'
+ * elif mode == 'c':
*/
+ __pyx_v_order = 'F';
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":159
+ * if mode == 'fortran':
+ * order = b'F'
+ * self.mode = u'fortran' # <<<<<<<<<<<<<<
+ * elif mode == 'c':
+ * order = b'C'
+ */
+ __Pyx_INCREF(__pyx_n_u_fortran);
+ __Pyx_GIVEREF(__pyx_n_u_fortran);
+ __Pyx_GOTREF(__pyx_v_self->mode);
+ __Pyx_DECREF(__pyx_v_self->mode);
+ __pyx_v_self->mode = __pyx_n_u_fortran;
-/* "moab.pyx":151
- * moab_enableHat(enabled)
- *
- * def pollTemp() -> float: # <<<<<<<<<<<<<<
- * return moab_pollTemp()
+ /* "View.MemoryView":157
*
+ * cdef char order
+ * if mode == 'fortran': # <<<<<<<<<<<<<<
+ * order = b'F'
+ * self.mode = u'fortran'
*/
+ goto __pyx_L10;
+ }
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_35pollTemp(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_35pollTemp = {"pollTemp", (PyCFunction)__pyx_pw_6pymoab_35pollTemp, METH_NOARGS, 0};
-static PyObject *__pyx_pw_6pymoab_35pollTemp(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("pollTemp (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_34pollTemp(__pyx_self);
+ /* "View.MemoryView":160
+ * order = b'F'
+ * self.mode = u'fortran'
+ * elif mode == 'c': # <<<<<<<<<<<<<<
+ * order = b'C'
+ * self.mode = u'c'
+ */
+ __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 160, __pyx_L1_error)
+ if (likely(__pyx_t_4)) {
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":161
+ * self.mode = u'fortran'
+ * elif mode == 'c':
+ * order = b'C' # <<<<<<<<<<<<<<
+ * self.mode = u'c'
+ * else:
+ */
+ __pyx_v_order = 'C';
-static PyObject *__pyx_pf_6pymoab_34pollTemp(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("pollTemp", 0);
+ /* "View.MemoryView":162
+ * elif mode == 'c':
+ * order = b'C'
+ * self.mode = u'c' # <<<<<<<<<<<<<<
+ * else:
+ * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)
+ */
+ __Pyx_INCREF(__pyx_n_u_c);
+ __Pyx_GIVEREF(__pyx_n_u_c);
+ __Pyx_GOTREF(__pyx_v_self->mode);
+ __Pyx_DECREF(__pyx_v_self->mode);
+ __pyx_v_self->mode = __pyx_n_u_c;
+
+ /* "View.MemoryView":160
+ * order = b'F'
+ * self.mode = u'fortran'
+ * elif mode == 'c': # <<<<<<<<<<<<<<
+ * order = b'C'
+ * self.mode = u'c'
+ */
+ goto __pyx_L10;
+ }
+
+ /* "View.MemoryView":164
+ * self.mode = u'c'
+ * else:
+ * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) # <<<<<<<<<<<<<<
+ *
+ * self.len = fill_contig_strides_array(self._shape, self._strides,
+ */
+ /*else*/ {
+ __pyx_t_3 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_v_mode); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 164, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 164, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_10);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_Raise(__pyx_t_10, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+ __PYX_ERR(1, 164, __pyx_L1_error)
+ }
+ __pyx_L10:;
- /* "moab.pyx":152
+ /* "View.MemoryView":166
+ * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)
*
- * def pollTemp() -> float:
- * return moab_pollTemp() # <<<<<<<<<<<<<<
+ * self.len = fill_contig_strides_array(self._shape, self._strides, # <<<<<<<<<<<<<<
+ * itemsize, self.ndim, order)
*
- * def pollPowerBtn() -> bool:
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyFloat_FromDouble(moab_pollTemp()); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
+ __pyx_v_self->len = __pyx_fill_contig_strides_array(__pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_itemsize, __pyx_v_self->ndim, __pyx_v_order);
+
+ /* "View.MemoryView":169
+ * itemsize, self.ndim, order)
+ *
+ * self.free_data = allocate_buffer # <<<<<<<<<<<<<<
+ * self.dtype_is_object = format == b'O'
+ * if allocate_buffer:
+ */
+ __pyx_v_self->free_data = __pyx_v_allocate_buffer;
- /* "moab.pyx":151
- * moab_enableHat(enabled)
+ /* "View.MemoryView":170
*
- * def pollTemp() -> float: # <<<<<<<<<<<<<<
- * return moab_pollTemp()
+ * self.free_data = allocate_buffer
+ * self.dtype_is_object = format == b'O' # <<<<<<<<<<<<<<
+ * if allocate_buffer:
*
*/
+ __pyx_t_10 = PyObject_RichCompare(__pyx_v_format, __pyx_n_b_O, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 170, __pyx_L1_error)
+ __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 170, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+ __pyx_v_self->dtype_is_object = __pyx_t_4;
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("pymoab.pollTemp", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":171
+ * self.free_data = allocate_buffer
+ * self.dtype_is_object = format == b'O'
+ * if allocate_buffer: # <<<<<<<<<<<<<<
+ *
+ *
+ */
+ __pyx_t_4 = (__pyx_v_allocate_buffer != 0);
+ if (__pyx_t_4) {
-/* "moab.pyx":154
- * return moab_pollTemp()
+ /* "View.MemoryView":174
*
- * def pollPowerBtn() -> bool: # <<<<<<<<<<<<<<
- * return True if moab_pollPowerBtn() else False
*
+ * self.data = malloc(self.len) # <<<<<<<<<<<<<<
+ * if not self.data:
+ * raise MemoryError("unable to allocate array data.")
*/
+ __pyx_v_self->data = ((char *)malloc(__pyx_v_self->len));
-/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_37pollPowerBtn(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_37pollPowerBtn = {"pollPowerBtn", (PyCFunction)__pyx_pw_6pymoab_37pollPowerBtn, METH_NOARGS, 0};
-static PyObject *__pyx_pw_6pymoab_37pollPowerBtn(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("pollPowerBtn (wrapper)", 0);
- __pyx_r = __pyx_pf_6pymoab_36pollPowerBtn(__pyx_self);
+ /* "View.MemoryView":175
+ *
+ * self.data = malloc(self.len)
+ * if not self.data: # <<<<<<<<<<<<<<
+ * raise MemoryError("unable to allocate array data.")
+ *
+ */
+ __pyx_t_4 = ((!(__pyx_v_self->data != 0)) != 0);
+ if (unlikely(__pyx_t_4)) {
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":176
+ * self.data = malloc(self.len)
+ * if not self.data:
+ * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<<
+ *
+ * if self.dtype_is_object:
+ */
+ __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 176, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_10);
+ __Pyx_Raise(__pyx_t_10, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+ __PYX_ERR(1, 176, __pyx_L1_error)
-static PyObject *__pyx_pf_6pymoab_36pollPowerBtn(CYTHON_UNUSED PyObject *__pyx_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- __Pyx_RefNannySetupContext("pollPowerBtn", 0);
+ /* "View.MemoryView":175
+ *
+ * self.data = malloc(self.len)
+ * if not self.data: # <<<<<<<<<<<<<<
+ * raise MemoryError("unable to allocate array data.")
+ *
+ */
+ }
+
+ /* "View.MemoryView":178
+ * raise MemoryError("unable to allocate array data.")
+ *
+ * if self.dtype_is_object: # <<<<<<<<<<<<<<
+ * p = self.data
+ * for i in range(self.len / itemsize):
+ */
+ __pyx_t_4 = (__pyx_v_self->dtype_is_object != 0);
+ if (__pyx_t_4) {
+
+ /* "View.MemoryView":179
+ *
+ * if self.dtype_is_object:
+ * p = self.data # <<<<<<<<<<<<<<
+ * for i in range(self.len / itemsize):
+ * p[i] = Py_None
+ */
+ __pyx_v_p = ((PyObject **)__pyx_v_self->data);
+
+ /* "View.MemoryView":180
+ * if self.dtype_is_object:
+ * p = self.data
+ * for i in range(self.len / itemsize): # <<<<<<<<<<<<<<
+ * p[i] = Py_None
+ * Py_INCREF(Py_None)
+ */
+ if (unlikely(__pyx_v_itemsize == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
+ __PYX_ERR(1, 180, __pyx_L1_error)
+ }
+ else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) {
+ PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
+ __PYX_ERR(1, 180, __pyx_L1_error)
+ }
+ __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize);
+ __pyx_t_9 = __pyx_t_1;
+ for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_9; __pyx_t_11+=1) {
+ __pyx_v_i = __pyx_t_11;
- /* "moab.pyx":155
+ /* "View.MemoryView":181
+ * p = self.data
+ * for i in range(self.len / itemsize):
+ * p[i] = Py_None # <<<<<<<<<<<<<<
+ * Py_INCREF(Py_None)
*
- * def pollPowerBtn() -> bool:
- * return True if moab_pollPowerBtn() else False # <<<<<<<<<<<<<<
+ */
+ (__pyx_v_p[__pyx_v_i]) = Py_None;
+
+ /* "View.MemoryView":182
+ * for i in range(self.len / itemsize):
+ * p[i] = Py_None
+ * Py_INCREF(Py_None) # <<<<<<<<<<<<<<
+ *
+ * @cname('getbuffer')
+ */
+ Py_INCREF(Py_None);
+ }
+
+ /* "View.MemoryView":178
+ * raise MemoryError("unable to allocate array data.")
+ *
+ * if self.dtype_is_object: # <<<<<<<<<<<<<<
+ * p = self.data
+ * for i in range(self.len / itemsize):
+ */
+ }
+
+ /* "View.MemoryView":171
+ * self.free_data = allocate_buffer
+ * self.dtype_is_object = format == b'O'
+ * if allocate_buffer: # <<<<<<<<<<<<<<
*
*
*/
- __Pyx_XDECREF(__pyx_r);
- if ((moab_pollPowerBtn() != 0)) {
- __Pyx_INCREF(Py_True);
- __pyx_t_1 = Py_True;
- } else {
- __Pyx_INCREF(Py_False);
- __pyx_t_1 = Py_False;
}
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
- /* "moab.pyx":154
- * return moab_pollTemp()
+ /* "View.MemoryView":122
+ * cdef bint dtype_is_object
*
- * def pollPowerBtn() -> bool: # <<<<<<<<<<<<<<
- * return True if moab_pollPowerBtn() else False
+ * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<<
+ * mode="c", bint allocate_buffer=True):
*
*/
/* function exit code */
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_XDECREF(__pyx_t_10);
+ __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
__pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_XDECREF(__pyx_v_format);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "moab.pyx":165
- * @cython.boundscheck(False)
- * @cython.wraparound(False)
- * def _update_bandpass_lookup(unsigned char center, float sigma, float gain): # <<<<<<<<<<<<<<
- * global _bandpass_lookup
- * global _last_center
+/* "View.MemoryView":185
+ *
+ * @cname('getbuffer')
+ * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<<
+ * cdef int bufmode = -1
+ * if self.mode == u"c":
*/
/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_39_update_bandpass_lookup(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_39_update_bandpass_lookup = {"_update_bandpass_lookup", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pymoab_39_update_bandpass_lookup, METH_VARARGS|METH_KEYWORDS, 0};
-static PyObject *__pyx_pw_6pymoab_39_update_bandpass_lookup(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- unsigned char __pyx_v_center;
- float __pyx_v_sigma;
- float __pyx_v_gain;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- PyObject *__pyx_r = 0;
+static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
+static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
+ int __pyx_r;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("_update_bandpass_lookup (wrapper)", 0);
- {
- static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_center,&__pyx_n_s_sigma,&__pyx_n_s_gain,0};
- PyObject* values[3] = {0,0,0};
- if (unlikely(__pyx_kwds)) {
- Py_ssize_t kw_args;
- const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
- switch (pos_args) {
- case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
- CYTHON_FALLTHROUGH;
- case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- CYTHON_FALLTHROUGH;
- case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- CYTHON_FALLTHROUGH;
- case 0: break;
- default: goto __pyx_L5_argtuple_error;
- }
- kw_args = PyDict_Size(__pyx_kwds);
- switch (pos_args) {
- case 0:
- if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_center)) != 0)) kw_args--;
- else goto __pyx_L5_argtuple_error;
- CYTHON_FALLTHROUGH;
- case 1:
- if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sigma)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("_update_bandpass_lookup", 1, 3, 3, 1); __PYX_ERR(0, 165, __pyx_L3_error)
- }
- CYTHON_FALLTHROUGH;
- case 2:
- if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gain)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("_update_bandpass_lookup", 1, 3, 3, 2); __PYX_ERR(0, 165, __pyx_L3_error)
- }
- }
- if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_update_bandpass_lookup") < 0)) __PYX_ERR(0, 165, __pyx_L3_error)
- }
- } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
- goto __pyx_L5_argtuple_error;
- } else {
- values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
- }
- __pyx_v_center = __Pyx_PyInt_As_unsigned_char(values[0]); if (unlikely((__pyx_v_center == (unsigned char)-1) && PyErr_Occurred())) __PYX_ERR(0, 165, __pyx_L3_error)
- __pyx_v_sigma = __pyx_PyFloat_AsFloat(values[1]); if (unlikely((__pyx_v_sigma == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 165, __pyx_L3_error)
- __pyx_v_gain = __pyx_PyFloat_AsFloat(values[2]); if (unlikely((__pyx_v_gain == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 165, __pyx_L3_error)
- }
- goto __pyx_L4_argument_unpacking_done;
- __pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("_update_bandpass_lookup", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 165, __pyx_L3_error)
- __pyx_L3_error:;
- __Pyx_AddTraceback("pymoab._update_bandpass_lookup", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __Pyx_RefNannyFinishContext();
- return NULL;
- __pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_pf_6pymoab_38_update_bandpass_lookup(__pyx_self, __pyx_v_center, __pyx_v_sigma, __pyx_v_gain);
+ __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
+ __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_6pymoab_38_update_bandpass_lookup(CYTHON_UNUSED PyObject *__pyx_self, unsigned char __pyx_v_center, float __pyx_v_sigma, float __pyx_v_gain) {
- double __pyx_v_mu;
- PyObject *__pyx_v_n = NULL;
- PyObject *__pyx_v_h = NULL;
- PyObject *__pyx_v_f = NULL;
- PyObject *__pyx_r = NULL;
+static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
+ int __pyx_v_bufmode;
+ int __pyx_r;
__Pyx_RefNannyDeclarations
- long __pyx_t_1;
- PyObject *__pyx_t_2 = NULL;
+ int __pyx_t_1;
+ int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
- int __pyx_t_4;
- PyObject *__pyx_t_5 = NULL;
- PyObject *__pyx_t_6 = NULL;
- PyObject *__pyx_t_7 = NULL;
- float __pyx_t_8;
- Py_ssize_t __pyx_t_9;
+ char *__pyx_t_4;
+ Py_ssize_t __pyx_t_5;
+ int __pyx_t_6;
+ Py_ssize_t *__pyx_t_7;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("_update_bandpass_lookup", 0);
+ if (__pyx_v_info == NULL) {
+ PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
+ return -1;
+ }
+ __Pyx_RefNannySetupContext("__getbuffer__", 0);
+ __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_GIVEREF(__pyx_v_info->obj);
- /* "moab.pyx":171
- * global _last_sigma
- *
- * _last_center = center # <<<<<<<<<<<<<<
- * _last_sigma = sigma
- * _last_gain = gain
+ /* "View.MemoryView":186
+ * @cname('getbuffer')
+ * def __getbuffer__(self, Py_buffer *info, int flags):
+ * cdef int bufmode = -1 # <<<<<<<<<<<<<<
+ * if self.mode == u"c":
+ * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
*/
- __pyx_v_6pymoab__last_center = __pyx_v_center;
+ __pyx_v_bufmode = -1;
- /* "moab.pyx":172
- *
- * _last_center = center
- * _last_sigma = sigma # <<<<<<<<<<<<<<
- * _last_gain = gain
- *
+ /* "View.MemoryView":187
+ * def __getbuffer__(self, Py_buffer *info, int flags):
+ * cdef int bufmode = -1
+ * if self.mode == u"c": # <<<<<<<<<<<<<<
+ * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * elif self.mode == u"fortran":
*/
- __pyx_v_6pymoab__last_sigma = __pyx_v_sigma;
+ __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_c, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 187, __pyx_L1_error)
+ __pyx_t_2 = (__pyx_t_1 != 0);
+ if (__pyx_t_2) {
- /* "moab.pyx":173
- * _last_center = center
- * _last_sigma = sigma
- * _last_gain = gain # <<<<<<<<<<<<<<
- *
- * mu = 0.5
+ /* "View.MemoryView":188
+ * cdef int bufmode = -1
+ * if self.mode == u"c":
+ * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<<
+ * elif self.mode == u"fortran":
+ * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
*/
- __pyx_v_6pymoab__last_gain = __pyx_v_gain;
+ __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS);
- /* "moab.pyx":175
- * _last_gain = gain
- *
- * mu = 0.5 # <<<<<<<<<<<<<<
- * for n in range(256):
- * h = n / 255.0
+ /* "View.MemoryView":187
+ * def __getbuffer__(self, Py_buffer *info, int flags):
+ * cdef int bufmode = -1
+ * if self.mode == u"c": # <<<<<<<<<<<<<<
+ * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * elif self.mode == u"fortran":
*/
- __pyx_v_mu = 0.5;
+ goto __pyx_L3;
+ }
- /* "moab.pyx":176
- *
- * mu = 0.5
- * for n in range(256): # <<<<<<<<<<<<<<
- * h = n / 255.0
- *
+ /* "View.MemoryView":189
+ * if self.mode == u"c":
+ * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * elif self.mode == u"fortran": # <<<<<<<<<<<<<<
+ * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * if not (flags & bufmode):
*/
- for (__pyx_t_1 = 0; __pyx_t_1 < 0x100; __pyx_t_1+=1) {
- __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_2);
- __pyx_t_2 = 0;
+ __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_fortran, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 189, __pyx_L1_error)
+ __pyx_t_1 = (__pyx_t_2 != 0);
+ if (__pyx_t_1) {
- /* "moab.pyx":177
- * mu = 0.5
- * for n in range(256):
- * h = n / 255.0 # <<<<<<<<<<<<<<
- *
- * # rotate the hue phase so that `center` is at 0.5
+ /* "View.MemoryView":190
+ * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * elif self.mode == u"fortran":
+ * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<<
+ * if not (flags & bufmode):
+ * raise ValueError("Can only create a buffer that is contiguous in memory.")
*/
- __pyx_t_2 = __Pyx_PyFloat_TrueDivideObjC(__pyx_v_n, __pyx_float_255_0, 255.0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_XDECREF_SET(__pyx_v_h, __pyx_t_2);
- __pyx_t_2 = 0;
+ __pyx_v_bufmode = (PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS);
- /* "moab.pyx":180
- *
- * # rotate the hue phase so that `center` is at 0.5
- * h = h + (0.5 - (center / 255.0)) # <<<<<<<<<<<<<<
- * if (h > 1.0):
- * h = h - 1.0
+ /* "View.MemoryView":189
+ * if self.mode == u"c":
+ * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * elif self.mode == u"fortran": # <<<<<<<<<<<<<<
+ * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * if not (flags & bufmode):
*/
- __pyx_t_2 = PyFloat_FromDouble((0.5 - (((double)__pyx_v_center) / 255.0))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 180, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyNumber_Add(__pyx_v_h, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 180, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF_SET(__pyx_v_h, __pyx_t_3);
- __pyx_t_3 = 0;
+ }
+ __pyx_L3:;
- /* "moab.pyx":181
- * # rotate the hue phase so that `center` is at 0.5
- * h = h + (0.5 - (center / 255.0))
- * if (h > 1.0): # <<<<<<<<<<<<<<
- * h = h - 1.0
- * if (h < 0.0):
+ /* "View.MemoryView":191
+ * elif self.mode == u"fortran":
+ * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * if not (flags & bufmode): # <<<<<<<<<<<<<<
+ * raise ValueError("Can only create a buffer that is contiguous in memory.")
+ * info.buf = self.data
+ */
+ __pyx_t_1 = ((!((__pyx_v_flags & __pyx_v_bufmode) != 0)) != 0);
+ if (unlikely(__pyx_t_1)) {
+
+ /* "View.MemoryView":192
+ * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * if not (flags & bufmode):
+ * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<<
+ * info.buf = self.data
+ * info.len = self.len
*/
- __pyx_t_3 = PyObject_RichCompare(__pyx_v_h, __pyx_float_1_0, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 181, __pyx_L1_error)
- __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 181, __pyx_L1_error)
+ __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 192, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (__pyx_t_4) {
+ __PYX_ERR(1, 192, __pyx_L1_error)
- /* "moab.pyx":182
- * h = h + (0.5 - (center / 255.0))
- * if (h > 1.0):
- * h = h - 1.0 # <<<<<<<<<<<<<<
- * if (h < 0.0):
- * h = h + 1.0
+ /* "View.MemoryView":191
+ * elif self.mode == u"fortran":
+ * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ * if not (flags & bufmode): # <<<<<<<<<<<<<<
+ * raise ValueError("Can only create a buffer that is contiguous in memory.")
+ * info.buf = self.data
*/
- __pyx_t_3 = __Pyx_PyFloat_SubtractObjC(__pyx_v_h, __pyx_float_1_0, 1.0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF_SET(__pyx_v_h, __pyx_t_3);
- __pyx_t_3 = 0;
+ }
- /* "moab.pyx":181
- * # rotate the hue phase so that `center` is at 0.5
- * h = h + (0.5 - (center / 255.0))
- * if (h > 1.0): # <<<<<<<<<<<<<<
- * h = h - 1.0
- * if (h < 0.0):
+ /* "View.MemoryView":193
+ * if not (flags & bufmode):
+ * raise ValueError("Can only create a buffer that is contiguous in memory.")
+ * info.buf = self.data # <<<<<<<<<<<<<<
+ * info.len = self.len
+ * info.ndim = self.ndim
*/
- }
+ __pyx_t_4 = __pyx_v_self->data;
+ __pyx_v_info->buf = __pyx_t_4;
- /* "moab.pyx":183
- * if (h > 1.0):
- * h = h - 1.0
- * if (h < 0.0): # <<<<<<<<<<<<<<
- * h = h + 1.0
- *
+ /* "View.MemoryView":194
+ * raise ValueError("Can only create a buffer that is contiguous in memory.")
+ * info.buf = self.data
+ * info.len = self.len # <<<<<<<<<<<<<<
+ * info.ndim = self.ndim
+ * info.shape = self._shape
*/
- __pyx_t_3 = PyObject_RichCompare(__pyx_v_h, __pyx_float_0_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 183, __pyx_L1_error)
- __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 183, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (__pyx_t_4) {
+ __pyx_t_5 = __pyx_v_self->len;
+ __pyx_v_info->len = __pyx_t_5;
- /* "moab.pyx":184
- * h = h - 1.0
- * if (h < 0.0):
- * h = h + 1.0 # <<<<<<<<<<<<<<
- *
- * # gaussian bandpass filter
+ /* "View.MemoryView":195
+ * info.buf = self.data
+ * info.len = self.len
+ * info.ndim = self.ndim # <<<<<<<<<<<<<<
+ * info.shape = self._shape
+ * info.strides = self._strides
*/
- __pyx_t_3 = __Pyx_PyFloat_AddObjC(__pyx_v_h, __pyx_float_1_0, 1.0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 184, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF_SET(__pyx_v_h, __pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_t_6 = __pyx_v_self->ndim;
+ __pyx_v_info->ndim = __pyx_t_6;
- /* "moab.pyx":183
- * if (h > 1.0):
- * h = h - 1.0
- * if (h < 0.0): # <<<<<<<<<<<<<<
- * h = h + 1.0
- *
+ /* "View.MemoryView":196
+ * info.len = self.len
+ * info.ndim = self.ndim
+ * info.shape = self._shape # <<<<<<<<<<<<<<
+ * info.strides = self._strides
+ * info.suboffsets = NULL
*/
- }
+ __pyx_t_7 = __pyx_v_self->_shape;
+ __pyx_v_info->shape = __pyx_t_7;
- /* "moab.pyx":187
- *
- * # gaussian bandpass filter
- * f = math.exp(-( (h - mu)**2 / ( 2.0 * sigma**2 ) ) ) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":197
+ * info.ndim = self.ndim
+ * info.shape = self._shape
+ * info.strides = self._strides # <<<<<<<<<<<<<<
+ * info.suboffsets = NULL
+ * info.itemsize = self.itemsize
+ */
+ __pyx_t_7 = __pyx_v_self->_strides;
+ __pyx_v_info->strides = __pyx_t_7;
+
+ /* "View.MemoryView":198
+ * info.shape = self._shape
+ * info.strides = self._strides
+ * info.suboffsets = NULL # <<<<<<<<<<<<<<
+ * info.itemsize = self.itemsize
+ * info.readonly = 0
+ */
+ __pyx_v_info->suboffsets = NULL;
+
+ /* "View.MemoryView":199
+ * info.strides = self._strides
+ * info.suboffsets = NULL
+ * info.itemsize = self.itemsize # <<<<<<<<<<<<<<
+ * info.readonly = 0
*
- * # pre-gain around center
*/
- __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_math); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 187, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_exp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 187, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 187, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_6 = PyNumber_Subtract(__pyx_v_h, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyNumber_Power(__pyx_t_6, __pyx_int_2, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 187, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __pyx_t_6 = PyFloat_FromDouble((2.0 * powf(__pyx_v_sigma, 2.0))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 187, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_7);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __pyx_t_6 = PyNumber_Negative(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
- __pyx_t_7 = NULL;
- if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
- __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
- if (likely(__pyx_t_7)) {
- PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
- __Pyx_INCREF(__pyx_t_7);
- __Pyx_INCREF(function);
- __Pyx_DECREF_SET(__pyx_t_5, function);
- }
- }
- __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6);
- __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 187, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_XDECREF_SET(__pyx_v_f, __pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_t_5 = __pyx_v_self->itemsize;
+ __pyx_v_info->itemsize = __pyx_t_5;
- /* "moab.pyx":190
+ /* "View.MemoryView":200
+ * info.suboffsets = NULL
+ * info.itemsize = self.itemsize
+ * info.readonly = 0 # <<<<<<<<<<<<<<
*
- * # pre-gain around center
- * f = f * gain # <<<<<<<<<<<<<<
- * if f > 1.0:
- * f = 1.0
+ * if flags & PyBUF_FORMAT:
*/
- __pyx_t_3 = PyFloat_FromDouble(__pyx_v_gain); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 190, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = PyNumber_Multiply(__pyx_v_f, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 190, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_DECREF_SET(__pyx_v_f, __pyx_t_5);
- __pyx_t_5 = 0;
+ __pyx_v_info->readonly = 0;
- /* "moab.pyx":191
- * # pre-gain around center
- * f = f * gain
- * if f > 1.0: # <<<<<<<<<<<<<<
- * f = 1.0
+ /* "View.MemoryView":202
+ * info.readonly = 0
*
+ * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
+ * info.format = self.format
+ * else:
*/
- __pyx_t_5 = PyObject_RichCompare(__pyx_v_f, __pyx_float_1_0, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 191, __pyx_L1_error)
- __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 191, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- if (__pyx_t_4) {
+ __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
+ if (__pyx_t_1) {
- /* "moab.pyx":192
- * f = f * gain
- * if f > 1.0:
- * f = 1.0 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":203
*
- * _bandpass_lookup[n] = f
+ * if flags & PyBUF_FORMAT:
+ * info.format = self.format # <<<<<<<<<<<<<<
+ * else:
+ * info.format = NULL
*/
- __Pyx_INCREF(__pyx_float_1_0);
- __Pyx_DECREF_SET(__pyx_v_f, __pyx_float_1_0);
+ __pyx_t_4 = __pyx_v_self->format;
+ __pyx_v_info->format = __pyx_t_4;
- /* "moab.pyx":191
- * # pre-gain around center
- * f = f * gain
- * if f > 1.0: # <<<<<<<<<<<<<<
- * f = 1.0
+ /* "View.MemoryView":202
+ * info.readonly = 0
*
+ * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
+ * info.format = self.format
+ * else:
*/
- }
+ goto __pyx_L5;
+ }
- /* "moab.pyx":194
- * f = 1.0
+ /* "View.MemoryView":205
+ * info.format = self.format
+ * else:
+ * info.format = NULL # <<<<<<<<<<<<<<
*
- * _bandpass_lookup[n] = f # <<<<<<<<<<<<<<
+ * info.obj = self
+ */
+ /*else*/ {
+ __pyx_v_info->format = NULL;
+ }
+ __pyx_L5:;
+
+ /* "View.MemoryView":207
+ * info.format = NULL
*
+ * info.obj = self # <<<<<<<<<<<<<<
*
+ * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
*/
- __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_v_f); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 194, __pyx_L1_error)
- __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_v_n); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 194, __pyx_L1_error)
- (__pyx_v_6pymoab__bandpass_lookup[__pyx_t_9]) = __pyx_t_8;
- }
+ __Pyx_INCREF(((PyObject *)__pyx_v_self));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
+ __Pyx_GOTREF(__pyx_v_info->obj);
+ __Pyx_DECREF(__pyx_v_info->obj);
+ __pyx_v_info->obj = ((PyObject *)__pyx_v_self);
- /* "moab.pyx":165
- * @cython.boundscheck(False)
- * @cython.wraparound(False)
- * def _update_bandpass_lookup(unsigned char center, float sigma, float gain): # <<<<<<<<<<<<<<
- * global _bandpass_lookup
- * global _last_center
+ /* "View.MemoryView":185
+ *
+ * @cname('getbuffer')
+ * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<<
+ * cdef int bufmode = -1
+ * if self.mode == u"c":
*/
/* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __pyx_r = 0;
goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_5);
- __Pyx_XDECREF(__pyx_t_6);
- __Pyx_XDECREF(__pyx_t_7);
- __Pyx_AddTraceback("pymoab._update_bandpass_lookup", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
+ __Pyx_AddTraceback("View.MemoryView.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ if (__pyx_v_info->obj != NULL) {
+ __Pyx_GOTREF(__pyx_v_info->obj);
+ __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
+ }
+ goto __pyx_L2;
__pyx_L0:;
- __Pyx_XDECREF(__pyx_v_n);
- __Pyx_XDECREF(__pyx_v_h);
- __Pyx_XDECREF(__pyx_v_f);
- __Pyx_XGIVEREF(__pyx_r);
+ if (__pyx_v_info->obj == Py_None) {
+ __Pyx_GOTREF(__pyx_v_info->obj);
+ __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
+ }
+ __pyx_L2:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "moab.pyx":199
- * @cython.boundscheck(False)
- * @cython.wraparound(False)
- * def hue_mask(unsigned char [:, :, :] image, unsigned char center, float sigma, float gain, float mask_gain): # <<<<<<<<<<<<<<
- * global _bandpass_lookup
+/* "View.MemoryView":211
+ * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
*
+ * def __dealloc__(array self): # <<<<<<<<<<<<<<
+ * if self.callback_free_data != NULL:
+ * self.callback_free_data(self.data)
*/
/* Python wrapper */
-static PyObject *__pyx_pw_6pymoab_41hue_mask(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static PyMethodDef __pyx_mdef_6pymoab_41hue_mask = {"hue_mask", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_6pymoab_41hue_mask, METH_VARARGS|METH_KEYWORDS, 0};
-static PyObject *__pyx_pw_6pymoab_41hue_mask(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- __Pyx_memviewslice __pyx_v_image = { 0, 0, { 0 }, { 0 }, { 0 } };
- unsigned char __pyx_v_center;
- float __pyx_v_sigma;
- float __pyx_v_gain;
- float __pyx_v_mask_gain;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- PyObject *__pyx_r = 0;
+static void __pyx_array___dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_array___dealloc__(PyObject *__pyx_v_self) {
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("hue_mask (wrapper)", 0);
- {
- static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_image,&__pyx_n_s_center,&__pyx_n_s_sigma,&__pyx_n_s_gain,&__pyx_n_s_mask_gain,0};
- PyObject* values[5] = {0,0,0,0,0};
- if (unlikely(__pyx_kwds)) {
- Py_ssize_t kw_args;
- const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
- switch (pos_args) {
- case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
- CYTHON_FALLTHROUGH;
- case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
- CYTHON_FALLTHROUGH;
- case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
- CYTHON_FALLTHROUGH;
- case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- CYTHON_FALLTHROUGH;
- case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- CYTHON_FALLTHROUGH;
- case 0: break;
- default: goto __pyx_L5_argtuple_error;
- }
- kw_args = PyDict_Size(__pyx_kwds);
- switch (pos_args) {
- case 0:
- if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_image)) != 0)) kw_args--;
- else goto __pyx_L5_argtuple_error;
- CYTHON_FALLTHROUGH;
- case 1:
- if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_center)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, 1); __PYX_ERR(0, 199, __pyx_L3_error)
- }
- CYTHON_FALLTHROUGH;
- case 2:
- if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sigma)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, 2); __PYX_ERR(0, 199, __pyx_L3_error)
- }
- CYTHON_FALLTHROUGH;
- case 3:
- if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gain)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, 3); __PYX_ERR(0, 199, __pyx_L3_error)
- }
- CYTHON_FALLTHROUGH;
- case 4:
- if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mask_gain)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, 4); __PYX_ERR(0, 199, __pyx_L3_error)
- }
- }
- if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "hue_mask") < 0)) __PYX_ERR(0, 199, __pyx_L3_error)
- }
- } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
- goto __pyx_L5_argtuple_error;
- } else {
- values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
- values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
- values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
- }
- __pyx_v_image = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_unsigned_char(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_image.memview)) __PYX_ERR(0, 199, __pyx_L3_error)
- __pyx_v_center = __Pyx_PyInt_As_unsigned_char(values[1]); if (unlikely((__pyx_v_center == (unsigned char)-1) && PyErr_Occurred())) __PYX_ERR(0, 199, __pyx_L3_error)
- __pyx_v_sigma = __pyx_PyFloat_AsFloat(values[2]); if (unlikely((__pyx_v_sigma == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 199, __pyx_L3_error)
- __pyx_v_gain = __pyx_PyFloat_AsFloat(values[3]); if (unlikely((__pyx_v_gain == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 199, __pyx_L3_error)
- __pyx_v_mask_gain = __pyx_PyFloat_AsFloat(values[4]); if (unlikely((__pyx_v_mask_gain == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 199, __pyx_L3_error)
- }
- goto __pyx_L4_argument_unpacking_done;
- __pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("hue_mask", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 199, __pyx_L3_error)
- __pyx_L3_error:;
- __Pyx_AddTraceback("pymoab.hue_mask", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __Pyx_RefNannyFinishContext();
- return NULL;
- __pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_pf_6pymoab_40hue_mask(__pyx_self, __pyx_v_image, __pyx_v_center, __pyx_v_sigma, __pyx_v_gain, __pyx_v_mask_gain);
+ __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
+ __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
- return __pyx_r;
}
-static PyObject *__pyx_pf_6pymoab_40hue_mask(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_image, unsigned char __pyx_v_center, float __pyx_v_sigma, float __pyx_v_gain, float __pyx_v_mask_gain) {
- int __pyx_v_x;
- int __pyx_v_y;
- int __pyx_v_width;
- int __pyx_v_height;
- float __pyx_v_h;
- float __pyx_v_s;
- float __pyx_v_v;
- float __pyx_v_f;
- unsigned char __pyx_v_mask;
- unsigned char __pyx_v_ih;
- PyObject *__pyx_r = NULL;
+static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) {
__Pyx_RefNannyDeclarations
int __pyx_t_1;
- int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- PyObject *__pyx_t_4 = NULL;
- PyObject *__pyx_t_5 = NULL;
- PyObject *__pyx_t_6 = NULL;
- PyObject *__pyx_t_7 = NULL;
- PyObject *__pyx_t_8 = NULL;
- int __pyx_t_9;
- PyObject *__pyx_t_10 = NULL;
- int __pyx_t_11;
- int __pyx_t_12;
- int __pyx_t_13;
- int __pyx_t_14;
- int __pyx_t_15;
- Py_ssize_t __pyx_t_16;
- Py_ssize_t __pyx_t_17;
- Py_ssize_t __pyx_t_18;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("hue_mask", 0);
+ __Pyx_RefNannySetupContext("__dealloc__", 0);
- /* "moab.pyx":208
- *
- * # grab the image dimensions
- * height = image.shape[0] # <<<<<<<<<<<<<<
- * width = image.shape[1]
+ /* "View.MemoryView":212
*
+ * def __dealloc__(array self):
+ * if self.callback_free_data != NULL: # <<<<<<<<<<<<<<
+ * self.callback_free_data(self.data)
+ * elif self.free_data:
*/
- __pyx_v_height = (__pyx_v_image.shape[0]);
+ __pyx_t_1 = ((__pyx_v_self->callback_free_data != NULL) != 0);
+ if (__pyx_t_1) {
- /* "moab.pyx":209
- * # grab the image dimensions
- * height = image.shape[0]
- * width = image.shape[1] # <<<<<<<<<<<<<<
- *
- * # generate a lookup table for center, sigma & gain
+ /* "View.MemoryView":213
+ * def __dealloc__(array self):
+ * if self.callback_free_data != NULL:
+ * self.callback_free_data(self.data) # <<<<<<<<<<<<<<
+ * elif self.free_data:
+ * if self.dtype_is_object:
*/
- __pyx_v_width = (__pyx_v_image.shape[1]);
+ __pyx_v_self->callback_free_data(__pyx_v_self->data);
- /* "moab.pyx":212
- *
- * # generate a lookup table for center, sigma & gain
- * if (center != _last_center or sigma != _last_sigma or gain != _last_gain): # <<<<<<<<<<<<<<
- * _update_bandpass_lookup(center, sigma, gain)
+ /* "View.MemoryView":212
*
+ * def __dealloc__(array self):
+ * if self.callback_free_data != NULL: # <<<<<<<<<<<<<<
+ * self.callback_free_data(self.data)
+ * elif self.free_data:
*/
- __pyx_t_2 = ((__pyx_v_center != __pyx_v_6pymoab__last_center) != 0);
- if (!__pyx_t_2) {
- } else {
- __pyx_t_1 = __pyx_t_2;
- goto __pyx_L4_bool_binop_done;
- }
- __pyx_t_2 = ((__pyx_v_sigma != __pyx_v_6pymoab__last_sigma) != 0);
- if (!__pyx_t_2) {
- } else {
- __pyx_t_1 = __pyx_t_2;
- goto __pyx_L4_bool_binop_done;
+ goto __pyx_L3;
}
- __pyx_t_2 = ((__pyx_v_gain != __pyx_v_6pymoab__last_gain) != 0);
- __pyx_t_1 = __pyx_t_2;
- __pyx_L4_bool_binop_done:;
+
+ /* "View.MemoryView":214
+ * if self.callback_free_data != NULL:
+ * self.callback_free_data(self.data)
+ * elif self.free_data: # <<<<<<<<<<<<<<
+ * if self.dtype_is_object:
+ * refcount_objects_in_slice(self.data, self._shape,
+ */
+ __pyx_t_1 = (__pyx_v_self->free_data != 0);
if (__pyx_t_1) {
- /* "moab.pyx":213
- * # generate a lookup table for center, sigma & gain
- * if (center != _last_center or sigma != _last_sigma or gain != _last_gain):
- * _update_bandpass_lookup(center, sigma, gain) # <<<<<<<<<<<<<<
- *
- * for y in range(0, height):
+ /* "View.MemoryView":215
+ * self.callback_free_data(self.data)
+ * elif self.free_data:
+ * if self.dtype_is_object: # <<<<<<<<<<<<<<
+ * refcount_objects_in_slice(self.data, self._shape,
+ * self._strides, self.ndim, False)
+ */
+ __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0);
+ if (__pyx_t_1) {
+
+ /* "View.MemoryView":216
+ * elif self.free_data:
+ * if self.dtype_is_object:
+ * refcount_objects_in_slice(self.data, self._shape, # <<<<<<<<<<<<<<
+ * self._strides, self.ndim, False)
+ * free(self.data)
+ */
+ __pyx_memoryview_refcount_objects_in_slice(__pyx_v_self->data, __pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_self->ndim, 0);
+
+ /* "View.MemoryView":215
+ * self.callback_free_data(self.data)
+ * elif self.free_data:
+ * if self.dtype_is_object: # <<<<<<<<<<<<<<
+ * refcount_objects_in_slice(self.data, self._shape,
+ * self._strides, self.ndim, False)
*/
- __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_update_bandpass_lookup); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 213, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = __Pyx_PyInt_From_unsigned_char(__pyx_v_center); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 213, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_6 = PyFloat_FromDouble(__pyx_v_sigma); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 213, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __pyx_t_7 = PyFloat_FromDouble(__pyx_v_gain); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 213, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_7);
- __pyx_t_8 = NULL;
- __pyx_t_9 = 0;
- if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
- __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4);
- if (likely(__pyx_t_8)) {
- PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
- __Pyx_INCREF(__pyx_t_8);
- __Pyx_INCREF(function);
- __Pyx_DECREF_SET(__pyx_t_4, function);
- __pyx_t_9 = 1;
- }
- }
- #if CYTHON_FAST_PYCALL
- if (PyFunction_Check(__pyx_t_4)) {
- PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_t_5, __pyx_t_6, __pyx_t_7};
- __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
- __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
- } else
- #endif
- #if CYTHON_FAST_PYCCALL
- if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
- PyObject *__pyx_temp[4] = {__pyx_t_8, __pyx_t_5, __pyx_t_6, __pyx_t_7};
- __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
- __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
- } else
- #endif
- {
- __pyx_t_10 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 213, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_10);
- if (__pyx_t_8) {
- __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
- }
- __Pyx_GIVEREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_6);
- PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_t_6);
- __Pyx_GIVEREF(__pyx_t_7);
- PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_t_7);
- __pyx_t_5 = 0;
- __pyx_t_6 = 0;
- __pyx_t_7 = 0;
- __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
}
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "moab.pyx":212
- *
- * # generate a lookup table for center, sigma & gain
- * if (center != _last_center or sigma != _last_sigma or gain != _last_gain): # <<<<<<<<<<<<<<
- * _update_bandpass_lookup(center, sigma, gain)
+ /* "View.MemoryView":218
+ * refcount_objects_in_slice(self.data, self._shape,
+ * self._strides, self.ndim, False)
+ * free(self.data) # <<<<<<<<<<<<<<
+ * PyObject_Free(self._shape)
*
+ */
+ free(__pyx_v_self->data);
+
+ /* "View.MemoryView":214
+ * if self.callback_free_data != NULL:
+ * self.callback_free_data(self.data)
+ * elif self.free_data: # <<<<<<<<<<<<<<
+ * if self.dtype_is_object:
+ * refcount_objects_in_slice(self.data, self._shape,
*/
}
+ __pyx_L3:;
- /* "moab.pyx":215
- * _update_bandpass_lookup(center, sigma, gain)
+ /* "View.MemoryView":219
+ * self._strides, self.ndim, False)
+ * free(self.data)
+ * PyObject_Free(self._shape) # <<<<<<<<<<<<<<
*
- * for y in range(0, height): # <<<<<<<<<<<<<<
- * for x in range(0, width):
- * # pull each component out as a float [0..1]
+ * @property
*/
- __pyx_t_9 = __pyx_v_height;
- __pyx_t_11 = __pyx_t_9;
- for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
- __pyx_v_y = __pyx_t_12;
+ PyObject_Free(__pyx_v_self->_shape);
- /* "moab.pyx":216
+ /* "View.MemoryView":211
+ * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
*
- * for y in range(0, height):
- * for x in range(0, width): # <<<<<<<<<<<<<<
- * # pull each component out as a float [0..1]
- * ih = image[y, x, 0]
+ * def __dealloc__(array self): # <<<<<<<<<<<<<<
+ * if self.callback_free_data != NULL:
+ * self.callback_free_data(self.data)
*/
- __pyx_t_13 = __pyx_v_width;
- __pyx_t_14 = __pyx_t_13;
- for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
- __pyx_v_x = __pyx_t_15;
- /* "moab.pyx":218
- * for x in range(0, width):
- * # pull each component out as a float [0..1]
- * ih = image[y, x, 0] # <<<<<<<<<<<<<<
- * s = image[y, x, 1] / 255.0
- * v = image[y, x, 2] / 255.0
- */
- __pyx_t_16 = __pyx_v_y;
- __pyx_t_17 = __pyx_v_x;
- __pyx_t_18 = 0;
- __pyx_v_ih = (*((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_16 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_18 * __pyx_v_image.strides[2]) )));
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+}
- /* "moab.pyx":219
- * # pull each component out as a float [0..1]
- * ih = image[y, x, 0]
- * s = image[y, x, 1] / 255.0 # <<<<<<<<<<<<<<
- * v = image[y, x, 2] / 255.0
+/* "View.MemoryView":222
*
- */
- __pyx_t_18 = __pyx_v_y;
- __pyx_t_17 = __pyx_v_x;
- __pyx_t_16 = 1;
- __pyx_v_s = (((double)(*((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_18 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_16 * __pyx_v_image.strides[2]) )))) / 255.0);
-
- /* "moab.pyx":220
- * ih = image[y, x, 0]
- * s = image[y, x, 1] / 255.0
- * v = image[y, x, 2] / 255.0 # <<<<<<<<<<<<<<
+ * @property
+ * def memview(self): # <<<<<<<<<<<<<<
+ * return self.get_memview()
*
- * # map from [0..255] -> [0..1] through lookup table
*/
- __pyx_t_16 = __pyx_v_y;
- __pyx_t_17 = __pyx_v_x;
- __pyx_t_18 = 2;
- __pyx_v_v = (((double)(*((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_16 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_18 * __pyx_v_image.strides[2]) )))) / 255.0);
- /* "moab.pyx":224
- * # map from [0..255] -> [0..1] through lookup table
- * # this applies the bandpass filter on hue
- * h = _bandpass_lookup[ih] # <<<<<<<<<<<<<<
- *
- * # mask the hue with sat, val and apply another gain filter
- */
- __pyx_v_h = (__pyx_v_6pymoab__bandpass_lookup[__pyx_v_ih]);
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self));
- /* "moab.pyx":227
- *
- * # mask the hue with sat, val and apply another gain filter
- * f = (h * s * v) * mask_gain # <<<<<<<<<<<<<<
- * if f > 1.0:
- * f = 1.0
- */
- __pyx_v_f = (((__pyx_v_h * __pyx_v_s) * __pyx_v_v) * __pyx_v_mask_gain);
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "moab.pyx":228
- * # mask the hue with sat, val and apply another gain filter
- * f = (h * s * v) * mask_gain
- * if f > 1.0: # <<<<<<<<<<<<<<
- * f = 1.0
- *
- */
- __pyx_t_1 = ((__pyx_v_f > 1.0) != 0);
- if (__pyx_t_1) {
+static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__get__", 0);
- /* "moab.pyx":229
- * f = (h * s * v) * mask_gain
- * if f > 1.0:
- * f = 1.0 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":223
+ * @property
+ * def memview(self):
+ * return self.get_memview() # <<<<<<<<<<<<<<
*
- * # covert back to char space
+ * @cname('get_memview')
*/
- __pyx_v_f = 1.0;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = ((struct __pyx_vtabstruct_array *)__pyx_v_self->__pyx_vtab)->get_memview(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 223, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
- /* "moab.pyx":228
- * # mask the hue with sat, val and apply another gain filter
- * f = (h * s * v) * mask_gain
- * if f > 1.0: # <<<<<<<<<<<<<<
- * f = 1.0
+ /* "View.MemoryView":222
*
- */
- }
-
- /* "moab.pyx":232
+ * @property
+ * def memview(self): # <<<<<<<<<<<<<<
+ * return self.get_memview()
*
- * # covert back to char space
- * mask = (f * 255) # <<<<<<<<<<<<<<
- * image[y, x, 0] = mask
- * image[y, x, 1] = mask
*/
- __pyx_v_mask = ((unsigned char)(__pyx_v_f * 255.0));
- /* "moab.pyx":233
- * # covert back to char space
- * mask = (f * 255)
- * image[y, x, 0] = mask # <<<<<<<<<<<<<<
- * image[y, x, 1] = mask
- * image[y, x, 2] = mask
- */
- __pyx_t_18 = __pyx_v_y;
- __pyx_t_17 = __pyx_v_x;
- __pyx_t_16 = 0;
- *((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_18 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_16 * __pyx_v_image.strides[2]) )) = __pyx_v_mask;
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "moab.pyx":234
- * mask = (f * 255)
- * image[y, x, 0] = mask
- * image[y, x, 1] = mask # <<<<<<<<<<<<<<
- * image[y, x, 2] = mask
+/* "View.MemoryView":226
*
+ * @cname('get_memview')
+ * cdef get_memview(self): # <<<<<<<<<<<<<<
+ * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
+ * return memoryview(self, flags, self.dtype_is_object)
*/
- __pyx_t_16 = __pyx_v_y;
- __pyx_t_17 = __pyx_v_x;
- __pyx_t_18 = 1;
- *((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_16 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_18 * __pyx_v_image.strides[2]) )) = __pyx_v_mask;
- /* "moab.pyx":235
- * image[y, x, 0] = mask
- * image[y, x, 1] = mask
- * image[y, x, 2] = mask # <<<<<<<<<<<<<<
+static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self) {
+ int __pyx_v_flags;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("get_memview", 0);
+
+ /* "View.MemoryView":227
+ * @cname('get_memview')
+ * cdef get_memview(self):
+ * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE # <<<<<<<<<<<<<<
+ * return memoryview(self, flags, self.dtype_is_object)
*
- * # return the thresholded image
*/
- __pyx_t_18 = __pyx_v_y;
- __pyx_t_17 = __pyx_v_x;
- __pyx_t_16 = 2;
- *((unsigned char *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_image.data + __pyx_t_18 * __pyx_v_image.strides[0]) ) + __pyx_t_17 * __pyx_v_image.strides[1]) ) + __pyx_t_16 * __pyx_v_image.strides[2]) )) = __pyx_v_mask;
- }
- }
+ __pyx_v_flags = ((PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) | PyBUF_WRITABLE);
- /* "moab.pyx":238
+ /* "View.MemoryView":228
+ * cdef get_memview(self):
+ * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
+ * return memoryview(self, flags, self.dtype_is_object) # <<<<<<<<<<<<<<
*
- * # return the thresholded image
- * return image # <<<<<<<<<<<<<<
+ * def __len__(self):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_image, 3, (PyObject *(*)(char *)) __pyx_memview_get_unsigned_char, (int (*)(char *, PyObject *)) __pyx_memview_set_unsigned_char, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 238, __pyx_L1_error)
+ __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 228, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 228, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 228, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
- __pyx_r = __pyx_t_3;
- __pyx_t_3 = 0;
+ __Pyx_INCREF(((PyObject *)__pyx_v_self));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
+ PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self));
+ __Pyx_GIVEREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
+ __pyx_t_1 = 0;
+ __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 228, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
- /* "moab.pyx":199
- * @cython.boundscheck(False)
- * @cython.wraparound(False)
- * def hue_mask(unsigned char [:, :, :] image, unsigned char center, float sigma, float gain, float mask_gain): # <<<<<<<<<<<<<<
- * global _bandpass_lookup
+ /* "View.MemoryView":226
*
+ * @cname('get_memview')
+ * cdef get_memview(self): # <<<<<<<<<<<<<<
+ * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
+ * return memoryview(self, flags, self.dtype_is_object)
*/
/* function exit code */
__pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_4);
- __Pyx_XDECREF(__pyx_t_5);
- __Pyx_XDECREF(__pyx_t_6);
- __Pyx_XDECREF(__pyx_t_7);
- __Pyx_XDECREF(__pyx_t_8);
- __Pyx_XDECREF(__pyx_t_10);
- __Pyx_AddTraceback("pymoab.hue_mask", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
+ __Pyx_AddTraceback("View.MemoryView.array.get_memview", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
__pyx_L0:;
- __PYX_XDEC_MEMVIEW(&__pyx_v_image, 1);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":122
- * cdef bint dtype_is_object
+/* "View.MemoryView":230
+ * return memoryview(self, flags, self.dtype_is_object)
*
- * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<<
- * mode="c", bint allocate_buffer=True):
+ * def __len__(self): # <<<<<<<<<<<<<<
+ * return self._shape[0]
*
*/
/* Python wrapper */
-static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static int __pyx_array___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- PyObject *__pyx_v_shape = 0;
- Py_ssize_t __pyx_v_itemsize;
- PyObject *__pyx_v_format = 0;
- PyObject *__pyx_v_mode = 0;
- int __pyx_v_allocate_buffer;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- int __pyx_r;
+static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self); /*proto*/
+static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self) {
+ Py_ssize_t __pyx_r;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
- {
- static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_shape,&__pyx_n_s_itemsize,&__pyx_n_s_format,&__pyx_n_s_mode,&__pyx_n_s_allocate_buffer,0};
- PyObject* values[5] = {0,0,0,0,0};
- values[3] = ((PyObject *)__pyx_n_s_c);
- if (unlikely(__pyx_kwds)) {
- Py_ssize_t kw_args;
- const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
- switch (pos_args) {
- case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
- CYTHON_FALLTHROUGH;
- case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
- CYTHON_FALLTHROUGH;
- case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
- CYTHON_FALLTHROUGH;
- case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- CYTHON_FALLTHROUGH;
- case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- CYTHON_FALLTHROUGH;
- case 0: break;
- default: goto __pyx_L5_argtuple_error;
- }
- kw_args = PyDict_Size(__pyx_kwds);
- switch (pos_args) {
- case 0:
- if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_shape)) != 0)) kw_args--;
- else goto __pyx_L5_argtuple_error;
- CYTHON_FALLTHROUGH;
- case 1:
- if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_itemsize)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 1); __PYX_ERR(1, 122, __pyx_L3_error)
- }
- CYTHON_FALLTHROUGH;
- case 2:
- if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_format)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, 2); __PYX_ERR(1, 122, __pyx_L3_error)
- }
- CYTHON_FALLTHROUGH;
- case 3:
- if (kw_args > 0) {
- PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mode);
- if (value) { values[3] = value; kw_args--; }
- }
- CYTHON_FALLTHROUGH;
- case 4:
- if (kw_args > 0) {
- PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_allocate_buffer);
- if (value) { values[4] = value; kw_args--; }
- }
- }
- if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 122, __pyx_L3_error)
- }
- } else {
- switch (PyTuple_GET_SIZE(__pyx_args)) {
- case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
- CYTHON_FALLTHROUGH;
- case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
- CYTHON_FALLTHROUGH;
- case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
- values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- break;
- default: goto __pyx_L5_argtuple_error;
- }
- }
- __pyx_v_shape = ((PyObject*)values[0]);
- __pyx_v_itemsize = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_itemsize == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 122, __pyx_L3_error)
- __pyx_v_format = values[2];
- __pyx_v_mode = values[3];
- if (values[4]) {
- __pyx_v_allocate_buffer = __Pyx_PyObject_IsTrue(values[4]); if (unlikely((__pyx_v_allocate_buffer == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 123, __pyx_L3_error)
- } else {
+ __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
+ __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(((struct __pyx_array_obj *)__pyx_v_self));
- /* "View.MemoryView":123
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self) {
+ Py_ssize_t __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__len__", 0);
+
+ /* "View.MemoryView":231
*
- * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None,
- * mode="c", bint allocate_buffer=True): # <<<<<<<<<<<<<<
+ * def __len__(self):
+ * return self._shape[0] # <<<<<<<<<<<<<<
*
- * cdef int idx
+ * def __getattr__(self, attr):
*/
- __pyx_v_allocate_buffer = ((int)1);
- }
- }
- goto __pyx_L4_argument_unpacking_done;
- __pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 122, __pyx_L3_error)
- __pyx_L3_error:;
- __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __Pyx_RefNannyFinishContext();
- return -1;
- __pyx_L4_argument_unpacking_done:;
- if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_shape), (&PyTuple_Type), 1, "shape", 1))) __PYX_ERR(1, 122, __pyx_L1_error)
- if (unlikely(((PyObject *)__pyx_v_format) == Py_None)) {
- PyErr_Format(PyExc_TypeError, "Argument '%.200s' must not be None", "format"); __PYX_ERR(1, 122, __pyx_L1_error)
- }
- __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(((struct __pyx_array_obj *)__pyx_v_self), __pyx_v_shape, __pyx_v_itemsize, __pyx_v_format, __pyx_v_mode, __pyx_v_allocate_buffer);
+ __pyx_r = (__pyx_v_self->_shape[0]);
+ goto __pyx_L0;
- /* "View.MemoryView":122
- * cdef bint dtype_is_object
+ /* "View.MemoryView":230
+ * return memoryview(self, flags, self.dtype_is_object)
*
- * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<<
- * mode="c", bint allocate_buffer=True):
+ * def __len__(self): # <<<<<<<<<<<<<<
+ * return self._shape[0]
*
*/
/* function exit code */
- goto __pyx_L0;
- __pyx_L1_error:;
- __pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer) {
- int __pyx_v_idx;
- Py_ssize_t __pyx_v_i;
- Py_ssize_t __pyx_v_dim;
- PyObject **__pyx_v_p;
- char __pyx_v_order;
- int __pyx_r;
+/* "View.MemoryView":233
+ * return self._shape[0]
+ *
+ * def __getattr__(self, attr): # <<<<<<<<<<<<<<
+ * return getattr(self.memview, attr)
+ *
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr); /*proto*/
+static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr) {
+ PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- Py_ssize_t __pyx_t_1;
- int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- int __pyx_t_4;
- PyObject *__pyx_t_5 = NULL;
- PyObject *__pyx_t_6 = NULL;
- char *__pyx_t_7;
- int __pyx_t_8;
- Py_ssize_t __pyx_t_9;
- PyObject *__pyx_t_10 = NULL;
- Py_ssize_t __pyx_t_11;
+ __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0);
+ __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__cinit__", 0);
- __Pyx_INCREF(__pyx_v_format);
+ __Pyx_RefNannySetupContext("__getattr__", 0);
- /* "View.MemoryView":129
- * cdef PyObject **p
+ /* "View.MemoryView":234
*
- * self.ndim = len(shape) # <<<<<<<<<<<<<<
- * self.itemsize = itemsize
+ * def __getattr__(self, attr):
+ * return getattr(self.memview, attr) # <<<<<<<<<<<<<<
*
+ * def __getitem__(self, item):
*/
- if (unlikely(__pyx_v_shape == Py_None)) {
- PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
- __PYX_ERR(1, 129, __pyx_L1_error)
- }
- __pyx_t_1 = PyTuple_GET_SIZE(__pyx_v_shape); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(1, 129, __pyx_L1_error)
- __pyx_v_self->ndim = ((int)__pyx_t_1);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 234, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = __Pyx_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 234, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":130
+ /* "View.MemoryView":233
+ * return self._shape[0]
*
- * self.ndim = len(shape)
- * self.itemsize = itemsize # <<<<<<<<<<<<<<
+ * def __getattr__(self, attr): # <<<<<<<<<<<<<<
+ * return getattr(self.memview, attr)
*
- * if not self.ndim:
*/
- __pyx_v_self->itemsize = __pyx_v_itemsize;
- /* "View.MemoryView":132
- * self.itemsize = itemsize
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("View.MemoryView.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":236
+ * return getattr(self.memview, attr)
*
- * if not self.ndim: # <<<<<<<<<<<<<<
- * raise ValueError("Empty shape tuple for cython.array")
+ * def __getitem__(self, item): # <<<<<<<<<<<<<<
+ * return self.memview[item]
*
*/
- __pyx_t_2 = ((!(__pyx_v_self->ndim != 0)) != 0);
- if (unlikely(__pyx_t_2)) {
- /* "View.MemoryView":133
+/* Python wrapper */
+static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/
+static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
+ __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__getitem__", 0);
+
+ /* "View.MemoryView":237
*
- * if not self.ndim:
- * raise ValueError("Empty shape tuple for cython.array") # <<<<<<<<<<<<<<
+ * def __getitem__(self, item):
+ * return self.memview[item] # <<<<<<<<<<<<<<
*
- * if itemsize <= 0:
+ * def __setitem__(self, item, value):
*/
- __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 133, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_Raise(__pyx_t_3, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __PYX_ERR(1, 133, __pyx_L1_error)
-
- /* "View.MemoryView":132
- * self.itemsize = itemsize
- *
- * if not self.ndim: # <<<<<<<<<<<<<<
- * raise ValueError("Empty shape tuple for cython.array")
- *
- */
- }
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 237, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 237, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":135
- * raise ValueError("Empty shape tuple for cython.array")
+ /* "View.MemoryView":236
+ * return getattr(self.memview, attr)
*
- * if itemsize <= 0: # <<<<<<<<<<<<<<
- * raise ValueError("itemsize <= 0 for cython.array")
+ * def __getitem__(self, item): # <<<<<<<<<<<<<<
+ * return self.memview[item]
*
*/
- __pyx_t_2 = ((__pyx_v_itemsize <= 0) != 0);
- if (unlikely(__pyx_t_2)) {
- /* "View.MemoryView":136
- *
- * if itemsize <= 0:
- * raise ValueError("itemsize <= 0 for cython.array") # <<<<<<<<<<<<<<
- *
- * if not isinstance(format, bytes):
- */
- __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 136, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_Raise(__pyx_t_3, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __PYX_ERR(1, 136, __pyx_L1_error)
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("View.MemoryView.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":135
- * raise ValueError("Empty shape tuple for cython.array")
+/* "View.MemoryView":239
+ * return self.memview[item]
*
- * if itemsize <= 0: # <<<<<<<<<<<<<<
- * raise ValueError("itemsize <= 0 for cython.array")
+ * def __setitem__(self, item, value): # <<<<<<<<<<<<<<
+ * self.memview[item] = value
*
*/
- }
- /* "View.MemoryView":138
- * raise ValueError("itemsize <= 0 for cython.array")
- *
- * if not isinstance(format, bytes): # <<<<<<<<<<<<<<
- * format = format.encode('ASCII')
- * self._format = format # keep a reference to the byte string
- */
- __pyx_t_2 = PyBytes_Check(__pyx_v_format);
- __pyx_t_4 = ((!(__pyx_t_2 != 0)) != 0);
- if (__pyx_t_4) {
+/* Python wrapper */
+static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /*proto*/
+static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
+ __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value));
- /* "View.MemoryView":139
- *
- * if not isinstance(format, bytes):
- * format = format.encode('ASCII') # <<<<<<<<<<<<<<
- * self._format = format # keep a reference to the byte string
- * self.format = self._format
- */
- __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_format, __pyx_n_s_encode); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 139, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_6 = NULL;
- if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
- __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
- if (likely(__pyx_t_6)) {
- PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
- __Pyx_INCREF(__pyx_t_6);
- __Pyx_INCREF(function);
- __Pyx_DECREF_SET(__pyx_t_5, function);
- }
- }
- __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_n_s_ASCII) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_n_s_ASCII);
- __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
- if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 139, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF_SET(__pyx_v_format, __pyx_t_3);
- __pyx_t_3 = 0;
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":138
- * raise ValueError("itemsize <= 0 for cython.array")
- *
- * if not isinstance(format, bytes): # <<<<<<<<<<<<<<
- * format = format.encode('ASCII')
- * self._format = format # keep a reference to the byte string
- */
- }
+static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__setitem__", 0);
- /* "View.MemoryView":140
- * if not isinstance(format, bytes):
- * format = format.encode('ASCII')
- * self._format = format # keep a reference to the byte string # <<<<<<<<<<<<<<
- * self.format = self._format
+ /* "View.MemoryView":240
*
- */
- if (!(likely(PyBytes_CheckExact(__pyx_v_format))||((__pyx_v_format) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_v_format)->tp_name), 0))) __PYX_ERR(1, 140, __pyx_L1_error)
- __pyx_t_3 = __pyx_v_format;
- __Pyx_INCREF(__pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_3);
- __Pyx_GOTREF(__pyx_v_self->_format);
- __Pyx_DECREF(__pyx_v_self->_format);
- __pyx_v_self->_format = ((PyObject*)__pyx_t_3);
- __pyx_t_3 = 0;
-
- /* "View.MemoryView":141
- * format = format.encode('ASCII')
- * self._format = format # keep a reference to the byte string
- * self.format = self._format # <<<<<<<<<<<<<<
+ * def __setitem__(self, item, value):
+ * self.memview[item] = value # <<<<<<<<<<<<<<
*
*
*/
- if (unlikely(__pyx_v_self->_format == Py_None)) {
- PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
- __PYX_ERR(1, 141, __pyx_L1_error)
- }
- __pyx_t_7 = __Pyx_PyBytes_AsWritableString(__pyx_v_self->_format); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) __PYX_ERR(1, 141, __pyx_L1_error)
- __pyx_v_self->format = __pyx_t_7;
+ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 240, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0)) __PYX_ERR(1, 240, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "View.MemoryView":144
- *
+ /* "View.MemoryView":239
+ * return self.memview[item]
*
- * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2) # <<<<<<<<<<<<<<
- * self._strides = self._shape + self.ndim
+ * def __setitem__(self, item, value): # <<<<<<<<<<<<<<
+ * self.memview[item] = value
*
*/
- __pyx_v_self->_shape = ((Py_ssize_t *)PyObject_Malloc((((sizeof(Py_ssize_t)) * __pyx_v_self->ndim) * 2)));
- /* "View.MemoryView":145
- *
- * self._shape = PyObject_Malloc(sizeof(Py_ssize_t)*self.ndim*2)
- * self._strides = self._shape + self.ndim # <<<<<<<<<<<<<<
- *
- * if not self._shape:
- */
- __pyx_v_self->_strides = (__pyx_v_self->_shape + __pyx_v_self->ndim);
+ /* function exit code */
+ __pyx_r = 0;
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("View.MemoryView.array.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":147
- * self._strides = self._shape + self.ndim
- *
- * if not self._shape: # <<<<<<<<<<<<<<
- * raise MemoryError("unable to allocate shape and strides.")
- *
+/* "(tree fragment)":1
+ * def __reduce_cython__(self): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
*/
- __pyx_t_4 = ((!(__pyx_v_self->_shape != 0)) != 0);
- if (unlikely(__pyx_t_4)) {
- /* "View.MemoryView":148
- *
- * if not self._shape:
- * raise MemoryError("unable to allocate shape and strides.") # <<<<<<<<<<<<<<
- *
- *
- */
- __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 148, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_Raise(__pyx_t_3, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __PYX_ERR(1, 148, __pyx_L1_error)
+/* Python wrapper */
+static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+ __pyx_r = __pyx_pf___pyx_array___reduce_cython__(((struct __pyx_array_obj *)__pyx_v_self));
- /* "View.MemoryView":147
- * self._strides = self._shape + self.ndim
- *
- * if not self._shape: # <<<<<<<<<<<<<<
- * raise MemoryError("unable to allocate shape and strides.")
- *
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+
+ /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
*/
- }
+ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __PYX_ERR(1, 2, __pyx_L1_error)
- /* "View.MemoryView":151
- *
- *
- * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<<
- * if dim <= 0:
- * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
+ /* "(tree fragment)":1
+ * def __reduce_cython__(self): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
*/
- __pyx_t_8 = 0;
- __pyx_t_3 = __pyx_v_shape; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
- for (;;) {
- if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
- #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
- __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(1, 151, __pyx_L1_error)
- #else
- __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 151, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- #endif
- __pyx_t_9 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_9 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 151, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_v_dim = __pyx_t_9;
- __pyx_v_idx = __pyx_t_8;
- __pyx_t_8 = (__pyx_t_8 + 1);
- /* "View.MemoryView":152
- *
- * for idx, dim in enumerate(shape):
- * if dim <= 0: # <<<<<<<<<<<<<<
- * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
- * self._shape[idx] = dim
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("View.MemoryView.array.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
*/
- __pyx_t_4 = ((__pyx_v_dim <= 0) != 0);
- if (unlikely(__pyx_t_4)) {
- /* "View.MemoryView":153
- * for idx, dim in enumerate(shape):
- * if dim <= 0:
- * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim)) # <<<<<<<<<<<<<<
- * self._shape[idx] = dim
- *
+/* Python wrapper */
+static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+ __pyx_r = __pyx_pf___pyx_array_2__setstate_cython__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+ /* "(tree fragment)":4
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
*/
- __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 153, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 153, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 153, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_10);
- __Pyx_GIVEREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_6);
- PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_6);
- __pyx_t_5 = 0;
- __pyx_t_6 = 0;
- __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_shape_in_axis_d_d, __pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 153, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
- __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 153, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_10);
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __Pyx_Raise(__pyx_t_10, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
- __PYX_ERR(1, 153, __pyx_L1_error)
+ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __PYX_ERR(1, 4, __pyx_L1_error)
- /* "View.MemoryView":152
- *
- * for idx, dim in enumerate(shape):
- * if dim <= 0: # <<<<<<<<<<<<<<
- * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
- * self._shape[idx] = dim
+ /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
*/
- }
- /* "View.MemoryView":154
- * if dim <= 0:
- * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
- * self._shape[idx] = dim # <<<<<<<<<<<<<<
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("View.MemoryView.array.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":244
*
- * cdef char order
+ * @cname("__pyx_array_new")
+ * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<<
+ * char *mode, char *buf):
+ * cdef array result
*/
- (__pyx_v_self->_shape[__pyx_v_idx]) = __pyx_v_dim;
- /* "View.MemoryView":151
- *
+static struct __pyx_array_obj *__pyx_array_new(PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, char *__pyx_v_format, char *__pyx_v_mode, char *__pyx_v_buf) {
+ struct __pyx_array_obj *__pyx_v_result = 0;
+ struct __pyx_array_obj *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("array_cwrapper", 0);
+
+ /* "View.MemoryView":248
+ * cdef array result
*
- * for idx, dim in enumerate(shape): # <<<<<<<<<<<<<<
- * if dim <= 0:
- * raise ValueError("Invalid shape in axis %d: %d." % (idx, dim))
+ * if buf == NULL: # <<<<<<<<<<<<<<
+ * result = array(shape, itemsize, format, mode.decode('ASCII'))
+ * else:
*/
- }
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_1 = ((__pyx_v_buf == NULL) != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":157
+ /* "View.MemoryView":249
*
- * cdef char order
- * if mode == 'fortran': # <<<<<<<<<<<<<<
- * order = b'F'
- * self.mode = u'fortran'
+ * if buf == NULL:
+ * result = array(shape, itemsize, format, mode.decode('ASCII')) # <<<<<<<<<<<<<<
+ * else:
+ * result = array(shape, itemsize, format, mode.decode('ASCII'),
*/
- __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_fortran, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 157, __pyx_L1_error)
- if (__pyx_t_4) {
+ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 249, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 249, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_4 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 249, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 249, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_INCREF(__pyx_v_shape);
+ __Pyx_GIVEREF(__pyx_v_shape);
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape);
+ __Pyx_GIVEREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_4);
+ PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4);
+ __pyx_t_2 = 0;
+ __pyx_t_3 = 0;
+ __pyx_t_4 = 0;
+ __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 249, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "View.MemoryView":158
- * cdef char order
- * if mode == 'fortran':
- * order = b'F' # <<<<<<<<<<<<<<
- * self.mode = u'fortran'
- * elif mode == 'c':
+ /* "View.MemoryView":248
+ * cdef array result
+ *
+ * if buf == NULL: # <<<<<<<<<<<<<<
+ * result = array(shape, itemsize, format, mode.decode('ASCII'))
+ * else:
*/
- __pyx_v_order = 'F';
+ goto __pyx_L3;
+ }
- /* "View.MemoryView":159
- * if mode == 'fortran':
- * order = b'F'
- * self.mode = u'fortran' # <<<<<<<<<<<<<<
- * elif mode == 'c':
- * order = b'C'
+ /* "View.MemoryView":251
+ * result = array(shape, itemsize, format, mode.decode('ASCII'))
+ * else:
+ * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<<
+ * allocate_buffer=False)
+ * result.data = buf
*/
- __Pyx_INCREF(__pyx_n_u_fortran);
- __Pyx_GIVEREF(__pyx_n_u_fortran);
- __Pyx_GOTREF(__pyx_v_self->mode);
- __Pyx_DECREF(__pyx_v_self->mode);
- __pyx_v_self->mode = __pyx_n_u_fortran;
+ /*else*/ {
+ __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 251, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 251, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 251, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 251, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_INCREF(__pyx_v_shape);
+ __Pyx_GIVEREF(__pyx_v_shape);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape);
+ __Pyx_GIVEREF(__pyx_t_4);
+ PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
+ __Pyx_GIVEREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5);
+ __Pyx_GIVEREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3);
+ __pyx_t_4 = 0;
+ __pyx_t_5 = 0;
+ __pyx_t_3 = 0;
- /* "View.MemoryView":157
+ /* "View.MemoryView":252
+ * else:
+ * result = array(shape, itemsize, format, mode.decode('ASCII'),
+ * allocate_buffer=False) # <<<<<<<<<<<<<<
+ * result.data = buf
*
- * cdef char order
- * if mode == 'fortran': # <<<<<<<<<<<<<<
- * order = b'F'
- * self.mode = u'fortran'
*/
- goto __pyx_L10;
- }
-
- /* "View.MemoryView":160
- * order = b'F'
- * self.mode = u'fortran'
- * elif mode == 'c': # <<<<<<<<<<<<<<
- * order = b'C'
- * self.mode = u'c'
- */
- __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 160, __pyx_L1_error)
- if (likely(__pyx_t_4)) {
-
- /* "View.MemoryView":161
- * self.mode = u'fortran'
- * elif mode == 'c':
- * order = b'C' # <<<<<<<<<<<<<<
- * self.mode = u'c'
- * else:
- */
- __pyx_v_order = 'C';
-
- /* "View.MemoryView":162
- * elif mode == 'c':
- * order = b'C'
- * self.mode = u'c' # <<<<<<<<<<<<<<
- * else:
- * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)
- */
- __Pyx_INCREF(__pyx_n_u_c);
- __Pyx_GIVEREF(__pyx_n_u_c);
- __Pyx_GOTREF(__pyx_v_self->mode);
- __Pyx_DECREF(__pyx_v_self->mode);
- __pyx_v_self->mode = __pyx_n_u_c;
+ __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 252, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_allocate_buffer, Py_False) < 0) __PYX_ERR(1, 252, __pyx_L1_error)
- /* "View.MemoryView":160
- * order = b'F'
- * self.mode = u'fortran'
- * elif mode == 'c': # <<<<<<<<<<<<<<
- * order = b'C'
- * self.mode = u'c'
+ /* "View.MemoryView":251
+ * result = array(shape, itemsize, format, mode.decode('ASCII'))
+ * else:
+ * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<<
+ * allocate_buffer=False)
+ * result.data = buf
*/
- goto __pyx_L10;
- }
+ __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 251, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_5);
+ __pyx_t_5 = 0;
- /* "View.MemoryView":164
- * self.mode = u'c'
- * else:
- * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":253
+ * result = array(shape, itemsize, format, mode.decode('ASCII'),
+ * allocate_buffer=False)
+ * result.data = buf # <<<<<<<<<<<<<<
*
- * self.len = fill_contig_strides_array(self._shape, self._strides,
+ * return result
*/
- /*else*/ {
- __pyx_t_3 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Invalid_mode_expected_c_or_fortr, __pyx_v_mode); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 164, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 164, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_10);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_Raise(__pyx_t_10, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
- __PYX_ERR(1, 164, __pyx_L1_error)
+ __pyx_v_result->data = __pyx_v_buf;
}
- __pyx_L10:;
+ __pyx_L3:;
- /* "View.MemoryView":166
- * raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)
+ /* "View.MemoryView":255
+ * result.data = buf
*
- * self.len = fill_contig_strides_array(self._shape, self._strides, # <<<<<<<<<<<<<<
- * itemsize, self.ndim, order)
+ * return result # <<<<<<<<<<<<<<
*
- */
- __pyx_v_self->len = __pyx_fill_contig_strides_array(__pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_itemsize, __pyx_v_self->ndim, __pyx_v_order);
-
- /* "View.MemoryView":169
- * itemsize, self.ndim, order)
*
- * self.free_data = allocate_buffer # <<<<<<<<<<<<<<
- * self.dtype_is_object = format == b'O'
- * if allocate_buffer:
*/
- __pyx_v_self->free_data = __pyx_v_allocate_buffer;
+ __Pyx_XDECREF(((PyObject *)__pyx_r));
+ __Pyx_INCREF(((PyObject *)__pyx_v_result));
+ __pyx_r = __pyx_v_result;
+ goto __pyx_L0;
- /* "View.MemoryView":170
- *
- * self.free_data = allocate_buffer
- * self.dtype_is_object = format == b'O' # <<<<<<<<<<<<<<
- * if allocate_buffer:
+ /* "View.MemoryView":244
*
+ * @cname("__pyx_array_new")
+ * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<<
+ * char *mode, char *buf):
+ * cdef array result
*/
- __pyx_t_10 = PyObject_RichCompare(__pyx_v_format, __pyx_n_b_O, Py_EQ); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 170, __pyx_L1_error)
- __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 170, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
- __pyx_v_self->dtype_is_object = __pyx_t_4;
- /* "View.MemoryView":171
- * self.free_data = allocate_buffer
- * self.dtype_is_object = format == b'O'
- * if allocate_buffer: # <<<<<<<<<<<<<<
- *
- *
- */
- __pyx_t_4 = (__pyx_v_allocate_buffer != 0);
- if (__pyx_t_4) {
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XDECREF((PyObject *)__pyx_v_result);
+ __Pyx_XGIVEREF((PyObject *)__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":174
- *
- *
- * self.data = malloc(self.len) # <<<<<<<<<<<<<<
- * if not self.data:
- * raise MemoryError("unable to allocate array data.")
+/* "View.MemoryView":281
+ * cdef class Enum(object):
+ * cdef object name
+ * def __init__(self, name): # <<<<<<<<<<<<<<
+ * self.name = name
+ * def __repr__(self):
*/
- __pyx_v_self->data = ((char *)malloc(__pyx_v_self->len));
- /* "View.MemoryView":175
- *
- * self.data = malloc(self.len)
- * if not self.data: # <<<<<<<<<<<<<<
- * raise MemoryError("unable to allocate array data.")
- *
- */
- __pyx_t_4 = ((!(__pyx_v_self->data != 0)) != 0);
- if (unlikely(__pyx_t_4)) {
+/* Python wrapper */
+static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_name = 0;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
+ {
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,0};
+ PyObject* values[1] = {0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+ switch (pos_args) {
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ CYTHON_FALLTHROUGH;
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (pos_args) {
+ case 0:
+ if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(1, 281, __pyx_L3_error)
+ }
+ } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
+ goto __pyx_L5_argtuple_error;
+ } else {
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ }
+ __pyx_v_name = values[0];
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 281, __pyx_L3_error)
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name);
- /* "View.MemoryView":176
- * self.data = malloc(self.len)
- * if not self.data:
- * raise MemoryError("unable to allocate array data.") # <<<<<<<<<<<<<<
- *
- * if self.dtype_is_object:
- */
- __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 176, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_10);
- __Pyx_Raise(__pyx_t_10, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
- __PYX_ERR(1, 176, __pyx_L1_error)
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":175
- *
- * self.data = malloc(self.len)
- * if not self.data: # <<<<<<<<<<<<<<
- * raise MemoryError("unable to allocate array data.")
- *
+static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__init__", 0);
+
+ /* "View.MemoryView":282
+ * cdef object name
+ * def __init__(self, name):
+ * self.name = name # <<<<<<<<<<<<<<
+ * def __repr__(self):
+ * return self.name
*/
- }
+ __Pyx_INCREF(__pyx_v_name);
+ __Pyx_GIVEREF(__pyx_v_name);
+ __Pyx_GOTREF(__pyx_v_self->name);
+ __Pyx_DECREF(__pyx_v_self->name);
+ __pyx_v_self->name = __pyx_v_name;
- /* "View.MemoryView":178
- * raise MemoryError("unable to allocate array data.")
- *
- * if self.dtype_is_object: # <<<<<<<<<<<<<<
- * p = self.data
- * for i in range(self.len / itemsize):
+ /* "View.MemoryView":281
+ * cdef class Enum(object):
+ * cdef object name
+ * def __init__(self, name): # <<<<<<<<<<<<<<
+ * self.name = name
+ * def __repr__(self):
*/
- __pyx_t_4 = (__pyx_v_self->dtype_is_object != 0);
- if (__pyx_t_4) {
- /* "View.MemoryView":179
- *
- * if self.dtype_is_object:
- * p = self.data # <<<<<<<<<<<<<<
- * for i in range(self.len / itemsize):
- * p[i] = Py_None
- */
- __pyx_v_p = ((PyObject **)__pyx_v_self->data);
-
- /* "View.MemoryView":180
- * if self.dtype_is_object:
- * p = self.data
- * for i in range(self.len / itemsize): # <<<<<<<<<<<<<<
- * p[i] = Py_None
- * Py_INCREF(Py_None)
- */
- if (unlikely(__pyx_v_itemsize == 0)) {
- PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
- __PYX_ERR(1, 180, __pyx_L1_error)
- }
- else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_self->len))) {
- PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
- __PYX_ERR(1, 180, __pyx_L1_error)
- }
- __pyx_t_1 = __Pyx_div_Py_ssize_t(__pyx_v_self->len, __pyx_v_itemsize);
- __pyx_t_9 = __pyx_t_1;
- for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_9; __pyx_t_11+=1) {
- __pyx_v_i = __pyx_t_11;
+ /* function exit code */
+ __pyx_r = 0;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":181
- * p = self.data
- * for i in range(self.len / itemsize):
- * p[i] = Py_None # <<<<<<<<<<<<<<
- * Py_INCREF(Py_None)
+/* "View.MemoryView":283
+ * def __init__(self, name):
+ * self.name = name
+ * def __repr__(self): # <<<<<<<<<<<<<<
+ * return self.name
*
*/
- (__pyx_v_p[__pyx_v_i]) = Py_None;
- /* "View.MemoryView":182
- * for i in range(self.len / itemsize):
- * p[i] = Py_None
- * Py_INCREF(Py_None) # <<<<<<<<<<<<<<
- *
- * @cname('getbuffer')
- */
- Py_INCREF(Py_None);
- }
+/* Python wrapper */
+static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
+ __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self));
- /* "View.MemoryView":178
- * raise MemoryError("unable to allocate array data.")
- *
- * if self.dtype_is_object: # <<<<<<<<<<<<<<
- * p = self.data
- * for i in range(self.len / itemsize):
- */
- }
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":171
- * self.free_data = allocate_buffer
- * self.dtype_is_object = format == b'O'
- * if allocate_buffer: # <<<<<<<<<<<<<<
- *
+static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__repr__", 0);
+
+ /* "View.MemoryView":284
+ * self.name = name
+ * def __repr__(self):
+ * return self.name # <<<<<<<<<<<<<<
*
+ * cdef generic = Enum("")
*/
- }
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(__pyx_v_self->name);
+ __pyx_r = __pyx_v_self->name;
+ goto __pyx_L0;
- /* "View.MemoryView":122
- * cdef bint dtype_is_object
- *
- * def __cinit__(array self, tuple shape, Py_ssize_t itemsize, format not None, # <<<<<<<<<<<<<<
- * mode="c", bint allocate_buffer=True):
+ /* "View.MemoryView":283
+ * def __init__(self, name):
+ * self.name = name
+ * def __repr__(self): # <<<<<<<<<<<<<<
+ * return self.name
*
*/
/* function exit code */
- __pyx_r = 0;
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_5);
- __Pyx_XDECREF(__pyx_t_6);
- __Pyx_XDECREF(__pyx_t_10);
- __Pyx_AddTraceback("View.MemoryView.array.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = -1;
__pyx_L0:;
- __Pyx_XDECREF(__pyx_v_format);
+ __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":185
- *
- * @cname('getbuffer')
- * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<<
- * cdef int bufmode = -1
- * if self.mode == u"c":
+/* "(tree fragment)":1
+ * def __reduce_cython__(self): # <<<<<<<<<<<<<<
+ * cdef tuple state
+ * cdef object _dict
*/
/* Python wrapper */
-static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
-static CYTHON_UNUSED int __pyx_array_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
- int __pyx_r;
+static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
- __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(((struct __pyx_array_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));
+ __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+ __pyx_r = __pyx_pf___pyx_MemviewEnum___reduce_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
- int __pyx_v_bufmode;
- int __pyx_r;
+static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self) {
+ PyObject *__pyx_v_state = 0;
+ PyObject *__pyx_v__dict = 0;
+ int __pyx_v_use_setstate;
+ PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- int __pyx_t_1;
+ PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- char *__pyx_t_4;
- Py_ssize_t __pyx_t_5;
- int __pyx_t_6;
- Py_ssize_t *__pyx_t_7;
+ int __pyx_t_3;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- if (__pyx_v_info == NULL) {
- PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
- return -1;
- }
- __Pyx_RefNannySetupContext("__getbuffer__", 0);
- __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
- __Pyx_GIVEREF(__pyx_v_info->obj);
+ __Pyx_RefNannySetupContext("__reduce_cython__", 0);
- /* "View.MemoryView":186
- * @cname('getbuffer')
- * def __getbuffer__(self, Py_buffer *info, int flags):
- * cdef int bufmode = -1 # <<<<<<<<<<<<<<
- * if self.mode == u"c":
- * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ /* "(tree fragment)":5
+ * cdef object _dict
+ * cdef bint use_setstate
+ * state = (self.name,) # <<<<<<<<<<<<<<
+ * _dict = getattr(self, '__dict__', None)
+ * if _dict is not None:
*/
- __pyx_v_bufmode = -1;
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(__pyx_v_self->name);
+ __Pyx_GIVEREF(__pyx_v_self->name);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name);
+ __pyx_v_state = ((PyObject*)__pyx_t_1);
+ __pyx_t_1 = 0;
- /* "View.MemoryView":187
- * def __getbuffer__(self, Py_buffer *info, int flags):
- * cdef int bufmode = -1
- * if self.mode == u"c": # <<<<<<<<<<<<<<
- * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * elif self.mode == u"fortran":
+ /* "(tree fragment)":6
+ * cdef bint use_setstate
+ * state = (self.name,)
+ * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<<
+ * if _dict is not None:
+ * state += (_dict,)
*/
- __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_c, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 187, __pyx_L1_error)
- __pyx_t_2 = (__pyx_t_1 != 0);
- if (__pyx_t_2) {
+ __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v__dict = __pyx_t_1;
+ __pyx_t_1 = 0;
- /* "View.MemoryView":188
- * cdef int bufmode = -1
- * if self.mode == u"c":
- * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<<
- * elif self.mode == u"fortran":
- * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
+ /* "(tree fragment)":7
+ * state = (self.name,)
+ * _dict = getattr(self, '__dict__', None)
+ * if _dict is not None: # <<<<<<<<<<<<<<
+ * state += (_dict,)
+ * use_setstate = True
*/
- __pyx_v_bufmode = (PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS);
+ __pyx_t_2 = (__pyx_v__dict != Py_None);
+ __pyx_t_3 = (__pyx_t_2 != 0);
+ if (__pyx_t_3) {
- /* "View.MemoryView":187
- * def __getbuffer__(self, Py_buffer *info, int flags):
- * cdef int bufmode = -1
- * if self.mode == u"c": # <<<<<<<<<<<<<<
- * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * elif self.mode == u"fortran":
+ /* "(tree fragment)":8
+ * _dict = getattr(self, '__dict__', None)
+ * if _dict is not None:
+ * state += (_dict,) # <<<<<<<<<<<<<<
+ * use_setstate = True
+ * else:
*/
- goto __pyx_L3;
- }
+ __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 8, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(__pyx_v__dict);
+ __Pyx_GIVEREF(__pyx_v__dict);
+ PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict);
+ __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 8, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4));
+ __pyx_t_4 = 0;
- /* "View.MemoryView":189
- * if self.mode == u"c":
- * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * elif self.mode == u"fortran": # <<<<<<<<<<<<<<
- * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * if not (flags & bufmode):
+ /* "(tree fragment)":9
+ * if _dict is not None:
+ * state += (_dict,)
+ * use_setstate = True # <<<<<<<<<<<<<<
+ * else:
+ * use_setstate = self.name is not None
*/
- __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_self->mode, __pyx_n_u_fortran, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 189, __pyx_L1_error)
- __pyx_t_1 = (__pyx_t_2 != 0);
- if (__pyx_t_1) {
+ __pyx_v_use_setstate = 1;
- /* "View.MemoryView":190
- * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * elif self.mode == u"fortran":
- * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS # <<<<<<<<<<<<<<
- * if not (flags & bufmode):
- * raise ValueError("Can only create a buffer that is contiguous in memory.")
+ /* "(tree fragment)":7
+ * state = (self.name,)
+ * _dict = getattr(self, '__dict__', None)
+ * if _dict is not None: # <<<<<<<<<<<<<<
+ * state += (_dict,)
+ * use_setstate = True
*/
- __pyx_v_bufmode = (PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS);
+ goto __pyx_L3;
+ }
- /* "View.MemoryView":189
- * if self.mode == u"c":
- * bufmode = PyBUF_C_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * elif self.mode == u"fortran": # <<<<<<<<<<<<<<
- * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * if not (flags & bufmode):
+ /* "(tree fragment)":11
+ * use_setstate = True
+ * else:
+ * use_setstate = self.name is not None # <<<<<<<<<<<<<<
+ * if use_setstate:
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
*/
+ /*else*/ {
+ __pyx_t_3 = (__pyx_v_self->name != Py_None);
+ __pyx_v_use_setstate = __pyx_t_3;
}
__pyx_L3:;
- /* "View.MemoryView":191
- * elif self.mode == u"fortran":
- * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * if not (flags & bufmode): # <<<<<<<<<<<<<<
- * raise ValueError("Can only create a buffer that is contiguous in memory.")
- * info.buf = self.data
+ /* "(tree fragment)":12
+ * else:
+ * use_setstate = self.name is not None
+ * if use_setstate: # <<<<<<<<<<<<<<
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
+ * else:
*/
- __pyx_t_1 = ((!((__pyx_v_flags & __pyx_v_bufmode) != 0)) != 0);
- if (unlikely(__pyx_t_1)) {
+ __pyx_t_3 = (__pyx_v_use_setstate != 0);
+ if (__pyx_t_3) {
- /* "View.MemoryView":192
- * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * if not (flags & bufmode):
- * raise ValueError("Can only create a buffer that is contiguous in memory.") # <<<<<<<<<<<<<<
- * info.buf = self.data
- * info.len = self.len
+ /* "(tree fragment)":13
+ * use_setstate = self.name is not None
+ * if use_setstate:
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state # <<<<<<<<<<<<<<
+ * else:
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
*/
- __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 192, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_Raise(__pyx_t_3, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __PYX_ERR(1, 192, __pyx_L1_error)
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+ __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+ __Pyx_INCREF(__pyx_int_184977713);
+ __Pyx_GIVEREF(__pyx_int_184977713);
+ PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713);
+ __Pyx_INCREF(Py_None);
+ __Pyx_GIVEREF(Py_None);
+ PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None);
+ __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_GIVEREF(__pyx_t_4);
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
+ __Pyx_GIVEREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
+ __Pyx_INCREF(__pyx_v_state);
+ __Pyx_GIVEREF(__pyx_v_state);
+ PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state);
+ __pyx_t_4 = 0;
+ __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":191
- * elif self.mode == u"fortran":
- * bufmode = PyBUF_F_CONTIGUOUS | PyBUF_ANY_CONTIGUOUS
- * if not (flags & bufmode): # <<<<<<<<<<<<<<
- * raise ValueError("Can only create a buffer that is contiguous in memory.")
- * info.buf = self.data
+ /* "(tree fragment)":12
+ * else:
+ * use_setstate = self.name is not None
+ * if use_setstate: # <<<<<<<<<<<<<<
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
+ * else:
*/
}
- /* "View.MemoryView":193
- * if not (flags & bufmode):
- * raise ValueError("Can only create a buffer that is contiguous in memory.")
- * info.buf = self.data # <<<<<<<<<<<<<<
- * info.len = self.len
- * info.ndim = self.ndim
+ /* "(tree fragment)":15
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
+ * else:
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ * __pyx_unpickle_Enum__set_state(self, __pyx_state)
*/
- __pyx_t_4 = __pyx_v_self->data;
- __pyx_v_info->buf = __pyx_t_4;
+ /*else*/ {
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 15, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+ __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+ PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
+ __Pyx_INCREF(__pyx_int_184977713);
+ __Pyx_GIVEREF(__pyx_int_184977713);
+ PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713);
+ __Pyx_INCREF(__pyx_v_state);
+ __Pyx_GIVEREF(__pyx_v_state);
+ PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state);
+ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 15, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_GIVEREF(__pyx_t_5);
+ PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
+ __Pyx_GIVEREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
+ __pyx_t_5 = 0;
+ __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_4;
+ __pyx_t_4 = 0;
+ goto __pyx_L0;
+ }
- /* "View.MemoryView":194
- * raise ValueError("Can only create a buffer that is contiguous in memory.")
- * info.buf = self.data
- * info.len = self.len # <<<<<<<<<<<<<<
- * info.ndim = self.ndim
- * info.shape = self._shape
+ /* "(tree fragment)":1
+ * def __reduce_cython__(self): # <<<<<<<<<<<<<<
+ * cdef tuple state
+ * cdef object _dict
*/
- __pyx_t_5 = __pyx_v_self->len;
- __pyx_v_info->len = __pyx_t_5;
- /* "View.MemoryView":195
- * info.buf = self.data
- * info.len = self.len
- * info.ndim = self.ndim # <<<<<<<<<<<<<<
- * info.shape = self._shape
- * info.strides = self._strides
- */
- __pyx_t_6 = __pyx_v_self->ndim;
- __pyx_v_info->ndim = __pyx_t_6;
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("View.MemoryView.Enum.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_state);
+ __Pyx_XDECREF(__pyx_v__dict);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":196
- * info.len = self.len
- * info.ndim = self.ndim
- * info.shape = self._shape # <<<<<<<<<<<<<<
- * info.strides = self._strides
- * info.suboffsets = NULL
+/* "(tree fragment)":16
+ * else:
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
+ * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
+ * __pyx_unpickle_Enum__set_state(self, __pyx_state)
*/
- __pyx_t_7 = __pyx_v_self->_shape;
- __pyx_v_info->shape = __pyx_t_7;
- /* "View.MemoryView":197
- * info.ndim = self.ndim
- * info.shape = self._shape
- * info.strides = self._strides # <<<<<<<<<<<<<<
- * info.suboffsets = NULL
- * info.itemsize = self.itemsize
- */
- __pyx_t_7 = __pyx_v_self->_strides;
- __pyx_v_info->strides = __pyx_t_7;
+/* Python wrapper */
+static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+ __pyx_r = __pyx_pf___pyx_MemviewEnum_2__setstate_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
- /* "View.MemoryView":198
- * info.shape = self._shape
- * info.strides = self._strides
- * info.suboffsets = NULL # <<<<<<<<<<<<<<
- * info.itemsize = self.itemsize
- * info.readonly = 0
- */
- __pyx_v_info->suboffsets = NULL;
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":199
- * info.strides = self._strides
- * info.suboffsets = NULL
- * info.itemsize = self.itemsize # <<<<<<<<<<<<<<
- * info.readonly = 0
- *
+static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+
+ /* "(tree fragment)":17
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
+ * def __setstate_cython__(self, __pyx_state):
+ * __pyx_unpickle_Enum__set_state(self, __pyx_state) # <<<<<<<<<<<<<<
*/
- __pyx_t_5 = __pyx_v_self->itemsize;
- __pyx_v_info->itemsize = __pyx_t_5;
+ if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error)
+ __pyx_t_1 = __pyx_unpickle_Enum__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- /* "View.MemoryView":200
- * info.suboffsets = NULL
- * info.itemsize = self.itemsize
- * info.readonly = 0 # <<<<<<<<<<<<<<
- *
- * if flags & PyBUF_FORMAT:
- */
- __pyx_v_info->readonly = 0;
-
- /* "View.MemoryView":202
- * info.readonly = 0
- *
- * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
- * info.format = self.format
- * else:
- */
- __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
- if (__pyx_t_1) {
-
- /* "View.MemoryView":203
- *
- * if flags & PyBUF_FORMAT:
- * info.format = self.format # <<<<<<<<<<<<<<
- * else:
- * info.format = NULL
- */
- __pyx_t_4 = __pyx_v_self->format;
- __pyx_v_info->format = __pyx_t_4;
-
- /* "View.MemoryView":202
- * info.readonly = 0
- *
- * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
- * info.format = self.format
- * else:
- */
- goto __pyx_L5;
- }
-
- /* "View.MemoryView":205
- * info.format = self.format
- * else:
- * info.format = NULL # <<<<<<<<<<<<<<
- *
- * info.obj = self
- */
- /*else*/ {
- __pyx_v_info->format = NULL;
- }
- __pyx_L5:;
-
- /* "View.MemoryView":207
- * info.format = NULL
- *
- * info.obj = self # <<<<<<<<<<<<<<
- *
- * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
- */
- __Pyx_INCREF(((PyObject *)__pyx_v_self));
- __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
- __Pyx_GOTREF(__pyx_v_info->obj);
- __Pyx_DECREF(__pyx_v_info->obj);
- __pyx_v_info->obj = ((PyObject *)__pyx_v_self);
-
- /* "View.MemoryView":185
- *
- * @cname('getbuffer')
- * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<<
- * cdef int bufmode = -1
- * if self.mode == u"c":
+ /* "(tree fragment)":16
+ * else:
+ * return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
+ * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
+ * __pyx_unpickle_Enum__set_state(self, __pyx_state)
*/
/* function exit code */
- __pyx_r = 0;
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_AddTraceback("View.MemoryView.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = -1;
- if (__pyx_v_info->obj != NULL) {
- __Pyx_GOTREF(__pyx_v_info->obj);
- __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
- }
- goto __pyx_L2;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("View.MemoryView.Enum.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
__pyx_L0:;
- if (__pyx_v_info->obj == Py_None) {
- __Pyx_GOTREF(__pyx_v_info->obj);
- __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
- }
- __pyx_L2:;
+ __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":211
- * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
+/* "View.MemoryView":298
*
- * def __dealloc__(array self): # <<<<<<<<<<<<<<
- * if self.callback_free_data != NULL:
- * self.callback_free_data(self.data)
+ * @cname('__pyx_align_pointer')
+ * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<<
+ * "Align pointer memory on a given boundary"
+ * cdef Py_intptr_t aligned_p = memory
*/
-/* Python wrapper */
-static void __pyx_array___dealloc__(PyObject *__pyx_v_self); /*proto*/
-static void __pyx_array___dealloc__(PyObject *__pyx_v_self) {
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
- __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(((struct __pyx_array_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
-}
-
-static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self) {
- __Pyx_RefNannyDeclarations
+static void *__pyx_align_pointer(void *__pyx_v_memory, size_t __pyx_v_alignment) {
+ Py_intptr_t __pyx_v_aligned_p;
+ size_t __pyx_v_offset;
+ void *__pyx_r;
int __pyx_t_1;
- __Pyx_RefNannySetupContext("__dealloc__", 0);
- /* "View.MemoryView":212
+ /* "View.MemoryView":300
+ * cdef void *align_pointer(void *memory, size_t alignment) nogil:
+ * "Align pointer memory on a given boundary"
+ * cdef Py_intptr_t aligned_p = memory # <<<<<<<<<<<<<<
+ * cdef size_t offset
*
- * def __dealloc__(array self):
- * if self.callback_free_data != NULL: # <<<<<<<<<<<<<<
- * self.callback_free_data(self.data)
- * elif self.free_data:
- */
- __pyx_t_1 = ((__pyx_v_self->callback_free_data != NULL) != 0);
- if (__pyx_t_1) {
-
- /* "View.MemoryView":213
- * def __dealloc__(array self):
- * if self.callback_free_data != NULL:
- * self.callback_free_data(self.data) # <<<<<<<<<<<<<<
- * elif self.free_data:
- * if self.dtype_is_object:
*/
- __pyx_v_self->callback_free_data(__pyx_v_self->data);
+ __pyx_v_aligned_p = ((Py_intptr_t)__pyx_v_memory);
- /* "View.MemoryView":212
+ /* "View.MemoryView":304
*
- * def __dealloc__(array self):
- * if self.callback_free_data != NULL: # <<<<<<<<<<<<<<
- * self.callback_free_data(self.data)
- * elif self.free_data:
+ * with cython.cdivision(True):
+ * offset = aligned_p % alignment # <<<<<<<<<<<<<<
+ *
+ * if offset > 0:
*/
- goto __pyx_L3;
- }
+ __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment);
- /* "View.MemoryView":214
- * if self.callback_free_data != NULL:
- * self.callback_free_data(self.data)
- * elif self.free_data: # <<<<<<<<<<<<<<
- * if self.dtype_is_object:
- * refcount_objects_in_slice(self.data, self._shape,
+ /* "View.MemoryView":306
+ * offset = aligned_p % alignment
+ *
+ * if offset > 0: # <<<<<<<<<<<<<<
+ * aligned_p += alignment - offset
+ *
*/
- __pyx_t_1 = (__pyx_v_self->free_data != 0);
+ __pyx_t_1 = ((__pyx_v_offset > 0) != 0);
if (__pyx_t_1) {
- /* "View.MemoryView":215
- * self.callback_free_data(self.data)
- * elif self.free_data:
- * if self.dtype_is_object: # <<<<<<<<<<<<<<
- * refcount_objects_in_slice(self.data, self._shape,
- * self._strides, self.ndim, False)
- */
- __pyx_t_1 = (__pyx_v_self->dtype_is_object != 0);
- if (__pyx_t_1) {
-
- /* "View.MemoryView":216
- * elif self.free_data:
- * if self.dtype_is_object:
- * refcount_objects_in_slice(self.data, self._shape, # <<<<<<<<<<<<<<
- * self._strides, self.ndim, False)
- * free(self.data)
- */
- __pyx_memoryview_refcount_objects_in_slice(__pyx_v_self->data, __pyx_v_self->_shape, __pyx_v_self->_strides, __pyx_v_self->ndim, 0);
-
- /* "View.MemoryView":215
- * self.callback_free_data(self.data)
- * elif self.free_data:
- * if self.dtype_is_object: # <<<<<<<<<<<<<<
- * refcount_objects_in_slice(self.data, self._shape,
- * self._strides, self.ndim, False)
- */
- }
-
- /* "View.MemoryView":218
- * refcount_objects_in_slice(self.data, self._shape,
- * self._strides, self.ndim, False)
- * free(self.data) # <<<<<<<<<<<<<<
- * PyObject_Free(self._shape)
+ /* "View.MemoryView":307
*
+ * if offset > 0:
+ * aligned_p += alignment - offset # <<<<<<<<<<<<<<
+ *
+ * return aligned_p
*/
- free(__pyx_v_self->data);
+ __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset));
- /* "View.MemoryView":214
- * if self.callback_free_data != NULL:
- * self.callback_free_data(self.data)
- * elif self.free_data: # <<<<<<<<<<<<<<
- * if self.dtype_is_object:
- * refcount_objects_in_slice(self.data, self._shape,
+ /* "View.MemoryView":306
+ * offset = aligned_p % alignment
+ *
+ * if offset > 0: # <<<<<<<<<<<<<<
+ * aligned_p += alignment - offset
+ *
*/
}
- __pyx_L3:;
- /* "View.MemoryView":219
- * self._strides, self.ndim, False)
- * free(self.data)
- * PyObject_Free(self._shape) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":309
+ * aligned_p += alignment - offset
+ *
+ * return aligned_p # <<<<<<<<<<<<<<
+ *
*
- * @property
*/
- PyObject_Free(__pyx_v_self->_shape);
+ __pyx_r = ((void *)__pyx_v_aligned_p);
+ goto __pyx_L0;
- /* "View.MemoryView":211
- * __pyx_getbuffer = capsule( &__pyx_array_getbuffer, "getbuffer(obj, view, flags)")
+ /* "View.MemoryView":298
*
- * def __dealloc__(array self): # <<<<<<<<<<<<<<
- * if self.callback_free_data != NULL:
- * self.callback_free_data(self.data)
+ * @cname('__pyx_align_pointer')
+ * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<<
+ * "Align pointer memory on a given boundary"
+ * cdef Py_intptr_t aligned_p = memory
*/
/* function exit code */
- __Pyx_RefNannyFinishContext();
+ __pyx_L0:;
+ return __pyx_r;
}
-/* "View.MemoryView":222
- *
- * @property
- * def memview(self): # <<<<<<<<<<<<<<
- * return self.get_memview()
+/* "View.MemoryView":345
+ * cdef __Pyx_TypeInfo *typeinfo
*
+ * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<<
+ * self.obj = obj
+ * self.flags = flags
*/
/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_5array_7memview_1__get__(PyObject *__pyx_v_self) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_5array_7memview___get__(((struct __pyx_array_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_15View_dot_MemoryView_5array_7memview___get__(struct __pyx_array_obj *__pyx_v_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
+static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
+static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
+ PyObject *__pyx_v_obj = 0;
+ int __pyx_v_flags;
+ int __pyx_v_dtype_is_object;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__get__", 0);
-
- /* "View.MemoryView":223
- * @property
- * def memview(self):
- * return self.get_memview() # <<<<<<<<<<<<<<
- *
- * @cname('get_memview')
- */
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = ((struct __pyx_vtabstruct_array *)__pyx_v_self->__pyx_vtab)->get_memview(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 223, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
-
- /* "View.MemoryView":222
- *
- * @property
- * def memview(self): # <<<<<<<<<<<<<<
- * return self.get_memview()
- *
- */
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
+ {
+ static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_flags,&__pyx_n_s_dtype_is_object,0};
+ PyObject* values[3] = {0,0,0};
+ if (unlikely(__pyx_kwds)) {
+ Py_ssize_t kw_args;
+ const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
+ switch (pos_args) {
+ case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+ CYTHON_FALLTHROUGH;
+ case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ CYTHON_FALLTHROUGH;
+ case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ CYTHON_FALLTHROUGH;
+ case 0: break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ kw_args = PyDict_Size(__pyx_kwds);
+ switch (pos_args) {
+ case 0:
+ if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_obj)) != 0)) kw_args--;
+ else goto __pyx_L5_argtuple_error;
+ CYTHON_FALLTHROUGH;
+ case 1:
+ if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flags)) != 0)) kw_args--;
+ else {
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(1, 345, __pyx_L3_error)
+ }
+ CYTHON_FALLTHROUGH;
+ case 2:
+ if (kw_args > 0) {
+ PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dtype_is_object);
+ if (value) { values[2] = value; kw_args--; }
+ }
+ }
+ if (unlikely(kw_args > 0)) {
+ if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 345, __pyx_L3_error)
+ }
+ } else {
+ switch (PyTuple_GET_SIZE(__pyx_args)) {
+ case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
+ CYTHON_FALLTHROUGH;
+ case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
+ values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
+ break;
+ default: goto __pyx_L5_argtuple_error;
+ }
+ }
+ __pyx_v_obj = values[0];
+ __pyx_v_flags = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 345, __pyx_L3_error)
+ if (values[2]) {
+ __pyx_v_dtype_is_object = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_dtype_is_object == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 345, __pyx_L3_error)
+ } else {
+ __pyx_v_dtype_is_object = ((int)0);
+ }
+ }
+ goto __pyx_L4_argument_unpacking_done;
+ __pyx_L5_argtuple_error:;
+ __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 345, __pyx_L3_error)
+ __pyx_L3_error:;
+ __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_RefNannyFinishContext();
+ return -1;
+ __pyx_L4_argument_unpacking_done:;
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object);
/* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.array.memview.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":226
- *
- * @cname('get_memview')
- * cdef get_memview(self): # <<<<<<<<<<<<<<
- * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
- * return memoryview(self, flags, self.dtype_is_object)
- */
-
-static PyObject *__pyx_array_get_memview(struct __pyx_array_obj *__pyx_v_self) {
- int __pyx_v_flags;
- PyObject *__pyx_r = NULL;
+static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object) {
+ int __pyx_r;
__Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- PyObject *__pyx_t_2 = NULL;
- PyObject *__pyx_t_3 = NULL;
+ int __pyx_t_1;
+ int __pyx_t_2;
+ int __pyx_t_3;
+ int __pyx_t_4;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("get_memview", 0);
+ __Pyx_RefNannySetupContext("__cinit__", 0);
- /* "View.MemoryView":227
- * @cname('get_memview')
- * cdef get_memview(self):
- * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE # <<<<<<<<<<<<<<
- * return memoryview(self, flags, self.dtype_is_object)
+ /* "View.MemoryView":346
*
+ * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):
+ * self.obj = obj # <<<<<<<<<<<<<<
+ * self.flags = flags
+ * if type(self) is memoryview or obj is not None:
*/
- __pyx_v_flags = ((PyBUF_ANY_CONTIGUOUS | PyBUF_FORMAT) | PyBUF_WRITABLE);
+ __Pyx_INCREF(__pyx_v_obj);
+ __Pyx_GIVEREF(__pyx_v_obj);
+ __Pyx_GOTREF(__pyx_v_self->obj);
+ __Pyx_DECREF(__pyx_v_self->obj);
+ __pyx_v_self->obj = __pyx_v_obj;
- /* "View.MemoryView":228
- * cdef get_memview(self):
- * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
- * return memoryview(self, flags, self.dtype_is_object) # <<<<<<<<<<<<<<
- *
- * def __len__(self):
+ /* "View.MemoryView":347
+ * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):
+ * self.obj = obj
+ * self.flags = flags # <<<<<<<<<<<<<<
+ * if type(self) is memoryview or obj is not None:
+ * __Pyx_GetBuffer(obj, &self.view, flags)
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 228, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 228, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 228, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(((PyObject *)__pyx_v_self));
- __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
- PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self));
- __Pyx_GIVEREF(__pyx_t_1);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
- __Pyx_GIVEREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
- __pyx_t_1 = 0;
- __pyx_t_2 = 0;
- __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 228, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_r = __pyx_t_2;
- __pyx_t_2 = 0;
- goto __pyx_L0;
+ __pyx_v_self->flags = __pyx_v_flags;
- /* "View.MemoryView":226
- *
- * @cname('get_memview')
- * cdef get_memview(self): # <<<<<<<<<<<<<<
- * flags = PyBUF_ANY_CONTIGUOUS|PyBUF_FORMAT|PyBUF_WRITABLE
- * return memoryview(self, flags, self.dtype_is_object)
+ /* "View.MemoryView":348
+ * self.obj = obj
+ * self.flags = flags
+ * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<<
+ * __Pyx_GetBuffer(obj, &self.view, flags)
+ * if self.view.obj == NULL:
*/
+ __pyx_t_2 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_memoryview_type));
+ __pyx_t_3 = (__pyx_t_2 != 0);
+ if (!__pyx_t_3) {
+ } else {
+ __pyx_t_1 = __pyx_t_3;
+ goto __pyx_L4_bool_binop_done;
+ }
+ __pyx_t_3 = (__pyx_v_obj != Py_None);
+ __pyx_t_2 = (__pyx_t_3 != 0);
+ __pyx_t_1 = __pyx_t_2;
+ __pyx_L4_bool_binop_done:;
+ if (__pyx_t_1) {
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_AddTraceback("View.MemoryView.array.get_memview", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":349
+ * self.flags = flags
+ * if type(self) is memoryview or obj is not None:
+ * __Pyx_GetBuffer(obj, &self.view, flags) # <<<<<<<<<<<<<<
+ * if self.view.obj == NULL:
+ * (<__pyx_buffer *> &self.view).obj = Py_None
+ */
+ __pyx_t_4 = __Pyx_GetBuffer(__pyx_v_obj, (&__pyx_v_self->view), __pyx_v_flags); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 349, __pyx_L1_error)
-/* "View.MemoryView":230
- * return memoryview(self, flags, self.dtype_is_object)
+ /* "View.MemoryView":350
+ * if type(self) is memoryview or obj is not None:
+ * __Pyx_GetBuffer(obj, &self.view, flags)
+ * if self.view.obj == NULL: # <<<<<<<<<<<<<<
+ * (<__pyx_buffer *> &self.view).obj = Py_None
+ * Py_INCREF(Py_None)
+ */
+ __pyx_t_1 = ((((PyObject *)__pyx_v_self->view.obj) == NULL) != 0);
+ if (__pyx_t_1) {
+
+ /* "View.MemoryView":351
+ * __Pyx_GetBuffer(obj, &self.view, flags)
+ * if self.view.obj == NULL:
+ * (<__pyx_buffer *> &self.view).obj = Py_None # <<<<<<<<<<<<<<
+ * Py_INCREF(Py_None)
*
- * def __len__(self): # <<<<<<<<<<<<<<
- * return self._shape[0]
+ */
+ ((Py_buffer *)(&__pyx_v_self->view))->obj = Py_None;
+
+ /* "View.MemoryView":352
+ * if self.view.obj == NULL:
+ * (<__pyx_buffer *> &self.view).obj = Py_None
+ * Py_INCREF(Py_None) # <<<<<<<<<<<<<<
*
+ * global __pyx_memoryview_thread_locks_used
*/
+ Py_INCREF(Py_None);
-/* Python wrapper */
-static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self); /*proto*/
-static Py_ssize_t __pyx_array___len__(PyObject *__pyx_v_self) {
- Py_ssize_t __pyx_r;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
- __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(((struct __pyx_array_obj *)__pyx_v_self));
+ /* "View.MemoryView":350
+ * if type(self) is memoryview or obj is not None:
+ * __Pyx_GetBuffer(obj, &self.view, flags)
+ * if self.view.obj == NULL: # <<<<<<<<<<<<<<
+ * (<__pyx_buffer *> &self.view).obj = Py_None
+ * Py_INCREF(Py_None)
+ */
+ }
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":348
+ * self.obj = obj
+ * self.flags = flags
+ * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<<
+ * __Pyx_GetBuffer(obj, &self.view, flags)
+ * if self.view.obj == NULL:
+ */
+ }
-static Py_ssize_t __pyx_array___pyx_pf_15View_dot_MemoryView_5array_6__len__(struct __pyx_array_obj *__pyx_v_self) {
- Py_ssize_t __pyx_r;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__len__", 0);
+ /* "View.MemoryView":355
+ *
+ * global __pyx_memoryview_thread_locks_used
+ * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<<
+ * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
+ * __pyx_memoryview_thread_locks_used += 1
+ */
+ __pyx_t_1 = ((__pyx_memoryview_thread_locks_used < 8) != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":231
+ /* "View.MemoryView":356
+ * global __pyx_memoryview_thread_locks_used
+ * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
+ * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] # <<<<<<<<<<<<<<
+ * __pyx_memoryview_thread_locks_used += 1
+ * if self.lock is NULL:
+ */
+ __pyx_v_self->lock = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]);
+
+ /* "View.MemoryView":357
+ * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
+ * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
+ * __pyx_memoryview_thread_locks_used += 1 # <<<<<<<<<<<<<<
+ * if self.lock is NULL:
+ * self.lock = PyThread_allocate_lock()
+ */
+ __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used + 1);
+
+ /* "View.MemoryView":355
*
- * def __len__(self):
- * return self._shape[0] # <<<<<<<<<<<<<<
+ * global __pyx_memoryview_thread_locks_used
+ * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<<
+ * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
+ * __pyx_memoryview_thread_locks_used += 1
+ */
+ }
+
+ /* "View.MemoryView":358
+ * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
+ * __pyx_memoryview_thread_locks_used += 1
+ * if self.lock is NULL: # <<<<<<<<<<<<<<
+ * self.lock = PyThread_allocate_lock()
+ * if self.lock is NULL:
+ */
+ __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0);
+ if (__pyx_t_1) {
+
+ /* "View.MemoryView":359
+ * __pyx_memoryview_thread_locks_used += 1
+ * if self.lock is NULL:
+ * self.lock = PyThread_allocate_lock() # <<<<<<<<<<<<<<
+ * if self.lock is NULL:
+ * raise MemoryError
+ */
+ __pyx_v_self->lock = PyThread_allocate_lock();
+
+ /* "View.MemoryView":360
+ * if self.lock is NULL:
+ * self.lock = PyThread_allocate_lock()
+ * if self.lock is NULL: # <<<<<<<<<<<<<<
+ * raise MemoryError
*
- * def __getattr__(self, attr):
*/
- __pyx_r = (__pyx_v_self->_shape[0]);
- goto __pyx_L0;
+ __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0);
+ if (unlikely(__pyx_t_1)) {
- /* "View.MemoryView":230
- * return memoryview(self, flags, self.dtype_is_object)
+ /* "View.MemoryView":361
+ * self.lock = PyThread_allocate_lock()
+ * if self.lock is NULL:
+ * raise MemoryError # <<<<<<<<<<<<<<
*
- * def __len__(self): # <<<<<<<<<<<<<<
- * return self._shape[0]
+ * if flags & PyBUF_FORMAT:
+ */
+ PyErr_NoMemory(); __PYX_ERR(1, 361, __pyx_L1_error)
+
+ /* "View.MemoryView":360
+ * if self.lock is NULL:
+ * self.lock = PyThread_allocate_lock()
+ * if self.lock is NULL: # <<<<<<<<<<<<<<
+ * raise MemoryError
*
*/
+ }
- /* function exit code */
- __pyx_L0:;
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":358
+ * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
+ * __pyx_memoryview_thread_locks_used += 1
+ * if self.lock is NULL: # <<<<<<<<<<<<<<
+ * self.lock = PyThread_allocate_lock()
+ * if self.lock is NULL:
+ */
+ }
-/* "View.MemoryView":233
- * return self._shape[0]
- *
- * def __getattr__(self, attr): # <<<<<<<<<<<<<<
- * return getattr(self.memview, attr)
+ /* "View.MemoryView":363
+ * raise MemoryError
*
+ * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
+ * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
+ * else:
*/
+ __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
+ if (__pyx_t_1) {
-/* Python wrapper */
-static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr); /*proto*/
-static PyObject *__pyx_array___getattr__(PyObject *__pyx_v_self, PyObject *__pyx_v_attr) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__getattr__ (wrapper)", 0);
- __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_attr));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":364
+ *
+ * if flags & PyBUF_FORMAT:
+ * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') # <<<<<<<<<<<<<<
+ * else:
+ * self.dtype_is_object = dtype_is_object
+ */
+ __pyx_t_2 = (((__pyx_v_self->view.format[0]) == 'O') != 0);
+ if (__pyx_t_2) {
+ } else {
+ __pyx_t_1 = __pyx_t_2;
+ goto __pyx_L11_bool_binop_done;
+ }
+ __pyx_t_2 = (((__pyx_v_self->view.format[1]) == '\x00') != 0);
+ __pyx_t_1 = __pyx_t_2;
+ __pyx_L11_bool_binop_done:;
+ __pyx_v_self->dtype_is_object = __pyx_t_1;
-static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_8__getattr__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_attr) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- PyObject *__pyx_t_2 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__getattr__", 0);
+ /* "View.MemoryView":363
+ * raise MemoryError
+ *
+ * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
+ * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
+ * else:
+ */
+ goto __pyx_L10;
+ }
- /* "View.MemoryView":234
+ /* "View.MemoryView":366
+ * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
+ * else:
+ * self.dtype_is_object = dtype_is_object # <<<<<<<<<<<<<<
*
- * def __getattr__(self, attr):
- * return getattr(self.memview, attr) # <<<<<<<<<<<<<<
+ * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(
+ */
+ /*else*/ {
+ __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object;
+ }
+ __pyx_L10:;
+
+ /* "View.MemoryView":368
+ * self.dtype_is_object = dtype_is_object
*
- * def __getitem__(self, item):
+ * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( # <<<<<<<<<<<<<<
+ * &self.acquisition_count[0], sizeof(__pyx_atomic_int))
+ * self.typeinfo = NULL
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 234, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_GetAttr(__pyx_t_1, __pyx_v_attr); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 234, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_r = __pyx_t_2;
- __pyx_t_2 = 0;
- goto __pyx_L0;
+ __pyx_v_self->acquisition_count_aligned_p = ((__pyx_atomic_int *)__pyx_align_pointer(((void *)(&(__pyx_v_self->acquisition_count[0]))), (sizeof(__pyx_atomic_int))));
- /* "View.MemoryView":233
- * return self._shape[0]
+ /* "View.MemoryView":370
+ * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(
+ * &self.acquisition_count[0], sizeof(__pyx_atomic_int))
+ * self.typeinfo = NULL # <<<<<<<<<<<<<<
*
- * def __getattr__(self, attr): # <<<<<<<<<<<<<<
- * return getattr(self.memview, attr)
+ * def __dealloc__(memoryview self):
+ */
+ __pyx_v_self->typeinfo = NULL;
+
+ /* "View.MemoryView":345
+ * cdef __Pyx_TypeInfo *typeinfo
*
+ * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<<
+ * self.obj = obj
+ * self.flags = flags
*/
/* function exit code */
+ __pyx_r = 0;
+ goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_AddTraceback("View.MemoryView.array.__getattr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
+ __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
__pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":236
- * return getattr(self.memview, attr)
- *
- * def __getitem__(self, item): # <<<<<<<<<<<<<<
- * return self.memview[item]
+/* "View.MemoryView":372
+ * self.typeinfo = NULL
*
+ * def __dealloc__(memoryview self): # <<<<<<<<<<<<<<
+ * if self.obj is not None:
+ * __Pyx_ReleaseBuffer(&self.view)
*/
/* Python wrapper */
-static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/
-static PyObject *__pyx_array___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) {
- PyObject *__pyx_r = 0;
+static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self) {
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
- __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item));
+ __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
+ __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
- return __pyx_r;
}
-static PyObject *__pyx_array___pyx_pf_15View_dot_MemoryView_5array_10__getitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item) {
- PyObject *__pyx_r = NULL;
+static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) {
+ int __pyx_v_i;
__Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- PyObject *__pyx_t_2 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__getitem__", 0);
+ int __pyx_t_1;
+ int __pyx_t_2;
+ int __pyx_t_3;
+ int __pyx_t_4;
+ int __pyx_t_5;
+ PyThread_type_lock __pyx_t_6;
+ PyThread_type_lock __pyx_t_7;
+ __Pyx_RefNannySetupContext("__dealloc__", 0);
- /* "View.MemoryView":237
- *
- * def __getitem__(self, item):
- * return self.memview[item] # <<<<<<<<<<<<<<
+ /* "View.MemoryView":373
*
- * def __setitem__(self, item, value):
+ * def __dealloc__(memoryview self):
+ * if self.obj is not None: # <<<<<<<<<<<<<<
+ * __Pyx_ReleaseBuffer(&self.view)
+ * elif (<__pyx_buffer *> &self.view).obj == Py_None:
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 237, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 237, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_r = __pyx_t_2;
- __pyx_t_2 = 0;
- goto __pyx_L0;
+ __pyx_t_1 = (__pyx_v_self->obj != Py_None);
+ __pyx_t_2 = (__pyx_t_1 != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":236
- * return getattr(self.memview, attr)
- *
- * def __getitem__(self, item): # <<<<<<<<<<<<<<
- * return self.memview[item]
+ /* "View.MemoryView":374
+ * def __dealloc__(memoryview self):
+ * if self.obj is not None:
+ * __Pyx_ReleaseBuffer(&self.view) # <<<<<<<<<<<<<<
+ * elif (<__pyx_buffer *> &self.view).obj == Py_None:
*
*/
+ __Pyx_ReleaseBuffer((&__pyx_v_self->view));
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_AddTraceback("View.MemoryView.array.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":239
- * return self.memview[item]
- *
- * def __setitem__(self, item, value): # <<<<<<<<<<<<<<
- * self.memview[item] = value
+ /* "View.MemoryView":373
*
+ * def __dealloc__(memoryview self):
+ * if self.obj is not None: # <<<<<<<<<<<<<<
+ * __Pyx_ReleaseBuffer(&self.view)
+ * elif (<__pyx_buffer *> &self.view).obj == Py_None:
*/
+ goto __pyx_L3;
+ }
-/* Python wrapper */
-static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value); /*proto*/
-static int __pyx_array___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) {
- int __pyx_r;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
- __pyx_r = __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v_item), ((PyObject *)__pyx_v_value));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_12__setitem__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_item, PyObject *__pyx_v_value) {
- int __pyx_r;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__setitem__", 0);
-
- /* "View.MemoryView":240
+ /* "View.MemoryView":375
+ * if self.obj is not None:
+ * __Pyx_ReleaseBuffer(&self.view)
+ * elif (<__pyx_buffer *> &self.view).obj == Py_None: # <<<<<<<<<<<<<<
*
- * def __setitem__(self, item, value):
- * self.memview[item] = value # <<<<<<<<<<<<<<
+ * (<__pyx_buffer *> &self.view).obj = NULL
+ */
+ __pyx_t_2 = ((((Py_buffer *)(&__pyx_v_self->view))->obj == Py_None) != 0);
+ if (__pyx_t_2) {
+
+ /* "View.MemoryView":377
+ * elif (<__pyx_buffer *> &self.view).obj == Py_None:
*
+ * (<__pyx_buffer *> &self.view).obj = NULL # <<<<<<<<<<<<<<
+ * Py_DECREF(Py_None)
*
*/
- __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_memview); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 240, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- if (unlikely(PyObject_SetItem(__pyx_t_1, __pyx_v_item, __pyx_v_value) < 0)) __PYX_ERR(1, 240, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ ((Py_buffer *)(&__pyx_v_self->view))->obj = NULL;
- /* "View.MemoryView":239
- * return self.memview[item]
+ /* "View.MemoryView":378
*
- * def __setitem__(self, item, value): # <<<<<<<<<<<<<<
- * self.memview[item] = value
+ * (<__pyx_buffer *> &self.view).obj = NULL
+ * Py_DECREF(Py_None) # <<<<<<<<<<<<<<
*
+ * cdef int i
*/
+ Py_DECREF(Py_None);
- /* function exit code */
- __pyx_r = 0;
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.array.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = -1;
- __pyx_L0:;
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "(tree fragment)":1
- * def __reduce_cython__(self): # <<<<<<<<<<<<<<
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state):
+ /* "View.MemoryView":375
+ * if self.obj is not None:
+ * __Pyx_ReleaseBuffer(&self.view)
+ * elif (<__pyx_buffer *> &self.view).obj == Py_None: # <<<<<<<<<<<<<<
+ *
+ * (<__pyx_buffer *> &self.view).obj = NULL
*/
+ }
+ __pyx_L3:;
-/* Python wrapper */
-static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyObject *__pyx_pw___pyx_array_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
- __pyx_r = __pyx_pf___pyx_array___reduce_cython__(((struct __pyx_array_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":382
+ * cdef int i
+ * global __pyx_memoryview_thread_locks_used
+ * if self.lock != NULL: # <<<<<<<<<<<<<<
+ * for i in range(__pyx_memoryview_thread_locks_used):
+ * if __pyx_memoryview_thread_locks[i] is self.lock:
+ */
+ __pyx_t_2 = ((__pyx_v_self->lock != NULL) != 0);
+ if (__pyx_t_2) {
-static PyObject *__pyx_pf___pyx_array___reduce_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+ /* "View.MemoryView":383
+ * global __pyx_memoryview_thread_locks_used
+ * if self.lock != NULL:
+ * for i in range(__pyx_memoryview_thread_locks_used): # <<<<<<<<<<<<<<
+ * if __pyx_memoryview_thread_locks[i] is self.lock:
+ * __pyx_memoryview_thread_locks_used -= 1
+ */
+ __pyx_t_3 = __pyx_memoryview_thread_locks_used;
+ __pyx_t_4 = __pyx_t_3;
+ for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
+ __pyx_v_i = __pyx_t_5;
- /* "(tree fragment)":2
- * def __reduce_cython__(self):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
- * def __setstate_cython__(self, __pyx_state):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ /* "View.MemoryView":384
+ * if self.lock != NULL:
+ * for i in range(__pyx_memoryview_thread_locks_used):
+ * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<<
+ * __pyx_memoryview_thread_locks_used -= 1
+ * if i != __pyx_memoryview_thread_locks_used:
*/
- __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_Raise(__pyx_t_1, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __PYX_ERR(1, 2, __pyx_L1_error)
+ __pyx_t_2 = (((__pyx_memoryview_thread_locks[__pyx_v_i]) == __pyx_v_self->lock) != 0);
+ if (__pyx_t_2) {
- /* "(tree fragment)":1
- * def __reduce_cython__(self): # <<<<<<<<<<<<<<
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state):
+ /* "View.MemoryView":385
+ * for i in range(__pyx_memoryview_thread_locks_used):
+ * if __pyx_memoryview_thread_locks[i] is self.lock:
+ * __pyx_memoryview_thread_locks_used -= 1 # <<<<<<<<<<<<<<
+ * if i != __pyx_memoryview_thread_locks_used:
+ * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
*/
+ __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used - 1);
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.array.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":386
+ * if __pyx_memoryview_thread_locks[i] is self.lock:
+ * __pyx_memoryview_thread_locks_used -= 1
+ * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<<
+ * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
+ * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
+ */
+ __pyx_t_2 = ((__pyx_v_i != __pyx_memoryview_thread_locks_used) != 0);
+ if (__pyx_t_2) {
-/* "(tree fragment)":3
- * def __reduce_cython__(self):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ /* "View.MemoryView":388
+ * if i != __pyx_memoryview_thread_locks_used:
+ * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
+ * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) # <<<<<<<<<<<<<<
+ * break
+ * else:
*/
+ __pyx_t_6 = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]);
+ __pyx_t_7 = (__pyx_memoryview_thread_locks[__pyx_v_i]);
-/* Python wrapper */
-static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
-static PyObject *__pyx_pw___pyx_array_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
- __pyx_r = __pyx_pf___pyx_array_2__setstate_cython__(((struct __pyx_array_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+ /* "View.MemoryView":387
+ * __pyx_memoryview_thread_locks_used -= 1
+ * if i != __pyx_memoryview_thread_locks_used:
+ * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( # <<<<<<<<<<<<<<
+ * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
+ * break
+ */
+ (__pyx_memoryview_thread_locks[__pyx_v_i]) = __pyx_t_6;
+ (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]) = __pyx_t_7;
+
+ /* "View.MemoryView":386
+ * if __pyx_memoryview_thread_locks[i] is self.lock:
+ * __pyx_memoryview_thread_locks_used -= 1
+ * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<<
+ * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
+ * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
+ */
+ }
+
+ /* "View.MemoryView":389
+ * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
+ * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
+ * break # <<<<<<<<<<<<<<
+ * else:
+ * PyThread_free_lock(self.lock)
+ */
+ goto __pyx_L6_break;
+
+ /* "View.MemoryView":384
+ * if self.lock != NULL:
+ * for i in range(__pyx_memoryview_thread_locks_used):
+ * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<<
+ * __pyx_memoryview_thread_locks_used -= 1
+ * if i != __pyx_memoryview_thread_locks_used:
+ */
+ }
+ }
+ /*else*/ {
+
+ /* "View.MemoryView":391
+ * break
+ * else:
+ * PyThread_free_lock(self.lock) # <<<<<<<<<<<<<<
+ *
+ * cdef char *get_item_pointer(memoryview self, object index) except NULL:
+ */
+ PyThread_free_lock(__pyx_v_self->lock);
+ }
+ __pyx_L6_break:;
+
+ /* "View.MemoryView":382
+ * cdef int i
+ * global __pyx_memoryview_thread_locks_used
+ * if self.lock != NULL: # <<<<<<<<<<<<<<
+ * for i in range(__pyx_memoryview_thread_locks_used):
+ * if __pyx_memoryview_thread_locks[i] is self.lock:
+ */
+ }
+
+ /* "View.MemoryView":372
+ * self.typeinfo = NULL
+ *
+ * def __dealloc__(memoryview self): # <<<<<<<<<<<<<<
+ * if self.obj is not None:
+ * __Pyx_ReleaseBuffer(&self.view)
+ */
/* function exit code */
__Pyx_RefNannyFinishContext();
- return __pyx_r;
}
-static PyObject *__pyx_pf___pyx_array_2__setstate_cython__(CYTHON_UNUSED struct __pyx_array_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
- PyObject *__pyx_r = NULL;
+/* "View.MemoryView":393
+ * PyThread_free_lock(self.lock)
+ *
+ * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<<
+ * cdef Py_ssize_t dim
+ * cdef char *itemp = self.view.buf
+ */
+
+static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) {
+ Py_ssize_t __pyx_v_dim;
+ char *__pyx_v_itemp;
+ PyObject *__pyx_v_idx = NULL;
+ char *__pyx_r;
__Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
+ Py_ssize_t __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ Py_ssize_t __pyx_t_3;
+ PyObject *(*__pyx_t_4)(PyObject *);
+ PyObject *__pyx_t_5 = NULL;
+ Py_ssize_t __pyx_t_6;
+ char *__pyx_t_7;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+ __Pyx_RefNannySetupContext("get_item_pointer", 0);
- /* "(tree fragment)":4
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
+ /* "View.MemoryView":395
+ * cdef char *get_item_pointer(memoryview self, object index) except NULL:
+ * cdef Py_ssize_t dim
+ * cdef char *itemp = self.view.buf # <<<<<<<<<<<<<<
+ *
+ * for dim, idx in enumerate(index):
*/
- __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_Raise(__pyx_t_1, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __PYX_ERR(1, 4, __pyx_L1_error)
+ __pyx_v_itemp = ((char *)__pyx_v_self->view.buf);
- /* "(tree fragment)":3
- * def __reduce_cython__(self):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ /* "View.MemoryView":397
+ * cdef char *itemp = self.view.buf
+ *
+ * for dim, idx in enumerate(index): # <<<<<<<<<<<<<<
+ * itemp = pybuffer_index(&self.view, itemp, idx, dim)
+ *
+ */
+ __pyx_t_1 = 0;
+ if (likely(PyList_CheckExact(__pyx_v_index)) || PyTuple_CheckExact(__pyx_v_index)) {
+ __pyx_t_2 = __pyx_v_index; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
+ __pyx_t_4 = NULL;
+ } else {
+ __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 397, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 397, __pyx_L1_error)
+ }
+ for (;;) {
+ if (likely(!__pyx_t_4)) {
+ if (likely(PyList_CheckExact(__pyx_t_2))) {
+ if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+ __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 397, __pyx_L1_error)
+ #else
+ __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 397, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ #endif
+ } else {
+ if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+ __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 397, __pyx_L1_error)
+ #else
+ __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 397, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ #endif
+ }
+ } else {
+ __pyx_t_5 = __pyx_t_4(__pyx_t_2);
+ if (unlikely(!__pyx_t_5)) {
+ PyObject* exc_type = PyErr_Occurred();
+ if (exc_type) {
+ if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+ else __PYX_ERR(1, 397, __pyx_L1_error)
+ }
+ break;
+ }
+ __Pyx_GOTREF(__pyx_t_5);
+ }
+ __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_5);
+ __pyx_t_5 = 0;
+ __pyx_v_dim = __pyx_t_1;
+ __pyx_t_1 = (__pyx_t_1 + 1);
+
+ /* "View.MemoryView":398
+ *
+ * for dim, idx in enumerate(index):
+ * itemp = pybuffer_index(&self.view, itemp, idx, dim) # <<<<<<<<<<<<<<
+ *
+ * return itemp
+ */
+ __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 398, __pyx_L1_error)
+ __pyx_t_7 = __pyx_pybuffer_index((&__pyx_v_self->view), __pyx_v_itemp, __pyx_t_6, __pyx_v_dim); if (unlikely(__pyx_t_7 == ((char *)NULL))) __PYX_ERR(1, 398, __pyx_L1_error)
+ __pyx_v_itemp = __pyx_t_7;
+
+ /* "View.MemoryView":397
+ * cdef char *itemp = self.view.buf
+ *
+ * for dim, idx in enumerate(index): # <<<<<<<<<<<<<<
+ * itemp = pybuffer_index(&self.view, itemp, idx, dim)
+ *
+ */
+ }
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+
+ /* "View.MemoryView":400
+ * itemp = pybuffer_index(&self.view, itemp, idx, dim)
+ *
+ * return itemp # <<<<<<<<<<<<<<
+ *
+ *
+ */
+ __pyx_r = __pyx_v_itemp;
+ goto __pyx_L0;
+
+ /* "View.MemoryView":393
+ * PyThread_free_lock(self.lock)
+ *
+ * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<<
+ * cdef Py_ssize_t dim
+ * cdef char *itemp = self.view.buf
*/
/* function exit code */
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.array.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.get_item_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
- __Pyx_XGIVEREF(__pyx_r);
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_idx);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":244
+/* "View.MemoryView":403
*
- * @cname("__pyx_array_new")
- * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<<
- * char *mode, char *buf):
- * cdef array result
+ *
+ * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<<
+ * if index is Ellipsis:
+ * return self
*/
-static struct __pyx_array_obj *__pyx_array_new(PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, char *__pyx_v_format, char *__pyx_v_mode, char *__pyx_v_buf) {
- struct __pyx_array_obj *__pyx_v_result = 0;
- struct __pyx_array_obj *__pyx_r = NULL;
+/* Python wrapper */
+static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/
+static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) {
+ PyObject *__pyx_v_have_slices = NULL;
+ PyObject *__pyx_v_indices = NULL;
+ char *__pyx_v_itemp;
+ PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
- PyObject *__pyx_t_2 = NULL;
+ int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
+ char *__pyx_t_6;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("array_cwrapper", 0);
+ __Pyx_RefNannySetupContext("__getitem__", 0);
- /* "View.MemoryView":248
- * cdef array result
+ /* "View.MemoryView":404
+ *
+ * def __getitem__(memoryview self, object index):
+ * if index is Ellipsis: # <<<<<<<<<<<<<<
+ * return self
*
- * if buf == NULL: # <<<<<<<<<<<<<<
- * result = array(shape, itemsize, format, mode.decode('ASCII'))
- * else:
*/
- __pyx_t_1 = ((__pyx_v_buf == NULL) != 0);
- if (__pyx_t_1) {
+ __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis);
+ __pyx_t_2 = (__pyx_t_1 != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":249
+ /* "View.MemoryView":405
+ * def __getitem__(memoryview self, object index):
+ * if index is Ellipsis:
+ * return self # <<<<<<<<<<<<<<
*
- * if buf == NULL:
- * result = array(shape, itemsize, format, mode.decode('ASCII')) # <<<<<<<<<<<<<<
- * else:
- * result = array(shape, itemsize, format, mode.decode('ASCII'),
+ * have_slices, indices = _unellipsify(index, self.view.ndim)
*/
- __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 249, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 249, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 249, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = PyTuple_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 249, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_INCREF(__pyx_v_shape);
- __Pyx_GIVEREF(__pyx_v_shape);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_shape);
- __Pyx_GIVEREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
- __Pyx_GIVEREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4);
- __pyx_t_2 = 0;
- __pyx_t_3 = 0;
- __pyx_t_4 = 0;
- __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 249, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_4);
- __pyx_t_4 = 0;
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)__pyx_v_self));
+ __pyx_r = ((PyObject *)__pyx_v_self);
+ goto __pyx_L0;
- /* "View.MemoryView":248
- * cdef array result
+ /* "View.MemoryView":404
+ *
+ * def __getitem__(memoryview self, object index):
+ * if index is Ellipsis: # <<<<<<<<<<<<<<
+ * return self
*
- * if buf == NULL: # <<<<<<<<<<<<<<
- * result = array(shape, itemsize, format, mode.decode('ASCII'))
- * else:
*/
- goto __pyx_L3;
}
- /* "View.MemoryView":251
- * result = array(shape, itemsize, format, mode.decode('ASCII'))
- * else:
- * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<<
- * allocate_buffer=False)
- * result.data = buf
+ /* "View.MemoryView":407
+ * return self
+ *
+ * have_slices, indices = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<<
+ *
+ * cdef char *itemp
*/
- /*else*/ {
- __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_itemsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 251, __pyx_L1_error)
+ __pyx_t_3 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 407, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ if (likely(__pyx_t_3 != Py_None)) {
+ PyObject* sequence = __pyx_t_3;
+ Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
+ if (unlikely(size != 2)) {
+ if (size > 2) __Pyx_RaiseTooManyValuesError(2);
+ else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
+ __PYX_ERR(1, 407, __pyx_L1_error)
+ }
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+ __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0);
+ __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1);
+ __Pyx_INCREF(__pyx_t_4);
+ __Pyx_INCREF(__pyx_t_5);
+ #else
+ __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 407, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = __Pyx_PyBytes_FromString(__pyx_v_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 251, __pyx_L1_error)
+ __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 407, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
- __pyx_t_3 = __Pyx_decode_c_string(__pyx_v_mode, 0, strlen(__pyx_v_mode), NULL, NULL, PyUnicode_DecodeASCII); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 251, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 251, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_INCREF(__pyx_v_shape);
- __Pyx_GIVEREF(__pyx_v_shape);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_shape);
- __Pyx_GIVEREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4);
- __Pyx_GIVEREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3);
- __pyx_t_4 = 0;
- __pyx_t_5 = 0;
- __pyx_t_3 = 0;
+ #endif
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ } else {
+ __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 407, __pyx_L1_error)
+ }
+ __pyx_v_have_slices = __pyx_t_4;
+ __pyx_t_4 = 0;
+ __pyx_v_indices = __pyx_t_5;
+ __pyx_t_5 = 0;
- /* "View.MemoryView":252
- * else:
- * result = array(shape, itemsize, format, mode.decode('ASCII'),
- * allocate_buffer=False) # <<<<<<<<<<<<<<
- * result.data = buf
+ /* "View.MemoryView":410
*
+ * cdef char *itemp
+ * if have_slices: # <<<<<<<<<<<<<<
+ * return memview_slice(self, indices)
+ * else:
*/
- __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 252, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_allocate_buffer, Py_False) < 0) __PYX_ERR(1, 252, __pyx_L1_error)
+ __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 410, __pyx_L1_error)
+ if (__pyx_t_2) {
- /* "View.MemoryView":251
- * result = array(shape, itemsize, format, mode.decode('ASCII'))
- * else:
- * result = array(shape, itemsize, format, mode.decode('ASCII'), # <<<<<<<<<<<<<<
- * allocate_buffer=False)
- * result.data = buf
+ /* "View.MemoryView":411
+ * cdef char *itemp
+ * if have_slices:
+ * return memview_slice(self, indices) # <<<<<<<<<<<<<<
+ * else:
+ * itemp = self.get_item_pointer(indices)
*/
- __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_array_type), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 251, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_v_result = ((struct __pyx_array_obj *)__pyx_t_5);
- __pyx_t_5 = 0;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 411, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":253
- * result = array(shape, itemsize, format, mode.decode('ASCII'),
- * allocate_buffer=False)
- * result.data = buf # <<<<<<<<<<<<<<
+ /* "View.MemoryView":410
*
- * return result
+ * cdef char *itemp
+ * if have_slices: # <<<<<<<<<<<<<<
+ * return memview_slice(self, indices)
+ * else:
*/
- __pyx_v_result->data = __pyx_v_buf;
}
- __pyx_L3:;
- /* "View.MemoryView":255
- * result.data = buf
- *
- * return result # <<<<<<<<<<<<<<
+ /* "View.MemoryView":413
+ * return memview_slice(self, indices)
+ * else:
+ * itemp = self.get_item_pointer(indices) # <<<<<<<<<<<<<<
+ * return self.convert_item_to_object(itemp)
*
+ */
+ /*else*/ {
+ __pyx_t_6 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_6 == ((char *)NULL))) __PYX_ERR(1, 413, __pyx_L1_error)
+ __pyx_v_itemp = __pyx_t_6;
+
+ /* "View.MemoryView":414
+ * else:
+ * itemp = self.get_item_pointer(indices)
+ * return self.convert_item_to_object(itemp) # <<<<<<<<<<<<<<
*
+ * def __setitem__(memoryview self, object index, object value):
*/
- __Pyx_XDECREF(((PyObject *)__pyx_r));
- __Pyx_INCREF(((PyObject *)__pyx_v_result));
- __pyx_r = __pyx_v_result;
- goto __pyx_L0;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 414, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+ }
- /* "View.MemoryView":244
+ /* "View.MemoryView":403
*
- * @cname("__pyx_array_new")
- * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, # <<<<<<<<<<<<<<
- * char *mode, char *buf):
- * cdef array result
+ *
+ * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<<
+ * if index is Ellipsis:
+ * return self
*/
/* function exit code */
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
- __Pyx_AddTraceback("View.MemoryView.array_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
+ __Pyx_AddTraceback("View.MemoryView.memoryview.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
__pyx_L0:;
- __Pyx_XDECREF((PyObject *)__pyx_v_result);
- __Pyx_XGIVEREF((PyObject *)__pyx_r);
+ __Pyx_XDECREF(__pyx_v_have_slices);
+ __Pyx_XDECREF(__pyx_v_indices);
+ __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":281
- * cdef class Enum(object):
- * cdef object name
- * def __init__(self, name): # <<<<<<<<<<<<<<
- * self.name = name
- * def __repr__(self):
+/* "View.MemoryView":416
+ * return self.convert_item_to_object(itemp)
+ *
+ * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<<
+ * if self.view.readonly:
+ * raise TypeError("Cannot assign to read-only memoryview")
*/
/* Python wrapper */
-static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static int __pyx_MemviewEnum___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- PyObject *__pyx_v_name = 0;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
+static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /*proto*/
+static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
int __pyx_r;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
- {
- static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,0};
- PyObject* values[1] = {0};
- if (unlikely(__pyx_kwds)) {
- Py_ssize_t kw_args;
- const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
- switch (pos_args) {
- case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- CYTHON_FALLTHROUGH;
- case 0: break;
- default: goto __pyx_L5_argtuple_error;
- }
- kw_args = PyDict_Size(__pyx_kwds);
- switch (pos_args) {
- case 0:
- if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_name)) != 0)) kw_args--;
- else goto __pyx_L5_argtuple_error;
- }
- if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(1, 281, __pyx_L3_error)
- }
- } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
- goto __pyx_L5_argtuple_error;
- } else {
- values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- }
- __pyx_v_name = values[0];
- }
- goto __pyx_L4_argument_unpacking_done;
- __pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 281, __pyx_L3_error)
- __pyx_L3_error:;
- __Pyx_AddTraceback("View.MemoryView.Enum.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __Pyx_RefNannyFinishContext();
- return -1;
- __pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), __pyx_v_name);
+ __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static int __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum___init__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v_name) {
+static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
+ PyObject *__pyx_v_have_slices = NULL;
+ PyObject *__pyx_v_obj = NULL;
int __pyx_r;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__init__", 0);
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__setitem__", 0);
+ __Pyx_INCREF(__pyx_v_index);
- /* "View.MemoryView":282
- * cdef object name
- * def __init__(self, name):
- * self.name = name # <<<<<<<<<<<<<<
- * def __repr__(self):
- * return self.name
+ /* "View.MemoryView":417
+ *
+ * def __setitem__(memoryview self, object index, object value):
+ * if self.view.readonly: # <<<<<<<<<<<<<<
+ * raise TypeError("Cannot assign to read-only memoryview")
+ *
*/
- __Pyx_INCREF(__pyx_v_name);
- __Pyx_GIVEREF(__pyx_v_name);
- __Pyx_GOTREF(__pyx_v_self->name);
- __Pyx_DECREF(__pyx_v_self->name);
- __pyx_v_self->name = __pyx_v_name;
+ __pyx_t_1 = (__pyx_v_self->view.readonly != 0);
+ if (unlikely(__pyx_t_1)) {
- /* "View.MemoryView":281
- * cdef class Enum(object):
- * cdef object name
- * def __init__(self, name): # <<<<<<<<<<<<<<
- * self.name = name
- * def __repr__(self):
+ /* "View.MemoryView":418
+ * def __setitem__(memoryview self, object index, object value):
+ * if self.view.readonly:
+ * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<<
+ *
+ * have_slices, index = _unellipsify(index, self.view.ndim)
*/
+ __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 418, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __PYX_ERR(1, 418, __pyx_L1_error)
- /* function exit code */
- __pyx_r = 0;
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":283
- * def __init__(self, name):
- * self.name = name
- * def __repr__(self): # <<<<<<<<<<<<<<
- * return self.name
+ /* "View.MemoryView":417
+ *
+ * def __setitem__(memoryview self, object index, object value):
+ * if self.view.readonly: # <<<<<<<<<<<<<<
+ * raise TypeError("Cannot assign to read-only memoryview")
*
*/
+ }
-/* Python wrapper */
-static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_MemviewEnum___repr__(PyObject *__pyx_v_self) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
- __pyx_r = __pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_MemviewEnum___pyx_pf_15View_dot_MemoryView_4Enum_2__repr__(struct __pyx_MemviewEnum_obj *__pyx_v_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__repr__", 0);
-
- /* "View.MemoryView":284
- * self.name = name
- * def __repr__(self):
- * return self.name # <<<<<<<<<<<<<<
+ /* "View.MemoryView":420
+ * raise TypeError("Cannot assign to read-only memoryview")
*
- * cdef generic = Enum("")
+ * have_slices, index = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<<
+ *
+ * if have_slices:
*/
- __Pyx_XDECREF(__pyx_r);
- __Pyx_INCREF(__pyx_v_self->name);
- __pyx_r = __pyx_v_self->name;
- goto __pyx_L0;
+ __pyx_t_2 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 420, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ if (likely(__pyx_t_2 != Py_None)) {
+ PyObject* sequence = __pyx_t_2;
+ Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
+ if (unlikely(size != 2)) {
+ if (size > 2) __Pyx_RaiseTooManyValuesError(2);
+ else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
+ __PYX_ERR(1, 420, __pyx_L1_error)
+ }
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+ __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0);
+ __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1);
+ __Pyx_INCREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_t_4);
+ #else
+ __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 420, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 420, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ #endif
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ } else {
+ __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 420, __pyx_L1_error)
+ }
+ __pyx_v_have_slices = __pyx_t_3;
+ __pyx_t_3 = 0;
+ __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_4);
+ __pyx_t_4 = 0;
- /* "View.MemoryView":283
- * def __init__(self, name):
- * self.name = name
- * def __repr__(self): # <<<<<<<<<<<<<<
- * return self.name
+ /* "View.MemoryView":422
+ * have_slices, index = _unellipsify(index, self.view.ndim)
*
+ * if have_slices: # <<<<<<<<<<<<<<
+ * obj = self.is_slice(value)
+ * if obj:
*/
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 422, __pyx_L1_error)
+ if (__pyx_t_1) {
- /* function exit code */
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "(tree fragment)":1
- * def __reduce_cython__(self): # <<<<<<<<<<<<<<
- * cdef tuple state
- * cdef object _dict
+ /* "View.MemoryView":423
+ *
+ * if have_slices:
+ * obj = self.is_slice(value) # <<<<<<<<<<<<<<
+ * if obj:
+ * self.setitem_slice_assignment(self[index], obj)
*/
+ __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 423, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_v_obj = __pyx_t_2;
+ __pyx_t_2 = 0;
-/* Python wrapper */
-static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyObject *__pyx_pw___pyx_MemviewEnum_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
- __pyx_r = __pyx_pf___pyx_MemviewEnum___reduce_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":424
+ * if have_slices:
+ * obj = self.is_slice(value)
+ * if obj: # <<<<<<<<<<<<<<
+ * self.setitem_slice_assignment(self[index], obj)
+ * else:
+ */
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 424, __pyx_L1_error)
+ if (__pyx_t_1) {
-static PyObject *__pyx_pf___pyx_MemviewEnum___reduce_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self) {
- PyObject *__pyx_v_state = 0;
- PyObject *__pyx_v__dict = 0;
- int __pyx_v_use_setstate;
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_t_2;
- int __pyx_t_3;
- PyObject *__pyx_t_4 = NULL;
- PyObject *__pyx_t_5 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+ /* "View.MemoryView":425
+ * obj = self.is_slice(value)
+ * if obj:
+ * self.setitem_slice_assignment(self[index], obj) # <<<<<<<<<<<<<<
+ * else:
+ * self.setitem_slice_assign_scalar(self[index], value)
+ */
+ __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 425, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_2, __pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 425, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- /* "(tree fragment)":5
- * cdef object _dict
- * cdef bint use_setstate
- * state = (self.name,) # <<<<<<<<<<<<<<
- * _dict = getattr(self, '__dict__', None)
- * if _dict is not None:
+ /* "View.MemoryView":424
+ * if have_slices:
+ * obj = self.is_slice(value)
+ * if obj: # <<<<<<<<<<<<<<
+ * self.setitem_slice_assignment(self[index], obj)
+ * else:
*/
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_INCREF(__pyx_v_self->name);
- __Pyx_GIVEREF(__pyx_v_self->name);
- PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->name);
- __pyx_v_state = ((PyObject*)__pyx_t_1);
- __pyx_t_1 = 0;
+ goto __pyx_L5;
+ }
- /* "(tree fragment)":6
- * cdef bint use_setstate
- * state = (self.name,)
- * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<<
- * if _dict is not None:
- * state += (_dict,)
- */
- __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_v__dict = __pyx_t_1;
- __pyx_t_1 = 0;
-
- /* "(tree fragment)":7
- * state = (self.name,)
- * _dict = getattr(self, '__dict__', None)
- * if _dict is not None: # <<<<<<<<<<<<<<
- * state += (_dict,)
- * use_setstate = True
- */
- __pyx_t_2 = (__pyx_v__dict != Py_None);
- __pyx_t_3 = (__pyx_t_2 != 0);
- if (__pyx_t_3) {
-
- /* "(tree fragment)":8
- * _dict = getattr(self, '__dict__', None)
- * if _dict is not None:
- * state += (_dict,) # <<<<<<<<<<<<<<
- * use_setstate = True
- * else:
- */
- __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 8, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_INCREF(__pyx_v__dict);
- __Pyx_GIVEREF(__pyx_v__dict);
- PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict);
- __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 8, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_4));
- __pyx_t_4 = 0;
-
- /* "(tree fragment)":9
- * if _dict is not None:
- * state += (_dict,)
- * use_setstate = True # <<<<<<<<<<<<<<
- * else:
- * use_setstate = self.name is not None
- */
- __pyx_v_use_setstate = 1;
-
- /* "(tree fragment)":7
- * state = (self.name,)
- * _dict = getattr(self, '__dict__', None)
- * if _dict is not None: # <<<<<<<<<<<<<<
- * state += (_dict,)
- * use_setstate = True
- */
- goto __pyx_L3;
- }
-
- /* "(tree fragment)":11
- * use_setstate = True
- * else:
- * use_setstate = self.name is not None # <<<<<<<<<<<<<<
- * if use_setstate:
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
- */
- /*else*/ {
- __pyx_t_3 = (__pyx_v_self->name != Py_None);
- __pyx_v_use_setstate = __pyx_t_3;
- }
- __pyx_L3:;
-
- /* "(tree fragment)":12
- * else:
- * use_setstate = self.name is not None
- * if use_setstate: # <<<<<<<<<<<<<<
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
- * else:
- */
- __pyx_t_3 = (__pyx_v_use_setstate != 0);
- if (__pyx_t_3) {
-
- /* "(tree fragment)":13
- * use_setstate = self.name is not None
- * if use_setstate:
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state # <<<<<<<<<<<<<<
- * else:
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
+ /* "View.MemoryView":427
+ * self.setitem_slice_assignment(self[index], obj)
+ * else:
+ * self.setitem_slice_assign_scalar(self[index], value) # <<<<<<<<<<<<<<
+ * else:
+ * self.setitem_indexed(index, value)
*/
- __Pyx_XDECREF(__pyx_r);
- __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 13, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
- __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
- PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
- __Pyx_INCREF(__pyx_int_184977713);
- __Pyx_GIVEREF(__pyx_int_184977713);
- PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713);
- __Pyx_INCREF(Py_None);
- __Pyx_GIVEREF(Py_None);
- PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None);
- __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
- __Pyx_GIVEREF(__pyx_t_1);
- PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
- __Pyx_INCREF(__pyx_v_state);
- __Pyx_GIVEREF(__pyx_v_state);
- PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state);
- __pyx_t_4 = 0;
- __pyx_t_1 = 0;
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
- goto __pyx_L0;
+ /*else*/ {
+ __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 427, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_memoryview_type))))) __PYX_ERR(1, 427, __pyx_L1_error)
+ __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_4), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 427, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ }
+ __pyx_L5:;
- /* "(tree fragment)":12
- * else:
- * use_setstate = self.name is not None
- * if use_setstate: # <<<<<<<<<<<<<<
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
- * else:
+ /* "View.MemoryView":422
+ * have_slices, index = _unellipsify(index, self.view.ndim)
+ *
+ * if have_slices: # <<<<<<<<<<<<<<
+ * obj = self.is_slice(value)
+ * if obj:
*/
+ goto __pyx_L4;
}
- /* "(tree fragment)":15
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, None), state
- * else:
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, state) # <<<<<<<<<<<<<<
- * def __setstate_cython__(self, __pyx_state):
- * __pyx_unpickle_Enum__set_state(self, __pyx_state)
+ /* "View.MemoryView":429
+ * self.setitem_slice_assign_scalar(self[index], value)
+ * else:
+ * self.setitem_indexed(index, value) # <<<<<<<<<<<<<<
+ *
+ * cdef is_slice(self, obj):
*/
/*else*/ {
- __Pyx_XDECREF(__pyx_r);
- __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_Enum); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 15, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
- __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
- PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
- __Pyx_INCREF(__pyx_int_184977713);
- __Pyx_GIVEREF(__pyx_int_184977713);
- PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_184977713);
- __Pyx_INCREF(__pyx_v_state);
- __Pyx_GIVEREF(__pyx_v_state);
- PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state);
- __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 15, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_GIVEREF(__pyx_t_5);
- PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_1);
- PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
- __pyx_t_5 = 0;
- __pyx_t_1 = 0;
- __pyx_r = __pyx_t_4;
- __pyx_t_4 = 0;
- goto __pyx_L0;
+ __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 429, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
}
+ __pyx_L4:;
- /* "(tree fragment)":1
- * def __reduce_cython__(self): # <<<<<<<<<<<<<<
- * cdef tuple state
- * cdef object _dict
+ /* "View.MemoryView":416
+ * return self.convert_item_to_object(itemp)
+ *
+ * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<<
+ * if self.view.readonly:
+ * raise TypeError("Cannot assign to read-only memoryview")
*/
/* function exit code */
+ __pyx_r = 0;
+ goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
- __Pyx_XDECREF(__pyx_t_5);
- __Pyx_AddTraceback("View.MemoryView.Enum.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
+ __Pyx_AddTraceback("View.MemoryView.memoryview.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
__pyx_L0:;
- __Pyx_XDECREF(__pyx_v_state);
- __Pyx_XDECREF(__pyx_v__dict);
- __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_XDECREF(__pyx_v_have_slices);
+ __Pyx_XDECREF(__pyx_v_obj);
+ __Pyx_XDECREF(__pyx_v_index);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "(tree fragment)":16
- * else:
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
- * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
- * __pyx_unpickle_Enum__set_state(self, __pyx_state)
+/* "View.MemoryView":431
+ * self.setitem_indexed(index, value)
+ *
+ * cdef is_slice(self, obj): # <<<<<<<<<<<<<<
+ * if not isinstance(obj, memoryview):
+ * try:
*/
-/* Python wrapper */
-static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
-static PyObject *__pyx_pw___pyx_MemviewEnum_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
- __pyx_r = __pyx_pf___pyx_MemviewEnum_2__setstate_cython__(((struct __pyx_MemviewEnum_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf___pyx_MemviewEnum_2__setstate_cython__(struct __pyx_MemviewEnum_obj *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
+ int __pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ PyObject *__pyx_t_6 = NULL;
+ PyObject *__pyx_t_7 = NULL;
+ PyObject *__pyx_t_8 = NULL;
+ int __pyx_t_9;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+ __Pyx_RefNannySetupContext("is_slice", 0);
+ __Pyx_INCREF(__pyx_v_obj);
- /* "(tree fragment)":17
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
- * def __setstate_cython__(self, __pyx_state):
- * __pyx_unpickle_Enum__set_state(self, __pyx_state) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":432
+ *
+ * cdef is_slice(self, obj):
+ * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<<
+ * try:
+ * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
*/
- if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_v___pyx_state)->tp_name), 0))) __PYX_ERR(1, 17, __pyx_L1_error)
- __pyx_t_1 = __pyx_unpickle_Enum__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_memoryview_type);
+ __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
+ if (__pyx_t_2) {
- /* "(tree fragment)":16
- * else:
- * return __pyx_unpickle_Enum, (type(self), 0xb068931, state)
- * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
- * __pyx_unpickle_Enum__set_state(self, __pyx_state)
+ /* "View.MemoryView":433
+ * cdef is_slice(self, obj):
+ * if not isinstance(obj, memoryview):
+ * try: # <<<<<<<<<<<<<<
+ * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
+ * self.dtype_is_object)
*/
+ {
+ __Pyx_PyThreadState_declare
+ __Pyx_PyThreadState_assign
+ __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
+ __Pyx_XGOTREF(__pyx_t_3);
+ __Pyx_XGOTREF(__pyx_t_4);
+ __Pyx_XGOTREF(__pyx_t_5);
+ /*try:*/ {
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.Enum.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":434
+ * if not isinstance(obj, memoryview):
+ * try:
+ * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<<
+ * self.dtype_is_object)
+ * except TypeError:
+ */
+ __pyx_t_6 = __Pyx_PyInt_From_int(((__pyx_v_self->flags & (~PyBUF_WRITABLE)) | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 434, __pyx_L4_error)
+ __Pyx_GOTREF(__pyx_t_6);
-/* "View.MemoryView":298
- *
- * @cname('__pyx_align_pointer')
- * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<<
- * "Align pointer memory on a given boundary"
- * cdef Py_intptr_t aligned_p = memory
+ /* "View.MemoryView":435
+ * try:
+ * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
+ * self.dtype_is_object) # <<<<<<<<<<<<<<
+ * except TypeError:
+ * return None
*/
+ __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 435, __pyx_L4_error)
+ __Pyx_GOTREF(__pyx_t_7);
-static void *__pyx_align_pointer(void *__pyx_v_memory, size_t __pyx_v_alignment) {
- Py_intptr_t __pyx_v_aligned_p;
- size_t __pyx_v_offset;
- void *__pyx_r;
- int __pyx_t_1;
+ /* "View.MemoryView":434
+ * if not isinstance(obj, memoryview):
+ * try:
+ * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<<
+ * self.dtype_is_object)
+ * except TypeError:
+ */
+ __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 434, __pyx_L4_error)
+ __Pyx_GOTREF(__pyx_t_8);
+ __Pyx_INCREF(__pyx_v_obj);
+ __Pyx_GIVEREF(__pyx_v_obj);
+ PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj);
+ __Pyx_GIVEREF(__pyx_t_6);
+ PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
+ __Pyx_GIVEREF(__pyx_t_7);
+ PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
+ __pyx_t_6 = 0;
+ __pyx_t_7 = 0;
+ __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 434, __pyx_L4_error)
+ __Pyx_GOTREF(__pyx_t_7);
+ __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+ __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_7);
+ __pyx_t_7 = 0;
- /* "View.MemoryView":300
- * cdef void *align_pointer(void *memory, size_t alignment) nogil:
- * "Align pointer memory on a given boundary"
- * cdef Py_intptr_t aligned_p = memory # <<<<<<<<<<<<<<
- * cdef size_t offset
- *
+ /* "View.MemoryView":433
+ * cdef is_slice(self, obj):
+ * if not isinstance(obj, memoryview):
+ * try: # <<<<<<<<<<<<<<
+ * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
+ * self.dtype_is_object)
*/
- __pyx_v_aligned_p = ((Py_intptr_t)__pyx_v_memory);
+ }
+ __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+ goto __pyx_L9_try_end;
+ __pyx_L4_error:;
+ __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+ __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
- /* "View.MemoryView":304
- *
- * with cython.cdivision(True):
- * offset = aligned_p % alignment # <<<<<<<<<<<<<<
+ /* "View.MemoryView":436
+ * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
+ * self.dtype_is_object)
+ * except TypeError: # <<<<<<<<<<<<<<
+ * return None
*
- * if offset > 0:
*/
- __pyx_v_offset = (__pyx_v_aligned_p % __pyx_v_alignment);
+ __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
+ if (__pyx_t_9) {
+ __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(1, 436, __pyx_L6_except_error)
+ __Pyx_GOTREF(__pyx_t_7);
+ __Pyx_GOTREF(__pyx_t_8);
+ __Pyx_GOTREF(__pyx_t_6);
- /* "View.MemoryView":306
- * offset = aligned_p % alignment
- *
- * if offset > 0: # <<<<<<<<<<<<<<
- * aligned_p += alignment - offset
+ /* "View.MemoryView":437
+ * self.dtype_is_object)
+ * except TypeError:
+ * return None # <<<<<<<<<<<<<<
*
+ * return obj
*/
- __pyx_t_1 = ((__pyx_v_offset > 0) != 0);
- if (__pyx_t_1) {
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+ __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+ goto __pyx_L7_except_return;
+ }
+ goto __pyx_L6_except_error;
+ __pyx_L6_except_error:;
- /* "View.MemoryView":307
- *
- * if offset > 0:
- * aligned_p += alignment - offset # <<<<<<<<<<<<<<
- *
- * return aligned_p
+ /* "View.MemoryView":433
+ * cdef is_slice(self, obj):
+ * if not isinstance(obj, memoryview):
+ * try: # <<<<<<<<<<<<<<
+ * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
+ * self.dtype_is_object)
*/
- __pyx_v_aligned_p = (__pyx_v_aligned_p + (__pyx_v_alignment - __pyx_v_offset));
+ __Pyx_XGIVEREF(__pyx_t_3);
+ __Pyx_XGIVEREF(__pyx_t_4);
+ __Pyx_XGIVEREF(__pyx_t_5);
+ __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
+ goto __pyx_L1_error;
+ __pyx_L7_except_return:;
+ __Pyx_XGIVEREF(__pyx_t_3);
+ __Pyx_XGIVEREF(__pyx_t_4);
+ __Pyx_XGIVEREF(__pyx_t_5);
+ __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
+ goto __pyx_L0;
+ __pyx_L9_try_end:;
+ }
- /* "View.MemoryView":306
- * offset = aligned_p % alignment
- *
- * if offset > 0: # <<<<<<<<<<<<<<
- * aligned_p += alignment - offset
+ /* "View.MemoryView":432
*
+ * cdef is_slice(self, obj):
+ * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<<
+ * try:
+ * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
*/
}
- /* "View.MemoryView":309
- * aligned_p += alignment - offset
- *
- * return aligned_p # <<<<<<<<<<<<<<
+ /* "View.MemoryView":439
+ * return None
*
+ * return obj # <<<<<<<<<<<<<<
*
+ * cdef setitem_slice_assignment(self, dst, src):
*/
- __pyx_r = ((void *)__pyx_v_aligned_p);
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(__pyx_v_obj);
+ __pyx_r = __pyx_v_obj;
goto __pyx_L0;
- /* "View.MemoryView":298
+ /* "View.MemoryView":431
+ * self.setitem_indexed(index, value)
*
- * @cname('__pyx_align_pointer')
- * cdef void *align_pointer(void *memory, size_t alignment) nogil: # <<<<<<<<<<<<<<
- * "Align pointer memory on a given boundary"
- * cdef Py_intptr_t aligned_p = memory
+ * cdef is_slice(self, obj): # <<<<<<<<<<<<<<
+ * if not isinstance(obj, memoryview):
+ * try:
*/
/* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_XDECREF(__pyx_t_7);
+ __Pyx_XDECREF(__pyx_t_8);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
__pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_obj);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":345
- * cdef __Pyx_TypeInfo *typeinfo
+/* "View.MemoryView":441
+ * return obj
*
- * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<<
- * self.obj = obj
- * self.flags = flags
+ * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice dst_slice
+ * cdef __Pyx_memviewslice src_slice
*/
-/* Python wrapper */
-static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static int __pyx_memoryview___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
- PyObject *__pyx_v_obj = 0;
- int __pyx_v_flags;
- int __pyx_v_dtype_is_object;
+static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src) {
+ __Pyx_memviewslice __pyx_v_dst_slice;
+ __Pyx_memviewslice __pyx_v_src_slice;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_memviewslice *__pyx_t_1;
+ __Pyx_memviewslice *__pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_t_4;
+ int __pyx_t_5;
+ int __pyx_t_6;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- int __pyx_r;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
- {
- static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_obj,&__pyx_n_s_flags,&__pyx_n_s_dtype_is_object,0};
- PyObject* values[3] = {0,0,0};
- if (unlikely(__pyx_kwds)) {
- Py_ssize_t kw_args;
- const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
- switch (pos_args) {
- case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
- CYTHON_FALLTHROUGH;
- case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- CYTHON_FALLTHROUGH;
- case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- CYTHON_FALLTHROUGH;
- case 0: break;
- default: goto __pyx_L5_argtuple_error;
- }
- kw_args = PyDict_Size(__pyx_kwds);
- switch (pos_args) {
- case 0:
- if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_obj)) != 0)) kw_args--;
- else goto __pyx_L5_argtuple_error;
- CYTHON_FALLTHROUGH;
- case 1:
- if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_flags)) != 0)) kw_args--;
- else {
- __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, 1); __PYX_ERR(1, 345, __pyx_L3_error)
- }
- CYTHON_FALLTHROUGH;
- case 2:
- if (kw_args > 0) {
- PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dtype_is_object);
- if (value) { values[2] = value; kw_args--; }
- }
- }
- if (unlikely(kw_args > 0)) {
- if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(1, 345, __pyx_L3_error)
- }
- } else {
- switch (PyTuple_GET_SIZE(__pyx_args)) {
- case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
- CYTHON_FALLTHROUGH;
- case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
- values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
- break;
- default: goto __pyx_L5_argtuple_error;
- }
- }
- __pyx_v_obj = values[0];
- __pyx_v_flags = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_flags == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 345, __pyx_L3_error)
- if (values[2]) {
- __pyx_v_dtype_is_object = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_dtype_is_object == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 345, __pyx_L3_error)
- } else {
- __pyx_v_dtype_is_object = ((int)0);
- }
- }
- goto __pyx_L4_argument_unpacking_done;
- __pyx_L5_argtuple_error:;
- __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 345, __pyx_L3_error)
- __pyx_L3_error:;
- __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __Pyx_RefNannyFinishContext();
- return -1;
- __pyx_L4_argument_unpacking_done:;
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_obj, __pyx_v_flags, __pyx_v_dtype_is_object);
+ __Pyx_RefNannySetupContext("setitem_slice_assignment", 0);
+
+ /* "View.MemoryView":445
+ * cdef __Pyx_memviewslice src_slice
+ *
+ * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<<
+ * get_slice_from_memview(dst, &dst_slice)[0],
+ * src.ndim, dst.ndim, self.dtype_is_object)
+ */
+ if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) __PYX_ERR(1, 445, __pyx_L1_error)
+ __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_src), (&__pyx_v_src_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 445, __pyx_L1_error)
+
+ /* "View.MemoryView":446
+ *
+ * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],
+ * get_slice_from_memview(dst, &dst_slice)[0], # <<<<<<<<<<<<<<
+ * src.ndim, dst.ndim, self.dtype_is_object)
+ *
+ */
+ if (!(likely(((__pyx_v_dst) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_dst, __pyx_memoryview_type))))) __PYX_ERR(1, 446, __pyx_L1_error)
+ __pyx_t_2 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_dst), (&__pyx_v_dst_slice)); if (unlikely(__pyx_t_2 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 446, __pyx_L1_error)
+
+ /* "View.MemoryView":447
+ * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],
+ * get_slice_from_memview(dst, &dst_slice)[0],
+ * src.ndim, dst.ndim, self.dtype_is_object) # <<<<<<<<<<<<<<
+ *
+ * cdef setitem_slice_assign_scalar(self, memoryview dst, value):
+ */
+ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_src, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 447, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 447, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dst, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 447, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 447, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+
+ /* "View.MemoryView":445
+ * cdef __Pyx_memviewslice src_slice
+ *
+ * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<<
+ * get_slice_from_memview(dst, &dst_slice)[0],
+ * src.ndim, dst.ndim, self.dtype_is_object)
+ */
+ __pyx_t_6 = __pyx_memoryview_copy_contents((__pyx_t_1[0]), (__pyx_t_2[0]), __pyx_t_4, __pyx_t_5, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 445, __pyx_L1_error)
+
+ /* "View.MemoryView":441
+ * return obj
+ *
+ * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice dst_slice
+ * cdef __Pyx_memviewslice src_slice
+ */
/* function exit code */
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview___cinit__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj, int __pyx_v_flags, int __pyx_v_dtype_is_object) {
- int __pyx_r;
+/* "View.MemoryView":449
+ * src.ndim, dst.ndim, self.dtype_is_object)
+ *
+ * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<<
+ * cdef int array[128]
+ * cdef void *tmp = NULL
+ */
+
+static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value) {
+ int __pyx_v_array[0x80];
+ void *__pyx_v_tmp;
+ void *__pyx_v_item;
+ __Pyx_memviewslice *__pyx_v_dst_slice;
+ __Pyx_memviewslice __pyx_v_tmp_slice;
+ PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- int __pyx_t_1;
+ __Pyx_memviewslice *__pyx_t_1;
int __pyx_t_2;
- int __pyx_t_3;
+ PyObject *__pyx_t_3 = NULL;
int __pyx_t_4;
+ int __pyx_t_5;
+ char const *__pyx_t_6;
+ PyObject *__pyx_t_7 = NULL;
+ PyObject *__pyx_t_8 = NULL;
+ PyObject *__pyx_t_9 = NULL;
+ PyObject *__pyx_t_10 = NULL;
+ PyObject *__pyx_t_11 = NULL;
+ PyObject *__pyx_t_12 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__cinit__", 0);
+ __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0);
- /* "View.MemoryView":346
+ /* "View.MemoryView":451
+ * cdef setitem_slice_assign_scalar(self, memoryview dst, value):
+ * cdef int array[128]
+ * cdef void *tmp = NULL # <<<<<<<<<<<<<<
+ * cdef void *item
*
- * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):
- * self.obj = obj # <<<<<<<<<<<<<<
- * self.flags = flags
- * if type(self) is memoryview or obj is not None:
*/
- __Pyx_INCREF(__pyx_v_obj);
- __Pyx_GIVEREF(__pyx_v_obj);
- __Pyx_GOTREF(__pyx_v_self->obj);
- __Pyx_DECREF(__pyx_v_self->obj);
- __pyx_v_self->obj = __pyx_v_obj;
+ __pyx_v_tmp = NULL;
- /* "View.MemoryView":347
- * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False):
- * self.obj = obj
- * self.flags = flags # <<<<<<<<<<<<<<
- * if type(self) is memoryview or obj is not None:
- * __Pyx_GetBuffer(obj, &self.view, flags)
+ /* "View.MemoryView":456
+ * cdef __Pyx_memviewslice *dst_slice
+ * cdef __Pyx_memviewslice tmp_slice
+ * dst_slice = get_slice_from_memview(dst, &tmp_slice) # <<<<<<<<<<<<<<
+ *
+ * if self.view.itemsize > sizeof(array):
*/
- __pyx_v_self->flags = __pyx_v_flags;
+ __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_dst, (&__pyx_v_tmp_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 456, __pyx_L1_error)
+ __pyx_v_dst_slice = __pyx_t_1;
- /* "View.MemoryView":348
- * self.obj = obj
- * self.flags = flags
- * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<<
- * __Pyx_GetBuffer(obj, &self.view, flags)
- * if self.view.obj == NULL:
+ /* "View.MemoryView":458
+ * dst_slice = get_slice_from_memview(dst, &tmp_slice)
+ *
+ * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<<
+ * tmp = PyMem_Malloc(self.view.itemsize)
+ * if tmp == NULL:
*/
- __pyx_t_2 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_memoryview_type));
- __pyx_t_3 = (__pyx_t_2 != 0);
- if (!__pyx_t_3) {
- } else {
- __pyx_t_1 = __pyx_t_3;
- goto __pyx_L4_bool_binop_done;
- }
- __pyx_t_3 = (__pyx_v_obj != Py_None);
- __pyx_t_2 = (__pyx_t_3 != 0);
- __pyx_t_1 = __pyx_t_2;
- __pyx_L4_bool_binop_done:;
- if (__pyx_t_1) {
+ __pyx_t_2 = ((((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":349
- * self.flags = flags
- * if type(self) is memoryview or obj is not None:
- * __Pyx_GetBuffer(obj, &self.view, flags) # <<<<<<<<<<<<<<
- * if self.view.obj == NULL:
- * (<__pyx_buffer *> &self.view).obj = Py_None
+ /* "View.MemoryView":459
+ *
+ * if self.view.itemsize > sizeof(array):
+ * tmp = PyMem_Malloc(self.view.itemsize) # <<<<<<<<<<<<<<
+ * if tmp == NULL:
+ * raise MemoryError
*/
- __pyx_t_4 = __Pyx_GetBuffer(__pyx_v_obj, (&__pyx_v_self->view), __pyx_v_flags); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 349, __pyx_L1_error)
+ __pyx_v_tmp = PyMem_Malloc(__pyx_v_self->view.itemsize);
- /* "View.MemoryView":350
- * if type(self) is memoryview or obj is not None:
- * __Pyx_GetBuffer(obj, &self.view, flags)
- * if self.view.obj == NULL: # <<<<<<<<<<<<<<
- * (<__pyx_buffer *> &self.view).obj = Py_None
- * Py_INCREF(Py_None)
+ /* "View.MemoryView":460
+ * if self.view.itemsize > sizeof(array):
+ * tmp = PyMem_Malloc(self.view.itemsize)
+ * if tmp == NULL: # <<<<<<<<<<<<<<
+ * raise MemoryError
+ * item = tmp
*/
- __pyx_t_1 = ((((PyObject *)__pyx_v_self->view.obj) == NULL) != 0);
- if (__pyx_t_1) {
+ __pyx_t_2 = ((__pyx_v_tmp == NULL) != 0);
+ if (unlikely(__pyx_t_2)) {
- /* "View.MemoryView":351
- * __Pyx_GetBuffer(obj, &self.view, flags)
- * if self.view.obj == NULL:
- * (<__pyx_buffer *> &self.view).obj = Py_None # <<<<<<<<<<<<<<
- * Py_INCREF(Py_None)
- *
+ /* "View.MemoryView":461
+ * tmp = PyMem_Malloc(self.view.itemsize)
+ * if tmp == NULL:
+ * raise MemoryError # <<<<<<<<<<<<<<
+ * item = tmp
+ * else:
*/
- ((Py_buffer *)(&__pyx_v_self->view))->obj = Py_None;
+ PyErr_NoMemory(); __PYX_ERR(1, 461, __pyx_L1_error)
- /* "View.MemoryView":352
- * if self.view.obj == NULL:
- * (<__pyx_buffer *> &self.view).obj = Py_None
- * Py_INCREF(Py_None) # <<<<<<<<<<<<<<
- *
- * global __pyx_memoryview_thread_locks_used
- */
- Py_INCREF(Py_None);
-
- /* "View.MemoryView":350
- * if type(self) is memoryview or obj is not None:
- * __Pyx_GetBuffer(obj, &self.view, flags)
- * if self.view.obj == NULL: # <<<<<<<<<<<<<<
- * (<__pyx_buffer *> &self.view).obj = Py_None
- * Py_INCREF(Py_None)
+ /* "View.MemoryView":460
+ * if self.view.itemsize > sizeof(array):
+ * tmp = PyMem_Malloc(self.view.itemsize)
+ * if tmp == NULL: # <<<<<<<<<<<<<<
+ * raise MemoryError
+ * item = tmp
*/
}
- /* "View.MemoryView":348
- * self.obj = obj
- * self.flags = flags
- * if type(self) is memoryview or obj is not None: # <<<<<<<<<<<<<<
- * __Pyx_GetBuffer(obj, &self.view, flags)
- * if self.view.obj == NULL:
+ /* "View.MemoryView":462
+ * if tmp == NULL:
+ * raise MemoryError
+ * item = tmp # <<<<<<<<<<<<<<
+ * else:
+ * item = array
*/
- }
+ __pyx_v_item = __pyx_v_tmp;
- /* "View.MemoryView":355
+ /* "View.MemoryView":458
+ * dst_slice = get_slice_from_memview(dst, &tmp_slice)
*
- * global __pyx_memoryview_thread_locks_used
- * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<<
- * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
- * __pyx_memoryview_thread_locks_used += 1
- */
- __pyx_t_1 = ((__pyx_memoryview_thread_locks_used < 8) != 0);
- if (__pyx_t_1) {
-
- /* "View.MemoryView":356
- * global __pyx_memoryview_thread_locks_used
- * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
- * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] # <<<<<<<<<<<<<<
- * __pyx_memoryview_thread_locks_used += 1
- * if self.lock is NULL:
- */
- __pyx_v_self->lock = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]);
-
- /* "View.MemoryView":357
- * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED:
- * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
- * __pyx_memoryview_thread_locks_used += 1 # <<<<<<<<<<<<<<
- * if self.lock is NULL:
- * self.lock = PyThread_allocate_lock()
+ * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<<
+ * tmp = PyMem_Malloc(self.view.itemsize)
+ * if tmp == NULL:
*/
- __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used + 1);
+ goto __pyx_L3;
+ }
- /* "View.MemoryView":355
+ /* "View.MemoryView":464
+ * item = tmp
+ * else:
+ * item = array # <<<<<<<<<<<<<<
*
- * global __pyx_memoryview_thread_locks_used
- * if __pyx_memoryview_thread_locks_used < THREAD_LOCKS_PREALLOCATED: # <<<<<<<<<<<<<<
- * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
- * __pyx_memoryview_thread_locks_used += 1
+ * try:
*/
+ /*else*/ {
+ __pyx_v_item = ((void *)__pyx_v_array);
}
+ __pyx_L3:;
- /* "View.MemoryView":358
- * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
- * __pyx_memoryview_thread_locks_used += 1
- * if self.lock is NULL: # <<<<<<<<<<<<<<
- * self.lock = PyThread_allocate_lock()
- * if self.lock is NULL:
- */
- __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0);
- if (__pyx_t_1) {
-
- /* "View.MemoryView":359
- * __pyx_memoryview_thread_locks_used += 1
- * if self.lock is NULL:
- * self.lock = PyThread_allocate_lock() # <<<<<<<<<<<<<<
- * if self.lock is NULL:
- * raise MemoryError
+ /* "View.MemoryView":466
+ * item = array
+ *
+ * try: # <<<<<<<<<<<<<<
+ * if self.dtype_is_object:
+ * ( item)[0] = value
*/
- __pyx_v_self->lock = PyThread_allocate_lock();
+ /*try:*/ {
- /* "View.MemoryView":360
- * if self.lock is NULL:
- * self.lock = PyThread_allocate_lock()
- * if self.lock is NULL: # <<<<<<<<<<<<<<
- * raise MemoryError
+ /* "View.MemoryView":467
*
+ * try:
+ * if self.dtype_is_object: # <<<<<<<<<<<<<<
+ * ( item)[0] = value
+ * else:
*/
- __pyx_t_1 = ((__pyx_v_self->lock == NULL) != 0);
- if (unlikely(__pyx_t_1)) {
+ __pyx_t_2 = (__pyx_v_self->dtype_is_object != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":361
- * self.lock = PyThread_allocate_lock()
- * if self.lock is NULL:
- * raise MemoryError # <<<<<<<<<<<<<<
- *
- * if flags & PyBUF_FORMAT:
+ /* "View.MemoryView":468
+ * try:
+ * if self.dtype_is_object:
+ * ( item)[0] = value # <<<<<<<<<<<<<<
+ * else:
+ * self.assign_item_from_object( item, value)
*/
- PyErr_NoMemory(); __PYX_ERR(1, 361, __pyx_L1_error)
+ (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value);
- /* "View.MemoryView":360
- * if self.lock is NULL:
- * self.lock = PyThread_allocate_lock()
- * if self.lock is NULL: # <<<<<<<<<<<<<<
- * raise MemoryError
+ /* "View.MemoryView":467
*
+ * try:
+ * if self.dtype_is_object: # <<<<<<<<<<<<<<
+ * ( item)[0] = value
+ * else:
*/
+ goto __pyx_L8;
}
- /* "View.MemoryView":358
- * self.lock = __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]
- * __pyx_memoryview_thread_locks_used += 1
- * if self.lock is NULL: # <<<<<<<<<<<<<<
- * self.lock = PyThread_allocate_lock()
- * if self.lock is NULL:
- */
- }
-
- /* "View.MemoryView":363
- * raise MemoryError
+ /* "View.MemoryView":470
+ * ( item)[0] = value
+ * else:
+ * self.assign_item_from_object( item, value) # <<<<<<<<<<<<<<
*
- * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
- * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
- * else:
- */
- __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
- if (__pyx_t_1) {
-
- /* "View.MemoryView":364
*
- * if flags & PyBUF_FORMAT:
- * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0') # <<<<<<<<<<<<<<
- * else:
- * self.dtype_is_object = dtype_is_object
*/
- __pyx_t_2 = (((__pyx_v_self->view.format[0]) == 'O') != 0);
- if (__pyx_t_2) {
- } else {
- __pyx_t_1 = __pyx_t_2;
- goto __pyx_L11_bool_binop_done;
+ /*else*/ {
+ __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, ((char *)__pyx_v_item), __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 470, __pyx_L6_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
}
- __pyx_t_2 = (((__pyx_v_self->view.format[1]) == '\x00') != 0);
- __pyx_t_1 = __pyx_t_2;
- __pyx_L11_bool_binop_done:;
- __pyx_v_self->dtype_is_object = __pyx_t_1;
+ __pyx_L8:;
- /* "View.MemoryView":363
- * raise MemoryError
+ /* "View.MemoryView":474
*
- * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
- * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
- * else:
+ *
+ * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<<
+ * assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
+ * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
*/
- goto __pyx_L10;
- }
+ __pyx_t_2 = ((__pyx_v_self->view.suboffsets != NULL) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":366
- * self.dtype_is_object = (self.view.format[0] == b'O' and self.view.format[1] == b'\0')
- * else:
- * self.dtype_is_object = dtype_is_object # <<<<<<<<<<<<<<
+ /* "View.MemoryView":475
*
- * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(
+ * if self.view.suboffsets != NULL:
+ * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) # <<<<<<<<<<<<<<
+ * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
+ * item, self.dtype_is_object)
*/
- /*else*/ {
- __pyx_v_self->dtype_is_object = __pyx_v_dtype_is_object;
- }
- __pyx_L10:;
+ __pyx_t_3 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 475, __pyx_L6_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "View.MemoryView":368
- * self.dtype_is_object = dtype_is_object
+ /* "View.MemoryView":474
*
- * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer( # <<<<<<<<<<<<<<
- * &self.acquisition_count[0], sizeof(__pyx_atomic_int))
- * self.typeinfo = NULL
+ *
+ * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<<
+ * assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
+ * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
*/
- __pyx_v_self->acquisition_count_aligned_p = ((__pyx_atomic_int *)__pyx_align_pointer(((void *)(&(__pyx_v_self->acquisition_count[0]))), (sizeof(__pyx_atomic_int))));
+ }
- /* "View.MemoryView":370
- * self.acquisition_count_aligned_p = <__pyx_atomic_int *> align_pointer(
- * &self.acquisition_count[0], sizeof(__pyx_atomic_int))
- * self.typeinfo = NULL # <<<<<<<<<<<<<<
- *
- * def __dealloc__(memoryview self):
+ /* "View.MemoryView":476
+ * if self.view.suboffsets != NULL:
+ * assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
+ * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, # <<<<<<<<<<<<<<
+ * item, self.dtype_is_object)
+ * finally:
*/
- __pyx_v_self->typeinfo = NULL;
+ __pyx_memoryview_slice_assign_scalar(__pyx_v_dst_slice, __pyx_v_dst->view.ndim, __pyx_v_self->view.itemsize, __pyx_v_item, __pyx_v_self->dtype_is_object);
+ }
- /* "View.MemoryView":345
- * cdef __Pyx_TypeInfo *typeinfo
+ /* "View.MemoryView":479
+ * item, self.dtype_is_object)
+ * finally:
+ * PyMem_Free(tmp) # <<<<<<<<<<<<<<
*
- * def __cinit__(memoryview self, object obj, int flags, bint dtype_is_object=False): # <<<<<<<<<<<<<<
- * self.obj = obj
- * self.flags = flags
+ * cdef setitem_indexed(self, index, value):
*/
+ /*finally:*/ {
+ /*normal exit:*/{
+ PyMem_Free(__pyx_v_tmp);
+ goto __pyx_L7;
+ }
+ __pyx_L6_error:;
+ /*exception exit:*/{
+ __Pyx_PyThreadState_declare
+ __Pyx_PyThreadState_assign
+ __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
+ __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
+ if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
+ if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
+ __Pyx_XGOTREF(__pyx_t_7);
+ __Pyx_XGOTREF(__pyx_t_8);
+ __Pyx_XGOTREF(__pyx_t_9);
+ __Pyx_XGOTREF(__pyx_t_10);
+ __Pyx_XGOTREF(__pyx_t_11);
+ __Pyx_XGOTREF(__pyx_t_12);
+ __pyx_t_4 = __pyx_lineno; __pyx_t_5 = __pyx_clineno; __pyx_t_6 = __pyx_filename;
+ {
+ PyMem_Free(__pyx_v_tmp);
+ }
+ if (PY_MAJOR_VERSION >= 3) {
+ __Pyx_XGIVEREF(__pyx_t_10);
+ __Pyx_XGIVEREF(__pyx_t_11);
+ __Pyx_XGIVEREF(__pyx_t_12);
+ __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
+ }
+ __Pyx_XGIVEREF(__pyx_t_7);
+ __Pyx_XGIVEREF(__pyx_t_8);
+ __Pyx_XGIVEREF(__pyx_t_9);
+ __Pyx_ErrRestore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
+ __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
+ __pyx_lineno = __pyx_t_4; __pyx_clineno = __pyx_t_5; __pyx_filename = __pyx_t_6;
+ goto __pyx_L1_error;
+ }
+ __pyx_L7:;
+ }
- /* function exit code */
- __pyx_r = 0;
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_AddTraceback("View.MemoryView.memoryview.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = -1;
- __pyx_L0:;
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":372
- * self.typeinfo = NULL
+ /* "View.MemoryView":449
+ * src.ndim, dst.ndim, self.dtype_is_object)
*
- * def __dealloc__(memoryview self): # <<<<<<<<<<<<<<
- * if self.obj is not None:
- * __Pyx_ReleaseBuffer(&self.view)
+ * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<<
+ * cdef int array[128]
+ * cdef void *tmp = NULL
*/
-/* Python wrapper */
-static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self); /*proto*/
-static void __pyx_memoryview___dealloc__(PyObject *__pyx_v_self) {
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
- __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(((struct __pyx_memoryview_obj *)__pyx_v_self));
-
/* function exit code */
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
+ return __pyx_r;
}
-static void __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_2__dealloc__(struct __pyx_memoryview_obj *__pyx_v_self) {
- int __pyx_v_i;
+/* "View.MemoryView":481
+ * PyMem_Free(tmp)
+ *
+ * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<<
+ * cdef char *itemp = self.get_item_pointer(index)
+ * self.assign_item_from_object(itemp, value)
+ */
+
+static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
+ char *__pyx_v_itemp;
+ PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- int __pyx_t_1;
- int __pyx_t_2;
- int __pyx_t_3;
- int __pyx_t_4;
- int __pyx_t_5;
- PyThread_type_lock __pyx_t_6;
- PyThread_type_lock __pyx_t_7;
- __Pyx_RefNannySetupContext("__dealloc__", 0);
+ char *__pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("setitem_indexed", 0);
- /* "View.MemoryView":373
+ /* "View.MemoryView":482
+ *
+ * cdef setitem_indexed(self, index, value):
+ * cdef char *itemp = self.get_item_pointer(index) # <<<<<<<<<<<<<<
+ * self.assign_item_from_object(itemp, value)
*
- * def __dealloc__(memoryview self):
- * if self.obj is not None: # <<<<<<<<<<<<<<
- * __Pyx_ReleaseBuffer(&self.view)
- * elif (<__pyx_buffer *> &self.view).obj == Py_None:
*/
- __pyx_t_1 = (__pyx_v_self->obj != Py_None);
- __pyx_t_2 = (__pyx_t_1 != 0);
- if (__pyx_t_2) {
+ __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_index); if (unlikely(__pyx_t_1 == ((char *)NULL))) __PYX_ERR(1, 482, __pyx_L1_error)
+ __pyx_v_itemp = __pyx_t_1;
- /* "View.MemoryView":374
- * def __dealloc__(memoryview self):
- * if self.obj is not None:
- * __Pyx_ReleaseBuffer(&self.view) # <<<<<<<<<<<<<<
- * elif (<__pyx_buffer *> &self.view).obj == Py_None:
+ /* "View.MemoryView":483
+ * cdef setitem_indexed(self, index, value):
+ * cdef char *itemp = self.get_item_pointer(index)
+ * self.assign_item_from_object(itemp, value) # <<<<<<<<<<<<<<
*
+ * cdef convert_item_to_object(self, char *itemp):
*/
- __Pyx_ReleaseBuffer((&__pyx_v_self->view));
+ __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 483, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "View.MemoryView":373
+ /* "View.MemoryView":481
+ * PyMem_Free(tmp)
*
- * def __dealloc__(memoryview self):
- * if self.obj is not None: # <<<<<<<<<<<<<<
- * __Pyx_ReleaseBuffer(&self.view)
- * elif (<__pyx_buffer *> &self.view).obj == Py_None:
+ * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<<
+ * cdef char *itemp = self.get_item_pointer(index)
+ * self.assign_item_from_object(itemp, value)
*/
- goto __pyx_L3;
- }
- /* "View.MemoryView":375
- * if self.obj is not None:
- * __Pyx_ReleaseBuffer(&self.view)
- * elif (<__pyx_buffer *> &self.view).obj == Py_None: # <<<<<<<<<<<<<<
+ /* function exit code */
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_indexed", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":485
+ * self.assign_item_from_object(itemp, value)
*
- * (<__pyx_buffer *> &self.view).obj = NULL
+ * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<<
+ * """Only used if instantiated manually by the user, or if Cython doesn't
+ * know how to convert the type"""
*/
- __pyx_t_2 = ((((Py_buffer *)(&__pyx_v_self->view))->obj == Py_None) != 0);
- if (__pyx_t_2) {
- /* "View.MemoryView":377
- * elif (<__pyx_buffer *> &self.view).obj == Py_None:
- *
- * (<__pyx_buffer *> &self.view).obj = NULL # <<<<<<<<<<<<<<
- * Py_DECREF(Py_None)
+static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp) {
+ PyObject *__pyx_v_struct = NULL;
+ PyObject *__pyx_v_bytesitem = 0;
+ PyObject *__pyx_v_result = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ PyObject *__pyx_t_5 = NULL;
+ PyObject *__pyx_t_6 = NULL;
+ PyObject *__pyx_t_7 = NULL;
+ int __pyx_t_8;
+ PyObject *__pyx_t_9 = NULL;
+ size_t __pyx_t_10;
+ int __pyx_t_11;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("convert_item_to_object", 0);
+
+ /* "View.MemoryView":488
+ * """Only used if instantiated manually by the user, or if Cython doesn't
+ * know how to convert the type"""
+ * import struct # <<<<<<<<<<<<<<
+ * cdef bytes bytesitem
*
*/
- ((Py_buffer *)(&__pyx_v_self->view))->obj = NULL;
+ __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 488, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_struct = __pyx_t_1;
+ __pyx_t_1 = 0;
- /* "View.MemoryView":378
- *
- * (<__pyx_buffer *> &self.view).obj = NULL
- * Py_DECREF(Py_None) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":491
+ * cdef bytes bytesitem
*
- * cdef int i
+ * bytesitem = itemp[:self.view.itemsize] # <<<<<<<<<<<<<<
+ * try:
+ * result = struct.unpack(self.view.format, bytesitem)
*/
- Py_DECREF(Py_None);
+ __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_itemp + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 491, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_bytesitem = ((PyObject*)__pyx_t_1);
+ __pyx_t_1 = 0;
- /* "View.MemoryView":375
- * if self.obj is not None:
- * __Pyx_ReleaseBuffer(&self.view)
- * elif (<__pyx_buffer *> &self.view).obj == Py_None: # <<<<<<<<<<<<<<
+ /* "View.MemoryView":492
*
- * (<__pyx_buffer *> &self.view).obj = NULL
+ * bytesitem = itemp[:self.view.itemsize]
+ * try: # <<<<<<<<<<<<<<
+ * result = struct.unpack(self.view.format, bytesitem)
+ * except struct.error:
*/
- }
- __pyx_L3:;
+ {
+ __Pyx_PyThreadState_declare
+ __Pyx_PyThreadState_assign
+ __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4);
+ __Pyx_XGOTREF(__pyx_t_2);
+ __Pyx_XGOTREF(__pyx_t_3);
+ __Pyx_XGOTREF(__pyx_t_4);
+ /*try:*/ {
- /* "View.MemoryView":382
- * cdef int i
- * global __pyx_memoryview_thread_locks_used
- * if self.lock != NULL: # <<<<<<<<<<<<<<
- * for i in range(__pyx_memoryview_thread_locks_used):
- * if __pyx_memoryview_thread_locks[i] is self.lock:
+ /* "View.MemoryView":493
+ * bytesitem = itemp[:self.view.itemsize]
+ * try:
+ * result = struct.unpack(self.view.format, bytesitem) # <<<<<<<<<<<<<<
+ * except struct.error:
+ * raise ValueError("Unable to convert item to object")
*/
- __pyx_t_2 = ((__pyx_v_self->lock != NULL) != 0);
- if (__pyx_t_2) {
-
- /* "View.MemoryView":383
- * global __pyx_memoryview_thread_locks_used
- * if self.lock != NULL:
- * for i in range(__pyx_memoryview_thread_locks_used): # <<<<<<<<<<<<<<
- * if __pyx_memoryview_thread_locks[i] is self.lock:
- * __pyx_memoryview_thread_locks_used -= 1
- */
- __pyx_t_3 = __pyx_memoryview_thread_locks_used;
- __pyx_t_4 = __pyx_t_3;
- for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
- __pyx_v_i = __pyx_t_5;
-
- /* "View.MemoryView":384
- * if self.lock != NULL:
- * for i in range(__pyx_memoryview_thread_locks_used):
- * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<<
- * __pyx_memoryview_thread_locks_used -= 1
- * if i != __pyx_memoryview_thread_locks_used:
- */
- __pyx_t_2 = (((__pyx_memoryview_thread_locks[__pyx_v_i]) == __pyx_v_self->lock) != 0);
- if (__pyx_t_2) {
+ __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_unpack); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 493, __pyx_L3_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 493, __pyx_L3_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_7 = NULL;
+ __pyx_t_8 = 0;
+ if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
+ __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
+ if (likely(__pyx_t_7)) {
+ PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
+ __Pyx_INCREF(__pyx_t_7);
+ __Pyx_INCREF(function);
+ __Pyx_DECREF_SET(__pyx_t_5, function);
+ __pyx_t_8 = 1;
+ }
+ }
+ #if CYTHON_FAST_PYCALL
+ if (PyFunction_Check(__pyx_t_5)) {
+ PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem};
+ __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 493, __pyx_L3_error)
+ __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ } else
+ #endif
+ #if CYTHON_FAST_PYCCALL
+ if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
+ PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem};
+ __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 493, __pyx_L3_error)
+ __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ } else
+ #endif
+ {
+ __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 493, __pyx_L3_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ if (__pyx_t_7) {
+ __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
+ }
+ __Pyx_GIVEREF(__pyx_t_6);
+ PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6);
+ __Pyx_INCREF(__pyx_v_bytesitem);
+ __Pyx_GIVEREF(__pyx_v_bytesitem);
+ PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_bytesitem);
+ __pyx_t_6 = 0;
+ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 493, __pyx_L3_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ }
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __pyx_v_result = __pyx_t_1;
+ __pyx_t_1 = 0;
- /* "View.MemoryView":385
- * for i in range(__pyx_memoryview_thread_locks_used):
- * if __pyx_memoryview_thread_locks[i] is self.lock:
- * __pyx_memoryview_thread_locks_used -= 1 # <<<<<<<<<<<<<<
- * if i != __pyx_memoryview_thread_locks_used:
- * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
+ /* "View.MemoryView":492
+ *
+ * bytesitem = itemp[:self.view.itemsize]
+ * try: # <<<<<<<<<<<<<<
+ * result = struct.unpack(self.view.format, bytesitem)
+ * except struct.error:
*/
- __pyx_memoryview_thread_locks_used = (__pyx_memoryview_thread_locks_used - 1);
+ }
- /* "View.MemoryView":386
- * if __pyx_memoryview_thread_locks[i] is self.lock:
- * __pyx_memoryview_thread_locks_used -= 1
- * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<<
- * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
- * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
+ /* "View.MemoryView":497
+ * raise ValueError("Unable to convert item to object")
+ * else:
+ * if len(self.view.format) == 1: # <<<<<<<<<<<<<<
+ * return result[0]
+ * return result
*/
- __pyx_t_2 = ((__pyx_v_i != __pyx_memoryview_thread_locks_used) != 0);
- if (__pyx_t_2) {
+ /*else:*/ {
+ __pyx_t_10 = strlen(__pyx_v_self->view.format);
+ __pyx_t_11 = ((__pyx_t_10 == 1) != 0);
+ if (__pyx_t_11) {
- /* "View.MemoryView":388
- * if i != __pyx_memoryview_thread_locks_used:
- * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
- * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i]) # <<<<<<<<<<<<<<
- * break
- * else:
+ /* "View.MemoryView":498
+ * else:
+ * if len(self.view.format) == 1:
+ * return result[0] # <<<<<<<<<<<<<<
+ * return result
+ *
*/
- __pyx_t_6 = (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]);
- __pyx_t_7 = (__pyx_memoryview_thread_locks[__pyx_v_i]);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_result, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 498, __pyx_L5_except_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L6_except_return;
- /* "View.MemoryView":387
- * __pyx_memoryview_thread_locks_used -= 1
- * if i != __pyx_memoryview_thread_locks_used:
- * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = ( # <<<<<<<<<<<<<<
- * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
- * break
+ /* "View.MemoryView":497
+ * raise ValueError("Unable to convert item to object")
+ * else:
+ * if len(self.view.format) == 1: # <<<<<<<<<<<<<<
+ * return result[0]
+ * return result
*/
- (__pyx_memoryview_thread_locks[__pyx_v_i]) = __pyx_t_6;
- (__pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used]) = __pyx_t_7;
+ }
- /* "View.MemoryView":386
- * if __pyx_memoryview_thread_locks[i] is self.lock:
- * __pyx_memoryview_thread_locks_used -= 1
- * if i != __pyx_memoryview_thread_locks_used: # <<<<<<<<<<<<<<
- * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
- * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
+ /* "View.MemoryView":499
+ * if len(self.view.format) == 1:
+ * return result[0]
+ * return result # <<<<<<<<<<<<<<
+ *
+ * cdef assign_item_from_object(self, char *itemp, object value):
*/
- }
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(__pyx_v_result);
+ __pyx_r = __pyx_v_result;
+ goto __pyx_L6_except_return;
+ }
+ __pyx_L3_error:;
+ __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
+ __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
- /* "View.MemoryView":389
- * __pyx_memoryview_thread_locks[i], __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used] = (
- * __pyx_memoryview_thread_locks[__pyx_memoryview_thread_locks_used], __pyx_memoryview_thread_locks[i])
- * break # <<<<<<<<<<<<<<
- * else:
- * PyThread_free_lock(self.lock)
+ /* "View.MemoryView":494
+ * try:
+ * result = struct.unpack(self.view.format, bytesitem)
+ * except struct.error: # <<<<<<<<<<<<<<
+ * raise ValueError("Unable to convert item to object")
+ * else:
*/
- goto __pyx_L6_break;
+ __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_5, &__pyx_t_9);
+ __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 494, __pyx_L5_except_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_6);
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __Pyx_ErrRestore(__pyx_t_1, __pyx_t_5, __pyx_t_9);
+ __pyx_t_1 = 0; __pyx_t_5 = 0; __pyx_t_9 = 0;
+ if (__pyx_t_8) {
+ __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(1, 494, __pyx_L5_except_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_GOTREF(__pyx_t_1);
- /* "View.MemoryView":384
- * if self.lock != NULL:
- * for i in range(__pyx_memoryview_thread_locks_used):
- * if __pyx_memoryview_thread_locks[i] is self.lock: # <<<<<<<<<<<<<<
- * __pyx_memoryview_thread_locks_used -= 1
- * if i != __pyx_memoryview_thread_locks_used:
+ /* "View.MemoryView":495
+ * result = struct.unpack(self.view.format, bytesitem)
+ * except struct.error:
+ * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<<
+ * else:
+ * if len(self.view.format) == 1:
*/
- }
+ __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 495, __pyx_L5_except_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __Pyx_Raise(__pyx_t_6, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ __PYX_ERR(1, 495, __pyx_L5_except_error)
}
- /*else*/ {
+ goto __pyx_L5_except_error;
+ __pyx_L5_except_error:;
- /* "View.MemoryView":391
- * break
- * else:
- * PyThread_free_lock(self.lock) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":492
*
- * cdef char *get_item_pointer(memoryview self, object index) except NULL:
- */
- PyThread_free_lock(__pyx_v_self->lock);
- }
- __pyx_L6_break:;
-
- /* "View.MemoryView":382
- * cdef int i
- * global __pyx_memoryview_thread_locks_used
- * if self.lock != NULL: # <<<<<<<<<<<<<<
- * for i in range(__pyx_memoryview_thread_locks_used):
- * if __pyx_memoryview_thread_locks[i] is self.lock:
+ * bytesitem = itemp[:self.view.itemsize]
+ * try: # <<<<<<<<<<<<<<
+ * result = struct.unpack(self.view.format, bytesitem)
+ * except struct.error:
*/
+ __Pyx_XGIVEREF(__pyx_t_2);
+ __Pyx_XGIVEREF(__pyx_t_3);
+ __Pyx_XGIVEREF(__pyx_t_4);
+ __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
+ goto __pyx_L1_error;
+ __pyx_L6_except_return:;
+ __Pyx_XGIVEREF(__pyx_t_2);
+ __Pyx_XGIVEREF(__pyx_t_3);
+ __Pyx_XGIVEREF(__pyx_t_4);
+ __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
+ goto __pyx_L0;
}
- /* "View.MemoryView":372
- * self.typeinfo = NULL
+ /* "View.MemoryView":485
+ * self.assign_item_from_object(itemp, value)
*
- * def __dealloc__(memoryview self): # <<<<<<<<<<<<<<
- * if self.obj is not None:
- * __Pyx_ReleaseBuffer(&self.view)
- */
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
-}
-
-/* "View.MemoryView":393
- * PyThread_free_lock(self.lock)
- *
- * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<<
- * cdef Py_ssize_t dim
- * cdef char *itemp = self.view.buf
- */
-
-static char *__pyx_memoryview_get_item_pointer(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) {
- Py_ssize_t __pyx_v_dim;
- char *__pyx_v_itemp;
- PyObject *__pyx_v_idx = NULL;
- char *__pyx_r;
- __Pyx_RefNannyDeclarations
- Py_ssize_t __pyx_t_1;
- PyObject *__pyx_t_2 = NULL;
- Py_ssize_t __pyx_t_3;
- PyObject *(*__pyx_t_4)(PyObject *);
- PyObject *__pyx_t_5 = NULL;
- Py_ssize_t __pyx_t_6;
- char *__pyx_t_7;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("get_item_pointer", 0);
-
- /* "View.MemoryView":395
- * cdef char *get_item_pointer(memoryview self, object index) except NULL:
- * cdef Py_ssize_t dim
- * cdef char *itemp = self.view.buf # <<<<<<<<<<<<<<
- *
- * for dim, idx in enumerate(index):
- */
- __pyx_v_itemp = ((char *)__pyx_v_self->view.buf);
-
- /* "View.MemoryView":397
- * cdef char *itemp = self.view.buf
- *
- * for dim, idx in enumerate(index): # <<<<<<<<<<<<<<
- * itemp = pybuffer_index(&self.view, itemp, idx, dim)
- *
- */
- __pyx_t_1 = 0;
- if (likely(PyList_CheckExact(__pyx_v_index)) || PyTuple_CheckExact(__pyx_v_index)) {
- __pyx_t_2 = __pyx_v_index; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
- __pyx_t_4 = NULL;
- } else {
- __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 397, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 397, __pyx_L1_error)
- }
- for (;;) {
- if (likely(!__pyx_t_4)) {
- if (likely(PyList_CheckExact(__pyx_t_2))) {
- if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
- #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
- __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 397, __pyx_L1_error)
- #else
- __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 397, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- #endif
- } else {
- if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
- #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
- __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(1, 397, __pyx_L1_error)
- #else
- __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 397, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- #endif
- }
- } else {
- __pyx_t_5 = __pyx_t_4(__pyx_t_2);
- if (unlikely(!__pyx_t_5)) {
- PyObject* exc_type = PyErr_Occurred();
- if (exc_type) {
- if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
- else __PYX_ERR(1, 397, __pyx_L1_error)
- }
- break;
- }
- __Pyx_GOTREF(__pyx_t_5);
- }
- __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_5);
- __pyx_t_5 = 0;
- __pyx_v_dim = __pyx_t_1;
- __pyx_t_1 = (__pyx_t_1 + 1);
-
- /* "View.MemoryView":398
- *
- * for dim, idx in enumerate(index):
- * itemp = pybuffer_index(&self.view, itemp, idx, dim) # <<<<<<<<<<<<<<
- *
- * return itemp
- */
- __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_idx); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 398, __pyx_L1_error)
- __pyx_t_7 = __pyx_pybuffer_index((&__pyx_v_self->view), __pyx_v_itemp, __pyx_t_6, __pyx_v_dim); if (unlikely(__pyx_t_7 == ((char *)NULL))) __PYX_ERR(1, 398, __pyx_L1_error)
- __pyx_v_itemp = __pyx_t_7;
-
- /* "View.MemoryView":397
- * cdef char *itemp = self.view.buf
- *
- * for dim, idx in enumerate(index): # <<<<<<<<<<<<<<
- * itemp = pybuffer_index(&self.view, itemp, idx, dim)
- *
- */
- }
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
-
- /* "View.MemoryView":400
- * itemp = pybuffer_index(&self.view, itemp, idx, dim)
- *
- * return itemp # <<<<<<<<<<<<<<
- *
- *
- */
- __pyx_r = __pyx_v_itemp;
- goto __pyx_L0;
-
- /* "View.MemoryView":393
- * PyThread_free_lock(self.lock)
- *
- * cdef char *get_item_pointer(memoryview self, object index) except NULL: # <<<<<<<<<<<<<<
- * cdef Py_ssize_t dim
- * cdef char *itemp = self.view.buf
+ * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<<
+ * """Only used if instantiated manually by the user, or if Cython doesn't
+ * know how to convert the type"""
*/
/* function exit code */
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_5);
- __Pyx_AddTraceback("View.MemoryView.memoryview.get_item_pointer", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_XDECREF(__pyx_t_7);
+ __Pyx_XDECREF(__pyx_t_9);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
__pyx_L0:;
- __Pyx_XDECREF(__pyx_v_idx);
+ __Pyx_XDECREF(__pyx_v_struct);
+ __Pyx_XDECREF(__pyx_v_bytesitem);
+ __Pyx_XDECREF(__pyx_v_result);
+ __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":403
- *
+/* "View.MemoryView":501
+ * return result
*
- * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<<
- * if index is Ellipsis:
- * return self
+ * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<<
+ * """Only used if instantiated manually by the user, or if Cython doesn't
+ * know how to convert the type"""
*/
-/* Python wrapper */
-static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index); /*proto*/
-static PyObject *__pyx_memoryview___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_4__getitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index) {
- PyObject *__pyx_v_have_slices = NULL;
- PyObject *__pyx_v_indices = NULL;
- char *__pyx_v_itemp;
+static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) {
+ PyObject *__pyx_v_struct = NULL;
+ char __pyx_v_c;
+ PyObject *__pyx_v_bytesvalue = 0;
+ Py_ssize_t __pyx_v_i;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- int __pyx_t_1;
+ PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
+ int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
- char *__pyx_t_6;
+ PyObject *__pyx_t_6 = NULL;
+ int __pyx_t_7;
+ PyObject *__pyx_t_8 = NULL;
+ Py_ssize_t __pyx_t_9;
+ PyObject *__pyx_t_10 = NULL;
+ char *__pyx_t_11;
+ char *__pyx_t_12;
+ char *__pyx_t_13;
+ char *__pyx_t_14;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__getitem__", 0);
+ __Pyx_RefNannySetupContext("assign_item_from_object", 0);
- /* "View.MemoryView":404
- *
- * def __getitem__(memoryview self, object index):
- * if index is Ellipsis: # <<<<<<<<<<<<<<
- * return self
- *
+ /* "View.MemoryView":504
+ * """Only used if instantiated manually by the user, or if Cython doesn't
+ * know how to convert the type"""
+ * import struct # <<<<<<<<<<<<<<
+ * cdef char c
+ * cdef bytes bytesvalue
*/
- __pyx_t_1 = (__pyx_v_index == __pyx_builtin_Ellipsis);
- __pyx_t_2 = (__pyx_t_1 != 0);
- if (__pyx_t_2) {
+ __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 504, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_v_struct = __pyx_t_1;
+ __pyx_t_1 = 0;
- /* "View.MemoryView":405
- * def __getitem__(memoryview self, object index):
- * if index is Ellipsis:
- * return self # <<<<<<<<<<<<<<
+ /* "View.MemoryView":509
+ * cdef Py_ssize_t i
*
- * have_slices, indices = _unellipsify(index, self.view.ndim)
+ * if isinstance(value, tuple): # <<<<<<<<<<<<<<
+ * bytesvalue = struct.pack(self.view.format, *value)
+ * else:
*/
- __Pyx_XDECREF(__pyx_r);
- __Pyx_INCREF(((PyObject *)__pyx_v_self));
- __pyx_r = ((PyObject *)__pyx_v_self);
- goto __pyx_L0;
+ __pyx_t_2 = PyTuple_Check(__pyx_v_value);
+ __pyx_t_3 = (__pyx_t_2 != 0);
+ if (__pyx_t_3) {
- /* "View.MemoryView":404
- *
- * def __getitem__(memoryview self, object index):
- * if index is Ellipsis: # <<<<<<<<<<<<<<
- * return self
+ /* "View.MemoryView":510
*
+ * if isinstance(value, tuple):
+ * bytesvalue = struct.pack(self.view.format, *value) # <<<<<<<<<<<<<<
+ * else:
+ * bytesvalue = struct.pack(self.view.format, value)
*/
- }
+ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 510, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 510, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 510, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_GIVEREF(__pyx_t_4);
+ PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
+ __pyx_t_4 = 0;
+ __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 510, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 510, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 510, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 510, __pyx_L1_error)
+ __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4);
+ __pyx_t_4 = 0;
- /* "View.MemoryView":407
- * return self
+ /* "View.MemoryView":509
+ * cdef Py_ssize_t i
*
- * have_slices, indices = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<<
+ * if isinstance(value, tuple): # <<<<<<<<<<<<<<
+ * bytesvalue = struct.pack(self.view.format, *value)
+ * else:
+ */
+ goto __pyx_L3;
+ }
+
+ /* "View.MemoryView":512
+ * bytesvalue = struct.pack(self.view.format, *value)
+ * else:
+ * bytesvalue = struct.pack(self.view.format, value) # <<<<<<<<<<<<<<
*
- * cdef char *itemp
+ * for i, c in enumerate(bytesvalue):
*/
- __pyx_t_3 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 407, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- if (likely(__pyx_t_3 != Py_None)) {
- PyObject* sequence = __pyx_t_3;
- Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
- if (unlikely(size != 2)) {
- if (size > 2) __Pyx_RaiseTooManyValuesError(2);
- else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
- __PYX_ERR(1, 407, __pyx_L1_error)
+ /*else*/ {
+ __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 512, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 512, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_5 = NULL;
+ __pyx_t_7 = 0;
+ if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
+ __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
+ if (likely(__pyx_t_5)) {
+ PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
+ __Pyx_INCREF(__pyx_t_5);
+ __Pyx_INCREF(function);
+ __Pyx_DECREF_SET(__pyx_t_6, function);
+ __pyx_t_7 = 1;
+ }
}
- #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
- __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0);
- __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1);
- __Pyx_INCREF(__pyx_t_4);
- __Pyx_INCREF(__pyx_t_5);
- #else
- __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 407, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 407, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
+ #if CYTHON_FAST_PYCALL
+ if (PyFunction_Check(__pyx_t_6)) {
+ PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value};
+ __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 512, __pyx_L1_error)
+ __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ } else
#endif
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- } else {
- __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 407, __pyx_L1_error)
+ #if CYTHON_FAST_PYCCALL
+ if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
+ PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value};
+ __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 512, __pyx_L1_error)
+ __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ } else
+ #endif
+ {
+ __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 512, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_8);
+ if (__pyx_t_5) {
+ __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL;
+ }
+ __Pyx_GIVEREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_1);
+ __Pyx_INCREF(__pyx_v_value);
+ __Pyx_GIVEREF(__pyx_v_value);
+ PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_value);
+ __pyx_t_1 = 0;
+ __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 512, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+ }
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+ if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 512, __pyx_L1_error)
+ __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4);
+ __pyx_t_4 = 0;
}
- __pyx_v_have_slices = __pyx_t_4;
- __pyx_t_4 = 0;
- __pyx_v_indices = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_L3:;
- /* "View.MemoryView":410
+ /* "View.MemoryView":514
+ * bytesvalue = struct.pack(self.view.format, value)
+ *
+ * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<<
+ * itemp[i] = c
*
- * cdef char *itemp
- * if have_slices: # <<<<<<<<<<<<<<
- * return memview_slice(self, indices)
- * else:
- */
- __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 410, __pyx_L1_error)
- if (__pyx_t_2) {
-
- /* "View.MemoryView":411
- * cdef char *itemp
- * if have_slices:
- * return memview_slice(self, indices) # <<<<<<<<<<<<<<
- * else:
- * itemp = self.get_item_pointer(indices)
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = ((PyObject *)__pyx_memview_slice(__pyx_v_self, __pyx_v_indices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 411, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_r = __pyx_t_3;
- __pyx_t_3 = 0;
- goto __pyx_L0;
+ __pyx_t_9 = 0;
+ if (unlikely(__pyx_v_bytesvalue == Py_None)) {
+ PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable");
+ __PYX_ERR(1, 514, __pyx_L1_error)
+ }
+ __Pyx_INCREF(__pyx_v_bytesvalue);
+ __pyx_t_10 = __pyx_v_bytesvalue;
+ __pyx_t_12 = PyBytes_AS_STRING(__pyx_t_10);
+ __pyx_t_13 = (__pyx_t_12 + PyBytes_GET_SIZE(__pyx_t_10));
+ for (__pyx_t_14 = __pyx_t_12; __pyx_t_14 < __pyx_t_13; __pyx_t_14++) {
+ __pyx_t_11 = __pyx_t_14;
+ __pyx_v_c = (__pyx_t_11[0]);
- /* "View.MemoryView":410
+ /* "View.MemoryView":515
*
- * cdef char *itemp
- * if have_slices: # <<<<<<<<<<<<<<
- * return memview_slice(self, indices)
- * else:
+ * for i, c in enumerate(bytesvalue):
+ * itemp[i] = c # <<<<<<<<<<<<<<
+ *
+ * @cname('getbuffer')
*/
- }
+ __pyx_v_i = __pyx_t_9;
- /* "View.MemoryView":413
- * return memview_slice(self, indices)
- * else:
- * itemp = self.get_item_pointer(indices) # <<<<<<<<<<<<<<
- * return self.convert_item_to_object(itemp)
+ /* "View.MemoryView":514
+ * bytesvalue = struct.pack(self.view.format, value)
+ *
+ * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<<
+ * itemp[i] = c
*
*/
- /*else*/ {
- __pyx_t_6 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_indices); if (unlikely(__pyx_t_6 == ((char *)NULL))) __PYX_ERR(1, 413, __pyx_L1_error)
- __pyx_v_itemp = __pyx_t_6;
+ __pyx_t_9 = (__pyx_t_9 + 1);
- /* "View.MemoryView":414
- * else:
- * itemp = self.get_item_pointer(indices)
- * return self.convert_item_to_object(itemp) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":515
*
- * def __setitem__(memoryview self, object index, object value):
+ * for i, c in enumerate(bytesvalue):
+ * itemp[i] = c # <<<<<<<<<<<<<<
+ *
+ * @cname('getbuffer')
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->convert_item_to_object(__pyx_v_self, __pyx_v_itemp); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 414, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_r = __pyx_t_3;
- __pyx_t_3 = 0;
- goto __pyx_L0;
+ (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c;
}
+ __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
- /* "View.MemoryView":403
- *
+ /* "View.MemoryView":501
+ * return result
*
- * def __getitem__(memoryview self, object index): # <<<<<<<<<<<<<<
- * if index is Ellipsis:
- * return self
+ * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<<
+ * """Only used if instantiated manually by the user, or if Cython doesn't
+ * know how to convert the type"""
*/
/* function exit code */
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
- __Pyx_AddTraceback("View.MemoryView.memoryview.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_XDECREF(__pyx_t_8);
+ __Pyx_XDECREF(__pyx_t_10);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
__pyx_L0:;
- __Pyx_XDECREF(__pyx_v_have_slices);
- __Pyx_XDECREF(__pyx_v_indices);
+ __Pyx_XDECREF(__pyx_v_struct);
+ __Pyx_XDECREF(__pyx_v_bytesvalue);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":416
- * return self.convert_item_to_object(itemp)
+/* "View.MemoryView":518
*
- * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<<
- * if self.view.readonly:
- * raise TypeError("Cannot assign to read-only memoryview")
+ * @cname('getbuffer')
+ * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<<
+ * if flags & PyBUF_WRITABLE and self.view.readonly:
+ * raise ValueError("Cannot create writable memory view from read-only memoryview")
*/
/* Python wrapper */
-static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value); /*proto*/
-static int __pyx_memoryview___setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
+static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
+static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
int __pyx_r;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v_index), ((PyObject *)__pyx_v_value));
+ __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_6__setitem__(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
- PyObject *__pyx_v_have_slices = NULL;
- PyObject *__pyx_v_obj = NULL;
+static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
- PyObject *__pyx_t_2 = NULL;
+ int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
- PyObject *__pyx_t_4 = NULL;
+ Py_ssize_t *__pyx_t_4;
+ char *__pyx_t_5;
+ void *__pyx_t_6;
+ int __pyx_t_7;
+ Py_ssize_t __pyx_t_8;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__setitem__", 0);
- __Pyx_INCREF(__pyx_v_index);
+ if (__pyx_v_info == NULL) {
+ PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
+ return -1;
+ }
+ __Pyx_RefNannySetupContext("__getbuffer__", 0);
+ __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
+ __Pyx_GIVEREF(__pyx_v_info->obj);
- /* "View.MemoryView":417
- *
- * def __setitem__(memoryview self, object index, object value):
- * if self.view.readonly: # <<<<<<<<<<<<<<
- * raise TypeError("Cannot assign to read-only memoryview")
+ /* "View.MemoryView":519
+ * @cname('getbuffer')
+ * def __getbuffer__(self, Py_buffer *info, int flags):
+ * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<<
+ * raise ValueError("Cannot create writable memory view from read-only memoryview")
*
*/
- __pyx_t_1 = (__pyx_v_self->view.readonly != 0);
- if (unlikely(__pyx_t_1)) {
-
- /* "View.MemoryView":418
- * def __setitem__(memoryview self, object index, object value):
- * if self.view.readonly:
- * raise TypeError("Cannot assign to read-only memoryview") # <<<<<<<<<<<<<<
- *
- * have_slices, index = _unellipsify(index, self.view.ndim)
- */
- __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 418, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_Raise(__pyx_t_2, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __PYX_ERR(1, 418, __pyx_L1_error)
+ __pyx_t_2 = ((__pyx_v_flags & PyBUF_WRITABLE) != 0);
+ if (__pyx_t_2) {
+ } else {
+ __pyx_t_1 = __pyx_t_2;
+ goto __pyx_L4_bool_binop_done;
+ }
+ __pyx_t_2 = (__pyx_v_self->view.readonly != 0);
+ __pyx_t_1 = __pyx_t_2;
+ __pyx_L4_bool_binop_done:;
+ if (unlikely(__pyx_t_1)) {
- /* "View.MemoryView":417
- *
- * def __setitem__(memoryview self, object index, object value):
- * if self.view.readonly: # <<<<<<<<<<<<<<
- * raise TypeError("Cannot assign to read-only memoryview")
+ /* "View.MemoryView":520
+ * def __getbuffer__(self, Py_buffer *info, int flags):
+ * if flags & PyBUF_WRITABLE and self.view.readonly:
+ * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<<
*
+ * if flags & PyBUF_ND:
*/
- }
+ __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 520, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __PYX_ERR(1, 520, __pyx_L1_error)
- /* "View.MemoryView":420
- * raise TypeError("Cannot assign to read-only memoryview")
- *
- * have_slices, index = _unellipsify(index, self.view.ndim) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":519
+ * @cname('getbuffer')
+ * def __getbuffer__(self, Py_buffer *info, int flags):
+ * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<<
+ * raise ValueError("Cannot create writable memory view from read-only memoryview")
*
- * if have_slices:
*/
- __pyx_t_2 = _unellipsify(__pyx_v_index, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 420, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- if (likely(__pyx_t_2 != Py_None)) {
- PyObject* sequence = __pyx_t_2;
- Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
- if (unlikely(size != 2)) {
- if (size > 2) __Pyx_RaiseTooManyValuesError(2);
- else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
- __PYX_ERR(1, 420, __pyx_L1_error)
- }
- #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
- __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0);
- __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1);
- __Pyx_INCREF(__pyx_t_3);
- __Pyx_INCREF(__pyx_t_4);
- #else
- __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 420, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 420, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- #endif
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- } else {
- __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(1, 420, __pyx_L1_error)
}
- __pyx_v_have_slices = __pyx_t_3;
- __pyx_t_3 = 0;
- __Pyx_DECREF_SET(__pyx_v_index, __pyx_t_4);
- __pyx_t_4 = 0;
- /* "View.MemoryView":422
- * have_slices, index = _unellipsify(index, self.view.ndim)
+ /* "View.MemoryView":522
+ * raise ValueError("Cannot create writable memory view from read-only memoryview")
*
- * if have_slices: # <<<<<<<<<<<<<<
- * obj = self.is_slice(value)
- * if obj:
+ * if flags & PyBUF_ND: # <<<<<<<<<<<<<<
+ * info.shape = self.view.shape
+ * else:
*/
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_have_slices); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 422, __pyx_L1_error)
+ __pyx_t_1 = ((__pyx_v_flags & PyBUF_ND) != 0);
if (__pyx_t_1) {
- /* "View.MemoryView":423
+ /* "View.MemoryView":523
*
- * if have_slices:
- * obj = self.is_slice(value) # <<<<<<<<<<<<<<
- * if obj:
- * self.setitem_slice_assignment(self[index], obj)
+ * if flags & PyBUF_ND:
+ * info.shape = self.view.shape # <<<<<<<<<<<<<<
+ * else:
+ * info.shape = NULL
*/
- __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->is_slice(__pyx_v_self, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 423, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_v_obj = __pyx_t_2;
- __pyx_t_2 = 0;
+ __pyx_t_4 = __pyx_v_self->view.shape;
+ __pyx_v_info->shape = __pyx_t_4;
- /* "View.MemoryView":424
- * if have_slices:
- * obj = self.is_slice(value)
- * if obj: # <<<<<<<<<<<<<<
- * self.setitem_slice_assignment(self[index], obj)
- * else:
+ /* "View.MemoryView":522
+ * raise ValueError("Cannot create writable memory view from read-only memoryview")
+ *
+ * if flags & PyBUF_ND: # <<<<<<<<<<<<<<
+ * info.shape = self.view.shape
+ * else:
*/
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_obj); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 424, __pyx_L1_error)
- if (__pyx_t_1) {
+ goto __pyx_L6;
+ }
- /* "View.MemoryView":425
- * obj = self.is_slice(value)
- * if obj:
- * self.setitem_slice_assignment(self[index], obj) # <<<<<<<<<<<<<<
- * else:
- * self.setitem_slice_assign_scalar(self[index], value)
+ /* "View.MemoryView":525
+ * info.shape = self.view.shape
+ * else:
+ * info.shape = NULL # <<<<<<<<<<<<<<
+ *
+ * if flags & PyBUF_STRIDES:
*/
- __pyx_t_2 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 425, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assignment(__pyx_v_self, __pyx_t_2, __pyx_v_obj); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 425, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ /*else*/ {
+ __pyx_v_info->shape = NULL;
+ }
+ __pyx_L6:;
- /* "View.MemoryView":424
- * if have_slices:
- * obj = self.is_slice(value)
- * if obj: # <<<<<<<<<<<<<<
- * self.setitem_slice_assignment(self[index], obj)
- * else:
+ /* "View.MemoryView":527
+ * info.shape = NULL
+ *
+ * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<<
+ * info.strides = self.view.strides
+ * else:
*/
- goto __pyx_L5;
- }
+ __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":427
- * self.setitem_slice_assignment(self[index], obj)
- * else:
- * self.setitem_slice_assign_scalar(self[index], value) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":528
+ *
+ * if flags & PyBUF_STRIDES:
+ * info.strides = self.view.strides # <<<<<<<<<<<<<<
* else:
- * self.setitem_indexed(index, value)
+ * info.strides = NULL
*/
- /*else*/ {
- __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_index); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 427, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_memoryview_type))))) __PYX_ERR(1, 427, __pyx_L1_error)
- __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_slice_assign_scalar(__pyx_v_self, ((struct __pyx_memoryview_obj *)__pyx_t_4), __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 427, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- }
- __pyx_L5:;
+ __pyx_t_4 = __pyx_v_self->view.strides;
+ __pyx_v_info->strides = __pyx_t_4;
- /* "View.MemoryView":422
- * have_slices, index = _unellipsify(index, self.view.ndim)
+ /* "View.MemoryView":527
+ * info.shape = NULL
*
- * if have_slices: # <<<<<<<<<<<<<<
- * obj = self.is_slice(value)
- * if obj:
+ * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<<
+ * info.strides = self.view.strides
+ * else:
*/
- goto __pyx_L4;
+ goto __pyx_L7;
}
- /* "View.MemoryView":429
- * self.setitem_slice_assign_scalar(self[index], value)
+ /* "View.MemoryView":530
+ * info.strides = self.view.strides
* else:
- * self.setitem_indexed(index, value) # <<<<<<<<<<<<<<
+ * info.strides = NULL # <<<<<<<<<<<<<<
*
- * cdef is_slice(self, obj):
+ * if flags & PyBUF_INDIRECT:
*/
/*else*/ {
- __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->setitem_indexed(__pyx_v_self, __pyx_v_index, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 429, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_v_info->strides = NULL;
}
- __pyx_L4:;
+ __pyx_L7:;
- /* "View.MemoryView":416
- * return self.convert_item_to_object(itemp)
+ /* "View.MemoryView":532
+ * info.strides = NULL
*
- * def __setitem__(memoryview self, object index, object value): # <<<<<<<<<<<<<<
- * if self.view.readonly:
- * raise TypeError("Cannot assign to read-only memoryview")
+ * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<<
+ * info.suboffsets = self.view.suboffsets
+ * else:
*/
+ __pyx_t_1 = ((__pyx_v_flags & PyBUF_INDIRECT) != 0);
+ if (__pyx_t_1) {
- /* function exit code */
- __pyx_r = 0;
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_4);
- __Pyx_AddTraceback("View.MemoryView.memoryview.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = -1;
- __pyx_L0:;
- __Pyx_XDECREF(__pyx_v_have_slices);
- __Pyx_XDECREF(__pyx_v_obj);
- __Pyx_XDECREF(__pyx_v_index);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":533
+ *
+ * if flags & PyBUF_INDIRECT:
+ * info.suboffsets = self.view.suboffsets # <<<<<<<<<<<<<<
+ * else:
+ * info.suboffsets = NULL
+ */
+ __pyx_t_4 = __pyx_v_self->view.suboffsets;
+ __pyx_v_info->suboffsets = __pyx_t_4;
-/* "View.MemoryView":431
- * self.setitem_indexed(index, value)
+ /* "View.MemoryView":532
+ * info.strides = NULL
*
- * cdef is_slice(self, obj): # <<<<<<<<<<<<<<
- * if not isinstance(obj, memoryview):
- * try:
+ * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<<
+ * info.suboffsets = self.view.suboffsets
+ * else:
*/
+ goto __pyx_L8;
+ }
-static PyObject *__pyx_memoryview_is_slice(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_obj) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- int __pyx_t_1;
- int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- PyObject *__pyx_t_4 = NULL;
- PyObject *__pyx_t_5 = NULL;
- PyObject *__pyx_t_6 = NULL;
- PyObject *__pyx_t_7 = NULL;
- PyObject *__pyx_t_8 = NULL;
- int __pyx_t_9;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("is_slice", 0);
- __Pyx_INCREF(__pyx_v_obj);
-
- /* "View.MemoryView":432
+ /* "View.MemoryView":535
+ * info.suboffsets = self.view.suboffsets
+ * else:
+ * info.suboffsets = NULL # <<<<<<<<<<<<<<
*
- * cdef is_slice(self, obj):
- * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<<
- * try:
- * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
+ * if flags & PyBUF_FORMAT:
*/
- __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_obj, __pyx_memoryview_type);
- __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
- if (__pyx_t_2) {
+ /*else*/ {
+ __pyx_v_info->suboffsets = NULL;
+ }
+ __pyx_L8:;
- /* "View.MemoryView":433
- * cdef is_slice(self, obj):
- * if not isinstance(obj, memoryview):
- * try: # <<<<<<<<<<<<<<
- * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
- * self.dtype_is_object)
+ /* "View.MemoryView":537
+ * info.suboffsets = NULL
+ *
+ * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
+ * info.format = self.view.format
+ * else:
*/
- {
- __Pyx_PyThreadState_declare
- __Pyx_PyThreadState_assign
- __Pyx_ExceptionSave(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
- __Pyx_XGOTREF(__pyx_t_3);
- __Pyx_XGOTREF(__pyx_t_4);
- __Pyx_XGOTREF(__pyx_t_5);
- /*try:*/ {
+ __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":434
- * if not isinstance(obj, memoryview):
- * try:
- * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<<
- * self.dtype_is_object)
- * except TypeError:
+ /* "View.MemoryView":538
+ *
+ * if flags & PyBUF_FORMAT:
+ * info.format = self.view.format # <<<<<<<<<<<<<<
+ * else:
+ * info.format = NULL
*/
- __pyx_t_6 = __Pyx_PyInt_From_int(((__pyx_v_self->flags & (~PyBUF_WRITABLE)) | PyBUF_ANY_CONTIGUOUS)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 434, __pyx_L4_error)
- __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_5 = __pyx_v_self->view.format;
+ __pyx_v_info->format = __pyx_t_5;
- /* "View.MemoryView":435
- * try:
- * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
- * self.dtype_is_object) # <<<<<<<<<<<<<<
- * except TypeError:
- * return None
+ /* "View.MemoryView":537
+ * info.suboffsets = NULL
+ *
+ * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
+ * info.format = self.view.format
+ * else:
*/
- __pyx_t_7 = __Pyx_PyBool_FromLong(__pyx_v_self->dtype_is_object); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 435, __pyx_L4_error)
- __Pyx_GOTREF(__pyx_t_7);
+ goto __pyx_L9;
+ }
- /* "View.MemoryView":434
- * if not isinstance(obj, memoryview):
- * try:
- * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS, # <<<<<<<<<<<<<<
- * self.dtype_is_object)
- * except TypeError:
+ /* "View.MemoryView":540
+ * info.format = self.view.format
+ * else:
+ * info.format = NULL # <<<<<<<<<<<<<<
+ *
+ * info.buf = self.view.buf
*/
- __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 434, __pyx_L4_error)
- __Pyx_GOTREF(__pyx_t_8);
- __Pyx_INCREF(__pyx_v_obj);
- __Pyx_GIVEREF(__pyx_v_obj);
- PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_obj);
- __Pyx_GIVEREF(__pyx_t_6);
- PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
- __Pyx_GIVEREF(__pyx_t_7);
- PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
- __pyx_t_6 = 0;
- __pyx_t_7 = 0;
- __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 434, __pyx_L4_error)
- __Pyx_GOTREF(__pyx_t_7);
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
- __Pyx_DECREF_SET(__pyx_v_obj, __pyx_t_7);
- __pyx_t_7 = 0;
+ /*else*/ {
+ __pyx_v_info->format = NULL;
+ }
+ __pyx_L9:;
- /* "View.MemoryView":433
- * cdef is_slice(self, obj):
- * if not isinstance(obj, memoryview):
- * try: # <<<<<<<<<<<<<<
- * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
- * self.dtype_is_object)
+ /* "View.MemoryView":542
+ * info.format = NULL
+ *
+ * info.buf = self.view.buf # <<<<<<<<<<<<<<
+ * info.ndim = self.view.ndim
+ * info.itemsize = self.view.itemsize
*/
- }
- __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
- __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
- goto __pyx_L9_try_end;
- __pyx_L4_error:;
- __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
- __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
- __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
+ __pyx_t_6 = __pyx_v_self->view.buf;
+ __pyx_v_info->buf = __pyx_t_6;
- /* "View.MemoryView":436
- * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
- * self.dtype_is_object)
- * except TypeError: # <<<<<<<<<<<<<<
- * return None
+ /* "View.MemoryView":543
*
+ * info.buf = self.view.buf
+ * info.ndim = self.view.ndim # <<<<<<<<<<<<<<
+ * info.itemsize = self.view.itemsize
+ * info.len = self.view.len
*/
- __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_TypeError);
- if (__pyx_t_9) {
- __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
- if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(1, 436, __pyx_L6_except_error)
- __Pyx_GOTREF(__pyx_t_7);
- __Pyx_GOTREF(__pyx_t_8);
- __Pyx_GOTREF(__pyx_t_6);
+ __pyx_t_7 = __pyx_v_self->view.ndim;
+ __pyx_v_info->ndim = __pyx_t_7;
- /* "View.MemoryView":437
- * self.dtype_is_object)
- * except TypeError:
- * return None # <<<<<<<<<<<<<<
- *
- * return obj
+ /* "View.MemoryView":544
+ * info.buf = self.view.buf
+ * info.ndim = self.view.ndim
+ * info.itemsize = self.view.itemsize # <<<<<<<<<<<<<<
+ * info.len = self.view.len
+ * info.readonly = self.view.readonly
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
- goto __pyx_L7_except_return;
- }
- goto __pyx_L6_except_error;
- __pyx_L6_except_error:;
+ __pyx_t_8 = __pyx_v_self->view.itemsize;
+ __pyx_v_info->itemsize = __pyx_t_8;
- /* "View.MemoryView":433
- * cdef is_slice(self, obj):
- * if not isinstance(obj, memoryview):
- * try: # <<<<<<<<<<<<<<
- * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
- * self.dtype_is_object)
+ /* "View.MemoryView":545
+ * info.ndim = self.view.ndim
+ * info.itemsize = self.view.itemsize
+ * info.len = self.view.len # <<<<<<<<<<<<<<
+ * info.readonly = self.view.readonly
+ * info.obj = self
*/
- __Pyx_XGIVEREF(__pyx_t_3);
- __Pyx_XGIVEREF(__pyx_t_4);
- __Pyx_XGIVEREF(__pyx_t_5);
- __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
- goto __pyx_L1_error;
- __pyx_L7_except_return:;
- __Pyx_XGIVEREF(__pyx_t_3);
- __Pyx_XGIVEREF(__pyx_t_4);
- __Pyx_XGIVEREF(__pyx_t_5);
- __Pyx_ExceptionReset(__pyx_t_3, __pyx_t_4, __pyx_t_5);
- goto __pyx_L0;
- __pyx_L9_try_end:;
- }
+ __pyx_t_8 = __pyx_v_self->view.len;
+ __pyx_v_info->len = __pyx_t_8;
- /* "View.MemoryView":432
+ /* "View.MemoryView":546
+ * info.itemsize = self.view.itemsize
+ * info.len = self.view.len
+ * info.readonly = self.view.readonly # <<<<<<<<<<<<<<
+ * info.obj = self
*
- * cdef is_slice(self, obj):
- * if not isinstance(obj, memoryview): # <<<<<<<<<<<<<<
- * try:
- * obj = memoryview(obj, self.flags & ~PyBUF_WRITABLE | PyBUF_ANY_CONTIGUOUS,
*/
- }
+ __pyx_t_1 = __pyx_v_self->view.readonly;
+ __pyx_v_info->readonly = __pyx_t_1;
- /* "View.MemoryView":439
- * return None
- *
- * return obj # <<<<<<<<<<<<<<
+ /* "View.MemoryView":547
+ * info.len = self.view.len
+ * info.readonly = self.view.readonly
+ * info.obj = self # <<<<<<<<<<<<<<
*
- * cdef setitem_slice_assignment(self, dst, src):
+ * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")
*/
- __Pyx_XDECREF(__pyx_r);
- __Pyx_INCREF(__pyx_v_obj);
- __pyx_r = __pyx_v_obj;
- goto __pyx_L0;
+ __Pyx_INCREF(((PyObject *)__pyx_v_self));
+ __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
+ __Pyx_GOTREF(__pyx_v_info->obj);
+ __Pyx_DECREF(__pyx_v_info->obj);
+ __pyx_v_info->obj = ((PyObject *)__pyx_v_self);
- /* "View.MemoryView":431
- * self.setitem_indexed(index, value)
+ /* "View.MemoryView":518
*
- * cdef is_slice(self, obj): # <<<<<<<<<<<<<<
- * if not isinstance(obj, memoryview):
- * try:
+ * @cname('getbuffer')
+ * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<<
+ * if flags & PyBUF_WRITABLE and self.view.readonly:
+ * raise ValueError("Cannot create writable memory view from read-only memoryview")
*/
/* function exit code */
+ __pyx_r = 0;
+ goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_6);
- __Pyx_XDECREF(__pyx_t_7);
- __Pyx_XDECREF(__pyx_t_8);
- __Pyx_AddTraceback("View.MemoryView.memoryview.is_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = -1;
+ if (__pyx_v_info->obj != NULL) {
+ __Pyx_GOTREF(__pyx_v_info->obj);
+ __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
+ }
+ goto __pyx_L2;
__pyx_L0:;
- __Pyx_XDECREF(__pyx_v_obj);
- __Pyx_XGIVEREF(__pyx_r);
+ if (__pyx_v_info->obj == Py_None) {
+ __Pyx_GOTREF(__pyx_v_info->obj);
+ __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
+ }
+ __pyx_L2:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":441
- * return obj
+/* "View.MemoryView":553
*
- * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice dst_slice
- * cdef __Pyx_memviewslice src_slice
+ * @property
+ * def T(self): # <<<<<<<<<<<<<<
+ * cdef _memoryviewslice result = memoryview_copy(self)
+ * transpose_memslice(&result.from_slice)
*/
-static PyObject *__pyx_memoryview_setitem_slice_assignment(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_dst, PyObject *__pyx_v_src) {
- __Pyx_memviewslice __pyx_v_dst_slice;
- __Pyx_memviewslice __pyx_v_src_slice;
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+ struct __pyx_memoryviewslice_obj *__pyx_v_result = 0;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- __Pyx_memviewslice *__pyx_t_1;
- __Pyx_memviewslice *__pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- int __pyx_t_4;
- int __pyx_t_5;
- int __pyx_t_6;
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_t_2;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("setitem_slice_assignment", 0);
-
- /* "View.MemoryView":445
- * cdef __Pyx_memviewslice src_slice
- *
- * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<<
- * get_slice_from_memview(dst, &dst_slice)[0],
- * src.ndim, dst.ndim, self.dtype_is_object)
- */
- if (!(likely(((__pyx_v_src) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_src, __pyx_memoryview_type))))) __PYX_ERR(1, 445, __pyx_L1_error)
- __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_src), (&__pyx_v_src_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 445, __pyx_L1_error)
+ __Pyx_RefNannySetupContext("__get__", 0);
- /* "View.MemoryView":446
- *
- * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],
- * get_slice_from_memview(dst, &dst_slice)[0], # <<<<<<<<<<<<<<
- * src.ndim, dst.ndim, self.dtype_is_object)
- *
+ /* "View.MemoryView":554
+ * @property
+ * def T(self):
+ * cdef _memoryviewslice result = memoryview_copy(self) # <<<<<<<<<<<<<<
+ * transpose_memslice(&result.from_slice)
+ * return result
*/
- if (!(likely(((__pyx_v_dst) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_dst, __pyx_memoryview_type))))) __PYX_ERR(1, 446, __pyx_L1_error)
- __pyx_t_2 = __pyx_memoryview_get_slice_from_memoryview(((struct __pyx_memoryview_obj *)__pyx_v_dst), (&__pyx_v_dst_slice)); if (unlikely(__pyx_t_2 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 446, __pyx_L1_error)
+ __pyx_t_1 = __pyx_memoryview_copy_object(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 554, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryviewslice_type))))) __PYX_ERR(1, 554, __pyx_L1_error)
+ __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1);
+ __pyx_t_1 = 0;
- /* "View.MemoryView":447
- * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0],
- * get_slice_from_memview(dst, &dst_slice)[0],
- * src.ndim, dst.ndim, self.dtype_is_object) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":555
+ * def T(self):
+ * cdef _memoryviewslice result = memoryview_copy(self)
+ * transpose_memslice(&result.from_slice) # <<<<<<<<<<<<<<
+ * return result
*
- * cdef setitem_slice_assign_scalar(self, memoryview dst, value):
*/
- __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_src, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 447, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 447, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dst, __pyx_n_s_ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 447, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 447, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_2 = __pyx_memslice_transpose((&__pyx_v_result->from_slice)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(1, 555, __pyx_L1_error)
- /* "View.MemoryView":445
- * cdef __Pyx_memviewslice src_slice
+ /* "View.MemoryView":556
+ * cdef _memoryviewslice result = memoryview_copy(self)
+ * transpose_memslice(&result.from_slice)
+ * return result # <<<<<<<<<<<<<<
*
- * memoryview_copy_contents(get_slice_from_memview(src, &src_slice)[0], # <<<<<<<<<<<<<<
- * get_slice_from_memview(dst, &dst_slice)[0],
- * src.ndim, dst.ndim, self.dtype_is_object)
+ * @property
*/
- __pyx_t_6 = __pyx_memoryview_copy_contents((__pyx_t_1[0]), (__pyx_t_2[0]), __pyx_t_4, __pyx_t_5, __pyx_v_self->dtype_is_object); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(1, 445, __pyx_L1_error)
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)__pyx_v_result));
+ __pyx_r = ((PyObject *)__pyx_v_result);
+ goto __pyx_L0;
- /* "View.MemoryView":441
- * return obj
+ /* "View.MemoryView":553
*
- * cdef setitem_slice_assignment(self, dst, src): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice dst_slice
- * cdef __Pyx_memviewslice src_slice
+ * @property
+ * def T(self): # <<<<<<<<<<<<<<
+ * cdef _memoryviewslice result = memoryview_copy(self)
+ * transpose_memslice(&result.from_slice)
*/
/* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assignment", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.T.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
__pyx_L0:;
+ __Pyx_XDECREF((PyObject *)__pyx_v_result);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":449
- * src.ndim, dst.ndim, self.dtype_is_object)
+/* "View.MemoryView":559
+ *
+ * @property
+ * def base(self): # <<<<<<<<<<<<<<
+ * return self.obj
*
- * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<<
- * cdef int array[128]
- * cdef void *tmp = NULL
*/
-static PyObject *__pyx_memoryview_setitem_slice_assign_scalar(struct __pyx_memoryview_obj *__pyx_v_self, struct __pyx_memoryview_obj *__pyx_v_dst, PyObject *__pyx_v_value) {
- int __pyx_v_array[0x80];
- void *__pyx_v_tmp;
- void *__pyx_v_item;
- __Pyx_memviewslice *__pyx_v_dst_slice;
- __Pyx_memviewslice __pyx_v_tmp_slice;
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- __Pyx_memviewslice *__pyx_t_1;
- int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- int __pyx_t_4;
- int __pyx_t_5;
- char const *__pyx_t_6;
- PyObject *__pyx_t_7 = NULL;
- PyObject *__pyx_t_8 = NULL;
- PyObject *__pyx_t_9 = NULL;
- PyObject *__pyx_t_10 = NULL;
- PyObject *__pyx_t_11 = NULL;
- PyObject *__pyx_t_12 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("setitem_slice_assign_scalar", 0);
+ __Pyx_RefNannySetupContext("__get__", 0);
- /* "View.MemoryView":451
- * cdef setitem_slice_assign_scalar(self, memoryview dst, value):
- * cdef int array[128]
- * cdef void *tmp = NULL # <<<<<<<<<<<<<<
- * cdef void *item
+ /* "View.MemoryView":560
+ * @property
+ * def base(self):
+ * return self.obj # <<<<<<<<<<<<<<
*
+ * @property
*/
- __pyx_v_tmp = NULL;
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(__pyx_v_self->obj);
+ __pyx_r = __pyx_v_self->obj;
+ goto __pyx_L0;
- /* "View.MemoryView":456
- * cdef __Pyx_memviewslice *dst_slice
- * cdef __Pyx_memviewslice tmp_slice
- * dst_slice = get_slice_from_memview(dst, &tmp_slice) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":559
*
- * if self.view.itemsize > sizeof(array):
- */
- __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_dst, (&__pyx_v_tmp_slice)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 456, __pyx_L1_error)
- __pyx_v_dst_slice = __pyx_t_1;
-
- /* "View.MemoryView":458
- * dst_slice = get_slice_from_memview(dst, &tmp_slice)
+ * @property
+ * def base(self): # <<<<<<<<<<<<<<
+ * return self.obj
*
- * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<<
- * tmp = PyMem_Malloc(self.view.itemsize)
- * if tmp == NULL:
*/
- __pyx_t_2 = ((((size_t)__pyx_v_self->view.itemsize) > (sizeof(__pyx_v_array))) != 0);
- if (__pyx_t_2) {
- /* "View.MemoryView":459
+ /* function exit code */
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":563
+ *
+ * @property
+ * def shape(self): # <<<<<<<<<<<<<<
+ * return tuple([length for length in self.view.shape[:self.view.ndim]])
*
- * if self.view.itemsize > sizeof(array):
- * tmp = PyMem_Malloc(self.view.itemsize) # <<<<<<<<<<<<<<
- * if tmp == NULL:
- * raise MemoryError
*/
- __pyx_v_tmp = PyMem_Malloc(__pyx_v_self->view.itemsize);
- /* "View.MemoryView":460
- * if self.view.itemsize > sizeof(array):
- * tmp = PyMem_Malloc(self.view.itemsize)
- * if tmp == NULL: # <<<<<<<<<<<<<<
- * raise MemoryError
- * item = tmp
- */
- __pyx_t_2 = ((__pyx_v_tmp == NULL) != 0);
- if (unlikely(__pyx_t_2)) {
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
- /* "View.MemoryView":461
- * tmp = PyMem_Malloc(self.view.itemsize)
- * if tmp == NULL:
- * raise MemoryError # <<<<<<<<<<<<<<
- * item = tmp
- * else:
- */
- PyErr_NoMemory(); __PYX_ERR(1, 461, __pyx_L1_error)
-
- /* "View.MemoryView":460
- * if self.view.itemsize > sizeof(array):
- * tmp = PyMem_Malloc(self.view.itemsize)
- * if tmp == NULL: # <<<<<<<<<<<<<<
- * raise MemoryError
- * item = tmp
- */
- }
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":462
- * if tmp == NULL:
- * raise MemoryError
- * item = tmp # <<<<<<<<<<<<<<
- * else:
- * item = array
- */
- __pyx_v_item = __pyx_v_tmp;
+static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+ Py_ssize_t __pyx_v_length;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ Py_ssize_t *__pyx_t_2;
+ Py_ssize_t *__pyx_t_3;
+ Py_ssize_t *__pyx_t_4;
+ PyObject *__pyx_t_5 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__get__", 0);
- /* "View.MemoryView":458
- * dst_slice = get_slice_from_memview(dst, &tmp_slice)
+ /* "View.MemoryView":564
+ * @property
+ * def shape(self):
+ * return tuple([length for length in self.view.shape[:self.view.ndim]]) # <<<<<<<<<<<<<<
*
- * if self.view.itemsize > sizeof(array): # <<<<<<<<<<<<<<
- * tmp = PyMem_Malloc(self.view.itemsize)
- * if tmp == NULL:
+ * @property
*/
- goto __pyx_L3;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 564, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_3 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim);
+ for (__pyx_t_4 = __pyx_v_self->view.shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) {
+ __pyx_t_2 = __pyx_t_4;
+ __pyx_v_length = (__pyx_t_2[0]);
+ __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 564, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(1, 564, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
+ __pyx_t_5 = PyList_AsTuple(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 564, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_r = __pyx_t_5;
+ __pyx_t_5 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":464
- * item = tmp
- * else:
- * item = array # <<<<<<<<<<<<<<
+ /* "View.MemoryView":563
*
- * try:
- */
- /*else*/ {
- __pyx_v_item = ((void *)__pyx_v_array);
- }
- __pyx_L3:;
-
- /* "View.MemoryView":466
- * item = array
+ * @property
+ * def shape(self): # <<<<<<<<<<<<<<
+ * return tuple([length for length in self.view.shape[:self.view.ndim]])
*
- * try: # <<<<<<<<<<<<<<
- * if self.dtype_is_object:
- * ( item)[0] = value
*/
- /*try:*/ {
- /* "View.MemoryView":467
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":567
+ *
+ * @property
+ * def strides(self): # <<<<<<<<<<<<<<
+ * if self.view.strides == NULL:
*
- * try:
- * if self.dtype_is_object: # <<<<<<<<<<<<<<
- * ( item)[0] = value
- * else:
*/
- __pyx_t_2 = (__pyx_v_self->dtype_is_object != 0);
- if (__pyx_t_2) {
- /* "View.MemoryView":468
- * try:
- * if self.dtype_is_object:
- * ( item)[0] = value # <<<<<<<<<<<<<<
- * else:
- * self.assign_item_from_object( item, value)
- */
- (((PyObject **)__pyx_v_item)[0]) = ((PyObject *)__pyx_v_value);
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
- /* "View.MemoryView":467
- *
- * try:
- * if self.dtype_is_object: # <<<<<<<<<<<<<<
- * ( item)[0] = value
- * else:
- */
- goto __pyx_L8;
- }
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":470
- * ( item)[0] = value
- * else:
- * self.assign_item_from_object( item, value) # <<<<<<<<<<<<<<
- *
+static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+ Py_ssize_t __pyx_v_stride;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ Py_ssize_t *__pyx_t_3;
+ Py_ssize_t *__pyx_t_4;
+ Py_ssize_t *__pyx_t_5;
+ PyObject *__pyx_t_6 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__get__", 0);
+
+ /* "View.MemoryView":568
+ * @property
+ * def strides(self):
+ * if self.view.strides == NULL: # <<<<<<<<<<<<<<
*
+ * raise ValueError("Buffer view does not expose strides")
*/
- /*else*/ {
- __pyx_t_3 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, ((char *)__pyx_v_item), __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 470, __pyx_L6_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- }
- __pyx_L8:;
+ __pyx_t_1 = ((__pyx_v_self->view.strides == NULL) != 0);
+ if (unlikely(__pyx_t_1)) {
- /* "View.MemoryView":474
+ /* "View.MemoryView":570
+ * if self.view.strides == NULL:
*
+ * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<<
*
- * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<<
- * assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
- * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
+ * return tuple([stride for stride in self.view.strides[:self.view.ndim]])
*/
- __pyx_t_2 = ((__pyx_v_self->view.suboffsets != NULL) != 0);
- if (__pyx_t_2) {
+ __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 570, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_Raise(__pyx_t_2, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __PYX_ERR(1, 570, __pyx_L1_error)
- /* "View.MemoryView":475
+ /* "View.MemoryView":568
+ * @property
+ * def strides(self):
+ * if self.view.strides == NULL: # <<<<<<<<<<<<<<
*
- * if self.view.suboffsets != NULL:
- * assert_direct_dimensions(self.view.suboffsets, self.view.ndim) # <<<<<<<<<<<<<<
- * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
- * item, self.dtype_is_object)
+ * raise ValueError("Buffer view does not expose strides")
*/
- __pyx_t_3 = assert_direct_dimensions(__pyx_v_self->view.suboffsets, __pyx_v_self->view.ndim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 475, __pyx_L6_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ }
- /* "View.MemoryView":474
+ /* "View.MemoryView":572
+ * raise ValueError("Buffer view does not expose strides")
*
+ * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) # <<<<<<<<<<<<<<
*
- * if self.view.suboffsets != NULL: # <<<<<<<<<<<<<<
- * assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
- * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize,
- */
- }
-
- /* "View.MemoryView":476
- * if self.view.suboffsets != NULL:
- * assert_direct_dimensions(self.view.suboffsets, self.view.ndim)
- * slice_assign_scalar(dst_slice, dst.view.ndim, self.view.itemsize, # <<<<<<<<<<<<<<
- * item, self.dtype_is_object)
- * finally:
+ * @property
*/
- __pyx_memoryview_slice_assign_scalar(__pyx_v_dst_slice, __pyx_v_dst->view.ndim, __pyx_v_self->view.itemsize, __pyx_v_item, __pyx_v_self->dtype_is_object);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 572, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_4 = (__pyx_v_self->view.strides + __pyx_v_self->view.ndim);
+ for (__pyx_t_5 = __pyx_v_self->view.strides; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) {
+ __pyx_t_3 = __pyx_t_5;
+ __pyx_v_stride = (__pyx_t_3[0]);
+ __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 572, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) __PYX_ERR(1, 572, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
}
+ __pyx_t_6 = PyList_AsTuple(((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 572, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_6;
+ __pyx_t_6 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":479
- * item, self.dtype_is_object)
- * finally:
- * PyMem_Free(tmp) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":567
+ *
+ * @property
+ * def strides(self): # <<<<<<<<<<<<<<
+ * if self.view.strides == NULL:
*
- * cdef setitem_indexed(self, index, value):
- */
- /*finally:*/ {
- /*normal exit:*/{
- PyMem_Free(__pyx_v_tmp);
- goto __pyx_L7;
- }
- __pyx_L6_error:;
- /*exception exit:*/{
- __Pyx_PyThreadState_declare
- __Pyx_PyThreadState_assign
- __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
- __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
- if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
- if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
- __Pyx_XGOTREF(__pyx_t_7);
- __Pyx_XGOTREF(__pyx_t_8);
- __Pyx_XGOTREF(__pyx_t_9);
- __Pyx_XGOTREF(__pyx_t_10);
- __Pyx_XGOTREF(__pyx_t_11);
- __Pyx_XGOTREF(__pyx_t_12);
- __pyx_t_4 = __pyx_lineno; __pyx_t_5 = __pyx_clineno; __pyx_t_6 = __pyx_filename;
- {
- PyMem_Free(__pyx_v_tmp);
- }
- if (PY_MAJOR_VERSION >= 3) {
- __Pyx_XGIVEREF(__pyx_t_10);
- __Pyx_XGIVEREF(__pyx_t_11);
- __Pyx_XGIVEREF(__pyx_t_12);
- __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12);
- }
- __Pyx_XGIVEREF(__pyx_t_7);
- __Pyx_XGIVEREF(__pyx_t_8);
- __Pyx_XGIVEREF(__pyx_t_9);
- __Pyx_ErrRestore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
- __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0;
- __pyx_lineno = __pyx_t_4; __pyx_clineno = __pyx_t_5; __pyx_filename = __pyx_t_6;
- goto __pyx_L1_error;
- }
- __pyx_L7:;
- }
-
- /* "View.MemoryView":449
- * src.ndim, dst.ndim, self.dtype_is_object)
- *
- * cdef setitem_slice_assign_scalar(self, memoryview dst, value): # <<<<<<<<<<<<<<
- * cdef int array[128]
- * cdef void *tmp = NULL
*/
/* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_slice_assign_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":481
- * PyMem_Free(tmp)
+/* "View.MemoryView":575
*
- * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<<
- * cdef char *itemp = self.get_item_pointer(index)
- * self.assign_item_from_object(itemp, value)
+ * @property
+ * def suboffsets(self): # <<<<<<<<<<<<<<
+ * if self.view.suboffsets == NULL:
+ * return (-1,) * self.view.ndim
*/
-static PyObject *__pyx_memoryview_setitem_indexed(struct __pyx_memoryview_obj *__pyx_v_self, PyObject *__pyx_v_index, PyObject *__pyx_v_value) {
- char *__pyx_v_itemp;
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+ Py_ssize_t __pyx_v_suboffset;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- char *__pyx_t_1;
+ int __pyx_t_1;
PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ Py_ssize_t *__pyx_t_4;
+ Py_ssize_t *__pyx_t_5;
+ Py_ssize_t *__pyx_t_6;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("setitem_indexed", 0);
+ __Pyx_RefNannySetupContext("__get__", 0);
- /* "View.MemoryView":482
+ /* "View.MemoryView":576
+ * @property
+ * def suboffsets(self):
+ * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<<
+ * return (-1,) * self.view.ndim
*
- * cdef setitem_indexed(self, index, value):
- * cdef char *itemp = self.get_item_pointer(index) # <<<<<<<<<<<<<<
- * self.assign_item_from_object(itemp, value)
+ */
+ __pyx_t_1 = ((__pyx_v_self->view.suboffsets == NULL) != 0);
+ if (__pyx_t_1) {
+
+ /* "View.MemoryView":577
+ * def suboffsets(self):
+ * if self.view.suboffsets == NULL:
+ * return (-1,) * self.view.ndim # <<<<<<<<<<<<<<
*
+ * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]])
*/
- __pyx_t_1 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->get_item_pointer(__pyx_v_self, __pyx_v_index); if (unlikely(__pyx_t_1 == ((char *)NULL))) __PYX_ERR(1, 482, __pyx_L1_error)
- __pyx_v_itemp = __pyx_t_1;
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 577, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__12, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 577, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":483
- * cdef setitem_indexed(self, index, value):
- * cdef char *itemp = self.get_item_pointer(index)
- * self.assign_item_from_object(itemp, value) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":576
+ * @property
+ * def suboffsets(self):
+ * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<<
+ * return (-1,) * self.view.ndim
*
- * cdef convert_item_to_object(self, char *itemp):
*/
- __pyx_t_2 = ((struct __pyx_vtabstruct_memoryview *)__pyx_v_self->__pyx_vtab)->assign_item_from_object(__pyx_v_self, __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 483, __pyx_L1_error)
+ }
+
+ /* "View.MemoryView":579
+ * return (-1,) * self.view.ndim
+ *
+ * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) # <<<<<<<<<<<<<<
+ *
+ * @property
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 579, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_5 = (__pyx_v_self->view.suboffsets + __pyx_v_self->view.ndim);
+ for (__pyx_t_6 = __pyx_v_self->view.suboffsets; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) {
+ __pyx_t_4 = __pyx_t_6;
+ __pyx_v_suboffset = (__pyx_t_4[0]);
+ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_suboffset); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 579, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_2))) __PYX_ERR(1, 579, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ }
+ __pyx_t_2 = PyList_AsTuple(((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 579, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":481
- * PyMem_Free(tmp)
+ /* "View.MemoryView":575
*
- * cdef setitem_indexed(self, index, value): # <<<<<<<<<<<<<<
- * cdef char *itemp = self.get_item_pointer(index)
- * self.assign_item_from_object(itemp, value)
+ * @property
+ * def suboffsets(self): # <<<<<<<<<<<<<<
+ * if self.view.suboffsets == NULL:
+ * return (-1,) * self.view.ndim
*/
/* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
- __Pyx_AddTraceback("View.MemoryView.memoryview.setitem_indexed", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":485
- * self.assign_item_from_object(itemp, value)
+/* "View.MemoryView":582
+ *
+ * @property
+ * def ndim(self): # <<<<<<<<<<<<<<
+ * return self.view.ndim
*
- * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<<
- * """Only used if instantiated manually by the user, or if Cython doesn't
- * know how to convert the type"""
*/
-static PyObject *__pyx_memoryview_convert_item_to_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp) {
- PyObject *__pyx_v_struct = NULL;
- PyObject *__pyx_v_bytesitem = 0;
- PyObject *__pyx_v_result = NULL;
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
- PyObject *__pyx_t_2 = NULL;
- PyObject *__pyx_t_3 = NULL;
- PyObject *__pyx_t_4 = NULL;
- PyObject *__pyx_t_5 = NULL;
- PyObject *__pyx_t_6 = NULL;
- PyObject *__pyx_t_7 = NULL;
- int __pyx_t_8;
- PyObject *__pyx_t_9 = NULL;
- size_t __pyx_t_10;
- int __pyx_t_11;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("convert_item_to_object", 0);
+ __Pyx_RefNannySetupContext("__get__", 0);
- /* "View.MemoryView":488
- * """Only used if instantiated manually by the user, or if Cython doesn't
- * know how to convert the type"""
- * import struct # <<<<<<<<<<<<<<
- * cdef bytes bytesitem
+ /* "View.MemoryView":583
+ * @property
+ * def ndim(self):
+ * return self.view.ndim # <<<<<<<<<<<<<<
*
+ * @property
*/
- __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 488, __pyx_L1_error)
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 583, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
- __pyx_v_struct = __pyx_t_1;
+ __pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":491
- * cdef bytes bytesitem
+ /* "View.MemoryView":582
*
- * bytesitem = itemp[:self.view.itemsize] # <<<<<<<<<<<<<<
- * try:
- * result = struct.unpack(self.view.format, bytesitem)
- */
- __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_itemp + 0, __pyx_v_self->view.itemsize - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 491, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_v_bytesitem = ((PyObject*)__pyx_t_1);
- __pyx_t_1 = 0;
-
- /* "View.MemoryView":492
+ * @property
+ * def ndim(self): # <<<<<<<<<<<<<<
+ * return self.view.ndim
*
- * bytesitem = itemp[:self.view.itemsize]
- * try: # <<<<<<<<<<<<<<
- * result = struct.unpack(self.view.format, bytesitem)
- * except struct.error:
*/
- {
- __Pyx_PyThreadState_declare
- __Pyx_PyThreadState_assign
- __Pyx_ExceptionSave(&__pyx_t_2, &__pyx_t_3, &__pyx_t_4);
- __Pyx_XGOTREF(__pyx_t_2);
- __Pyx_XGOTREF(__pyx_t_3);
- __Pyx_XGOTREF(__pyx_t_4);
- /*try:*/ {
- /* "View.MemoryView":493
- * bytesitem = itemp[:self.view.itemsize]
- * try:
- * result = struct.unpack(self.view.format, bytesitem) # <<<<<<<<<<<<<<
- * except struct.error:
- * raise ValueError("Unable to convert item to object")
- */
- __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_unpack); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 493, __pyx_L3_error)
- __Pyx_GOTREF(__pyx_t_5);
- __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 493, __pyx_L3_error)
- __Pyx_GOTREF(__pyx_t_6);
- __pyx_t_7 = NULL;
- __pyx_t_8 = 0;
- if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
- __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
- if (likely(__pyx_t_7)) {
- PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
- __Pyx_INCREF(__pyx_t_7);
- __Pyx_INCREF(function);
- __Pyx_DECREF_SET(__pyx_t_5, function);
- __pyx_t_8 = 1;
- }
- }
- #if CYTHON_FAST_PYCALL
- if (PyFunction_Check(__pyx_t_5)) {
- PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem};
- __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 493, __pyx_L3_error)
- __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- } else
- #endif
- #if CYTHON_FAST_PYCCALL
- if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
- PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_t_6, __pyx_v_bytesitem};
- __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 493, __pyx_L3_error)
- __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- } else
- #endif
- {
- __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 493, __pyx_L3_error)
- __Pyx_GOTREF(__pyx_t_9);
- if (__pyx_t_7) {
- __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
- }
- __Pyx_GIVEREF(__pyx_t_6);
- PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_6);
- __Pyx_INCREF(__pyx_v_bytesitem);
- __Pyx_GIVEREF(__pyx_v_bytesitem);
- PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_bytesitem);
- __pyx_t_6 = 0;
- __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 493, __pyx_L3_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- }
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __pyx_v_result = __pyx_t_1;
- __pyx_t_1 = 0;
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.ndim.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":492
+/* "View.MemoryView":586
*
- * bytesitem = itemp[:self.view.itemsize]
- * try: # <<<<<<<<<<<<<<
- * result = struct.unpack(self.view.format, bytesitem)
- * except struct.error:
- */
- }
-
- /* "View.MemoryView":497
- * raise ValueError("Unable to convert item to object")
- * else:
- * if len(self.view.format) == 1: # <<<<<<<<<<<<<<
- * return result[0]
- * return result
- */
- /*else:*/ {
- __pyx_t_10 = strlen(__pyx_v_self->view.format);
- __pyx_t_11 = ((__pyx_t_10 == 1) != 0);
- if (__pyx_t_11) {
-
- /* "View.MemoryView":498
- * else:
- * if len(self.view.format) == 1:
- * return result[0] # <<<<<<<<<<<<<<
- * return result
+ * @property
+ * def itemsize(self): # <<<<<<<<<<<<<<
+ * return self.view.itemsize
*
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_result, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 498, __pyx_L5_except_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L6_except_return;
-
- /* "View.MemoryView":497
- * raise ValueError("Unable to convert item to object")
- * else:
- * if len(self.view.format) == 1: # <<<<<<<<<<<<<<
- * return result[0]
- * return result
- */
- }
- /* "View.MemoryView":499
- * if len(self.view.format) == 1:
- * return result[0]
- * return result # <<<<<<<<<<<<<<
- *
- * cdef assign_item_from_object(self, char *itemp, object value):
- */
- __Pyx_XDECREF(__pyx_r);
- __Pyx_INCREF(__pyx_v_result);
- __pyx_r = __pyx_v_result;
- goto __pyx_L6_except_return;
- }
- __pyx_L3_error:;
- __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
- __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
- __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
- /* "View.MemoryView":494
- * try:
- * result = struct.unpack(self.view.format, bytesitem)
- * except struct.error: # <<<<<<<<<<<<<<
- * raise ValueError("Unable to convert item to object")
- * else:
- */
- __Pyx_ErrFetch(&__pyx_t_1, &__pyx_t_5, &__pyx_t_9);
- __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_error); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 494, __pyx_L5_except_error)
- __Pyx_GOTREF(__pyx_t_6);
- __pyx_t_8 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_1, __pyx_t_6);
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __Pyx_ErrRestore(__pyx_t_1, __pyx_t_5, __pyx_t_9);
- __pyx_t_1 = 0; __pyx_t_5 = 0; __pyx_t_9 = 0;
- if (__pyx_t_8) {
- __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
- if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_5, &__pyx_t_1) < 0) __PYX_ERR(1, 494, __pyx_L5_except_error)
- __Pyx_GOTREF(__pyx_t_9);
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_GOTREF(__pyx_t_1);
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":495
- * result = struct.unpack(self.view.format, bytesitem)
- * except struct.error:
- * raise ValueError("Unable to convert item to object") # <<<<<<<<<<<<<<
- * else:
- * if len(self.view.format) == 1:
- */
- __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 495, __pyx_L5_except_error)
- __Pyx_GOTREF(__pyx_t_6);
- __Pyx_Raise(__pyx_t_6, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- __PYX_ERR(1, 495, __pyx_L5_except_error)
- }
- goto __pyx_L5_except_error;
- __pyx_L5_except_error:;
+static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__get__", 0);
- /* "View.MemoryView":492
+ /* "View.MemoryView":587
+ * @property
+ * def itemsize(self):
+ * return self.view.itemsize # <<<<<<<<<<<<<<
*
- * bytesitem = itemp[:self.view.itemsize]
- * try: # <<<<<<<<<<<<<<
- * result = struct.unpack(self.view.format, bytesitem)
- * except struct.error:
+ * @property
*/
- __Pyx_XGIVEREF(__pyx_t_2);
- __Pyx_XGIVEREF(__pyx_t_3);
- __Pyx_XGIVEREF(__pyx_t_4);
- __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
- goto __pyx_L1_error;
- __pyx_L6_except_return:;
- __Pyx_XGIVEREF(__pyx_t_2);
- __Pyx_XGIVEREF(__pyx_t_3);
- __Pyx_XGIVEREF(__pyx_t_4);
- __Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
- goto __pyx_L0;
- }
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 587, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":485
- * self.assign_item_from_object(itemp, value)
+ /* "View.MemoryView":586
+ *
+ * @property
+ * def itemsize(self): # <<<<<<<<<<<<<<
+ * return self.view.itemsize
*
- * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<<
- * """Only used if instantiated manually by the user, or if Cython doesn't
- * know how to convert the type"""
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_5);
- __Pyx_XDECREF(__pyx_t_6);
- __Pyx_XDECREF(__pyx_t_7);
- __Pyx_XDECREF(__pyx_t_9);
- __Pyx_AddTraceback("View.MemoryView.memoryview.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
+ __Pyx_AddTraceback("View.MemoryView.memoryview.itemsize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
__pyx_L0:;
- __Pyx_XDECREF(__pyx_v_struct);
- __Pyx_XDECREF(__pyx_v_bytesitem);
- __Pyx_XDECREF(__pyx_v_result);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":501
- * return result
+/* "View.MemoryView":590
+ *
+ * @property
+ * def nbytes(self): # <<<<<<<<<<<<<<
+ * return self.size * self.view.itemsize
*
- * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<<
- * """Only used if instantiated manually by the user, or if Cython doesn't
- * know how to convert the type"""
*/
-static PyObject *__pyx_memoryview_assign_item_from_object(struct __pyx_memoryview_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) {
- PyObject *__pyx_v_struct = NULL;
- char __pyx_v_c;
- PyObject *__pyx_v_bytesvalue = 0;
- Py_ssize_t __pyx_v_i;
- PyObject *__pyx_r = NULL;
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_t_2;
- int __pyx_t_3;
- PyObject *__pyx_t_4 = NULL;
- PyObject *__pyx_t_5 = NULL;
- PyObject *__pyx_t_6 = NULL;
- int __pyx_t_7;
- PyObject *__pyx_t_8 = NULL;
- Py_ssize_t __pyx_t_9;
- PyObject *__pyx_t_10 = NULL;
- char *__pyx_t_11;
- char *__pyx_t_12;
- char *__pyx_t_13;
- char *__pyx_t_14;
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("assign_item_from_object", 0);
-
- /* "View.MemoryView":504
- * """Only used if instantiated manually by the user, or if Cython doesn't
- * know how to convert the type"""
- * import struct # <<<<<<<<<<<<<<
- * cdef char c
- * cdef bytes bytesvalue
- */
- __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 504, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_v_struct = __pyx_t_1;
- __pyx_t_1 = 0;
-
- /* "View.MemoryView":509
- * cdef Py_ssize_t i
- *
- * if isinstance(value, tuple): # <<<<<<<<<<<<<<
- * bytesvalue = struct.pack(self.view.format, *value)
- * else:
- */
- __pyx_t_2 = PyTuple_Check(__pyx_v_value);
- __pyx_t_3 = (__pyx_t_2 != 0);
- if (__pyx_t_3) {
-
- /* "View.MemoryView":510
- *
- * if isinstance(value, tuple):
- * bytesvalue = struct.pack(self.view.format, *value) # <<<<<<<<<<<<<<
- * else:
- * bytesvalue = struct.pack(self.view.format, value)
- */
- __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 510, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_4 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 510, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 510, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_GIVEREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
- __pyx_t_4 = 0;
- __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 510, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 510, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 510, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 510, __pyx_L1_error)
- __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4);
- __pyx_t_4 = 0;
-
- /* "View.MemoryView":509
- * cdef Py_ssize_t i
- *
- * if isinstance(value, tuple): # <<<<<<<<<<<<<<
- * bytesvalue = struct.pack(self.view.format, *value)
- * else:
- */
- goto __pyx_L3;
- }
-
- /* "View.MemoryView":512
- * bytesvalue = struct.pack(self.view.format, *value)
- * else:
- * bytesvalue = struct.pack(self.view.format, value) # <<<<<<<<<<<<<<
- *
- * for i, c in enumerate(bytesvalue):
- */
- /*else*/ {
- __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_struct, __pyx_n_s_pack); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 512, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_self->view.format); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 512, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_5 = NULL;
- __pyx_t_7 = 0;
- if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
- __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
- if (likely(__pyx_t_5)) {
- PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
- __Pyx_INCREF(__pyx_t_5);
- __Pyx_INCREF(function);
- __Pyx_DECREF_SET(__pyx_t_6, function);
- __pyx_t_7 = 1;
- }
- }
- #if CYTHON_FAST_PYCALL
- if (PyFunction_Check(__pyx_t_6)) {
- PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value};
- __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 512, __pyx_L1_error)
- __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- } else
- #endif
- #if CYTHON_FAST_PYCCALL
- if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
- PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_value};
- __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 512, __pyx_L1_error)
- __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- } else
- #endif
- {
- __pyx_t_8 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 512, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_8);
- if (__pyx_t_5) {
- __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL;
- }
- __Pyx_GIVEREF(__pyx_t_1);
- PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_1);
- __Pyx_INCREF(__pyx_v_value);
- __Pyx_GIVEREF(__pyx_v_value);
- PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_v_value);
- __pyx_t_1 = 0;
- __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 512, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
- }
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- if (!(likely(PyBytes_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(1, 512, __pyx_L1_error)
- __pyx_v_bytesvalue = ((PyObject*)__pyx_t_4);
- __pyx_t_4 = 0;
- }
- __pyx_L3:;
-
- /* "View.MemoryView":514
- * bytesvalue = struct.pack(self.view.format, value)
- *
- * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<<
- * itemp[i] = c
- *
- */
- __pyx_t_9 = 0;
- if (unlikely(__pyx_v_bytesvalue == Py_None)) {
- PyErr_SetString(PyExc_TypeError, "'NoneType' is not iterable");
- __PYX_ERR(1, 514, __pyx_L1_error)
- }
- __Pyx_INCREF(__pyx_v_bytesvalue);
- __pyx_t_10 = __pyx_v_bytesvalue;
- __pyx_t_12 = PyBytes_AS_STRING(__pyx_t_10);
- __pyx_t_13 = (__pyx_t_12 + PyBytes_GET_SIZE(__pyx_t_10));
- for (__pyx_t_14 = __pyx_t_12; __pyx_t_14 < __pyx_t_13; __pyx_t_14++) {
- __pyx_t_11 = __pyx_t_14;
- __pyx_v_c = (__pyx_t_11[0]);
-
- /* "View.MemoryView":515
- *
- * for i, c in enumerate(bytesvalue):
- * itemp[i] = c # <<<<<<<<<<<<<<
- *
- * @cname('getbuffer')
- */
- __pyx_v_i = __pyx_t_9;
+ __Pyx_RefNannySetupContext("__get__", 0);
- /* "View.MemoryView":514
- * bytesvalue = struct.pack(self.view.format, value)
- *
- * for i, c in enumerate(bytesvalue): # <<<<<<<<<<<<<<
- * itemp[i] = c
+ /* "View.MemoryView":591
+ * @property
+ * def nbytes(self):
+ * return self.size * self.view.itemsize # <<<<<<<<<<<<<<
*
+ * @property
*/
- __pyx_t_9 = (__pyx_t_9 + 1);
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 591, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 591, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 591, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_3;
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":515
- *
- * for i, c in enumerate(bytesvalue):
- * itemp[i] = c # <<<<<<<<<<<<<<
+ /* "View.MemoryView":590
*
- * @cname('getbuffer')
- */
- (__pyx_v_itemp[__pyx_v_i]) = __pyx_v_c;
- }
- __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
-
- /* "View.MemoryView":501
- * return result
+ * @property
+ * def nbytes(self): # <<<<<<<<<<<<<<
+ * return self.size * self.view.itemsize
*
- * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<<
- * """Only used if instantiated manually by the user, or if Cython doesn't
- * know how to convert the type"""
*/
/* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_4);
- __Pyx_XDECREF(__pyx_t_5);
- __Pyx_XDECREF(__pyx_t_6);
- __Pyx_XDECREF(__pyx_t_8);
- __Pyx_XDECREF(__pyx_t_10);
- __Pyx_AddTraceback("View.MemoryView.memoryview.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
__pyx_L0:;
- __Pyx_XDECREF(__pyx_v_struct);
- __Pyx_XDECREF(__pyx_v_bytesvalue);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":518
+/* "View.MemoryView":594
*
- * @cname('getbuffer')
- * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<<
- * if flags & PyBUF_WRITABLE and self.view.readonly:
- * raise ValueError("Cannot create writable memory view from read-only memoryview")
+ * @property
+ * def size(self): # <<<<<<<<<<<<<<
+ * if self._size is None:
+ * result = 1
*/
/* Python wrapper */
-static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
-static CYTHON_UNUSED int __pyx_memoryview_getbuffer(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
- int __pyx_r;
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static int __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_8__getbuffer__(struct __pyx_memoryview_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
- int __pyx_r;
+static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+ PyObject *__pyx_v_result = NULL;
+ PyObject *__pyx_v_length = NULL;
+ PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
+ Py_ssize_t *__pyx_t_3;
Py_ssize_t *__pyx_t_4;
- char *__pyx_t_5;
- void *__pyx_t_6;
- int __pyx_t_7;
- Py_ssize_t __pyx_t_8;
+ Py_ssize_t *__pyx_t_5;
+ PyObject *__pyx_t_6 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- if (__pyx_v_info == NULL) {
- PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
- return -1;
- }
- __Pyx_RefNannySetupContext("__getbuffer__", 0);
- __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
- __Pyx_GIVEREF(__pyx_v_info->obj);
+ __Pyx_RefNannySetupContext("__get__", 0);
- /* "View.MemoryView":519
- * @cname('getbuffer')
- * def __getbuffer__(self, Py_buffer *info, int flags):
- * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<<
- * raise ValueError("Cannot create writable memory view from read-only memoryview")
+ /* "View.MemoryView":595
+ * @property
+ * def size(self):
+ * if self._size is None: # <<<<<<<<<<<<<<
+ * result = 1
*
*/
- __pyx_t_2 = ((__pyx_v_flags & PyBUF_WRITABLE) != 0);
+ __pyx_t_1 = (__pyx_v_self->_size == Py_None);
+ __pyx_t_2 = (__pyx_t_1 != 0);
if (__pyx_t_2) {
- } else {
- __pyx_t_1 = __pyx_t_2;
- goto __pyx_L4_bool_binop_done;
- }
- __pyx_t_2 = (__pyx_v_self->view.readonly != 0);
- __pyx_t_1 = __pyx_t_2;
- __pyx_L4_bool_binop_done:;
- if (unlikely(__pyx_t_1)) {
- /* "View.MemoryView":520
- * def __getbuffer__(self, Py_buffer *info, int flags):
- * if flags & PyBUF_WRITABLE and self.view.readonly:
- * raise ValueError("Cannot create writable memory view from read-only memoryview") # <<<<<<<<<<<<<<
+ /* "View.MemoryView":596
+ * def size(self):
+ * if self._size is None:
+ * result = 1 # <<<<<<<<<<<<<<
*
- * if flags & PyBUF_ND:
+ * for length in self.view.shape[:self.view.ndim]:
*/
- __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 520, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_Raise(__pyx_t_3, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __PYX_ERR(1, 520, __pyx_L1_error)
+ __Pyx_INCREF(__pyx_int_1);
+ __pyx_v_result = __pyx_int_1;
- /* "View.MemoryView":519
- * @cname('getbuffer')
- * def __getbuffer__(self, Py_buffer *info, int flags):
- * if flags & PyBUF_WRITABLE and self.view.readonly: # <<<<<<<<<<<<<<
- * raise ValueError("Cannot create writable memory view from read-only memoryview")
+ /* "View.MemoryView":598
+ * result = 1
*
- */
- }
-
- /* "View.MemoryView":522
- * raise ValueError("Cannot create writable memory view from read-only memoryview")
+ * for length in self.view.shape[:self.view.ndim]: # <<<<<<<<<<<<<<
+ * result *= length
*
- * if flags & PyBUF_ND: # <<<<<<<<<<<<<<
- * info.shape = self.view.shape
- * else:
*/
- __pyx_t_1 = ((__pyx_v_flags & PyBUF_ND) != 0);
- if (__pyx_t_1) {
+ __pyx_t_4 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim);
+ for (__pyx_t_5 = __pyx_v_self->view.shape; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) {
+ __pyx_t_3 = __pyx_t_5;
+ __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_3[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 598, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_6);
+ __pyx_t_6 = 0;
- /* "View.MemoryView":523
+ /* "View.MemoryView":599
*
- * if flags & PyBUF_ND:
- * info.shape = self.view.shape # <<<<<<<<<<<<<<
- * else:
- * info.shape = NULL
+ * for length in self.view.shape[:self.view.ndim]:
+ * result *= length # <<<<<<<<<<<<<<
+ *
+ * self._size = result
*/
- __pyx_t_4 = __pyx_v_self->view.shape;
- __pyx_v_info->shape = __pyx_t_4;
+ __pyx_t_6 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 599, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_6);
+ __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_6);
+ __pyx_t_6 = 0;
+ }
- /* "View.MemoryView":522
- * raise ValueError("Cannot create writable memory view from read-only memoryview")
+ /* "View.MemoryView":601
+ * result *= length
*
- * if flags & PyBUF_ND: # <<<<<<<<<<<<<<
- * info.shape = self.view.shape
- * else:
+ * self._size = result # <<<<<<<<<<<<<<
+ *
+ * return self._size
*/
- goto __pyx_L6;
- }
+ __Pyx_INCREF(__pyx_v_result);
+ __Pyx_GIVEREF(__pyx_v_result);
+ __Pyx_GOTREF(__pyx_v_self->_size);
+ __Pyx_DECREF(__pyx_v_self->_size);
+ __pyx_v_self->_size = __pyx_v_result;
- /* "View.MemoryView":525
- * info.shape = self.view.shape
- * else:
- * info.shape = NULL # <<<<<<<<<<<<<<
+ /* "View.MemoryView":595
+ * @property
+ * def size(self):
+ * if self._size is None: # <<<<<<<<<<<<<<
+ * result = 1
*
- * if flags & PyBUF_STRIDES:
*/
- /*else*/ {
- __pyx_v_info->shape = NULL;
}
- __pyx_L6:;
- /* "View.MemoryView":527
- * info.shape = NULL
+ /* "View.MemoryView":603
+ * self._size = result
*
- * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<<
- * info.strides = self.view.strides
- * else:
- */
- __pyx_t_1 = ((__pyx_v_flags & PyBUF_STRIDES) != 0);
- if (__pyx_t_1) {
-
- /* "View.MemoryView":528
+ * return self._size # <<<<<<<<<<<<<<
*
- * if flags & PyBUF_STRIDES:
- * info.strides = self.view.strides # <<<<<<<<<<<<<<
- * else:
- * info.strides = NULL
+ * def __len__(self):
*/
- __pyx_t_4 = __pyx_v_self->view.strides;
- __pyx_v_info->strides = __pyx_t_4;
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(__pyx_v_self->_size);
+ __pyx_r = __pyx_v_self->_size;
+ goto __pyx_L0;
- /* "View.MemoryView":527
- * info.shape = NULL
+ /* "View.MemoryView":594
*
- * if flags & PyBUF_STRIDES: # <<<<<<<<<<<<<<
- * info.strides = self.view.strides
- * else:
+ * @property
+ * def size(self): # <<<<<<<<<<<<<<
+ * if self._size is None:
+ * result = 1
*/
- goto __pyx_L7;
- }
- /* "View.MemoryView":530
- * info.strides = self.view.strides
- * else:
- * info.strides = NULL # <<<<<<<<<<<<<<
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_6);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.size.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_result);
+ __Pyx_XDECREF(__pyx_v_length);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":605
+ * return self._size
*
- * if flags & PyBUF_INDIRECT:
+ * def __len__(self): # <<<<<<<<<<<<<<
+ * if self.view.ndim >= 1:
+ * return self.view.shape[0]
*/
- /*else*/ {
- __pyx_v_info->strides = NULL;
- }
- __pyx_L7:;
- /* "View.MemoryView":532
- * info.strides = NULL
+/* Python wrapper */
+static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self); /*proto*/
+static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self) {
+ Py_ssize_t __pyx_r;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) {
+ Py_ssize_t __pyx_r;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ __Pyx_RefNannySetupContext("__len__", 0);
+
+ /* "View.MemoryView":606
+ *
+ * def __len__(self):
+ * if self.view.ndim >= 1: # <<<<<<<<<<<<<<
+ * return self.view.shape[0]
*
- * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<<
- * info.suboffsets = self.view.suboffsets
- * else:
*/
- __pyx_t_1 = ((__pyx_v_flags & PyBUF_INDIRECT) != 0);
+ __pyx_t_1 = ((__pyx_v_self->view.ndim >= 1) != 0);
if (__pyx_t_1) {
- /* "View.MemoryView":533
+ /* "View.MemoryView":607
+ * def __len__(self):
+ * if self.view.ndim >= 1:
+ * return self.view.shape[0] # <<<<<<<<<<<<<<
*
- * if flags & PyBUF_INDIRECT:
- * info.suboffsets = self.view.suboffsets # <<<<<<<<<<<<<<
- * else:
- * info.suboffsets = NULL
+ * return 0
*/
- __pyx_t_4 = __pyx_v_self->view.suboffsets;
- __pyx_v_info->suboffsets = __pyx_t_4;
+ __pyx_r = (__pyx_v_self->view.shape[0]);
+ goto __pyx_L0;
- /* "View.MemoryView":532
- * info.strides = NULL
+ /* "View.MemoryView":606
+ *
+ * def __len__(self):
+ * if self.view.ndim >= 1: # <<<<<<<<<<<<<<
+ * return self.view.shape[0]
*
- * if flags & PyBUF_INDIRECT: # <<<<<<<<<<<<<<
- * info.suboffsets = self.view.suboffsets
- * else:
*/
- goto __pyx_L8;
}
- /* "View.MemoryView":535
- * info.suboffsets = self.view.suboffsets
- * else:
- * info.suboffsets = NULL # <<<<<<<<<<<<<<
- *
- * if flags & PyBUF_FORMAT:
- */
- /*else*/ {
- __pyx_v_info->suboffsets = NULL;
- }
- __pyx_L8:;
-
- /* "View.MemoryView":537
- * info.suboffsets = NULL
- *
- * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
- * info.format = self.view.format
- * else:
- */
- __pyx_t_1 = ((__pyx_v_flags & PyBUF_FORMAT) != 0);
- if (__pyx_t_1) {
-
- /* "View.MemoryView":538
- *
- * if flags & PyBUF_FORMAT:
- * info.format = self.view.format # <<<<<<<<<<<<<<
- * else:
- * info.format = NULL
- */
- __pyx_t_5 = __pyx_v_self->view.format;
- __pyx_v_info->format = __pyx_t_5;
-
- /* "View.MemoryView":537
- * info.suboffsets = NULL
- *
- * if flags & PyBUF_FORMAT: # <<<<<<<<<<<<<<
- * info.format = self.view.format
- * else:
- */
- goto __pyx_L9;
- }
-
- /* "View.MemoryView":540
- * info.format = self.view.format
- * else:
- * info.format = NULL # <<<<<<<<<<<<<<
- *
- * info.buf = self.view.buf
- */
- /*else*/ {
- __pyx_v_info->format = NULL;
- }
- __pyx_L9:;
-
- /* "View.MemoryView":542
- * info.format = NULL
- *
- * info.buf = self.view.buf # <<<<<<<<<<<<<<
- * info.ndim = self.view.ndim
- * info.itemsize = self.view.itemsize
- */
- __pyx_t_6 = __pyx_v_self->view.buf;
- __pyx_v_info->buf = __pyx_t_6;
-
- /* "View.MemoryView":543
- *
- * info.buf = self.view.buf
- * info.ndim = self.view.ndim # <<<<<<<<<<<<<<
- * info.itemsize = self.view.itemsize
- * info.len = self.view.len
- */
- __pyx_t_7 = __pyx_v_self->view.ndim;
- __pyx_v_info->ndim = __pyx_t_7;
-
- /* "View.MemoryView":544
- * info.buf = self.view.buf
- * info.ndim = self.view.ndim
- * info.itemsize = self.view.itemsize # <<<<<<<<<<<<<<
- * info.len = self.view.len
- * info.readonly = self.view.readonly
- */
- __pyx_t_8 = __pyx_v_self->view.itemsize;
- __pyx_v_info->itemsize = __pyx_t_8;
-
- /* "View.MemoryView":545
- * info.ndim = self.view.ndim
- * info.itemsize = self.view.itemsize
- * info.len = self.view.len # <<<<<<<<<<<<<<
- * info.readonly = self.view.readonly
- * info.obj = self
- */
- __pyx_t_8 = __pyx_v_self->view.len;
- __pyx_v_info->len = __pyx_t_8;
-
- /* "View.MemoryView":546
- * info.itemsize = self.view.itemsize
- * info.len = self.view.len
- * info.readonly = self.view.readonly # <<<<<<<<<<<<<<
- * info.obj = self
+ /* "View.MemoryView":609
+ * return self.view.shape[0]
*
- */
- __pyx_t_1 = __pyx_v_self->view.readonly;
- __pyx_v_info->readonly = __pyx_t_1;
-
- /* "View.MemoryView":547
- * info.len = self.view.len
- * info.readonly = self.view.readonly
- * info.obj = self # <<<<<<<<<<<<<<
+ * return 0 # <<<<<<<<<<<<<<
*
- * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")
+ * def __repr__(self):
*/
- __Pyx_INCREF(((PyObject *)__pyx_v_self));
- __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
- __Pyx_GOTREF(__pyx_v_info->obj);
- __Pyx_DECREF(__pyx_v_info->obj);
- __pyx_v_info->obj = ((PyObject *)__pyx_v_self);
+ __pyx_r = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":518
+ /* "View.MemoryView":605
+ * return self._size
*
- * @cname('getbuffer')
- * def __getbuffer__(self, Py_buffer *info, int flags): # <<<<<<<<<<<<<<
- * if flags & PyBUF_WRITABLE and self.view.readonly:
- * raise ValueError("Cannot create writable memory view from read-only memoryview")
+ * def __len__(self): # <<<<<<<<<<<<<<
+ * if self.view.ndim >= 1:
+ * return self.view.shape[0]
*/
/* function exit code */
- __pyx_r = 0;
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_AddTraceback("View.MemoryView.memoryview.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = -1;
- if (__pyx_v_info->obj != NULL) {
- __Pyx_GOTREF(__pyx_v_info->obj);
- __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
- }
- goto __pyx_L2;
__pyx_L0:;
- if (__pyx_v_info->obj == Py_None) {
- __Pyx_GOTREF(__pyx_v_info->obj);
- __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
- }
- __pyx_L2:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":553
+/* "View.MemoryView":611
+ * return 0
*
- * @property
- * def T(self): # <<<<<<<<<<<<<<
- * cdef _memoryviewslice result = memoryview_copy(self)
- * transpose_memslice(&result.from_slice)
+ * def __repr__(self): # <<<<<<<<<<<<<<
+ * return "" % (self.base.__class__.__name__,
+ * id(self))
*/
/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_1T_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_1T___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
- struct __pyx_memoryviewslice_obj *__pyx_v_result = 0;
+static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
- int __pyx_t_2;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__get__", 0);
+ __Pyx_RefNannySetupContext("__repr__", 0);
- /* "View.MemoryView":554
- * @property
- * def T(self):
- * cdef _memoryviewslice result = memoryview_copy(self) # <<<<<<<<<<<<<<
- * transpose_memslice(&result.from_slice)
- * return result
+ /* "View.MemoryView":612
+ *
+ * def __repr__(self):
+ * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<<
+ * id(self))
+ *
*/
- __pyx_t_1 = __pyx_memoryview_copy_object(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 554, __pyx_L1_error)
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 612, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
- if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_memoryviewslice_type))))) __PYX_ERR(1, 554, __pyx_L1_error)
- __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_1);
- __pyx_t_1 = 0;
+ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 612, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 612, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- /* "View.MemoryView":555
- * def T(self):
- * cdef _memoryviewslice result = memoryview_copy(self)
- * transpose_memslice(&result.from_slice) # <<<<<<<<<<<<<<
- * return result
+ /* "View.MemoryView":613
+ * def __repr__(self):
+ * return "" % (self.base.__class__.__name__,
+ * id(self)) # <<<<<<<<<<<<<<
*
+ * def __str__(self):
*/
- __pyx_t_2 = __pyx_memslice_transpose((&__pyx_v_result->from_slice)); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(1, 555, __pyx_L1_error)
+ __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 613, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
- /* "View.MemoryView":556
- * cdef _memoryviewslice result = memoryview_copy(self)
- * transpose_memslice(&result.from_slice)
- * return result # <<<<<<<<<<<<<<
+ /* "View.MemoryView":612
+ *
+ * def __repr__(self):
+ * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<<
+ * id(self))
*
- * @property
*/
- __Pyx_XDECREF(__pyx_r);
- __Pyx_INCREF(((PyObject *)__pyx_v_result));
- __pyx_r = ((PyObject *)__pyx_v_result);
+ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 612, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
+ __pyx_t_1 = 0;
+ __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 612, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
- /* "View.MemoryView":553
+ /* "View.MemoryView":611
+ * return 0
*
- * @property
- * def T(self): # <<<<<<<<<<<<<<
- * cdef _memoryviewslice result = memoryview_copy(self)
- * transpose_memslice(&result.from_slice)
+ * def __repr__(self): # <<<<<<<<<<<<<<
+ * return "" % (self.base.__class__.__name__,
+ * id(self))
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.memoryview.T.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
- __Pyx_XDECREF((PyObject *)__pyx_v_result);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":559
+/* "View.MemoryView":615
+ * id(self))
*
- * @property
- * def base(self): # <<<<<<<<<<<<<<
- * return self.obj
+ * def __str__(self): # <<<<<<<<<<<<<<
+ * return "" % (self.base.__class__.__name__,)
*
*/
/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4base_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4base___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__", 0);
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__str__", 0);
- /* "View.MemoryView":560
- * @property
- * def base(self):
- * return self.obj # <<<<<<<<<<<<<<
+ /* "View.MemoryView":616
+ *
+ * def __str__(self):
+ * return "" % (self.base.__class__.__name__,) # <<<<<<<<<<<<<<
+ *
*
- * @property
*/
__Pyx_XDECREF(__pyx_r);
- __Pyx_INCREF(__pyx_v_self->obj);
- __pyx_r = __pyx_v_self->obj;
+ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 616, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 616, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 616, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 616, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
+ __pyx_t_1 = 0;
+ __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_object, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 616, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_r = __pyx_t_1;
+ __pyx_t_1 = 0;
goto __pyx_L0;
- /* "View.MemoryView":559
+ /* "View.MemoryView":615
+ * id(self))
*
- * @property
- * def base(self): # <<<<<<<<<<<<<<
- * return self.obj
+ * def __str__(self): # <<<<<<<<<<<<<<
+ * return "" % (self.base.__class__.__name__,)
*
*/
/* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":563
+/* "View.MemoryView":619
*
- * @property
- * def shape(self): # <<<<<<<<<<<<<<
- * return tuple([length for length in self.view.shape[:self.view.ndim]])
*
+ * def is_c_contig(self): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice *mslice
+ * cdef __Pyx_memviewslice tmp
*/
/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_5shape_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ __Pyx_RefNannySetupContext("is_c_contig (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
- Py_ssize_t __pyx_v_length;
+static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self) {
+ __Pyx_memviewslice *__pyx_v_mslice;
+ __Pyx_memviewslice __pyx_v_tmp;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- Py_ssize_t *__pyx_t_2;
- Py_ssize_t *__pyx_t_3;
- Py_ssize_t *__pyx_t_4;
- PyObject *__pyx_t_5 = NULL;
+ __Pyx_memviewslice *__pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__get__", 0);
+ __Pyx_RefNannySetupContext("is_c_contig", 0);
- /* "View.MemoryView":564
- * @property
- * def shape(self):
- * return tuple([length for length in self.view.shape[:self.view.ndim]]) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":622
+ * cdef __Pyx_memviewslice *mslice
+ * cdef __Pyx_memviewslice tmp
+ * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<<
+ * return slice_is_contig(mslice[0], 'C', self.view.ndim)
*
- * @property
+ */
+ __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 622, __pyx_L1_error)
+ __pyx_v_mslice = __pyx_t_1;
+
+ /* "View.MemoryView":623
+ * cdef __Pyx_memviewslice tmp
+ * mslice = get_slice_from_memview(self, &tmp)
+ * return slice_is_contig(mslice[0], 'C', self.view.ndim) # <<<<<<<<<<<<<<
+ *
+ * def is_f_contig(self):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 564, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_3 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim);
- for (__pyx_t_4 = __pyx_v_self->view.shape; __pyx_t_4 < __pyx_t_3; __pyx_t_4++) {
- __pyx_t_2 = __pyx_t_4;
- __pyx_v_length = (__pyx_t_2[0]);
- __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 564, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(1, 564, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- }
- __pyx_t_5 = PyList_AsTuple(((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 564, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_r = __pyx_t_5;
- __pyx_t_5 = 0;
+ __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 623, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
- /* "View.MemoryView":563
+ /* "View.MemoryView":619
*
- * @property
- * def shape(self): # <<<<<<<<<<<<<<
- * return tuple([length for length in self.view.shape[:self.view.ndim]])
*
+ * def is_c_contig(self): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice *mslice
+ * cdef __Pyx_memviewslice tmp
*/
/* function exit code */
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_5);
- __Pyx_AddTraceback("View.MemoryView.memoryview.shape.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.is_c_contig", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
@@ -9862,113 +9112,75 @@ static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_5shape___get__(stru
return __pyx_r;
}
-/* "View.MemoryView":567
- *
- * @property
- * def strides(self): # <<<<<<<<<<<<<<
- * if self.view.strides == NULL:
+/* "View.MemoryView":625
+ * return slice_is_contig(mslice[0], 'C', self.view.ndim)
*
+ * def is_f_contig(self): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice *mslice
+ * cdef __Pyx_memviewslice tmp
*/
/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_7strides_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ __Pyx_RefNannySetupContext("is_f_contig (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
- Py_ssize_t __pyx_v_stride;
+static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self) {
+ __Pyx_memviewslice *__pyx_v_mslice;
+ __Pyx_memviewslice __pyx_v_tmp;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- int __pyx_t_1;
+ __Pyx_memviewslice *__pyx_t_1;
PyObject *__pyx_t_2 = NULL;
- Py_ssize_t *__pyx_t_3;
- Py_ssize_t *__pyx_t_4;
- Py_ssize_t *__pyx_t_5;
- PyObject *__pyx_t_6 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__get__", 0);
-
- /* "View.MemoryView":568
- * @property
- * def strides(self):
- * if self.view.strides == NULL: # <<<<<<<<<<<<<<
- *
- * raise ValueError("Buffer view does not expose strides")
- */
- __pyx_t_1 = ((__pyx_v_self->view.strides == NULL) != 0);
- if (unlikely(__pyx_t_1)) {
-
- /* "View.MemoryView":570
- * if self.view.strides == NULL:
- *
- * raise ValueError("Buffer view does not expose strides") # <<<<<<<<<<<<<<
- *
- * return tuple([stride for stride in self.view.strides[:self.view.ndim]])
- */
- __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 570, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_Raise(__pyx_t_2, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __PYX_ERR(1, 570, __pyx_L1_error)
+ __Pyx_RefNannySetupContext("is_f_contig", 0);
- /* "View.MemoryView":568
- * @property
- * def strides(self):
- * if self.view.strides == NULL: # <<<<<<<<<<<<<<
+ /* "View.MemoryView":628
+ * cdef __Pyx_memviewslice *mslice
+ * cdef __Pyx_memviewslice tmp
+ * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<<
+ * return slice_is_contig(mslice[0], 'F', self.view.ndim)
*
- * raise ValueError("Buffer view does not expose strides")
*/
- }
+ __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 628, __pyx_L1_error)
+ __pyx_v_mslice = __pyx_t_1;
- /* "View.MemoryView":572
- * raise ValueError("Buffer view does not expose strides")
- *
- * return tuple([stride for stride in self.view.strides[:self.view.ndim]]) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":629
+ * cdef __Pyx_memviewslice tmp
+ * mslice = get_slice_from_memview(self, &tmp)
+ * return slice_is_contig(mslice[0], 'F', self.view.ndim) # <<<<<<<<<<<<<<
*
- * @property
+ * def copy(self):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 572, __pyx_L1_error)
+ __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 629, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
- __pyx_t_4 = (__pyx_v_self->view.strides + __pyx_v_self->view.ndim);
- for (__pyx_t_5 = __pyx_v_self->view.strides; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) {
- __pyx_t_3 = __pyx_t_5;
- __pyx_v_stride = (__pyx_t_3[0]);
- __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 572, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) __PYX_ERR(1, 572, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
- }
- __pyx_t_6 = PyList_AsTuple(((PyObject*)__pyx_t_2)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 572, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_r = __pyx_t_6;
- __pyx_t_6 = 0;
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
- /* "View.MemoryView":567
- *
- * @property
- * def strides(self): # <<<<<<<<<<<<<<
- * if self.view.strides == NULL:
+ /* "View.MemoryView":625
+ * return slice_is_contig(mslice[0], 'C', self.view.ndim)
*
+ * def is_f_contig(self): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice *mslice
+ * cdef __Pyx_memviewslice tmp
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
- __Pyx_XDECREF(__pyx_t_6);
- __Pyx_AddTraceback("View.MemoryView.memoryview.strides.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.is_f_contig", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
@@ -9976,117 +9188,93 @@ static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_7strides___get__(st
return __pyx_r;
}
-/* "View.MemoryView":575
+/* "View.MemoryView":631
+ * return slice_is_contig(mslice[0], 'F', self.view.ndim)
*
- * @property
- * def suboffsets(self): # <<<<<<<<<<<<<<
- * if self.view.suboffsets == NULL:
- * return (-1,) * self.view.ndim
+ * def copy(self): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice mslice
+ * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
*/
/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_10suboffsets_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ __Pyx_RefNannySetupContext("copy (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
- Py_ssize_t __pyx_v_suboffset;
+static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) {
+ __Pyx_memviewslice __pyx_v_mslice;
+ int __pyx_v_flags;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- int __pyx_t_1;
+ __Pyx_memviewslice __pyx_t_1;
PyObject *__pyx_t_2 = NULL;
- PyObject *__pyx_t_3 = NULL;
- Py_ssize_t *__pyx_t_4;
- Py_ssize_t *__pyx_t_5;
- Py_ssize_t *__pyx_t_6;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__get__", 0);
+ __Pyx_RefNannySetupContext("copy", 0);
- /* "View.MemoryView":576
- * @property
- * def suboffsets(self):
- * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<<
- * return (-1,) * self.view.ndim
+ /* "View.MemoryView":633
+ * def copy(self):
+ * cdef __Pyx_memviewslice mslice
+ * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS # <<<<<<<<<<<<<<
*
+ * slice_copy(self, &mslice)
*/
- __pyx_t_1 = ((__pyx_v_self->view.suboffsets == NULL) != 0);
- if (__pyx_t_1) {
+ __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS));
- /* "View.MemoryView":577
- * def suboffsets(self):
- * if self.view.suboffsets == NULL:
- * return (-1,) * self.view.ndim # <<<<<<<<<<<<<<
+ /* "View.MemoryView":635
+ * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
*
- * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]])
+ * slice_copy(self, &mslice) # <<<<<<<<<<<<<<
+ * mslice = slice_copy_contig(&mslice, "c", self.view.ndim,
+ * self.view.itemsize,
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 577, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyNumber_Multiply(__pyx_tuple__12, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 577, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_r = __pyx_t_3;
- __pyx_t_3 = 0;
- goto __pyx_L0;
+ __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_mslice));
- /* "View.MemoryView":576
- * @property
- * def suboffsets(self):
- * if self.view.suboffsets == NULL: # <<<<<<<<<<<<<<
- * return (-1,) * self.view.ndim
+ /* "View.MemoryView":636
*
+ * slice_copy(self, &mslice)
+ * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, # <<<<<<<<<<<<<<
+ * self.view.itemsize,
+ * flags|PyBUF_C_CONTIGUOUS,
*/
- }
+ __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), ((char *)"c"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_C_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 636, __pyx_L1_error)
+ __pyx_v_mslice = __pyx_t_1;
- /* "View.MemoryView":579
- * return (-1,) * self.view.ndim
+ /* "View.MemoryView":641
+ * self.dtype_is_object)
*
- * return tuple([suboffset for suboffset in self.view.suboffsets[:self.view.ndim]]) # <<<<<<<<<<<<<<
+ * return memoryview_copy_from_slice(self, &mslice) # <<<<<<<<<<<<<<
*
- * @property
+ * def copy_fortran(self):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 579, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_5 = (__pyx_v_self->view.suboffsets + __pyx_v_self->view.ndim);
- for (__pyx_t_6 = __pyx_v_self->view.suboffsets; __pyx_t_6 < __pyx_t_5; __pyx_t_6++) {
- __pyx_t_4 = __pyx_t_6;
- __pyx_v_suboffset = (__pyx_t_4[0]);
- __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_suboffset); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 579, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_2))) __PYX_ERR(1, 579, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- }
- __pyx_t_2 = PyList_AsTuple(((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 579, __pyx_L1_error)
+ __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_mslice)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 641, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;
- /* "View.MemoryView":575
+ /* "View.MemoryView":631
+ * return slice_is_contig(mslice[0], 'F', self.view.ndim)
*
- * @property
- * def suboffsets(self): # <<<<<<<<<<<<<<
- * if self.view.suboffsets == NULL:
- * return (-1,) * self.view.ndim
+ * def copy(self): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice mslice
+ * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_AddTraceback("View.MemoryView.memoryview.suboffsets.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
@@ -10094,62 +9282,94 @@ static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_10suboffsets___get_
return __pyx_r;
}
-/* "View.MemoryView":582
- *
- * @property
- * def ndim(self): # <<<<<<<<<<<<<<
- * return self.view.ndim
+/* "View.MemoryView":643
+ * return memoryview_copy_from_slice(self, &mslice)
*
+ * def copy_fortran(self): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice src, dst
+ * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
*/
/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4ndim_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ __Pyx_RefNannySetupContext("copy_fortran (wrapper)", 0);
+ __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self) {
+ __Pyx_memviewslice __pyx_v_src;
+ __Pyx_memviewslice __pyx_v_dst;
+ int __pyx_v_flags;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
+ __Pyx_memviewslice __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__get__", 0);
+ __Pyx_RefNannySetupContext("copy_fortran", 0);
- /* "View.MemoryView":583
- * @property
- * def ndim(self):
- * return self.view.ndim # <<<<<<<<<<<<<<
+ /* "View.MemoryView":645
+ * def copy_fortran(self):
+ * cdef __Pyx_memviewslice src, dst
+ * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS # <<<<<<<<<<<<<<
+ *
+ * slice_copy(self, &src)
+ */
+ __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS));
+
+ /* "View.MemoryView":647
+ * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
+ *
+ * slice_copy(self, &src) # <<<<<<<<<<<<<<
+ * dst = slice_copy_contig(&src, "fortran", self.view.ndim,
+ * self.view.itemsize,
+ */
+ __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_src));
+
+ /* "View.MemoryView":648
+ *
+ * slice_copy(self, &src)
+ * dst = slice_copy_contig(&src, "fortran", self.view.ndim, # <<<<<<<<<<<<<<
+ * self.view.itemsize,
+ * flags|PyBUF_F_CONTIGUOUS,
+ */
+ __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), ((char *)"fortran"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_F_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 648, __pyx_L1_error)
+ __pyx_v_dst = __pyx_t_1;
+
+ /* "View.MemoryView":653
+ * self.dtype_is_object)
+ *
+ * return memoryview_copy_from_slice(self, &dst) # <<<<<<<<<<<<<<
+ *
*
- * @property
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->view.ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 583, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
+ __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_dst)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 653, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
goto __pyx_L0;
- /* "View.MemoryView":582
- *
- * @property
- * def ndim(self): # <<<<<<<<<<<<<<
- * return self.view.ndim
+ /* "View.MemoryView":643
+ * return memoryview_copy_from_slice(self, &mslice)
*
+ * def copy_fortran(self): # <<<<<<<<<<<<<<
+ * cdef __Pyx_memviewslice src, dst
+ * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
*/
/* function exit code */
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.memoryview.ndim.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.copy_fortran", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
@@ -10157,3660 +9377,3417 @@ static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4ndim___get__(struc
return __pyx_r;
}
-/* "View.MemoryView":586
- *
- * @property
- * def itemsize(self): # <<<<<<<<<<<<<<
- * return self.view.itemsize
- *
+/* "(tree fragment)":1
+ * def __reduce_cython__(self): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
*/
/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_8itemsize_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+ __pyx_r = __pyx_pf___pyx_memoryview___reduce_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_8itemsize___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__get__", 0);
+ __Pyx_RefNannySetupContext("__reduce_cython__", 0);
- /* "View.MemoryView":587
- * @property
- * def itemsize(self):
- * return self.view.itemsize # <<<<<<<<<<<<<<
- *
- * @property
+ /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 587, __pyx_L1_error)
+ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __PYX_ERR(1, 2, __pyx_L1_error)
- /* "View.MemoryView":586
- *
- * @property
- * def itemsize(self): # <<<<<<<<<<<<<<
- * return self.view.itemsize
- *
+ /* "(tree fragment)":1
+ * def __reduce_cython__(self): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.memoryview.itemsize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
- __pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":590
- *
- * @property
- * def nbytes(self): # <<<<<<<<<<<<<<
- * return self.size * self.view.itemsize
- *
+/* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
*/
/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_6nbytes_1__get__(PyObject *__pyx_v_self) {
+static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+ __pyx_r = __pyx_pf___pyx_memoryview_2__setstate_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_6nbytes___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
+static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
- PyObject *__pyx_t_2 = NULL;
- PyObject *__pyx_t_3 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__get__", 0);
+ __Pyx_RefNannySetupContext("__setstate_cython__", 0);
- /* "View.MemoryView":591
- * @property
- * def nbytes(self):
- * return self.size * self.view.itemsize # <<<<<<<<<<<<<<
- *
- * @property
+ /* "(tree fragment)":4
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 591, __pyx_L1_error)
+ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_self->view.itemsize); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 591, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 591, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_r = __pyx_t_3;
- __pyx_t_3 = 0;
- goto __pyx_L0;
+ __PYX_ERR(1, 4, __pyx_L1_error)
- /* "View.MemoryView":590
- *
- * @property
- * def nbytes(self): # <<<<<<<<<<<<<<
- * return self.size * self.view.itemsize
- *
+ /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
*/
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_AddTraceback("View.MemoryView.memoryview.nbytes.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __Pyx_AddTraceback("View.MemoryView.memoryview.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
- __pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":594
+/* "View.MemoryView":657
*
- * @property
- * def size(self): # <<<<<<<<<<<<<<
- * if self._size is None:
- * result = 1
+ * @cname('__pyx_memoryview_new')
+ * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<<
+ * cdef memoryview result = memoryview(o, flags, dtype_is_object)
+ * result.typeinfo = typeinfo
*/
-/* Python wrapper */
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_pw_15View_dot_MemoryView_10memoryview_4size_1__get__(PyObject *__pyx_v_self) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
- __pyx_r = __pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(((struct __pyx_memoryview_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf_15View_dot_MemoryView_10memoryview_4size___get__(struct __pyx_memoryview_obj *__pyx_v_self) {
- PyObject *__pyx_v_result = NULL;
- PyObject *__pyx_v_length = NULL;
+static PyObject *__pyx_memoryview_new(PyObject *__pyx_v_o, int __pyx_v_flags, int __pyx_v_dtype_is_object, __Pyx_TypeInfo *__pyx_v_typeinfo) {
+ struct __pyx_memoryview_obj *__pyx_v_result = 0;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- int __pyx_t_1;
- int __pyx_t_2;
- Py_ssize_t *__pyx_t_3;
- Py_ssize_t *__pyx_t_4;
- Py_ssize_t *__pyx_t_5;
- PyObject *__pyx_t_6 = NULL;
+ PyObject *__pyx_t_1 = NULL;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__get__", 0);
+ __Pyx_RefNannySetupContext("memoryview_cwrapper", 0);
- /* "View.MemoryView":595
- * @property
- * def size(self):
- * if self._size is None: # <<<<<<<<<<<<<<
- * result = 1
- *
+ /* "View.MemoryView":658
+ * @cname('__pyx_memoryview_new')
+ * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):
+ * cdef memoryview result = memoryview(o, flags, dtype_is_object) # <<<<<<<<<<<<<<
+ * result.typeinfo = typeinfo
+ * return result
*/
- __pyx_t_1 = (__pyx_v_self->_size == Py_None);
- __pyx_t_2 = (__pyx_t_1 != 0);
- if (__pyx_t_2) {
+ __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 658, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 658, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 658, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_v_o);
+ __Pyx_GIVEREF(__pyx_v_o);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o);
+ __Pyx_GIVEREF(__pyx_t_1);
+ PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
+ __Pyx_GIVEREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
+ __pyx_t_1 = 0;
+ __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 658, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "View.MemoryView":596
- * def size(self):
- * if self._size is None:
- * result = 1 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":659
+ * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):
+ * cdef memoryview result = memoryview(o, flags, dtype_is_object)
+ * result.typeinfo = typeinfo # <<<<<<<<<<<<<<
+ * return result
*
- * for length in self.view.shape[:self.view.ndim]:
*/
- __Pyx_INCREF(__pyx_int_1);
- __pyx_v_result = __pyx_int_1;
+ __pyx_v_result->typeinfo = __pyx_v_typeinfo;
- /* "View.MemoryView":598
- * result = 1
- *
- * for length in self.view.shape[:self.view.ndim]: # <<<<<<<<<<<<<<
- * result *= length
+ /* "View.MemoryView":660
+ * cdef memoryview result = memoryview(o, flags, dtype_is_object)
+ * result.typeinfo = typeinfo
+ * return result # <<<<<<<<<<<<<<
*
+ * @cname('__pyx_memoryview_check')
*/
- __pyx_t_4 = (__pyx_v_self->view.shape + __pyx_v_self->view.ndim);
- for (__pyx_t_5 = __pyx_v_self->view.shape; __pyx_t_5 < __pyx_t_4; __pyx_t_5++) {
- __pyx_t_3 = __pyx_t_5;
- __pyx_t_6 = PyInt_FromSsize_t((__pyx_t_3[0])); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 598, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_6);
- __pyx_t_6 = 0;
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(((PyObject *)__pyx_v_result));
+ __pyx_r = ((PyObject *)__pyx_v_result);
+ goto __pyx_L0;
- /* "View.MemoryView":599
- *
- * for length in self.view.shape[:self.view.ndim]:
- * result *= length # <<<<<<<<<<<<<<
+ /* "View.MemoryView":657
*
- * self._size = result
+ * @cname('__pyx_memoryview_new')
+ * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<<
+ * cdef memoryview result = memoryview(o, flags, dtype_is_object)
+ * result.typeinfo = typeinfo
*/
- __pyx_t_6 = PyNumber_InPlaceMultiply(__pyx_v_result, __pyx_v_length); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 599, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_6);
- __Pyx_DECREF_SET(__pyx_v_result, __pyx_t_6);
- __pyx_t_6 = 0;
- }
- /* "View.MemoryView":601
- * result *= length
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XDECREF((PyObject *)__pyx_v_result);
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":663
*
- * self._size = result # <<<<<<<<<<<<<<
+ * @cname('__pyx_memoryview_check')
+ * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<<
+ * return isinstance(o, memoryview)
*
- * return self._size
*/
- __Pyx_INCREF(__pyx_v_result);
- __Pyx_GIVEREF(__pyx_v_result);
- __Pyx_GOTREF(__pyx_v_self->_size);
- __Pyx_DECREF(__pyx_v_self->_size);
- __pyx_v_self->_size = __pyx_v_result;
- /* "View.MemoryView":595
- * @property
- * def size(self):
- * if self._size is None: # <<<<<<<<<<<<<<
- * result = 1
- *
- */
- }
+static CYTHON_INLINE int __pyx_memoryview_check(PyObject *__pyx_v_o) {
+ int __pyx_r;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ __Pyx_RefNannySetupContext("memoryview_check", 0);
- /* "View.MemoryView":603
- * self._size = result
- *
- * return self._size # <<<<<<<<<<<<<<
+ /* "View.MemoryView":664
+ * @cname('__pyx_memoryview_check')
+ * cdef inline bint memoryview_check(object o):
+ * return isinstance(o, memoryview) # <<<<<<<<<<<<<<
*
- * def __len__(self):
+ * cdef tuple _unellipsify(object index, int ndim):
*/
- __Pyx_XDECREF(__pyx_r);
- __Pyx_INCREF(__pyx_v_self->_size);
- __pyx_r = __pyx_v_self->_size;
+ __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_o, __pyx_memoryview_type);
+ __pyx_r = __pyx_t_1;
goto __pyx_L0;
- /* "View.MemoryView":594
+ /* "View.MemoryView":663
+ *
+ * @cname('__pyx_memoryview_check')
+ * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<<
+ * return isinstance(o, memoryview)
*
- * @property
- * def size(self): # <<<<<<<<<<<<<<
- * if self._size is None:
- * result = 1
*/
/* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_6);
- __Pyx_AddTraceback("View.MemoryView.memoryview.size.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
__pyx_L0:;
- __Pyx_XDECREF(__pyx_v_result);
- __Pyx_XDECREF(__pyx_v_length);
- __Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":605
- * return self._size
- *
- * def __len__(self): # <<<<<<<<<<<<<<
- * if self.view.ndim >= 1:
- * return self.view.shape[0]
+/* "View.MemoryView":666
+ * return isinstance(o, memoryview)
+ *
+ * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<<
+ * """
+ * Replace all ellipses with full slices and fill incomplete indices with
*/
-/* Python wrapper */
-static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self); /*proto*/
-static Py_ssize_t __pyx_memoryview___len__(PyObject *__pyx_v_self) {
- Py_ssize_t __pyx_r;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(((struct __pyx_memoryview_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static Py_ssize_t __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_10__len__(struct __pyx_memoryview_obj *__pyx_v_self) {
- Py_ssize_t __pyx_r;
+static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) {
+ PyObject *__pyx_v_tup = NULL;
+ PyObject *__pyx_v_result = NULL;
+ int __pyx_v_have_slices;
+ int __pyx_v_seen_ellipsis;
+ CYTHON_UNUSED PyObject *__pyx_v_idx = NULL;
+ PyObject *__pyx_v_item = NULL;
+ Py_ssize_t __pyx_v_nslices;
+ PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
- __Pyx_RefNannySetupContext("__len__", 0);
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ Py_ssize_t __pyx_t_5;
+ PyObject *(*__pyx_t_6)(PyObject *);
+ PyObject *__pyx_t_7 = NULL;
+ Py_ssize_t __pyx_t_8;
+ int __pyx_t_9;
+ int __pyx_t_10;
+ PyObject *__pyx_t_11 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("_unellipsify", 0);
- /* "View.MemoryView":606
- *
- * def __len__(self):
- * if self.view.ndim >= 1: # <<<<<<<<<<<<<<
- * return self.view.shape[0]
- *
+ /* "View.MemoryView":671
+ * full slices.
+ * """
+ * if not isinstance(index, tuple): # <<<<<<<<<<<<<<
+ * tup = (index,)
+ * else:
*/
- __pyx_t_1 = ((__pyx_v_self->view.ndim >= 1) != 0);
- if (__pyx_t_1) {
+ __pyx_t_1 = PyTuple_Check(__pyx_v_index);
+ __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":607
- * def __len__(self):
- * if self.view.ndim >= 1:
- * return self.view.shape[0] # <<<<<<<<<<<<<<
- *
- * return 0
+ /* "View.MemoryView":672
+ * """
+ * if not isinstance(index, tuple):
+ * tup = (index,) # <<<<<<<<<<<<<<
+ * else:
+ * tup = index
*/
- __pyx_r = (__pyx_v_self->view.shape[0]);
- goto __pyx_L0;
+ __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 672, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(__pyx_v_index);
+ __Pyx_GIVEREF(__pyx_v_index);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_index);
+ __pyx_v_tup = __pyx_t_3;
+ __pyx_t_3 = 0;
- /* "View.MemoryView":606
- *
- * def __len__(self):
- * if self.view.ndim >= 1: # <<<<<<<<<<<<<<
- * return self.view.shape[0]
- *
+ /* "View.MemoryView":671
+ * full slices.
+ * """
+ * if not isinstance(index, tuple): # <<<<<<<<<<<<<<
+ * tup = (index,)
+ * else:
*/
+ goto __pyx_L3;
}
- /* "View.MemoryView":609
- * return self.view.shape[0]
- *
- * return 0 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":674
+ * tup = (index,)
+ * else:
+ * tup = index # <<<<<<<<<<<<<<
*
- * def __repr__(self):
+ * result = []
*/
- __pyx_r = 0;
- goto __pyx_L0;
+ /*else*/ {
+ __Pyx_INCREF(__pyx_v_index);
+ __pyx_v_tup = __pyx_v_index;
+ }
+ __pyx_L3:;
- /* "View.MemoryView":605
- * return self._size
+ /* "View.MemoryView":676
+ * tup = index
*
- * def __len__(self): # <<<<<<<<<<<<<<
- * if self.view.ndim >= 1:
- * return self.view.shape[0]
+ * result = [] # <<<<<<<<<<<<<<
+ * have_slices = False
+ * seen_ellipsis = False
*/
+ __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 676, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_v_result = ((PyObject*)__pyx_t_3);
+ __pyx_t_3 = 0;
- /* function exit code */
- __pyx_L0:;
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":611
- * return 0
+ /* "View.MemoryView":677
*
- * def __repr__(self): # <<<<<<<<<<<<<<
- * return "" % (self.base.__class__.__name__,
- * id(self))
+ * result = []
+ * have_slices = False # <<<<<<<<<<<<<<
+ * seen_ellipsis = False
+ * for idx, item in enumerate(tup):
*/
+ __pyx_v_have_slices = 0;
-/* Python wrapper */
-static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_memoryview___repr__(PyObject *__pyx_v_self) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ /* "View.MemoryView":678
+ * result = []
+ * have_slices = False
+ * seen_ellipsis = False # <<<<<<<<<<<<<<
+ * for idx, item in enumerate(tup):
+ * if item is Ellipsis:
+ */
+ __pyx_v_seen_ellipsis = 0;
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":679
+ * have_slices = False
+ * seen_ellipsis = False
+ * for idx, item in enumerate(tup): # <<<<<<<<<<<<<<
+ * if item is Ellipsis:
+ * if not seen_ellipsis:
+ */
+ __Pyx_INCREF(__pyx_int_0);
+ __pyx_t_3 = __pyx_int_0;
+ if (likely(PyList_CheckExact(__pyx_v_tup)) || PyTuple_CheckExact(__pyx_v_tup)) {
+ __pyx_t_4 = __pyx_v_tup; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
+ __pyx_t_6 = NULL;
+ } else {
+ __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_tup); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 679, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 679, __pyx_L1_error)
+ }
+ for (;;) {
+ if (likely(!__pyx_t_6)) {
+ if (likely(PyList_CheckExact(__pyx_t_4))) {
+ if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+ __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 679, __pyx_L1_error)
+ #else
+ __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 679, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_7);
+ #endif
+ } else {
+ if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+ __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 679, __pyx_L1_error)
+ #else
+ __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 679, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_7);
+ #endif
+ }
+ } else {
+ __pyx_t_7 = __pyx_t_6(__pyx_t_4);
+ if (unlikely(!__pyx_t_7)) {
+ PyObject* exc_type = PyErr_Occurred();
+ if (exc_type) {
+ if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+ else __PYX_ERR(1, 679, __pyx_L1_error)
+ }
+ break;
+ }
+ __Pyx_GOTREF(__pyx_t_7);
+ }
+ __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7);
+ __pyx_t_7 = 0;
+ __Pyx_INCREF(__pyx_t_3);
+ __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_3);
+ __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 679, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_7);
+ __Pyx_DECREF(__pyx_t_3);
+ __pyx_t_3 = __pyx_t_7;
+ __pyx_t_7 = 0;
-static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_12__repr__(struct __pyx_memoryview_obj *__pyx_v_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- PyObject *__pyx_t_2 = NULL;
- PyObject *__pyx_t_3 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__repr__", 0);
+ /* "View.MemoryView":680
+ * seen_ellipsis = False
+ * for idx, item in enumerate(tup):
+ * if item is Ellipsis: # <<<<<<<<<<<<<<
+ * if not seen_ellipsis:
+ * result.extend([slice(None)] * (ndim - len(tup) + 1))
+ */
+ __pyx_t_2 = (__pyx_v_item == __pyx_builtin_Ellipsis);
+ __pyx_t_1 = (__pyx_t_2 != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":612
- *
- * def __repr__(self):
- * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<<
- * id(self))
- *
+ /* "View.MemoryView":681
+ * for idx, item in enumerate(tup):
+ * if item is Ellipsis:
+ * if not seen_ellipsis: # <<<<<<<<<<<<<<
+ * result.extend([slice(None)] * (ndim - len(tup) + 1))
+ * seen_ellipsis = True
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 612, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 612, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 612, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+ __pyx_t_1 = ((!(__pyx_v_seen_ellipsis != 0)) != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":613
- * def __repr__(self):
- * return "" % (self.base.__class__.__name__,
- * id(self)) # <<<<<<<<<<<<<<
- *
- * def __str__(self):
+ /* "View.MemoryView":682
+ * if item is Ellipsis:
+ * if not seen_ellipsis:
+ * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<<
+ * seen_ellipsis = True
+ * else:
*/
- __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_id, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 613, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_8 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(1, 682, __pyx_L1_error)
+ __pyx_t_7 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_8) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_8) + 1))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 682, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_7);
+ { Py_ssize_t __pyx_temp;
+ for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_8) + 1); __pyx_temp++) {
+ __Pyx_INCREF(__pyx_slice__15);
+ __Pyx_GIVEREF(__pyx_slice__15);
+ PyList_SET_ITEM(__pyx_t_7, __pyx_temp, __pyx_slice__15);
+ }
+ }
+ __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 682, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
- /* "View.MemoryView":612
- *
- * def __repr__(self):
- * return "" % (self.base.__class__.__name__, # <<<<<<<<<<<<<<
- * id(self))
- *
+ /* "View.MemoryView":683
+ * if not seen_ellipsis:
+ * result.extend([slice(None)] * (ndim - len(tup) + 1))
+ * seen_ellipsis = True # <<<<<<<<<<<<<<
+ * else:
+ * result.append(slice(None))
*/
- __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 612, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_1);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
- __Pyx_GIVEREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
- __pyx_t_1 = 0;
- __pyx_t_2 = 0;
- __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_at_0x_x, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 612, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_r = __pyx_t_2;
- __pyx_t_2 = 0;
- goto __pyx_L0;
+ __pyx_v_seen_ellipsis = 1;
- /* "View.MemoryView":611
- * return 0
- *
- * def __repr__(self): # <<<<<<<<<<<<<<
- * return "" % (self.base.__class__.__name__,
- * id(self))
+ /* "View.MemoryView":681
+ * for idx, item in enumerate(tup):
+ * if item is Ellipsis:
+ * if not seen_ellipsis: # <<<<<<<<<<<<<<
+ * result.extend([slice(None)] * (ndim - len(tup) + 1))
+ * seen_ellipsis = True
*/
+ goto __pyx_L7;
+ }
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_AddTraceback("View.MemoryView.memoryview.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":615
- * id(self))
- *
- * def __str__(self): # <<<<<<<<<<<<<<
- * return "" % (self.base.__class__.__name__,)
- *
+ /* "View.MemoryView":685
+ * seen_ellipsis = True
+ * else:
+ * result.append(slice(None)) # <<<<<<<<<<<<<<
+ * have_slices = True
+ * else:
*/
+ /*else*/ {
+ __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_slice__15); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 685, __pyx_L1_error)
+ }
+ __pyx_L7:;
-/* Python wrapper */
-static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self); /*proto*/
-static PyObject *__pyx_memoryview___str__(PyObject *__pyx_v_self) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(((struct __pyx_memoryview_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":686
+ * else:
+ * result.append(slice(None))
+ * have_slices = True # <<<<<<<<<<<<<<
+ * else:
+ * if not isinstance(item, slice) and not PyIndex_Check(item):
+ */
+ __pyx_v_have_slices = 1;
-static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_14__str__(struct __pyx_memoryview_obj *__pyx_v_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- PyObject *__pyx_t_2 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__str__", 0);
+ /* "View.MemoryView":680
+ * seen_ellipsis = False
+ * for idx, item in enumerate(tup):
+ * if item is Ellipsis: # <<<<<<<<<<<<<<
+ * if not seen_ellipsis:
+ * result.extend([slice(None)] * (ndim - len(tup) + 1))
+ */
+ goto __pyx_L6;
+ }
- /* "View.MemoryView":616
+ /* "View.MemoryView":688
+ * have_slices = True
+ * else:
+ * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<<
+ * raise TypeError("Cannot index with type '%s'" % type(item))
*
- * def __str__(self):
- * return "" % (self.base.__class__.__name__,) # <<<<<<<<<<<<<<
+ */
+ /*else*/ {
+ __pyx_t_2 = PySlice_Check(__pyx_v_item);
+ __pyx_t_10 = ((!(__pyx_t_2 != 0)) != 0);
+ if (__pyx_t_10) {
+ } else {
+ __pyx_t_1 = __pyx_t_10;
+ goto __pyx_L9_bool_binop_done;
+ }
+ __pyx_t_10 = ((!(PyIndex_Check(__pyx_v_item) != 0)) != 0);
+ __pyx_t_1 = __pyx_t_10;
+ __pyx_L9_bool_binop_done:;
+ if (unlikely(__pyx_t_1)) {
+
+ /* "View.MemoryView":689
+ * else:
+ * if not isinstance(item, slice) and not PyIndex_Check(item):
+ * raise TypeError("Cannot index with type '%s'" % type(item)) # <<<<<<<<<<<<<<
*
+ * have_slices = have_slices or isinstance(item, slice)
+ */
+ __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Cannot_index_with_type_s, ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 689, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_7);
+ __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 689, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_11);
+ __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+ __Pyx_Raise(__pyx_t_11, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
+ __PYX_ERR(1, 689, __pyx_L1_error)
+
+ /* "View.MemoryView":688
+ * have_slices = True
+ * else:
+ * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<<
+ * raise TypeError("Cannot index with type '%s'" % type(item))
*
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_base); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 616, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_class); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 616, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_name_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 616, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 616, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_GIVEREF(__pyx_t_1);
- PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
- __pyx_t_1 = 0;
- __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_MemoryView_of_r_object, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 616, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
- __pyx_r = __pyx_t_1;
- __pyx_t_1 = 0;
- goto __pyx_L0;
+ }
- /* "View.MemoryView":615
- * id(self))
+ /* "View.MemoryView":691
+ * raise TypeError("Cannot index with type '%s'" % type(item))
*
- * def __str__(self): # <<<<<<<<<<<<<<
- * return "" % (self.base.__class__.__name__,)
+ * have_slices = have_slices or isinstance(item, slice) # <<<<<<<<<<<<<<
+ * result.append(item)
*
*/
+ __pyx_t_10 = (__pyx_v_have_slices != 0);
+ if (!__pyx_t_10) {
+ } else {
+ __pyx_t_1 = __pyx_t_10;
+ goto __pyx_L11_bool_binop_done;
+ }
+ __pyx_t_10 = PySlice_Check(__pyx_v_item);
+ __pyx_t_2 = (__pyx_t_10 != 0);
+ __pyx_t_1 = __pyx_t_2;
+ __pyx_L11_bool_binop_done:;
+ __pyx_v_have_slices = __pyx_t_1;
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_AddTraceback("View.MemoryView.memoryview.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":619
+ /* "View.MemoryView":692
*
+ * have_slices = have_slices or isinstance(item, slice)
+ * result.append(item) # <<<<<<<<<<<<<<
*
- * def is_c_contig(self): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice *mslice
- * cdef __Pyx_memviewslice tmp
+ * nslices = ndim - len(result)
*/
+ __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 692, __pyx_L1_error)
+ }
+ __pyx_L6:;
-/* Python wrapper */
-static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyObject *__pyx_memoryview_is_c_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("is_c_contig (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(((struct __pyx_memoryview_obj *)__pyx_v_self));
+ /* "View.MemoryView":679
+ * have_slices = False
+ * seen_ellipsis = False
+ * for idx, item in enumerate(tup): # <<<<<<<<<<<<<<
+ * if item is Ellipsis:
+ * if not seen_ellipsis:
+ */
+ }
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":694
+ * result.append(item)
+ *
+ * nslices = ndim - len(result) # <<<<<<<<<<<<<<
+ * if nslices:
+ * result.extend([slice(None)] * nslices)
+ */
+ __pyx_t_5 = PyList_GET_SIZE(__pyx_v_result); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 694, __pyx_L1_error)
+ __pyx_v_nslices = (__pyx_v_ndim - __pyx_t_5);
-static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_16is_c_contig(struct __pyx_memoryview_obj *__pyx_v_self) {
- __Pyx_memviewslice *__pyx_v_mslice;
- __Pyx_memviewslice __pyx_v_tmp;
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __Pyx_memviewslice *__pyx_t_1;
- PyObject *__pyx_t_2 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("is_c_contig", 0);
+ /* "View.MemoryView":695
+ *
+ * nslices = ndim - len(result)
+ * if nslices: # <<<<<<<<<<<<<<
+ * result.extend([slice(None)] * nslices)
+ *
+ */
+ __pyx_t_1 = (__pyx_v_nslices != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":622
- * cdef __Pyx_memviewslice *mslice
- * cdef __Pyx_memviewslice tmp
- * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<<
- * return slice_is_contig(mslice[0], 'C', self.view.ndim)
+ /* "View.MemoryView":696
+ * nslices = ndim - len(result)
+ * if nslices:
+ * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<<
*
+ * return have_slices or nslices, tuple(result)
*/
- __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 622, __pyx_L1_error)
- __pyx_v_mslice = __pyx_t_1;
+ __pyx_t_3 = PyList_New(1 * ((__pyx_v_nslices<0) ? 0:__pyx_v_nslices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 696, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ { Py_ssize_t __pyx_temp;
+ for (__pyx_temp=0; __pyx_temp < __pyx_v_nslices; __pyx_temp++) {
+ __Pyx_INCREF(__pyx_slice__15);
+ __Pyx_GIVEREF(__pyx_slice__15);
+ PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_slice__15);
+ }
+ }
+ __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 696, __pyx_L1_error)
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "View.MemoryView":623
- * cdef __Pyx_memviewslice tmp
- * mslice = get_slice_from_memview(self, &tmp)
- * return slice_is_contig(mslice[0], 'C', self.view.ndim) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":695
*
- * def is_f_contig(self):
+ * nslices = ndim - len(result)
+ * if nslices: # <<<<<<<<<<<<<<
+ * result.extend([slice(None)] * nslices)
+ *
+ */
+ }
+
+ /* "View.MemoryView":698
+ * result.extend([slice(None)] * nslices)
+ *
+ * return have_slices or nslices, tuple(result) # <<<<<<<<<<<<<<
+ *
+ * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
*/
__Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'C', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 623, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_r = __pyx_t_2;
- __pyx_t_2 = 0;
+ if (!__pyx_v_have_slices) {
+ } else {
+ __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_have_slices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 698, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_3 = __pyx_t_4;
+ __pyx_t_4 = 0;
+ goto __pyx_L14_bool_binop_done;
+ }
+ __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_nslices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 698, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_3 = __pyx_t_4;
+ __pyx_t_4 = 0;
+ __pyx_L14_bool_binop_done:;
+ __pyx_t_4 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 698, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 698, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_11);
+ __Pyx_GIVEREF(__pyx_t_3);
+ PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3);
+ __Pyx_GIVEREF(__pyx_t_4);
+ PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_4);
+ __pyx_t_3 = 0;
+ __pyx_t_4 = 0;
+ __pyx_r = ((PyObject*)__pyx_t_11);
+ __pyx_t_11 = 0;
goto __pyx_L0;
- /* "View.MemoryView":619
- *
+ /* "View.MemoryView":666
+ * return isinstance(o, memoryview)
*
- * def is_c_contig(self): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice *mslice
- * cdef __Pyx_memviewslice tmp
+ * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<<
+ * """
+ * Replace all ellipses with full slices and fill incomplete indices with
*/
/* function exit code */
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_AddTraceback("View.MemoryView.memoryview.is_c_contig", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_XDECREF(__pyx_t_7);
+ __Pyx_XDECREF(__pyx_t_11);
+ __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
__pyx_L0:;
+ __Pyx_XDECREF(__pyx_v_tup);
+ __Pyx_XDECREF(__pyx_v_result);
+ __Pyx_XDECREF(__pyx_v_idx);
+ __Pyx_XDECREF(__pyx_v_item);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":625
- * return slice_is_contig(mslice[0], 'C', self.view.ndim)
+/* "View.MemoryView":700
+ * return have_slices or nslices, tuple(result)
*
- * def is_f_contig(self): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice *mslice
- * cdef __Pyx_memviewslice tmp
+ * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<<
+ * for suboffset in suboffsets[:ndim]:
+ * if suboffset >= 0:
*/
-/* Python wrapper */
-static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyObject *__pyx_memoryview_is_f_contig(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("is_f_contig (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(((struct __pyx_memoryview_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_18is_f_contig(struct __pyx_memoryview_obj *__pyx_v_self) {
- __Pyx_memviewslice *__pyx_v_mslice;
- __Pyx_memviewslice __pyx_v_tmp;
+static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) {
+ Py_ssize_t __pyx_v_suboffset;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- __Pyx_memviewslice *__pyx_t_1;
- PyObject *__pyx_t_2 = NULL;
+ Py_ssize_t *__pyx_t_1;
+ Py_ssize_t *__pyx_t_2;
+ Py_ssize_t *__pyx_t_3;
+ int __pyx_t_4;
+ PyObject *__pyx_t_5 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("is_f_contig", 0);
+ __Pyx_RefNannySetupContext("assert_direct_dimensions", 0);
- /* "View.MemoryView":628
- * cdef __Pyx_memviewslice *mslice
- * cdef __Pyx_memviewslice tmp
- * mslice = get_slice_from_memview(self, &tmp) # <<<<<<<<<<<<<<
- * return slice_is_contig(mslice[0], 'F', self.view.ndim)
+ /* "View.MemoryView":701
*
+ * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
+ * for suboffset in suboffsets[:ndim]: # <<<<<<<<<<<<<<
+ * if suboffset >= 0:
+ * raise ValueError("Indirect dimensions not supported")
*/
- __pyx_t_1 = __pyx_memoryview_get_slice_from_memoryview(__pyx_v_self, (&__pyx_v_tmp)); if (unlikely(__pyx_t_1 == ((__Pyx_memviewslice *)NULL))) __PYX_ERR(1, 628, __pyx_L1_error)
- __pyx_v_mslice = __pyx_t_1;
+ __pyx_t_2 = (__pyx_v_suboffsets + __pyx_v_ndim);
+ for (__pyx_t_3 = __pyx_v_suboffsets; __pyx_t_3 < __pyx_t_2; __pyx_t_3++) {
+ __pyx_t_1 = __pyx_t_3;
+ __pyx_v_suboffset = (__pyx_t_1[0]);
- /* "View.MemoryView":629
- * cdef __Pyx_memviewslice tmp
- * mslice = get_slice_from_memview(self, &tmp)
- * return slice_is_contig(mslice[0], 'F', self.view.ndim) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":702
+ * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
+ * for suboffset in suboffsets[:ndim]:
+ * if suboffset >= 0: # <<<<<<<<<<<<<<
+ * raise ValueError("Indirect dimensions not supported")
*
- * def copy(self):
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_memviewslice_is_contig((__pyx_v_mslice[0]), 'F', __pyx_v_self->view.ndim)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 629, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_r = __pyx_t_2;
- __pyx_t_2 = 0;
- goto __pyx_L0;
+ __pyx_t_4 = ((__pyx_v_suboffset >= 0) != 0);
+ if (unlikely(__pyx_t_4)) {
- /* "View.MemoryView":625
- * return slice_is_contig(mslice[0], 'C', self.view.ndim)
+ /* "View.MemoryView":703
+ * for suboffset in suboffsets[:ndim]:
+ * if suboffset >= 0:
+ * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<<
*
- * def is_f_contig(self): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice *mslice
- * cdef __Pyx_memviewslice tmp
+ *
+ */
+ __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 703, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_5);
+ __Pyx_Raise(__pyx_t_5, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+ __PYX_ERR(1, 703, __pyx_L1_error)
+
+ /* "View.MemoryView":702
+ * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
+ * for suboffset in suboffsets[:ndim]:
+ * if suboffset >= 0: # <<<<<<<<<<<<<<
+ * raise ValueError("Indirect dimensions not supported")
+ *
+ */
+ }
+ }
+
+ /* "View.MemoryView":700
+ * return have_slices or nslices, tuple(result)
+ *
+ * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<<
+ * for suboffset in suboffsets[:ndim]:
+ * if suboffset >= 0:
*/
/* function exit code */
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
__pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_AddTraceback("View.MemoryView.memoryview.is_f_contig", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
+ __Pyx_XDECREF(__pyx_t_5);
+ __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":631
- * return slice_is_contig(mslice[0], 'F', self.view.ndim)
+/* "View.MemoryView":710
*
- * def copy(self): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice mslice
- * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
- */
-
-/* Python wrapper */
-static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyObject *__pyx_memoryview_copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("copy (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(((struct __pyx_memoryview_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ * @cname('__pyx_memview_slice')
+ * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<<
+ * cdef int new_ndim = 0, suboffset_dim = -1, dim
+ * cdef bint negative_step
+ */
-static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_20copy(struct __pyx_memoryview_obj *__pyx_v_self) {
- __Pyx_memviewslice __pyx_v_mslice;
- int __pyx_v_flags;
- PyObject *__pyx_r = NULL;
+static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *__pyx_v_memview, PyObject *__pyx_v_indices) {
+ int __pyx_v_new_ndim;
+ int __pyx_v_suboffset_dim;
+ int __pyx_v_dim;
+ __Pyx_memviewslice __pyx_v_src;
+ __Pyx_memviewslice __pyx_v_dst;
+ __Pyx_memviewslice *__pyx_v_p_src;
+ struct __pyx_memoryviewslice_obj *__pyx_v_memviewsliceobj = 0;
+ __Pyx_memviewslice *__pyx_v_p_dst;
+ int *__pyx_v_p_suboffset_dim;
+ Py_ssize_t __pyx_v_start;
+ Py_ssize_t __pyx_v_stop;
+ Py_ssize_t __pyx_v_step;
+ int __pyx_v_have_start;
+ int __pyx_v_have_stop;
+ int __pyx_v_have_step;
+ PyObject *__pyx_v_index = NULL;
+ struct __pyx_memoryview_obj *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
- __Pyx_memviewslice __pyx_t_1;
- PyObject *__pyx_t_2 = NULL;
+ int __pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ struct __pyx_memoryview_obj *__pyx_t_4;
+ char *__pyx_t_5;
+ int __pyx_t_6;
+ Py_ssize_t __pyx_t_7;
+ PyObject *(*__pyx_t_8)(PyObject *);
+ PyObject *__pyx_t_9 = NULL;
+ Py_ssize_t __pyx_t_10;
+ int __pyx_t_11;
+ Py_ssize_t __pyx_t_12;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("copy", 0);
+ __Pyx_RefNannySetupContext("memview_slice", 0);
- /* "View.MemoryView":633
- * def copy(self):
- * cdef __Pyx_memviewslice mslice
- * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS # <<<<<<<<<<<<<<
- *
- * slice_copy(self, &mslice)
+ /* "View.MemoryView":711
+ * @cname('__pyx_memview_slice')
+ * cdef memoryview memview_slice(memoryview memview, object indices):
+ * cdef int new_ndim = 0, suboffset_dim = -1, dim # <<<<<<<<<<<<<<
+ * cdef bint negative_step
+ * cdef __Pyx_memviewslice src, dst
*/
- __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_F_CONTIGUOUS));
+ __pyx_v_new_ndim = 0;
+ __pyx_v_suboffset_dim = -1;
- /* "View.MemoryView":635
- * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
+ /* "View.MemoryView":718
*
- * slice_copy(self, &mslice) # <<<<<<<<<<<<<<
- * mslice = slice_copy_contig(&mslice, "c", self.view.ndim,
- * self.view.itemsize,
- */
- __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_mslice));
-
- /* "View.MemoryView":636
*
- * slice_copy(self, &mslice)
- * mslice = slice_copy_contig(&mslice, "c", self.view.ndim, # <<<<<<<<<<<<<<
- * self.view.itemsize,
- * flags|PyBUF_C_CONTIGUOUS,
+ * memset(&dst, 0, sizeof(dst)) # <<<<<<<<<<<<<<
+ *
+ * cdef _memoryviewslice memviewsliceobj
*/
- __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_mslice), ((char *)"c"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_C_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 636, __pyx_L1_error)
- __pyx_v_mslice = __pyx_t_1;
+ (void)(memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst))));
- /* "View.MemoryView":641
- * self.dtype_is_object)
+ /* "View.MemoryView":722
+ * cdef _memoryviewslice memviewsliceobj
*
- * return memoryview_copy_from_slice(self, &mslice) # <<<<<<<<<<<<<<
+ * assert memview.view.ndim > 0 # <<<<<<<<<<<<<<
*
- * def copy_fortran(self):
+ * if isinstance(memview, _memoryviewslice):
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_mslice)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 641, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_r = __pyx_t_2;
- __pyx_t_2 = 0;
- goto __pyx_L0;
+ #ifndef CYTHON_WITHOUT_ASSERTIONS
+ if (unlikely(!Py_OptimizeFlag)) {
+ if (unlikely(!((__pyx_v_memview->view.ndim > 0) != 0))) {
+ PyErr_SetNone(PyExc_AssertionError);
+ __PYX_ERR(1, 722, __pyx_L1_error)
+ }
+ }
+ #endif
- /* "View.MemoryView":631
- * return slice_is_contig(mslice[0], 'F', self.view.ndim)
+ /* "View.MemoryView":724
+ * assert memview.view.ndim > 0
*
- * def copy(self): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice mslice
- * cdef int flags = self.flags & ~PyBUF_F_CONTIGUOUS
+ * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<<
+ * memviewsliceobj = memview
+ * p_src = &memviewsliceobj.from_slice
*/
+ __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type);
+ __pyx_t_2 = (__pyx_t_1 != 0);
+ if (__pyx_t_2) {
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_AddTraceback("View.MemoryView.memoryview.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":643
- * return memoryview_copy_from_slice(self, &mslice)
+ /* "View.MemoryView":725
*
- * def copy_fortran(self): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice src, dst
- * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
+ * if isinstance(memview, _memoryviewslice):
+ * memviewsliceobj = memview # <<<<<<<<<<<<<<
+ * p_src = &memviewsliceobj.from_slice
+ * else:
*/
+ if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(1, 725, __pyx_L1_error)
+ __pyx_t_3 = ((PyObject *)__pyx_v_memview);
+ __Pyx_INCREF(__pyx_t_3);
+ __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3);
+ __pyx_t_3 = 0;
-/* Python wrapper */
-static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyObject *__pyx_memoryview_copy_fortran(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("copy_fortran (wrapper)", 0);
- __pyx_r = __pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(((struct __pyx_memoryview_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_memoryview___pyx_pf_15View_dot_MemoryView_10memoryview_22copy_fortran(struct __pyx_memoryview_obj *__pyx_v_self) {
- __Pyx_memviewslice __pyx_v_src;
- __Pyx_memviewslice __pyx_v_dst;
- int __pyx_v_flags;
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- __Pyx_memviewslice __pyx_t_1;
- PyObject *__pyx_t_2 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("copy_fortran", 0);
+ /* "View.MemoryView":726
+ * if isinstance(memview, _memoryviewslice):
+ * memviewsliceobj = memview
+ * p_src = &memviewsliceobj.from_slice # <<<<<<<<<<<<<<
+ * else:
+ * slice_copy(memview, &src)
+ */
+ __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice);
- /* "View.MemoryView":645
- * def copy_fortran(self):
- * cdef __Pyx_memviewslice src, dst
- * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS # <<<<<<<<<<<<<<
+ /* "View.MemoryView":724
+ * assert memview.view.ndim > 0
*
- * slice_copy(self, &src)
+ * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<<
+ * memviewsliceobj = memview
+ * p_src = &memviewsliceobj.from_slice
*/
- __pyx_v_flags = (__pyx_v_self->flags & (~PyBUF_C_CONTIGUOUS));
+ goto __pyx_L3;
+ }
- /* "View.MemoryView":647
- * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
+ /* "View.MemoryView":728
+ * p_src = &memviewsliceobj.from_slice
+ * else:
+ * slice_copy(memview, &src) # <<<<<<<<<<<<<<
+ * p_src = &src
*
- * slice_copy(self, &src) # <<<<<<<<<<<<<<
- * dst = slice_copy_contig(&src, "fortran", self.view.ndim,
- * self.view.itemsize,
*/
- __pyx_memoryview_slice_copy(__pyx_v_self, (&__pyx_v_src));
+ /*else*/ {
+ __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src));
- /* "View.MemoryView":648
+ /* "View.MemoryView":729
+ * else:
+ * slice_copy(memview, &src)
+ * p_src = &src # <<<<<<<<<<<<<<
+ *
*
- * slice_copy(self, &src)
- * dst = slice_copy_contig(&src, "fortran", self.view.ndim, # <<<<<<<<<<<<<<
- * self.view.itemsize,
- * flags|PyBUF_F_CONTIGUOUS,
*/
- __pyx_t_1 = __pyx_memoryview_copy_new_contig((&__pyx_v_src), ((char *)"fortran"), __pyx_v_self->view.ndim, __pyx_v_self->view.itemsize, (__pyx_v_flags | PyBUF_F_CONTIGUOUS), __pyx_v_self->dtype_is_object); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 648, __pyx_L1_error)
- __pyx_v_dst = __pyx_t_1;
+ __pyx_v_p_src = (&__pyx_v_src);
+ }
+ __pyx_L3:;
- /* "View.MemoryView":653
- * self.dtype_is_object)
+ /* "View.MemoryView":735
*
- * return memoryview_copy_from_slice(self, &dst) # <<<<<<<<<<<<<<
*
+ * dst.memview = p_src.memview # <<<<<<<<<<<<<<
+ * dst.data = p_src.data
*
*/
- __Pyx_XDECREF(__pyx_r);
- __pyx_t_2 = __pyx_memoryview_copy_object_from_slice(__pyx_v_self, (&__pyx_v_dst)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 653, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_r = __pyx_t_2;
- __pyx_t_2 = 0;
- goto __pyx_L0;
+ __pyx_t_4 = __pyx_v_p_src->memview;
+ __pyx_v_dst.memview = __pyx_t_4;
- /* "View.MemoryView":643
- * return memoryview_copy_from_slice(self, &mslice)
+ /* "View.MemoryView":736
+ *
+ * dst.memview = p_src.memview
+ * dst.data = p_src.data # <<<<<<<<<<<<<<
+ *
*
- * def copy_fortran(self): # <<<<<<<<<<<<<<
- * cdef __Pyx_memviewslice src, dst
- * cdef int flags = self.flags & ~PyBUF_C_CONTIGUOUS
*/
+ __pyx_t_5 = __pyx_v_p_src->data;
+ __pyx_v_dst.data = __pyx_t_5;
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_AddTraceback("View.MemoryView.memoryview.copy_fortran", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "(tree fragment)":1
- * def __reduce_cython__(self): # <<<<<<<<<<<<<<
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state):
+ /* "View.MemoryView":741
+ *
+ *
+ * cdef __Pyx_memviewslice *p_dst = &dst # <<<<<<<<<<<<<<
+ * cdef int *p_suboffset_dim = &suboffset_dim
+ * cdef Py_ssize_t start, stop, step
*/
+ __pyx_v_p_dst = (&__pyx_v_dst);
-/* Python wrapper */
-static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
-static PyObject *__pyx_pw___pyx_memoryview_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
- __pyx_r = __pyx_pf___pyx_memoryview___reduce_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self));
-
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-static PyObject *__pyx_pf___pyx_memoryview___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__reduce_cython__", 0);
+ /* "View.MemoryView":742
+ *
+ * cdef __Pyx_memviewslice *p_dst = &dst
+ * cdef int *p_suboffset_dim = &suboffset_dim # <<<<<<<<<<<<<<
+ * cdef Py_ssize_t start, stop, step
+ * cdef bint have_start, have_stop, have_step
+ */
+ __pyx_v_p_suboffset_dim = (&__pyx_v_suboffset_dim);
- /* "(tree fragment)":2
- * def __reduce_cython__(self):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
- * def __setstate_cython__(self, __pyx_state):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ /* "View.MemoryView":746
+ * cdef bint have_start, have_stop, have_step
+ *
+ * for dim, index in enumerate(indices): # <<<<<<<<<<<<<<
+ * if PyIndex_Check(index):
+ * slice_memviewslice(
*/
- __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_Raise(__pyx_t_1, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __PYX_ERR(1, 2, __pyx_L1_error)
+ __pyx_t_6 = 0;
+ if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) {
+ __pyx_t_3 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0;
+ __pyx_t_8 = NULL;
+ } else {
+ __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 746, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 746, __pyx_L1_error)
+ }
+ for (;;) {
+ if (likely(!__pyx_t_8)) {
+ if (likely(PyList_CheckExact(__pyx_t_3))) {
+ if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break;
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+ __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 746, __pyx_L1_error)
+ #else
+ __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 746, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ #endif
+ } else {
+ if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
+ #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
+ __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 746, __pyx_L1_error)
+ #else
+ __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 746, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ #endif
+ }
+ } else {
+ __pyx_t_9 = __pyx_t_8(__pyx_t_3);
+ if (unlikely(!__pyx_t_9)) {
+ PyObject* exc_type = PyErr_Occurred();
+ if (exc_type) {
+ if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
+ else __PYX_ERR(1, 746, __pyx_L1_error)
+ }
+ break;
+ }
+ __Pyx_GOTREF(__pyx_t_9);
+ }
+ __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_9);
+ __pyx_t_9 = 0;
+ __pyx_v_dim = __pyx_t_6;
+ __pyx_t_6 = (__pyx_t_6 + 1);
- /* "(tree fragment)":1
- * def __reduce_cython__(self): # <<<<<<<<<<<<<<
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state):
+ /* "View.MemoryView":747
+ *
+ * for dim, index in enumerate(indices):
+ * if PyIndex_Check(index): # <<<<<<<<<<<<<<
+ * slice_memviewslice(
+ * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
*/
+ __pyx_t_2 = (PyIndex_Check(__pyx_v_index) != 0);
+ if (__pyx_t_2) {
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.memoryview.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":751
+ * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
+ * dim, new_ndim, p_suboffset_dim,
+ * index, 0, 0, # start, stop, step # <<<<<<<<<<<<<<
+ * 0, 0, 0, # have_{start,stop,step}
+ * False)
+ */
+ __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 751, __pyx_L1_error)
-/* "(tree fragment)":3
- * def __reduce_cython__(self):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ /* "View.MemoryView":748
+ * for dim, index in enumerate(indices):
+ * if PyIndex_Check(index):
+ * slice_memviewslice( # <<<<<<<<<<<<<<
+ * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
+ * dim, new_ndim, p_suboffset_dim,
*/
+ __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_t_10, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 748, __pyx_L1_error)
-/* Python wrapper */
-static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
-static PyObject *__pyx_pw___pyx_memoryview_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
- PyObject *__pyx_r = 0;
- __Pyx_RefNannyDeclarations
- __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
- __pyx_r = __pyx_pf___pyx_memoryview_2__setstate_cython__(((struct __pyx_memoryview_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
+ /* "View.MemoryView":747
+ *
+ * for dim, index in enumerate(indices):
+ * if PyIndex_Check(index): # <<<<<<<<<<<<<<
+ * slice_memviewslice(
+ * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
+ */
+ goto __pyx_L6;
+ }
- /* function exit code */
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":754
+ * 0, 0, 0, # have_{start,stop,step}
+ * False)
+ * elif index is None: # <<<<<<<<<<<<<<
+ * p_dst.shape[new_ndim] = 1
+ * p_dst.strides[new_ndim] = 0
+ */
+ __pyx_t_2 = (__pyx_v_index == Py_None);
+ __pyx_t_1 = (__pyx_t_2 != 0);
+ if (__pyx_t_1) {
-static PyObject *__pyx_pf___pyx_memoryview_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryview_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("__setstate_cython__", 0);
+ /* "View.MemoryView":755
+ * False)
+ * elif index is None:
+ * p_dst.shape[new_ndim] = 1 # <<<<<<<<<<<<<<
+ * p_dst.strides[new_ndim] = 0
+ * p_dst.suboffsets[new_ndim] = -1
+ */
+ (__pyx_v_p_dst->shape[__pyx_v_new_ndim]) = 1;
- /* "(tree fragment)":4
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
+ /* "View.MemoryView":756
+ * elif index is None:
+ * p_dst.shape[new_ndim] = 1
+ * p_dst.strides[new_ndim] = 0 # <<<<<<<<<<<<<<
+ * p_dst.suboffsets[new_ndim] = -1
+ * new_ndim += 1
*/
- __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __Pyx_Raise(__pyx_t_1, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
- __PYX_ERR(1, 4, __pyx_L1_error)
+ (__pyx_v_p_dst->strides[__pyx_v_new_ndim]) = 0;
- /* "(tree fragment)":3
- * def __reduce_cython__(self):
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
- * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
- * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ /* "View.MemoryView":757
+ * p_dst.shape[new_ndim] = 1
+ * p_dst.strides[new_ndim] = 0
+ * p_dst.suboffsets[new_ndim] = -1 # <<<<<<<<<<<<<<
+ * new_ndim += 1
+ * else:
*/
+ (__pyx_v_p_dst->suboffsets[__pyx_v_new_ndim]) = -1L;
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_AddTraceback("View.MemoryView.memoryview.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":758
+ * p_dst.strides[new_ndim] = 0
+ * p_dst.suboffsets[new_ndim] = -1
+ * new_ndim += 1 # <<<<<<<<<<<<<<
+ * else:
+ * start = index.start or 0
+ */
+ __pyx_v_new_ndim = (__pyx_v_new_ndim + 1);
-/* "View.MemoryView":657
- *
- * @cname('__pyx_memoryview_new')
- * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<<
- * cdef memoryview result = memoryview(o, flags, dtype_is_object)
- * result.typeinfo = typeinfo
+ /* "View.MemoryView":754
+ * 0, 0, 0, # have_{start,stop,step}
+ * False)
+ * elif index is None: # <<<<<<<<<<<<<<
+ * p_dst.shape[new_ndim] = 1
+ * p_dst.strides[new_ndim] = 0
*/
+ goto __pyx_L6;
+ }
-static PyObject *__pyx_memoryview_new(PyObject *__pyx_v_o, int __pyx_v_flags, int __pyx_v_dtype_is_object, __Pyx_TypeInfo *__pyx_v_typeinfo) {
- struct __pyx_memoryview_obj *__pyx_v_result = 0;
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- PyObject *__pyx_t_1 = NULL;
- PyObject *__pyx_t_2 = NULL;
- PyObject *__pyx_t_3 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("memoryview_cwrapper", 0);
-
- /* "View.MemoryView":658
- * @cname('__pyx_memoryview_new')
- * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):
- * cdef memoryview result = memoryview(o, flags, dtype_is_object) # <<<<<<<<<<<<<<
- * result.typeinfo = typeinfo
- * return result
+ /* "View.MemoryView":760
+ * new_ndim += 1
+ * else:
+ * start = index.start or 0 # <<<<<<<<<<<<<<
+ * stop = index.stop or 0
+ * step = index.step or 0
*/
- __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_flags); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 658, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_1);
- __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 658, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 658, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(__pyx_v_o);
- __Pyx_GIVEREF(__pyx_v_o);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_o);
- __Pyx_GIVEREF(__pyx_t_1);
- PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
- __Pyx_GIVEREF(__pyx_t_2);
- PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
- __pyx_t_1 = 0;
- __pyx_t_2 = 0;
- __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryview_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 658, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_2);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_v_result = ((struct __pyx_memoryview_obj *)__pyx_t_2);
- __pyx_t_2 = 0;
+ /*else*/ {
+ __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 760, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 760, __pyx_L1_error)
+ if (!__pyx_t_1) {
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ } else {
+ __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 760, __pyx_L1_error)
+ __pyx_t_10 = __pyx_t_12;
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ goto __pyx_L7_bool_binop_done;
+ }
+ __pyx_t_10 = 0;
+ __pyx_L7_bool_binop_done:;
+ __pyx_v_start = __pyx_t_10;
- /* "View.MemoryView":659
- * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo):
- * cdef memoryview result = memoryview(o, flags, dtype_is_object)
- * result.typeinfo = typeinfo # <<<<<<<<<<<<<<
- * return result
+ /* "View.MemoryView":761
+ * else:
+ * start = index.start or 0
+ * stop = index.stop or 0 # <<<<<<<<<<<<<<
+ * step = index.step or 0
*
*/
- __pyx_v_result->typeinfo = __pyx_v_typeinfo;
+ __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 761, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 761, __pyx_L1_error)
+ if (!__pyx_t_1) {
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ } else {
+ __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 761, __pyx_L1_error)
+ __pyx_t_10 = __pyx_t_12;
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ goto __pyx_L9_bool_binop_done;
+ }
+ __pyx_t_10 = 0;
+ __pyx_L9_bool_binop_done:;
+ __pyx_v_stop = __pyx_t_10;
- /* "View.MemoryView":660
- * cdef memoryview result = memoryview(o, flags, dtype_is_object)
- * result.typeinfo = typeinfo
- * return result # <<<<<<<<<<<<<<
+ /* "View.MemoryView":762
+ * start = index.start or 0
+ * stop = index.stop or 0
+ * step = index.step or 0 # <<<<<<<<<<<<<<
*
- * @cname('__pyx_memoryview_check')
+ * have_start = index.start is not None
*/
- __Pyx_XDECREF(__pyx_r);
- __Pyx_INCREF(((PyObject *)__pyx_v_result));
- __pyx_r = ((PyObject *)__pyx_v_result);
- goto __pyx_L0;
+ __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 762, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 762, __pyx_L1_error)
+ if (!__pyx_t_1) {
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ } else {
+ __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 762, __pyx_L1_error)
+ __pyx_t_10 = __pyx_t_12;
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ goto __pyx_L11_bool_binop_done;
+ }
+ __pyx_t_10 = 0;
+ __pyx_L11_bool_binop_done:;
+ __pyx_v_step = __pyx_t_10;
- /* "View.MemoryView":657
+ /* "View.MemoryView":764
+ * step = index.step or 0
*
- * @cname('__pyx_memoryview_new')
- * cdef memoryview_cwrapper(object o, int flags, bint dtype_is_object, __Pyx_TypeInfo *typeinfo): # <<<<<<<<<<<<<<
- * cdef memoryview result = memoryview(o, flags, dtype_is_object)
- * result.typeinfo = typeinfo
+ * have_start = index.start is not None # <<<<<<<<<<<<<<
+ * have_stop = index.stop is not None
+ * have_step = index.step is not None
*/
+ __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 764, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_1 = (__pyx_t_9 != Py_None);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_v_have_start = __pyx_t_1;
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_1);
- __Pyx_XDECREF(__pyx_t_2);
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_AddTraceback("View.MemoryView.memoryview_cwrapper", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
- __pyx_L0:;
- __Pyx_XDECREF((PyObject *)__pyx_v_result);
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":663
+ /* "View.MemoryView":765
*
- * @cname('__pyx_memoryview_check')
- * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<<
- * return isinstance(o, memoryview)
+ * have_start = index.start is not None
+ * have_stop = index.stop is not None # <<<<<<<<<<<<<<
+ * have_step = index.step is not None
*
*/
+ __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 765, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_1 = (__pyx_t_9 != Py_None);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_v_have_stop = __pyx_t_1;
-static CYTHON_INLINE int __pyx_memoryview_check(PyObject *__pyx_v_o) {
- int __pyx_r;
- __Pyx_RefNannyDeclarations
- int __pyx_t_1;
- __Pyx_RefNannySetupContext("memoryview_check", 0);
-
- /* "View.MemoryView":664
- * @cname('__pyx_memoryview_check')
- * cdef inline bint memoryview_check(object o):
- * return isinstance(o, memoryview) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":766
+ * have_start = index.start is not None
+ * have_stop = index.stop is not None
+ * have_step = index.step is not None # <<<<<<<<<<<<<<
*
- * cdef tuple _unellipsify(object index, int ndim):
+ * slice_memviewslice(
*/
- __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_o, __pyx_memoryview_type);
- __pyx_r = __pyx_t_1;
- goto __pyx_L0;
+ __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 766, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_9);
+ __pyx_t_1 = (__pyx_t_9 != Py_None);
+ __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+ __pyx_v_have_step = __pyx_t_1;
- /* "View.MemoryView":663
- *
- * @cname('__pyx_memoryview_check')
- * cdef inline bint memoryview_check(object o): # <<<<<<<<<<<<<<
- * return isinstance(o, memoryview)
+ /* "View.MemoryView":768
+ * have_step = index.step is not None
*
+ * slice_memviewslice( # <<<<<<<<<<<<<<
+ * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
+ * dim, new_ndim, p_suboffset_dim,
*/
+ __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_v_start, __pyx_v_stop, __pyx_v_step, __pyx_v_have_start, __pyx_v_have_stop, __pyx_v_have_step, 1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 768, __pyx_L1_error)
- /* function exit code */
- __pyx_L0:;
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":666
- * return isinstance(o, memoryview)
+ /* "View.MemoryView":774
+ * have_start, have_stop, have_step,
+ * True)
+ * new_ndim += 1 # <<<<<<<<<<<<<<
*
- * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<<
- * """
- * Replace all ellipses with full slices and fill incomplete indices with
+ * if isinstance(memview, _memoryviewslice):
*/
+ __pyx_v_new_ndim = (__pyx_v_new_ndim + 1);
+ }
+ __pyx_L6:;
-static PyObject *_unellipsify(PyObject *__pyx_v_index, int __pyx_v_ndim) {
- PyObject *__pyx_v_tup = NULL;
- PyObject *__pyx_v_result = NULL;
- int __pyx_v_have_slices;
- int __pyx_v_seen_ellipsis;
- CYTHON_UNUSED PyObject *__pyx_v_idx = NULL;
- PyObject *__pyx_v_item = NULL;
- Py_ssize_t __pyx_v_nslices;
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- int __pyx_t_1;
- int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- PyObject *__pyx_t_4 = NULL;
- Py_ssize_t __pyx_t_5;
- PyObject *(*__pyx_t_6)(PyObject *);
- PyObject *__pyx_t_7 = NULL;
- Py_ssize_t __pyx_t_8;
- int __pyx_t_9;
- int __pyx_t_10;
- PyObject *__pyx_t_11 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("_unellipsify", 0);
+ /* "View.MemoryView":746
+ * cdef bint have_start, have_stop, have_step
+ *
+ * for dim, index in enumerate(indices): # <<<<<<<<<<<<<<
+ * if PyIndex_Check(index):
+ * slice_memviewslice(
+ */
+ }
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "View.MemoryView":671
- * full slices.
- * """
- * if not isinstance(index, tuple): # <<<<<<<<<<<<<<
- * tup = (index,)
- * else:
+ /* "View.MemoryView":776
+ * new_ndim += 1
+ *
+ * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<<
+ * return memoryview_fromslice(dst, new_ndim,
+ * memviewsliceobj.to_object_func,
*/
- __pyx_t_1 = PyTuple_Check(__pyx_v_index);
- __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
+ __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type);
+ __pyx_t_2 = (__pyx_t_1 != 0);
if (__pyx_t_2) {
- /* "View.MemoryView":672
- * """
- * if not isinstance(index, tuple):
- * tup = (index,) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":777
+ *
+ * if isinstance(memview, _memoryviewslice):
+ * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<<
+ * memviewsliceobj.to_object_func,
+ * memviewsliceobj.to_dtype_func,
+ */
+ __Pyx_XDECREF(((PyObject *)__pyx_r));
+
+ /* "View.MemoryView":778
+ * if isinstance(memview, _memoryviewslice):
+ * return memoryview_fromslice(dst, new_ndim,
+ * memviewsliceobj.to_object_func, # <<<<<<<<<<<<<<
+ * memviewsliceobj.to_dtype_func,
+ * memview.dtype_is_object)
+ */
+ if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 778, __pyx_L1_error) }
+
+ /* "View.MemoryView":779
+ * return memoryview_fromslice(dst, new_ndim,
+ * memviewsliceobj.to_object_func,
+ * memviewsliceobj.to_dtype_func, # <<<<<<<<<<<<<<
+ * memview.dtype_is_object)
* else:
- * tup = index
*/
- __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 672, __pyx_L1_error)
+ if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 779, __pyx_L1_error) }
+
+ /* "View.MemoryView":777
+ *
+ * if isinstance(memview, _memoryviewslice):
+ * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<<
+ * memviewsliceobj.to_object_func,
+ * memviewsliceobj.to_dtype_func,
+ */
+ __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, __pyx_v_memviewsliceobj->to_object_func, __pyx_v_memviewsliceobj->to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 777, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
- __Pyx_INCREF(__pyx_v_index);
- __Pyx_GIVEREF(__pyx_v_index);
- PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_index);
- __pyx_v_tup = __pyx_t_3;
+ if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 777, __pyx_L1_error)
+ __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3);
__pyx_t_3 = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":671
- * full slices.
- * """
- * if not isinstance(index, tuple): # <<<<<<<<<<<<<<
- * tup = (index,)
- * else:
+ /* "View.MemoryView":776
+ * new_ndim += 1
+ *
+ * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<<
+ * return memoryview_fromslice(dst, new_ndim,
+ * memviewsliceobj.to_object_func,
*/
- goto __pyx_L3;
}
- /* "View.MemoryView":674
- * tup = (index,)
+ /* "View.MemoryView":782
+ * memview.dtype_is_object)
* else:
- * tup = index # <<<<<<<<<<<<<<
+ * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<<
+ * memview.dtype_is_object)
*
- * result = []
*/
/*else*/ {
- __Pyx_INCREF(__pyx_v_index);
- __pyx_v_tup = __pyx_v_index;
- }
- __pyx_L3:;
+ __Pyx_XDECREF(((PyObject *)__pyx_r));
- /* "View.MemoryView":676
- * tup = index
+ /* "View.MemoryView":783
+ * else:
+ * return memoryview_fromslice(dst, new_ndim, NULL, NULL,
+ * memview.dtype_is_object) # <<<<<<<<<<<<<<
+ *
*
- * result = [] # <<<<<<<<<<<<<<
- * have_slices = False
- * seen_ellipsis = False
*/
- __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 676, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_v_result = ((PyObject*)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 782, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
- /* "View.MemoryView":677
+ /* "View.MemoryView":782
+ * memview.dtype_is_object)
+ * else:
+ * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<<
+ * memview.dtype_is_object)
*
- * result = []
- * have_slices = False # <<<<<<<<<<<<<<
- * seen_ellipsis = False
- * for idx, item in enumerate(tup):
*/
- __pyx_v_have_slices = 0;
+ if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 782, __pyx_L1_error)
+ __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3);
+ __pyx_t_3 = 0;
+ goto __pyx_L0;
+ }
- /* "View.MemoryView":678
- * result = []
- * have_slices = False
- * seen_ellipsis = False # <<<<<<<<<<<<<<
- * for idx, item in enumerate(tup):
- * if item is Ellipsis:
+ /* "View.MemoryView":710
+ *
+ * @cname('__pyx_memview_slice')
+ * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<<
+ * cdef int new_ndim = 0, suboffset_dim = -1, dim
+ * cdef bint negative_step
*/
- __pyx_v_seen_ellipsis = 0;
- /* "View.MemoryView":679
- * have_slices = False
- * seen_ellipsis = False
- * for idx, item in enumerate(tup): # <<<<<<<<<<<<<<
- * if item is Ellipsis:
- * if not seen_ellipsis:
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_9);
+ __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj);
+ __Pyx_XDECREF(__pyx_v_index);
+ __Pyx_XGIVEREF((PyObject *)__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":807
+ *
+ * @cname('__pyx_memoryview_slice_memviewslice')
+ * cdef int slice_memviewslice( # <<<<<<<<<<<<<<
+ * __Pyx_memviewslice *dst,
+ * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset,
*/
- __Pyx_INCREF(__pyx_int_0);
- __pyx_t_3 = __pyx_int_0;
- if (likely(PyList_CheckExact(__pyx_v_tup)) || PyTuple_CheckExact(__pyx_v_tup)) {
- __pyx_t_4 = __pyx_v_tup; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
- __pyx_t_6 = NULL;
- } else {
- __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_tup); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 679, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 679, __pyx_L1_error)
- }
- for (;;) {
- if (likely(!__pyx_t_6)) {
- if (likely(PyList_CheckExact(__pyx_t_4))) {
- if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
- #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
- __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 679, __pyx_L1_error)
- #else
- __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 679, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_7);
- #endif
- } else {
- if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
- #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
- __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 679, __pyx_L1_error)
- #else
- __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 679, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_7);
- #endif
- }
- } else {
- __pyx_t_7 = __pyx_t_6(__pyx_t_4);
- if (unlikely(!__pyx_t_7)) {
- PyObject* exc_type = PyErr_Occurred();
- if (exc_type) {
- if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
- else __PYX_ERR(1, 679, __pyx_L1_error)
- }
- break;
- }
- __Pyx_GOTREF(__pyx_t_7);
- }
- __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_7);
- __pyx_t_7 = 0;
- __Pyx_INCREF(__pyx_t_3);
- __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_3);
- __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 679, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_7);
- __Pyx_DECREF(__pyx_t_3);
- __pyx_t_3 = __pyx_t_7;
- __pyx_t_7 = 0;
- /* "View.MemoryView":680
- * seen_ellipsis = False
- * for idx, item in enumerate(tup):
- * if item is Ellipsis: # <<<<<<<<<<<<<<
- * if not seen_ellipsis:
- * result.extend([slice(None)] * (ndim - len(tup) + 1))
+static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *__pyx_v_dst, Py_ssize_t __pyx_v_shape, Py_ssize_t __pyx_v_stride, Py_ssize_t __pyx_v_suboffset, int __pyx_v_dim, int __pyx_v_new_ndim, int *__pyx_v_suboffset_dim, Py_ssize_t __pyx_v_start, Py_ssize_t __pyx_v_stop, Py_ssize_t __pyx_v_step, int __pyx_v_have_start, int __pyx_v_have_stop, int __pyx_v_have_step, int __pyx_v_is_slice) {
+ Py_ssize_t __pyx_v_new_shape;
+ int __pyx_v_negative_step;
+ int __pyx_r;
+ int __pyx_t_1;
+ int __pyx_t_2;
+ int __pyx_t_3;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+
+ /* "View.MemoryView":827
+ * cdef bint negative_step
+ *
+ * if not is_slice: # <<<<<<<<<<<<<<
+ *
+ * if start < 0:
*/
- __pyx_t_2 = (__pyx_v_item == __pyx_builtin_Ellipsis);
- __pyx_t_1 = (__pyx_t_2 != 0);
+ __pyx_t_1 = ((!(__pyx_v_is_slice != 0)) != 0);
+ if (__pyx_t_1) {
+
+ /* "View.MemoryView":829
+ * if not is_slice:
+ *
+ * if start < 0: # <<<<<<<<<<<<<<
+ * start += shape
+ * if not 0 <= start < shape:
+ */
+ __pyx_t_1 = ((__pyx_v_start < 0) != 0);
if (__pyx_t_1) {
- /* "View.MemoryView":681
- * for idx, item in enumerate(tup):
- * if item is Ellipsis:
- * if not seen_ellipsis: # <<<<<<<<<<<<<<
- * result.extend([slice(None)] * (ndim - len(tup) + 1))
- * seen_ellipsis = True
+ /* "View.MemoryView":830
+ *
+ * if start < 0:
+ * start += shape # <<<<<<<<<<<<<<
+ * if not 0 <= start < shape:
+ * _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
*/
- __pyx_t_1 = ((!(__pyx_v_seen_ellipsis != 0)) != 0);
- if (__pyx_t_1) {
+ __pyx_v_start = (__pyx_v_start + __pyx_v_shape);
- /* "View.MemoryView":682
- * if item is Ellipsis:
- * if not seen_ellipsis:
- * result.extend([slice(None)] * (ndim - len(tup) + 1)) # <<<<<<<<<<<<<<
- * seen_ellipsis = True
- * else:
+ /* "View.MemoryView":829
+ * if not is_slice:
+ *
+ * if start < 0: # <<<<<<<<<<<<<<
+ * start += shape
+ * if not 0 <= start < shape:
*/
- __pyx_t_8 = PyObject_Length(__pyx_v_tup); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(1, 682, __pyx_L1_error)
- __pyx_t_7 = PyList_New(1 * ((((__pyx_v_ndim - __pyx_t_8) + 1)<0) ? 0:((__pyx_v_ndim - __pyx_t_8) + 1))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 682, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_7);
- { Py_ssize_t __pyx_temp;
- for (__pyx_temp=0; __pyx_temp < ((__pyx_v_ndim - __pyx_t_8) + 1); __pyx_temp++) {
- __Pyx_INCREF(__pyx_slice__15);
- __Pyx_GIVEREF(__pyx_slice__15);
- PyList_SET_ITEM(__pyx_t_7, __pyx_temp, __pyx_slice__15);
- }
- }
- __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 682, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
-
- /* "View.MemoryView":683
- * if not seen_ellipsis:
- * result.extend([slice(None)] * (ndim - len(tup) + 1))
- * seen_ellipsis = True # <<<<<<<<<<<<<<
- * else:
- * result.append(slice(None))
- */
- __pyx_v_seen_ellipsis = 1;
-
- /* "View.MemoryView":681
- * for idx, item in enumerate(tup):
- * if item is Ellipsis:
- * if not seen_ellipsis: # <<<<<<<<<<<<<<
- * result.extend([slice(None)] * (ndim - len(tup) + 1))
- * seen_ellipsis = True
- */
- goto __pyx_L7;
- }
-
- /* "View.MemoryView":685
- * seen_ellipsis = True
- * else:
- * result.append(slice(None)) # <<<<<<<<<<<<<<
- * have_slices = True
- * else:
- */
- /*else*/ {
- __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_slice__15); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 685, __pyx_L1_error)
- }
- __pyx_L7:;
-
- /* "View.MemoryView":686
- * else:
- * result.append(slice(None))
- * have_slices = True # <<<<<<<<<<<<<<
- * else:
- * if not isinstance(item, slice) and not PyIndex_Check(item):
- */
- __pyx_v_have_slices = 1;
+ }
- /* "View.MemoryView":680
- * seen_ellipsis = False
- * for idx, item in enumerate(tup):
- * if item is Ellipsis: # <<<<<<<<<<<<<<
- * if not seen_ellipsis:
- * result.extend([slice(None)] * (ndim - len(tup) + 1))
+ /* "View.MemoryView":831
+ * if start < 0:
+ * start += shape
+ * if not 0 <= start < shape: # <<<<<<<<<<<<<<
+ * _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
+ * else:
*/
- goto __pyx_L6;
+ __pyx_t_1 = (0 <= __pyx_v_start);
+ if (__pyx_t_1) {
+ __pyx_t_1 = (__pyx_v_start < __pyx_v_shape);
}
+ __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":688
- * have_slices = True
- * else:
- * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<<
- * raise TypeError("Cannot index with type '%s'" % type(item))
+ /* "View.MemoryView":832
+ * start += shape
+ * if not 0 <= start < shape:
+ * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) # <<<<<<<<<<<<<<
+ * else:
*
*/
- /*else*/ {
- __pyx_t_2 = PySlice_Check(__pyx_v_item);
- __pyx_t_10 = ((!(__pyx_t_2 != 0)) != 0);
- if (__pyx_t_10) {
- } else {
- __pyx_t_1 = __pyx_t_10;
- goto __pyx_L9_bool_binop_done;
- }
- __pyx_t_10 = ((!(PyIndex_Check(__pyx_v_item) != 0)) != 0);
- __pyx_t_1 = __pyx_t_10;
- __pyx_L9_bool_binop_done:;
- if (unlikely(__pyx_t_1)) {
+ __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"Index out of bounds (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 832, __pyx_L1_error)
- /* "View.MemoryView":689
- * else:
- * if not isinstance(item, slice) and not PyIndex_Check(item):
- * raise TypeError("Cannot index with type '%s'" % type(item)) # <<<<<<<<<<<<<<
- *
- * have_slices = have_slices or isinstance(item, slice)
+ /* "View.MemoryView":831
+ * if start < 0:
+ * start += shape
+ * if not 0 <= start < shape: # <<<<<<<<<<<<<<
+ * _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
+ * else:
*/
- __pyx_t_7 = __Pyx_PyString_FormatSafe(__pyx_kp_s_Cannot_index_with_type_s, ((PyObject *)Py_TYPE(__pyx_v_item))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 689, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_7);
- __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 689, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_11);
- __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
- __Pyx_Raise(__pyx_t_11, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
- __PYX_ERR(1, 689, __pyx_L1_error)
+ }
- /* "View.MemoryView":688
- * have_slices = True
- * else:
- * if not isinstance(item, slice) and not PyIndex_Check(item): # <<<<<<<<<<<<<<
- * raise TypeError("Cannot index with type '%s'" % type(item))
+ /* "View.MemoryView":827
+ * cdef bint negative_step
+ *
+ * if not is_slice: # <<<<<<<<<<<<<<
*
+ * if start < 0:
*/
- }
+ goto __pyx_L3;
+ }
- /* "View.MemoryView":691
- * raise TypeError("Cannot index with type '%s'" % type(item))
+ /* "View.MemoryView":835
+ * else:
*
- * have_slices = have_slices or isinstance(item, slice) # <<<<<<<<<<<<<<
- * result.append(item)
+ * negative_step = have_step != 0 and step < 0 # <<<<<<<<<<<<<<
*
+ * if have_step and step == 0:
*/
- __pyx_t_10 = (__pyx_v_have_slices != 0);
- if (!__pyx_t_10) {
- } else {
- __pyx_t_1 = __pyx_t_10;
- goto __pyx_L11_bool_binop_done;
- }
- __pyx_t_10 = PySlice_Check(__pyx_v_item);
- __pyx_t_2 = (__pyx_t_10 != 0);
- __pyx_t_1 = __pyx_t_2;
- __pyx_L11_bool_binop_done:;
- __pyx_v_have_slices = __pyx_t_1;
+ /*else*/ {
+ __pyx_t_1 = ((__pyx_v_have_step != 0) != 0);
+ if (__pyx_t_1) {
+ } else {
+ __pyx_t_2 = __pyx_t_1;
+ goto __pyx_L6_bool_binop_done;
+ }
+ __pyx_t_1 = ((__pyx_v_step < 0) != 0);
+ __pyx_t_2 = __pyx_t_1;
+ __pyx_L6_bool_binop_done:;
+ __pyx_v_negative_step = __pyx_t_2;
- /* "View.MemoryView":692
+ /* "View.MemoryView":837
+ * negative_step = have_step != 0 and step < 0
*
- * have_slices = have_slices or isinstance(item, slice)
- * result.append(item) # <<<<<<<<<<<<<<
+ * if have_step and step == 0: # <<<<<<<<<<<<<<
+ * _err_dim(ValueError, "Step may not be zero (axis %d)", dim)
*
- * nslices = ndim - len(result)
*/
- __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_v_item); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 692, __pyx_L1_error)
+ __pyx_t_1 = (__pyx_v_have_step != 0);
+ if (__pyx_t_1) {
+ } else {
+ __pyx_t_2 = __pyx_t_1;
+ goto __pyx_L9_bool_binop_done;
}
- __pyx_L6:;
-
- /* "View.MemoryView":679
- * have_slices = False
- * seen_ellipsis = False
- * for idx, item in enumerate(tup): # <<<<<<<<<<<<<<
- * if item is Ellipsis:
- * if not seen_ellipsis:
- */
- }
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_1 = ((__pyx_v_step == 0) != 0);
+ __pyx_t_2 = __pyx_t_1;
+ __pyx_L9_bool_binop_done:;
+ if (__pyx_t_2) {
- /* "View.MemoryView":694
- * result.append(item)
+ /* "View.MemoryView":838
*
- * nslices = ndim - len(result) # <<<<<<<<<<<<<<
- * if nslices:
- * result.extend([slice(None)] * nslices)
- */
- __pyx_t_5 = PyList_GET_SIZE(__pyx_v_result); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(1, 694, __pyx_L1_error)
- __pyx_v_nslices = (__pyx_v_ndim - __pyx_t_5);
-
- /* "View.MemoryView":695
+ * if have_step and step == 0:
+ * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) # <<<<<<<<<<<<<<
*
- * nslices = ndim - len(result)
- * if nslices: # <<<<<<<<<<<<<<
- * result.extend([slice(None)] * nslices)
*
*/
- __pyx_t_1 = (__pyx_v_nslices != 0);
- if (__pyx_t_1) {
+ __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Step may not be zero (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 838, __pyx_L1_error)
- /* "View.MemoryView":696
- * nslices = ndim - len(result)
- * if nslices:
- * result.extend([slice(None)] * nslices) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":837
+ * negative_step = have_step != 0 and step < 0
+ *
+ * if have_step and step == 0: # <<<<<<<<<<<<<<
+ * _err_dim(ValueError, "Step may not be zero (axis %d)", dim)
*
- * return have_slices or nslices, tuple(result)
*/
- __pyx_t_3 = PyList_New(1 * ((__pyx_v_nslices<0) ? 0:__pyx_v_nslices)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 696, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- { Py_ssize_t __pyx_temp;
- for (__pyx_temp=0; __pyx_temp < __pyx_v_nslices; __pyx_temp++) {
- __Pyx_INCREF(__pyx_slice__15);
- __Pyx_GIVEREF(__pyx_slice__15);
- PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_slice__15);
- }
}
- __pyx_t_9 = __Pyx_PyList_Extend(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 696, __pyx_L1_error)
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- /* "View.MemoryView":695
+ /* "View.MemoryView":841
*
- * nslices = ndim - len(result)
- * if nslices: # <<<<<<<<<<<<<<
- * result.extend([slice(None)] * nslices)
*
+ * if have_start: # <<<<<<<<<<<<<<
+ * if start < 0:
+ * start += shape
*/
- }
+ __pyx_t_2 = (__pyx_v_have_start != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":698
- * result.extend([slice(None)] * nslices)
- *
- * return have_slices or nslices, tuple(result) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":842
*
- * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
+ * if have_start:
+ * if start < 0: # <<<<<<<<<<<<<<
+ * start += shape
+ * if start < 0:
*/
- __Pyx_XDECREF(__pyx_r);
- if (!__pyx_v_have_slices) {
- } else {
- __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_have_slices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 698, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = __pyx_t_4;
- __pyx_t_4 = 0;
- goto __pyx_L14_bool_binop_done;
- }
- __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_nslices); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 698, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_3 = __pyx_t_4;
- __pyx_t_4 = 0;
- __pyx_L14_bool_binop_done:;
- __pyx_t_4 = PyList_AsTuple(__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 698, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 698, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_11);
- __Pyx_GIVEREF(__pyx_t_3);
- PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3);
- __Pyx_GIVEREF(__pyx_t_4);
- PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_4);
- __pyx_t_3 = 0;
- __pyx_t_4 = 0;
- __pyx_r = ((PyObject*)__pyx_t_11);
- __pyx_t_11 = 0;
- goto __pyx_L0;
+ __pyx_t_2 = ((__pyx_v_start < 0) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":666
- * return isinstance(o, memoryview)
- *
- * cdef tuple _unellipsify(object index, int ndim): # <<<<<<<<<<<<<<
- * """
- * Replace all ellipses with full slices and fill incomplete indices with
+ /* "View.MemoryView":843
+ * if have_start:
+ * if start < 0:
+ * start += shape # <<<<<<<<<<<<<<
+ * if start < 0:
+ * start = 0
*/
+ __pyx_v_start = (__pyx_v_start + __pyx_v_shape);
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_4);
- __Pyx_XDECREF(__pyx_t_7);
- __Pyx_XDECREF(__pyx_t_11);
- __Pyx_AddTraceback("View.MemoryView._unellipsify", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
- __pyx_L0:;
- __Pyx_XDECREF(__pyx_v_tup);
- __Pyx_XDECREF(__pyx_v_result);
- __Pyx_XDECREF(__pyx_v_idx);
- __Pyx_XDECREF(__pyx_v_item);
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":700
- * return have_slices or nslices, tuple(result)
- *
- * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<<
- * for suboffset in suboffsets[:ndim]:
- * if suboffset >= 0:
+ /* "View.MemoryView":844
+ * if start < 0:
+ * start += shape
+ * if start < 0: # <<<<<<<<<<<<<<
+ * start = 0
+ * elif start >= shape:
*/
+ __pyx_t_2 = ((__pyx_v_start < 0) != 0);
+ if (__pyx_t_2) {
-static PyObject *assert_direct_dimensions(Py_ssize_t *__pyx_v_suboffsets, int __pyx_v_ndim) {
- Py_ssize_t __pyx_v_suboffset;
- PyObject *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- Py_ssize_t *__pyx_t_1;
- Py_ssize_t *__pyx_t_2;
- Py_ssize_t *__pyx_t_3;
- int __pyx_t_4;
- PyObject *__pyx_t_5 = NULL;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("assert_direct_dimensions", 0);
-
- /* "View.MemoryView":701
- *
- * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
- * for suboffset in suboffsets[:ndim]: # <<<<<<<<<<<<<<
- * if suboffset >= 0:
- * raise ValueError("Indirect dimensions not supported")
+ /* "View.MemoryView":845
+ * start += shape
+ * if start < 0:
+ * start = 0 # <<<<<<<<<<<<<<
+ * elif start >= shape:
+ * if negative_step:
*/
- __pyx_t_2 = (__pyx_v_suboffsets + __pyx_v_ndim);
- for (__pyx_t_3 = __pyx_v_suboffsets; __pyx_t_3 < __pyx_t_2; __pyx_t_3++) {
- __pyx_t_1 = __pyx_t_3;
- __pyx_v_suboffset = (__pyx_t_1[0]);
+ __pyx_v_start = 0;
- /* "View.MemoryView":702
- * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
- * for suboffset in suboffsets[:ndim]:
- * if suboffset >= 0: # <<<<<<<<<<<<<<
- * raise ValueError("Indirect dimensions not supported")
- *
+ /* "View.MemoryView":844
+ * if start < 0:
+ * start += shape
+ * if start < 0: # <<<<<<<<<<<<<<
+ * start = 0
+ * elif start >= shape:
*/
- __pyx_t_4 = ((__pyx_v_suboffset >= 0) != 0);
- if (unlikely(__pyx_t_4)) {
+ }
- /* "View.MemoryView":703
- * for suboffset in suboffsets[:ndim]:
- * if suboffset >= 0:
- * raise ValueError("Indirect dimensions not supported") # <<<<<<<<<<<<<<
- *
+ /* "View.MemoryView":842
*
+ * if have_start:
+ * if start < 0: # <<<<<<<<<<<<<<
+ * start += shape
+ * if start < 0:
*/
- __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 703, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_5);
- __Pyx_Raise(__pyx_t_5, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
- __PYX_ERR(1, 703, __pyx_L1_error)
+ goto __pyx_L12;
+ }
- /* "View.MemoryView":702
- * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim):
- * for suboffset in suboffsets[:ndim]:
- * if suboffset >= 0: # <<<<<<<<<<<<<<
- * raise ValueError("Indirect dimensions not supported")
- *
+ /* "View.MemoryView":846
+ * if start < 0:
+ * start = 0
+ * elif start >= shape: # <<<<<<<<<<<<<<
+ * if negative_step:
+ * start = shape - 1
*/
- }
- }
+ __pyx_t_2 = ((__pyx_v_start >= __pyx_v_shape) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":700
- * return have_slices or nslices, tuple(result)
- *
- * cdef assert_direct_dimensions(Py_ssize_t *suboffsets, int ndim): # <<<<<<<<<<<<<<
- * for suboffset in suboffsets[:ndim]:
- * if suboffset >= 0:
+ /* "View.MemoryView":847
+ * start = 0
+ * elif start >= shape:
+ * if negative_step: # <<<<<<<<<<<<<<
+ * start = shape - 1
+ * else:
*/
+ __pyx_t_2 = (__pyx_v_negative_step != 0);
+ if (__pyx_t_2) {
- /* function exit code */
- __pyx_r = Py_None; __Pyx_INCREF(Py_None);
- goto __pyx_L0;
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_5);
- __Pyx_AddTraceback("View.MemoryView.assert_direct_dimensions", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
- __pyx_L0:;
- __Pyx_XGIVEREF(__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
+ /* "View.MemoryView":848
+ * elif start >= shape:
+ * if negative_step:
+ * start = shape - 1 # <<<<<<<<<<<<<<
+ * else:
+ * start = shape
+ */
+ __pyx_v_start = (__pyx_v_shape - 1);
-/* "View.MemoryView":710
- *
- * @cname('__pyx_memview_slice')
- * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<<
- * cdef int new_ndim = 0, suboffset_dim = -1, dim
- * cdef bint negative_step
+ /* "View.MemoryView":847
+ * start = 0
+ * elif start >= shape:
+ * if negative_step: # <<<<<<<<<<<<<<
+ * start = shape - 1
+ * else:
*/
+ goto __pyx_L14;
+ }
-static struct __pyx_memoryview_obj *__pyx_memview_slice(struct __pyx_memoryview_obj *__pyx_v_memview, PyObject *__pyx_v_indices) {
- int __pyx_v_new_ndim;
- int __pyx_v_suboffset_dim;
- int __pyx_v_dim;
- __Pyx_memviewslice __pyx_v_src;
- __Pyx_memviewslice __pyx_v_dst;
- __Pyx_memviewslice *__pyx_v_p_src;
- struct __pyx_memoryviewslice_obj *__pyx_v_memviewsliceobj = 0;
- __Pyx_memviewslice *__pyx_v_p_dst;
- int *__pyx_v_p_suboffset_dim;
- Py_ssize_t __pyx_v_start;
- Py_ssize_t __pyx_v_stop;
- Py_ssize_t __pyx_v_step;
- int __pyx_v_have_start;
- int __pyx_v_have_stop;
- int __pyx_v_have_step;
- PyObject *__pyx_v_index = NULL;
- struct __pyx_memoryview_obj *__pyx_r = NULL;
- __Pyx_RefNannyDeclarations
- int __pyx_t_1;
- int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- struct __pyx_memoryview_obj *__pyx_t_4;
- char *__pyx_t_5;
- int __pyx_t_6;
- Py_ssize_t __pyx_t_7;
- PyObject *(*__pyx_t_8)(PyObject *);
- PyObject *__pyx_t_9 = NULL;
- Py_ssize_t __pyx_t_10;
- int __pyx_t_11;
- Py_ssize_t __pyx_t_12;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("memview_slice", 0);
+ /* "View.MemoryView":850
+ * start = shape - 1
+ * else:
+ * start = shape # <<<<<<<<<<<<<<
+ * else:
+ * if negative_step:
+ */
+ /*else*/ {
+ __pyx_v_start = __pyx_v_shape;
+ }
+ __pyx_L14:;
- /* "View.MemoryView":711
- * @cname('__pyx_memview_slice')
- * cdef memoryview memview_slice(memoryview memview, object indices):
- * cdef int new_ndim = 0, suboffset_dim = -1, dim # <<<<<<<<<<<<<<
- * cdef bint negative_step
- * cdef __Pyx_memviewslice src, dst
+ /* "View.MemoryView":846
+ * if start < 0:
+ * start = 0
+ * elif start >= shape: # <<<<<<<<<<<<<<
+ * if negative_step:
+ * start = shape - 1
*/
- __pyx_v_new_ndim = 0;
- __pyx_v_suboffset_dim = -1;
+ }
+ __pyx_L12:;
- /* "View.MemoryView":718
+ /* "View.MemoryView":841
*
*
- * memset(&dst, 0, sizeof(dst)) # <<<<<<<<<<<<<<
- *
- * cdef _memoryviewslice memviewsliceobj
- */
- (void)(memset((&__pyx_v_dst), 0, (sizeof(__pyx_v_dst))));
-
- /* "View.MemoryView":722
- * cdef _memoryviewslice memviewsliceobj
- *
- * assert memview.view.ndim > 0 # <<<<<<<<<<<<<<
- *
- * if isinstance(memview, _memoryviewslice):
+ * if have_start: # <<<<<<<<<<<<<<
+ * if start < 0:
+ * start += shape
*/
- #ifndef CYTHON_WITHOUT_ASSERTIONS
- if (unlikely(!Py_OptimizeFlag)) {
- if (unlikely(!((__pyx_v_memview->view.ndim > 0) != 0))) {
- PyErr_SetNone(PyExc_AssertionError);
- __PYX_ERR(1, 722, __pyx_L1_error)
+ goto __pyx_L11;
}
- }
- #endif
- /* "View.MemoryView":724
- * assert memview.view.ndim > 0
- *
- * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<<
- * memviewsliceobj = memview
- * p_src = &memviewsliceobj.from_slice
+ /* "View.MemoryView":852
+ * start = shape
+ * else:
+ * if negative_step: # <<<<<<<<<<<<<<
+ * start = shape - 1
+ * else:
*/
- __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type);
- __pyx_t_2 = (__pyx_t_1 != 0);
- if (__pyx_t_2) {
+ /*else*/ {
+ __pyx_t_2 = (__pyx_v_negative_step != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":725
- *
- * if isinstance(memview, _memoryviewslice):
- * memviewsliceobj = memview # <<<<<<<<<<<<<<
- * p_src = &memviewsliceobj.from_slice
- * else:
+ /* "View.MemoryView":853
+ * else:
+ * if negative_step:
+ * start = shape - 1 # <<<<<<<<<<<<<<
+ * else:
+ * start = 0
*/
- if (!(likely(((((PyObject *)__pyx_v_memview)) == Py_None) || likely(__Pyx_TypeTest(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type))))) __PYX_ERR(1, 725, __pyx_L1_error)
- __pyx_t_3 = ((PyObject *)__pyx_v_memview);
- __Pyx_INCREF(__pyx_t_3);
- __pyx_v_memviewsliceobj = ((struct __pyx_memoryviewslice_obj *)__pyx_t_3);
- __pyx_t_3 = 0;
+ __pyx_v_start = (__pyx_v_shape - 1);
- /* "View.MemoryView":726
- * if isinstance(memview, _memoryviewslice):
- * memviewsliceobj = memview
- * p_src = &memviewsliceobj.from_slice # <<<<<<<<<<<<<<
- * else:
- * slice_copy(memview, &src)
+ /* "View.MemoryView":852
+ * start = shape
+ * else:
+ * if negative_step: # <<<<<<<<<<<<<<
+ * start = shape - 1
+ * else:
*/
- __pyx_v_p_src = (&__pyx_v_memviewsliceobj->from_slice);
+ goto __pyx_L15;
+ }
- /* "View.MemoryView":724
- * assert memview.view.ndim > 0
+ /* "View.MemoryView":855
+ * start = shape - 1
+ * else:
+ * start = 0 # <<<<<<<<<<<<<<
*
- * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<<
- * memviewsliceobj = memview
- * p_src = &memviewsliceobj.from_slice
+ * if have_stop:
*/
- goto __pyx_L3;
- }
+ /*else*/ {
+ __pyx_v_start = 0;
+ }
+ __pyx_L15:;
+ }
+ __pyx_L11:;
- /* "View.MemoryView":728
- * p_src = &memviewsliceobj.from_slice
- * else:
- * slice_copy(memview, &src) # <<<<<<<<<<<<<<
- * p_src = &src
+ /* "View.MemoryView":857
+ * start = 0
*
+ * if have_stop: # <<<<<<<<<<<<<<
+ * if stop < 0:
+ * stop += shape
*/
- /*else*/ {
- __pyx_memoryview_slice_copy(__pyx_v_memview, (&__pyx_v_src));
+ __pyx_t_2 = (__pyx_v_have_stop != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":729
- * else:
- * slice_copy(memview, &src)
- * p_src = &src # <<<<<<<<<<<<<<
- *
+ /* "View.MemoryView":858
*
+ * if have_stop:
+ * if stop < 0: # <<<<<<<<<<<<<<
+ * stop += shape
+ * if stop < 0:
*/
- __pyx_v_p_src = (&__pyx_v_src);
- }
- __pyx_L3:;
+ __pyx_t_2 = ((__pyx_v_stop < 0) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":735
- *
- *
- * dst.memview = p_src.memview # <<<<<<<<<<<<<<
- * dst.data = p_src.data
- *
+ /* "View.MemoryView":859
+ * if have_stop:
+ * if stop < 0:
+ * stop += shape # <<<<<<<<<<<<<<
+ * if stop < 0:
+ * stop = 0
*/
- __pyx_t_4 = __pyx_v_p_src->memview;
- __pyx_v_dst.memview = __pyx_t_4;
+ __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape);
- /* "View.MemoryView":736
- *
- * dst.memview = p_src.memview
- * dst.data = p_src.data # <<<<<<<<<<<<<<
- *
- *
+ /* "View.MemoryView":860
+ * if stop < 0:
+ * stop += shape
+ * if stop < 0: # <<<<<<<<<<<<<<
+ * stop = 0
+ * elif stop > shape:
*/
- __pyx_t_5 = __pyx_v_p_src->data;
- __pyx_v_dst.data = __pyx_t_5;
+ __pyx_t_2 = ((__pyx_v_stop < 0) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":741
- *
- *
- * cdef __Pyx_memviewslice *p_dst = &dst # <<<<<<<<<<<<<<
- * cdef int *p_suboffset_dim = &suboffset_dim
- * cdef Py_ssize_t start, stop, step
+ /* "View.MemoryView":861
+ * stop += shape
+ * if stop < 0:
+ * stop = 0 # <<<<<<<<<<<<<<
+ * elif stop > shape:
+ * stop = shape
*/
- __pyx_v_p_dst = (&__pyx_v_dst);
+ __pyx_v_stop = 0;
- /* "View.MemoryView":742
- *
- * cdef __Pyx_memviewslice *p_dst = &dst
- * cdef int *p_suboffset_dim = &suboffset_dim # <<<<<<<<<<<<<<
- * cdef Py_ssize_t start, stop, step
- * cdef bint have_start, have_stop, have_step
+ /* "View.MemoryView":860
+ * if stop < 0:
+ * stop += shape
+ * if stop < 0: # <<<<<<<<<<<<<<
+ * stop = 0
+ * elif stop > shape:
*/
- __pyx_v_p_suboffset_dim = (&__pyx_v_suboffset_dim);
+ }
- /* "View.MemoryView":746
- * cdef bint have_start, have_stop, have_step
+ /* "View.MemoryView":858
*
- * for dim, index in enumerate(indices): # <<<<<<<<<<<<<<
- * if PyIndex_Check(index):
- * slice_memviewslice(
+ * if have_stop:
+ * if stop < 0: # <<<<<<<<<<<<<<
+ * stop += shape
+ * if stop < 0:
*/
- __pyx_t_6 = 0;
- if (likely(PyList_CheckExact(__pyx_v_indices)) || PyTuple_CheckExact(__pyx_v_indices)) {
- __pyx_t_3 = __pyx_v_indices; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0;
- __pyx_t_8 = NULL;
- } else {
- __pyx_t_7 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_indices); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 746, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 746, __pyx_L1_error)
- }
- for (;;) {
- if (likely(!__pyx_t_8)) {
- if (likely(PyList_CheckExact(__pyx_t_3))) {
- if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break;
- #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
- __pyx_t_9 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 746, __pyx_L1_error)
- #else
- __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 746, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_9);
- #endif
- } else {
- if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
- #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
- __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_9); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(1, 746, __pyx_L1_error)
- #else
- __pyx_t_9 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 746, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_9);
- #endif
- }
- } else {
- __pyx_t_9 = __pyx_t_8(__pyx_t_3);
- if (unlikely(!__pyx_t_9)) {
- PyObject* exc_type = PyErr_Occurred();
- if (exc_type) {
- if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
- else __PYX_ERR(1, 746, __pyx_L1_error)
- }
- break;
+ goto __pyx_L17;
}
- __Pyx_GOTREF(__pyx_t_9);
- }
- __Pyx_XDECREF_SET(__pyx_v_index, __pyx_t_9);
- __pyx_t_9 = 0;
- __pyx_v_dim = __pyx_t_6;
- __pyx_t_6 = (__pyx_t_6 + 1);
- /* "View.MemoryView":747
- *
- * for dim, index in enumerate(indices):
- * if PyIndex_Check(index): # <<<<<<<<<<<<<<
- * slice_memviewslice(
- * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
+ /* "View.MemoryView":862
+ * if stop < 0:
+ * stop = 0
+ * elif stop > shape: # <<<<<<<<<<<<<<
+ * stop = shape
+ * else:
*/
- __pyx_t_2 = (PyIndex_Check(__pyx_v_index) != 0);
- if (__pyx_t_2) {
+ __pyx_t_2 = ((__pyx_v_stop > __pyx_v_shape) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":751
- * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
- * dim, new_ndim, p_suboffset_dim,
- * index, 0, 0, # start, stop, step # <<<<<<<<<<<<<<
- * 0, 0, 0, # have_{start,stop,step}
- * False)
+ /* "View.MemoryView":863
+ * stop = 0
+ * elif stop > shape:
+ * stop = shape # <<<<<<<<<<<<<<
+ * else:
+ * if negative_step:
*/
- __pyx_t_10 = __Pyx_PyIndex_AsSsize_t(__pyx_v_index); if (unlikely((__pyx_t_10 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 751, __pyx_L1_error)
+ __pyx_v_stop = __pyx_v_shape;
- /* "View.MemoryView":748
- * for dim, index in enumerate(indices):
- * if PyIndex_Check(index):
- * slice_memviewslice( # <<<<<<<<<<<<<<
- * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
- * dim, new_ndim, p_suboffset_dim,
+ /* "View.MemoryView":862
+ * if stop < 0:
+ * stop = 0
+ * elif stop > shape: # <<<<<<<<<<<<<<
+ * stop = shape
+ * else:
*/
- __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_t_10, 0, 0, 0, 0, 0, 0); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 748, __pyx_L1_error)
+ }
+ __pyx_L17:;
- /* "View.MemoryView":747
+ /* "View.MemoryView":857
+ * start = 0
*
- * for dim, index in enumerate(indices):
- * if PyIndex_Check(index): # <<<<<<<<<<<<<<
- * slice_memviewslice(
- * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
+ * if have_stop: # <<<<<<<<<<<<<<
+ * if stop < 0:
+ * stop += shape
*/
- goto __pyx_L6;
+ goto __pyx_L16;
}
- /* "View.MemoryView":754
- * 0, 0, 0, # have_{start,stop,step}
- * False)
- * elif index is None: # <<<<<<<<<<<<<<
- * p_dst.shape[new_ndim] = 1
- * p_dst.strides[new_ndim] = 0
- */
- __pyx_t_2 = (__pyx_v_index == Py_None);
- __pyx_t_1 = (__pyx_t_2 != 0);
- if (__pyx_t_1) {
-
- /* "View.MemoryView":755
- * False)
- * elif index is None:
- * p_dst.shape[new_ndim] = 1 # <<<<<<<<<<<<<<
- * p_dst.strides[new_ndim] = 0
- * p_dst.suboffsets[new_ndim] = -1
- */
- (__pyx_v_p_dst->shape[__pyx_v_new_ndim]) = 1;
-
- /* "View.MemoryView":756
- * elif index is None:
- * p_dst.shape[new_ndim] = 1
- * p_dst.strides[new_ndim] = 0 # <<<<<<<<<<<<<<
- * p_dst.suboffsets[new_ndim] = -1
- * new_ndim += 1
- */
- (__pyx_v_p_dst->strides[__pyx_v_new_ndim]) = 0;
-
- /* "View.MemoryView":757
- * p_dst.shape[new_ndim] = 1
- * p_dst.strides[new_ndim] = 0
- * p_dst.suboffsets[new_ndim] = -1 # <<<<<<<<<<<<<<
- * new_ndim += 1
+ /* "View.MemoryView":865
+ * stop = shape
* else:
+ * if negative_step: # <<<<<<<<<<<<<<
+ * stop = -1
+ * else:
*/
- (__pyx_v_p_dst->suboffsets[__pyx_v_new_ndim]) = -1L;
+ /*else*/ {
+ __pyx_t_2 = (__pyx_v_negative_step != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":758
- * p_dst.strides[new_ndim] = 0
- * p_dst.suboffsets[new_ndim] = -1
- * new_ndim += 1 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":866
* else:
- * start = index.start or 0
- */
- __pyx_v_new_ndim = (__pyx_v_new_ndim + 1);
-
- /* "View.MemoryView":754
- * 0, 0, 0, # have_{start,stop,step}
- * False)
- * elif index is None: # <<<<<<<<<<<<<<
- * p_dst.shape[new_ndim] = 1
- * p_dst.strides[new_ndim] = 0
+ * if negative_step:
+ * stop = -1 # <<<<<<<<<<<<<<
+ * else:
+ * stop = shape
*/
- goto __pyx_L6;
- }
+ __pyx_v_stop = -1L;
- /* "View.MemoryView":760
- * new_ndim += 1
+ /* "View.MemoryView":865
+ * stop = shape
* else:
- * start = index.start or 0 # <<<<<<<<<<<<<<
- * stop = index.stop or 0
- * step = index.step or 0
+ * if negative_step: # <<<<<<<<<<<<<<
+ * stop = -1
+ * else:
*/
- /*else*/ {
- __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 760, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_9);
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 760, __pyx_L1_error)
- if (!__pyx_t_1) {
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- } else {
- __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 760, __pyx_L1_error)
- __pyx_t_10 = __pyx_t_12;
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- goto __pyx_L7_bool_binop_done;
+ goto __pyx_L19;
}
- __pyx_t_10 = 0;
- __pyx_L7_bool_binop_done:;
- __pyx_v_start = __pyx_t_10;
- /* "View.MemoryView":761
- * else:
- * start = index.start or 0
- * stop = index.stop or 0 # <<<<<<<<<<<<<<
- * step = index.step or 0
+ /* "View.MemoryView":868
+ * stop = -1
+ * else:
+ * stop = shape # <<<<<<<<<<<<<<
*
+ * if not have_step:
*/
- __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 761, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_9);
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 761, __pyx_L1_error)
- if (!__pyx_t_1) {
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- } else {
- __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 761, __pyx_L1_error)
- __pyx_t_10 = __pyx_t_12;
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- goto __pyx_L9_bool_binop_done;
+ /*else*/ {
+ __pyx_v_stop = __pyx_v_shape;
}
- __pyx_t_10 = 0;
- __pyx_L9_bool_binop_done:;
- __pyx_v_stop = __pyx_t_10;
+ __pyx_L19:;
+ }
+ __pyx_L16:;
- /* "View.MemoryView":762
- * start = index.start or 0
- * stop = index.stop or 0
- * step = index.step or 0 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":870
+ * stop = shape
+ *
+ * if not have_step: # <<<<<<<<<<<<<<
+ * step = 1
*
- * have_start = index.start is not None
*/
- __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 762, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_9);
- __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 762, __pyx_L1_error)
- if (!__pyx_t_1) {
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- } else {
- __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 762, __pyx_L1_error)
- __pyx_t_10 = __pyx_t_12;
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- goto __pyx_L11_bool_binop_done;
- }
- __pyx_t_10 = 0;
- __pyx_L11_bool_binop_done:;
- __pyx_v_step = __pyx_t_10;
+ __pyx_t_2 = ((!(__pyx_v_have_step != 0)) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":764
- * step = index.step or 0
+ /* "View.MemoryView":871
+ *
+ * if not have_step:
+ * step = 1 # <<<<<<<<<<<<<<
+ *
*
- * have_start = index.start is not None # <<<<<<<<<<<<<<
- * have_stop = index.stop is not None
- * have_step = index.step is not None
*/
- __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_start); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 764, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_9);
- __pyx_t_1 = (__pyx_t_9 != Py_None);
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- __pyx_v_have_start = __pyx_t_1;
+ __pyx_v_step = 1;
- /* "View.MemoryView":765
+ /* "View.MemoryView":870
+ * stop = shape
*
- * have_start = index.start is not None
- * have_stop = index.stop is not None # <<<<<<<<<<<<<<
- * have_step = index.step is not None
+ * if not have_step: # <<<<<<<<<<<<<<
+ * step = 1
*
*/
- __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_stop); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 765, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_9);
- __pyx_t_1 = (__pyx_t_9 != Py_None);
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- __pyx_v_have_stop = __pyx_t_1;
+ }
- /* "View.MemoryView":766
- * have_start = index.start is not None
- * have_stop = index.stop is not None
- * have_step = index.step is not None # <<<<<<<<<<<<<<
+ /* "View.MemoryView":875
*
- * slice_memviewslice(
+ * with cython.cdivision(True):
+ * new_shape = (stop - start) // step # <<<<<<<<<<<<<<
+ *
+ * if (stop - start) - step * new_shape:
*/
- __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_index, __pyx_n_s_step); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 766, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_9);
- __pyx_t_1 = (__pyx_t_9 != Py_None);
- __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
- __pyx_v_have_step = __pyx_t_1;
+ __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step);
- /* "View.MemoryView":768
- * have_step = index.step is not None
+ /* "View.MemoryView":877
+ * new_shape = (stop - start) // step
+ *
+ * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<<
+ * new_shape += 1
*
- * slice_memviewslice( # <<<<<<<<<<<<<<
- * p_dst, p_src.shape[dim], p_src.strides[dim], p_src.suboffsets[dim],
- * dim, new_ndim, p_suboffset_dim,
*/
- __pyx_t_11 = __pyx_memoryview_slice_memviewslice(__pyx_v_p_dst, (__pyx_v_p_src->shape[__pyx_v_dim]), (__pyx_v_p_src->strides[__pyx_v_dim]), (__pyx_v_p_src->suboffsets[__pyx_v_dim]), __pyx_v_dim, __pyx_v_new_ndim, __pyx_v_p_suboffset_dim, __pyx_v_start, __pyx_v_stop, __pyx_v_step, __pyx_v_have_start, __pyx_v_have_stop, __pyx_v_have_step, 1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(1, 768, __pyx_L1_error)
+ __pyx_t_2 = (((__pyx_v_stop - __pyx_v_start) - (__pyx_v_step * __pyx_v_new_shape)) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":774
- * have_start, have_stop, have_step,
- * True)
- * new_ndim += 1 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":878
*
- * if isinstance(memview, _memoryviewslice):
+ * if (stop - start) - step * new_shape:
+ * new_shape += 1 # <<<<<<<<<<<<<<
+ *
+ * if new_shape < 0:
*/
- __pyx_v_new_ndim = (__pyx_v_new_ndim + 1);
- }
- __pyx_L6:;
+ __pyx_v_new_shape = (__pyx_v_new_shape + 1);
- /* "View.MemoryView":746
- * cdef bint have_start, have_stop, have_step
+ /* "View.MemoryView":877
+ * new_shape = (stop - start) // step
*
- * for dim, index in enumerate(indices): # <<<<<<<<<<<<<<
- * if PyIndex_Check(index):
- * slice_memviewslice(
- */
- }
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
-
- /* "View.MemoryView":776
- * new_ndim += 1
+ * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<<
+ * new_shape += 1
*
- * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<<
- * return memoryview_fromslice(dst, new_ndim,
- * memviewsliceobj.to_object_func,
*/
- __pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_memview), __pyx_memoryviewslice_type);
- __pyx_t_2 = (__pyx_t_1 != 0);
- if (__pyx_t_2) {
+ }
- /* "View.MemoryView":777
+ /* "View.MemoryView":880
+ * new_shape += 1
+ *
+ * if new_shape < 0: # <<<<<<<<<<<<<<
+ * new_shape = 0
*
- * if isinstance(memview, _memoryviewslice):
- * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<<
- * memviewsliceobj.to_object_func,
- * memviewsliceobj.to_dtype_func,
- */
- __Pyx_XDECREF(((PyObject *)__pyx_r));
-
- /* "View.MemoryView":778
- * if isinstance(memview, _memoryviewslice):
- * return memoryview_fromslice(dst, new_ndim,
- * memviewsliceobj.to_object_func, # <<<<<<<<<<<<<<
- * memviewsliceobj.to_dtype_func,
- * memview.dtype_is_object)
- */
- if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 778, __pyx_L1_error) }
-
- /* "View.MemoryView":779
- * return memoryview_fromslice(dst, new_ndim,
- * memviewsliceobj.to_object_func,
- * memviewsliceobj.to_dtype_func, # <<<<<<<<<<<<<<
- * memview.dtype_is_object)
- * else:
*/
- if (unlikely(!__pyx_v_memviewsliceobj)) { __Pyx_RaiseUnboundLocalError("memviewsliceobj"); __PYX_ERR(1, 779, __pyx_L1_error) }
+ __pyx_t_2 = ((__pyx_v_new_shape < 0) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":777
+ /* "View.MemoryView":881
+ *
+ * if new_shape < 0:
+ * new_shape = 0 # <<<<<<<<<<<<<<
+ *
*
- * if isinstance(memview, _memoryviewslice):
- * return memoryview_fromslice(dst, new_ndim, # <<<<<<<<<<<<<<
- * memviewsliceobj.to_object_func,
- * memviewsliceobj.to_dtype_func,
*/
- __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, __pyx_v_memviewsliceobj->to_object_func, __pyx_v_memviewsliceobj->to_dtype_func, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 777, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 777, __pyx_L1_error)
- __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3);
- __pyx_t_3 = 0;
- goto __pyx_L0;
+ __pyx_v_new_shape = 0;
- /* "View.MemoryView":776
- * new_ndim += 1
+ /* "View.MemoryView":880
+ * new_shape += 1
+ *
+ * if new_shape < 0: # <<<<<<<<<<<<<<
+ * new_shape = 0
*
- * if isinstance(memview, _memoryviewslice): # <<<<<<<<<<<<<<
- * return memoryview_fromslice(dst, new_ndim,
- * memviewsliceobj.to_object_func,
*/
- }
+ }
- /* "View.MemoryView":782
- * memview.dtype_is_object)
- * else:
- * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<<
- * memview.dtype_is_object)
+ /* "View.MemoryView":884
*
+ *
+ * dst.strides[new_ndim] = stride * step # <<<<<<<<<<<<<<
+ * dst.shape[new_ndim] = new_shape
+ * dst.suboffsets[new_ndim] = suboffset
*/
- /*else*/ {
- __Pyx_XDECREF(((PyObject *)__pyx_r));
+ (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step);
- /* "View.MemoryView":783
- * else:
- * return memoryview_fromslice(dst, new_ndim, NULL, NULL,
- * memview.dtype_is_object) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":885
*
+ * dst.strides[new_ndim] = stride * step
+ * dst.shape[new_ndim] = new_shape # <<<<<<<<<<<<<<
+ * dst.suboffsets[new_ndim] = suboffset
*
*/
- __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_dst, __pyx_v_new_ndim, NULL, NULL, __pyx_v_memview->dtype_is_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 782, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
+ (__pyx_v_dst->shape[__pyx_v_new_ndim]) = __pyx_v_new_shape;
- /* "View.MemoryView":782
- * memview.dtype_is_object)
- * else:
- * return memoryview_fromslice(dst, new_ndim, NULL, NULL, # <<<<<<<<<<<<<<
- * memview.dtype_is_object)
+ /* "View.MemoryView":886
+ * dst.strides[new_ndim] = stride * step
+ * dst.shape[new_ndim] = new_shape
+ * dst.suboffsets[new_ndim] = suboffset # <<<<<<<<<<<<<<
+ *
*
*/
- if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_memoryview_type))))) __PYX_ERR(1, 782, __pyx_L1_error)
- __pyx_r = ((struct __pyx_memoryview_obj *)__pyx_t_3);
- __pyx_t_3 = 0;
- goto __pyx_L0;
+ (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset;
}
+ __pyx_L3:;
- /* "View.MemoryView":710
+ /* "View.MemoryView":889
*
- * @cname('__pyx_memview_slice')
- * cdef memoryview memview_slice(memoryview memview, object indices): # <<<<<<<<<<<<<<
- * cdef int new_ndim = 0, suboffset_dim = -1, dim
- * cdef bint negative_step
+ *
+ * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<<
+ * dst.data += start * stride
+ * else:
*/
+ __pyx_t_2 = (((__pyx_v_suboffset_dim[0]) < 0) != 0);
+ if (__pyx_t_2) {
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_9);
- __Pyx_AddTraceback("View.MemoryView.memview_slice", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = 0;
- __pyx_L0:;
- __Pyx_XDECREF((PyObject *)__pyx_v_memviewsliceobj);
- __Pyx_XDECREF(__pyx_v_index);
- __Pyx_XGIVEREF((PyObject *)__pyx_r);
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":807
+ /* "View.MemoryView":890
*
- * @cname('__pyx_memoryview_slice_memviewslice')
- * cdef int slice_memviewslice( # <<<<<<<<<<<<<<
- * __Pyx_memviewslice *dst,
- * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset,
+ * if suboffset_dim[0] < 0:
+ * dst.data += start * stride # <<<<<<<<<<<<<<
+ * else:
+ * dst.suboffsets[suboffset_dim[0]] += start * stride
*/
+ __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride));
-static int __pyx_memoryview_slice_memviewslice(__Pyx_memviewslice *__pyx_v_dst, Py_ssize_t __pyx_v_shape, Py_ssize_t __pyx_v_stride, Py_ssize_t __pyx_v_suboffset, int __pyx_v_dim, int __pyx_v_new_ndim, int *__pyx_v_suboffset_dim, Py_ssize_t __pyx_v_start, Py_ssize_t __pyx_v_stop, Py_ssize_t __pyx_v_step, int __pyx_v_have_start, int __pyx_v_have_stop, int __pyx_v_have_step, int __pyx_v_is_slice) {
- Py_ssize_t __pyx_v_new_shape;
- int __pyx_v_negative_step;
- int __pyx_r;
- int __pyx_t_1;
- int __pyx_t_2;
- int __pyx_t_3;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
-
- /* "View.MemoryView":827
- * cdef bint negative_step
+ /* "View.MemoryView":889
*
- * if not is_slice: # <<<<<<<<<<<<<<
*
- * if start < 0:
+ * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<<
+ * dst.data += start * stride
+ * else:
*/
- __pyx_t_1 = ((!(__pyx_v_is_slice != 0)) != 0);
- if (__pyx_t_1) {
+ goto __pyx_L23;
+ }
- /* "View.MemoryView":829
- * if not is_slice:
+ /* "View.MemoryView":892
+ * dst.data += start * stride
+ * else:
+ * dst.suboffsets[suboffset_dim[0]] += start * stride # <<<<<<<<<<<<<<
*
- * if start < 0: # <<<<<<<<<<<<<<
- * start += shape
- * if not 0 <= start < shape:
+ * if suboffset >= 0:
*/
- __pyx_t_1 = ((__pyx_v_start < 0) != 0);
- if (__pyx_t_1) {
+ /*else*/ {
+ __pyx_t_3 = (__pyx_v_suboffset_dim[0]);
+ (__pyx_v_dst->suboffsets[__pyx_t_3]) = ((__pyx_v_dst->suboffsets[__pyx_t_3]) + (__pyx_v_start * __pyx_v_stride));
+ }
+ __pyx_L23:;
- /* "View.MemoryView":830
+ /* "View.MemoryView":894
+ * dst.suboffsets[suboffset_dim[0]] += start * stride
*
- * if start < 0:
- * start += shape # <<<<<<<<<<<<<<
- * if not 0 <= start < shape:
- * _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
+ * if suboffset >= 0: # <<<<<<<<<<<<<<
+ * if not is_slice:
+ * if new_ndim == 0:
*/
- __pyx_v_start = (__pyx_v_start + __pyx_v_shape);
+ __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":829
- * if not is_slice:
+ /* "View.MemoryView":895
*
- * if start < 0: # <<<<<<<<<<<<<<
- * start += shape
- * if not 0 <= start < shape:
+ * if suboffset >= 0:
+ * if not is_slice: # <<<<<<<<<<<<<<
+ * if new_ndim == 0:
+ * dst.data = ( dst.data)[0] + suboffset
*/
- }
+ __pyx_t_2 = ((!(__pyx_v_is_slice != 0)) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":831
- * if start < 0:
- * start += shape
- * if not 0 <= start < shape: # <<<<<<<<<<<<<<
- * _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
- * else:
+ /* "View.MemoryView":896
+ * if suboffset >= 0:
+ * if not is_slice:
+ * if new_ndim == 0: # <<<<<<<<<<<<<<
+ * dst.data = ( dst.data)[0] + suboffset
+ * else:
*/
- __pyx_t_1 = (0 <= __pyx_v_start);
- if (__pyx_t_1) {
- __pyx_t_1 = (__pyx_v_start < __pyx_v_shape);
- }
- __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
- if (__pyx_t_2) {
+ __pyx_t_2 = ((__pyx_v_new_ndim == 0) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":832
- * start += shape
- * if not 0 <= start < shape:
- * _err_dim(IndexError, "Index out of bounds (axis %d)", dim) # <<<<<<<<<<<<<<
- * else:
- *
+ /* "View.MemoryView":897
+ * if not is_slice:
+ * if new_ndim == 0:
+ * dst.data = ( dst.data)[0] + suboffset # <<<<<<<<<<<<<<
+ * else:
+ * _err_dim(IndexError, "All dimensions preceding dimension %d "
*/
- __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"Index out of bounds (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 832, __pyx_L1_error)
+ __pyx_v_dst->data = ((((char **)__pyx_v_dst->data)[0]) + __pyx_v_suboffset);
- /* "View.MemoryView":831
- * if start < 0:
- * start += shape
- * if not 0 <= start < shape: # <<<<<<<<<<<<<<
- * _err_dim(IndexError, "Index out of bounds (axis %d)", dim)
- * else:
+ /* "View.MemoryView":896
+ * if suboffset >= 0:
+ * if not is_slice:
+ * if new_ndim == 0: # <<<<<<<<<<<<<<
+ * dst.data = ( dst.data)[0] + suboffset
+ * else:
*/
- }
+ goto __pyx_L26;
+ }
- /* "View.MemoryView":827
- * cdef bint negative_step
- *
- * if not is_slice: # <<<<<<<<<<<<<<
- *
- * if start < 0:
+ /* "View.MemoryView":899
+ * dst.data = ( dst.data)[0] + suboffset
+ * else:
+ * _err_dim(IndexError, "All dimensions preceding dimension %d " # <<<<<<<<<<<<<<
+ * "must be indexed and not sliced", dim)
+ * else:
*/
- goto __pyx_L3;
- }
+ /*else*/ {
- /* "View.MemoryView":835
- * else:
- *
- * negative_step = have_step != 0 and step < 0 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":900
+ * else:
+ * _err_dim(IndexError, "All dimensions preceding dimension %d "
+ * "must be indexed and not sliced", dim) # <<<<<<<<<<<<<<
+ * else:
+ * suboffset_dim[0] = new_ndim
+ */
+ __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"All dimensions preceding dimension %d must be indexed and not sliced"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 899, __pyx_L1_error)
+ }
+ __pyx_L26:;
+
+ /* "View.MemoryView":895
*
- * if have_step and step == 0:
+ * if suboffset >= 0:
+ * if not is_slice: # <<<<<<<<<<<<<<
+ * if new_ndim == 0:
+ * dst.data = ( dst.data)[0] + suboffset
*/
- /*else*/ {
- __pyx_t_1 = ((__pyx_v_have_step != 0) != 0);
- if (__pyx_t_1) {
- } else {
- __pyx_t_2 = __pyx_t_1;
- goto __pyx_L6_bool_binop_done;
+ goto __pyx_L25;
}
- __pyx_t_1 = ((__pyx_v_step < 0) != 0);
- __pyx_t_2 = __pyx_t_1;
- __pyx_L6_bool_binop_done:;
- __pyx_v_negative_step = __pyx_t_2;
- /* "View.MemoryView":837
- * negative_step = have_step != 0 and step < 0
- *
- * if have_step and step == 0: # <<<<<<<<<<<<<<
- * _err_dim(ValueError, "Step may not be zero (axis %d)", dim)
+ /* "View.MemoryView":902
+ * "must be indexed and not sliced", dim)
+ * else:
+ * suboffset_dim[0] = new_ndim # <<<<<<<<<<<<<<
*
+ * return 0
*/
- __pyx_t_1 = (__pyx_v_have_step != 0);
- if (__pyx_t_1) {
- } else {
- __pyx_t_2 = __pyx_t_1;
- goto __pyx_L9_bool_binop_done;
+ /*else*/ {
+ (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim;
}
- __pyx_t_1 = ((__pyx_v_step == 0) != 0);
- __pyx_t_2 = __pyx_t_1;
- __pyx_L9_bool_binop_done:;
- if (__pyx_t_2) {
+ __pyx_L25:;
- /* "View.MemoryView":838
- *
- * if have_step and step == 0:
- * _err_dim(ValueError, "Step may not be zero (axis %d)", dim) # <<<<<<<<<<<<<<
- *
+ /* "View.MemoryView":894
+ * dst.suboffsets[suboffset_dim[0]] += start * stride
*
+ * if suboffset >= 0: # <<<<<<<<<<<<<<
+ * if not is_slice:
+ * if new_ndim == 0:
*/
- __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_ValueError, ((char *)"Step may not be zero (axis %d)"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 838, __pyx_L1_error)
+ }
- /* "View.MemoryView":837
- * negative_step = have_step != 0 and step < 0
+ /* "View.MemoryView":904
+ * suboffset_dim[0] = new_ndim
+ *
+ * return 0 # <<<<<<<<<<<<<<
*
- * if have_step and step == 0: # <<<<<<<<<<<<<<
- * _err_dim(ValueError, "Step may not be zero (axis %d)", dim)
*
*/
- }
+ __pyx_r = 0;
+ goto __pyx_L0;
- /* "View.MemoryView":841
- *
+ /* "View.MemoryView":807
*
- * if have_start: # <<<<<<<<<<<<<<
- * if start < 0:
- * start += shape
+ * @cname('__pyx_memoryview_slice_memviewslice')
+ * cdef int slice_memviewslice( # <<<<<<<<<<<<<<
+ * __Pyx_memviewslice *dst,
+ * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset,
*/
- __pyx_t_2 = (__pyx_v_have_start != 0);
- if (__pyx_t_2) {
- /* "View.MemoryView":842
+ /* function exit code */
+ __pyx_L1_error:;
+ {
+ #ifdef WITH_THREAD
+ PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
+ #endif
+ __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ #ifdef WITH_THREAD
+ __Pyx_PyGILState_Release(__pyx_gilstate_save);
+ #endif
+ }
+ __pyx_r = -1;
+ __pyx_L0:;
+ return __pyx_r;
+}
+
+/* "View.MemoryView":910
*
- * if have_start:
- * if start < 0: # <<<<<<<<<<<<<<
- * start += shape
- * if start < 0:
+ * @cname('__pyx_pybuffer_index')
+ * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<<
+ * Py_ssize_t dim) except NULL:
+ * cdef Py_ssize_t shape, stride, suboffset = -1
*/
- __pyx_t_2 = ((__pyx_v_start < 0) != 0);
- if (__pyx_t_2) {
- /* "View.MemoryView":843
- * if have_start:
- * if start < 0:
- * start += shape # <<<<<<<<<<<<<<
- * if start < 0:
- * start = 0
- */
- __pyx_v_start = (__pyx_v_start + __pyx_v_shape);
+static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, Py_ssize_t __pyx_v_dim) {
+ Py_ssize_t __pyx_v_shape;
+ Py_ssize_t __pyx_v_stride;
+ Py_ssize_t __pyx_v_suboffset;
+ Py_ssize_t __pyx_v_itemsize;
+ char *__pyx_v_resultp;
+ char *__pyx_r;
+ __Pyx_RefNannyDeclarations
+ Py_ssize_t __pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ PyObject *__pyx_t_4 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("pybuffer_index", 0);
- /* "View.MemoryView":844
- * if start < 0:
- * start += shape
- * if start < 0: # <<<<<<<<<<<<<<
- * start = 0
- * elif start >= shape:
+ /* "View.MemoryView":912
+ * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,
+ * Py_ssize_t dim) except NULL:
+ * cdef Py_ssize_t shape, stride, suboffset = -1 # <<<<<<<<<<<<<<
+ * cdef Py_ssize_t itemsize = view.itemsize
+ * cdef char *resultp
*/
- __pyx_t_2 = ((__pyx_v_start < 0) != 0);
- if (__pyx_t_2) {
+ __pyx_v_suboffset = -1L;
- /* "View.MemoryView":845
- * start += shape
- * if start < 0:
- * start = 0 # <<<<<<<<<<<<<<
- * elif start >= shape:
- * if negative_step:
+ /* "View.MemoryView":913
+ * Py_ssize_t dim) except NULL:
+ * cdef Py_ssize_t shape, stride, suboffset = -1
+ * cdef Py_ssize_t itemsize = view.itemsize # <<<<<<<<<<<<<<
+ * cdef char *resultp
+ *
*/
- __pyx_v_start = 0;
+ __pyx_t_1 = __pyx_v_view->itemsize;
+ __pyx_v_itemsize = __pyx_t_1;
- /* "View.MemoryView":844
- * if start < 0:
- * start += shape
- * if start < 0: # <<<<<<<<<<<<<<
- * start = 0
- * elif start >= shape:
+ /* "View.MemoryView":916
+ * cdef char *resultp
+ *
+ * if view.ndim == 0: # <<<<<<<<<<<<<<
+ * shape = view.len / itemsize
+ * stride = itemsize
*/
- }
+ __pyx_t_2 = ((__pyx_v_view->ndim == 0) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":842
+ /* "View.MemoryView":917
*
- * if have_start:
- * if start < 0: # <<<<<<<<<<<<<<
- * start += shape
- * if start < 0:
+ * if view.ndim == 0:
+ * shape = view.len / itemsize # <<<<<<<<<<<<<<
+ * stride = itemsize
+ * else:
*/
- goto __pyx_L12;
- }
+ if (unlikely(__pyx_v_itemsize == 0)) {
+ PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
+ __PYX_ERR(1, 917, __pyx_L1_error)
+ }
+ else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) {
+ PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
+ __PYX_ERR(1, 917, __pyx_L1_error)
+ }
+ __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize);
- /* "View.MemoryView":846
- * if start < 0:
- * start = 0
- * elif start >= shape: # <<<<<<<<<<<<<<
- * if negative_step:
- * start = shape - 1
+ /* "View.MemoryView":918
+ * if view.ndim == 0:
+ * shape = view.len / itemsize
+ * stride = itemsize # <<<<<<<<<<<<<<
+ * else:
+ * shape = view.shape[dim]
*/
- __pyx_t_2 = ((__pyx_v_start >= __pyx_v_shape) != 0);
- if (__pyx_t_2) {
+ __pyx_v_stride = __pyx_v_itemsize;
- /* "View.MemoryView":847
- * start = 0
- * elif start >= shape:
- * if negative_step: # <<<<<<<<<<<<<<
- * start = shape - 1
- * else:
+ /* "View.MemoryView":916
+ * cdef char *resultp
+ *
+ * if view.ndim == 0: # <<<<<<<<<<<<<<
+ * shape = view.len / itemsize
+ * stride = itemsize
*/
- __pyx_t_2 = (__pyx_v_negative_step != 0);
- if (__pyx_t_2) {
+ goto __pyx_L3;
+ }
- /* "View.MemoryView":848
- * elif start >= shape:
- * if negative_step:
- * start = shape - 1 # <<<<<<<<<<<<<<
- * else:
- * start = shape
+ /* "View.MemoryView":920
+ * stride = itemsize
+ * else:
+ * shape = view.shape[dim] # <<<<<<<<<<<<<<
+ * stride = view.strides[dim]
+ * if view.suboffsets != NULL:
*/
- __pyx_v_start = (__pyx_v_shape - 1);
+ /*else*/ {
+ __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]);
- /* "View.MemoryView":847
- * start = 0
- * elif start >= shape:
- * if negative_step: # <<<<<<<<<<<<<<
- * start = shape - 1
- * else:
+ /* "View.MemoryView":921
+ * else:
+ * shape = view.shape[dim]
+ * stride = view.strides[dim] # <<<<<<<<<<<<<<
+ * if view.suboffsets != NULL:
+ * suboffset = view.suboffsets[dim]
*/
- goto __pyx_L14;
- }
+ __pyx_v_stride = (__pyx_v_view->strides[__pyx_v_dim]);
- /* "View.MemoryView":850
- * start = shape - 1
- * else:
- * start = shape # <<<<<<<<<<<<<<
- * else:
- * if negative_step:
+ /* "View.MemoryView":922
+ * shape = view.shape[dim]
+ * stride = view.strides[dim]
+ * if view.suboffsets != NULL: # <<<<<<<<<<<<<<
+ * suboffset = view.suboffsets[dim]
+ *
*/
- /*else*/ {
- __pyx_v_start = __pyx_v_shape;
- }
- __pyx_L14:;
+ __pyx_t_2 = ((__pyx_v_view->suboffsets != NULL) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":846
- * if start < 0:
- * start = 0
- * elif start >= shape: # <<<<<<<<<<<<<<
- * if negative_step:
- * start = shape - 1
+ /* "View.MemoryView":923
+ * stride = view.strides[dim]
+ * if view.suboffsets != NULL:
+ * suboffset = view.suboffsets[dim] # <<<<<<<<<<<<<<
+ *
+ * if index < 0:
*/
- }
- __pyx_L12:;
+ __pyx_v_suboffset = (__pyx_v_view->suboffsets[__pyx_v_dim]);
- /* "View.MemoryView":841
- *
+ /* "View.MemoryView":922
+ * shape = view.shape[dim]
+ * stride = view.strides[dim]
+ * if view.suboffsets != NULL: # <<<<<<<<<<<<<<
+ * suboffset = view.suboffsets[dim]
*
- * if have_start: # <<<<<<<<<<<<<<
- * if start < 0:
- * start += shape
*/
- goto __pyx_L11;
}
+ }
+ __pyx_L3:;
- /* "View.MemoryView":852
- * start = shape
- * else:
- * if negative_step: # <<<<<<<<<<<<<<
- * start = shape - 1
- * else:
+ /* "View.MemoryView":925
+ * suboffset = view.suboffsets[dim]
+ *
+ * if index < 0: # <<<<<<<<<<<<<<
+ * index += view.shape[dim]
+ * if index < 0:
*/
- /*else*/ {
- __pyx_t_2 = (__pyx_v_negative_step != 0);
- if (__pyx_t_2) {
+ __pyx_t_2 = ((__pyx_v_index < 0) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":853
- * else:
- * if negative_step:
- * start = shape - 1 # <<<<<<<<<<<<<<
- * else:
- * start = 0
+ /* "View.MemoryView":926
+ *
+ * if index < 0:
+ * index += view.shape[dim] # <<<<<<<<<<<<<<
+ * if index < 0:
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
*/
- __pyx_v_start = (__pyx_v_shape - 1);
+ __pyx_v_index = (__pyx_v_index + (__pyx_v_view->shape[__pyx_v_dim]));
- /* "View.MemoryView":852
- * start = shape
- * else:
- * if negative_step: # <<<<<<<<<<<<<<
- * start = shape - 1
- * else:
+ /* "View.MemoryView":927
+ * if index < 0:
+ * index += view.shape[dim]
+ * if index < 0: # <<<<<<<<<<<<<<
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ *
*/
- goto __pyx_L15;
- }
+ __pyx_t_2 = ((__pyx_v_index < 0) != 0);
+ if (unlikely(__pyx_t_2)) {
- /* "View.MemoryView":855
- * start = shape - 1
- * else:
- * start = 0 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":928
+ * index += view.shape[dim]
+ * if index < 0:
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<<
*
- * if have_stop:
+ * if index >= shape:
*/
- /*else*/ {
- __pyx_v_start = 0;
- }
- __pyx_L15:;
- }
- __pyx_L11:;
+ __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 928, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 928, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 928, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __PYX_ERR(1, 928, __pyx_L1_error)
- /* "View.MemoryView":857
- * start = 0
+ /* "View.MemoryView":927
+ * if index < 0:
+ * index += view.shape[dim]
+ * if index < 0: # <<<<<<<<<<<<<<
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
*
- * if have_stop: # <<<<<<<<<<<<<<
- * if stop < 0:
- * stop += shape
*/
- __pyx_t_2 = (__pyx_v_have_stop != 0);
- if (__pyx_t_2) {
+ }
- /* "View.MemoryView":858
+ /* "View.MemoryView":925
+ * suboffset = view.suboffsets[dim]
*
- * if have_stop:
- * if stop < 0: # <<<<<<<<<<<<<<
- * stop += shape
- * if stop < 0:
+ * if index < 0: # <<<<<<<<<<<<<<
+ * index += view.shape[dim]
+ * if index < 0:
*/
- __pyx_t_2 = ((__pyx_v_stop < 0) != 0);
- if (__pyx_t_2) {
+ }
- /* "View.MemoryView":859
- * if have_stop:
- * if stop < 0:
- * stop += shape # <<<<<<<<<<<<<<
- * if stop < 0:
- * stop = 0
+ /* "View.MemoryView":930
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ *
+ * if index >= shape: # <<<<<<<<<<<<<<
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ *
*/
- __pyx_v_stop = (__pyx_v_stop + __pyx_v_shape);
+ __pyx_t_2 = ((__pyx_v_index >= __pyx_v_shape) != 0);
+ if (unlikely(__pyx_t_2)) {
- /* "View.MemoryView":860
- * if stop < 0:
- * stop += shape
- * if stop < 0: # <<<<<<<<<<<<<<
- * stop = 0
- * elif stop > shape:
+ /* "View.MemoryView":931
+ *
+ * if index >= shape:
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<<
+ *
+ * resultp = bufp + index * stride
*/
- __pyx_t_2 = ((__pyx_v_stop < 0) != 0);
- if (__pyx_t_2) {
+ __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 931, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 931, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_4);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 931, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+ __Pyx_Raise(__pyx_t_3, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __PYX_ERR(1, 931, __pyx_L1_error)
- /* "View.MemoryView":861
- * stop += shape
- * if stop < 0:
- * stop = 0 # <<<<<<<<<<<<<<
- * elif stop > shape:
- * stop = shape
+ /* "View.MemoryView":930
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ *
+ * if index >= shape: # <<<<<<<<<<<<<<
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ *
*/
- __pyx_v_stop = 0;
+ }
- /* "View.MemoryView":860
- * if stop < 0:
- * stop += shape
- * if stop < 0: # <<<<<<<<<<<<<<
- * stop = 0
- * elif stop > shape:
+ /* "View.MemoryView":933
+ * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ *
+ * resultp = bufp + index * stride # <<<<<<<<<<<<<<
+ * if suboffset >= 0:
+ * resultp = ( resultp)[0] + suboffset
*/
- }
+ __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride));
- /* "View.MemoryView":858
+ /* "View.MemoryView":934
+ *
+ * resultp = bufp + index * stride
+ * if suboffset >= 0: # <<<<<<<<<<<<<<
+ * resultp = ( resultp)[0] + suboffset
*
- * if have_stop:
- * if stop < 0: # <<<<<<<<<<<<<<
- * stop += shape
- * if stop < 0:
*/
- goto __pyx_L17;
- }
+ __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0);
+ if (__pyx_t_2) {
- /* "View.MemoryView":862
- * if stop < 0:
- * stop = 0
- * elif stop > shape: # <<<<<<<<<<<<<<
- * stop = shape
- * else:
+ /* "View.MemoryView":935
+ * resultp = bufp + index * stride
+ * if suboffset >= 0:
+ * resultp = ( resultp)[0] + suboffset # <<<<<<<<<<<<<<
+ *
+ * return resultp
*/
- __pyx_t_2 = ((__pyx_v_stop > __pyx_v_shape) != 0);
- if (__pyx_t_2) {
+ __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset);
- /* "View.MemoryView":863
- * stop = 0
- * elif stop > shape:
- * stop = shape # <<<<<<<<<<<<<<
- * else:
- * if negative_step:
+ /* "View.MemoryView":934
+ *
+ * resultp = bufp + index * stride
+ * if suboffset >= 0: # <<<<<<<<<<<<<<
+ * resultp = ( resultp)[0] + suboffset
+ *
*/
- __pyx_v_stop = __pyx_v_shape;
+ }
- /* "View.MemoryView":862
- * if stop < 0:
- * stop = 0
- * elif stop > shape: # <<<<<<<<<<<<<<
- * stop = shape
- * else:
+ /* "View.MemoryView":937
+ * resultp = ( resultp)[0] + suboffset
+ *
+ * return resultp # <<<<<<<<<<<<<<
+ *
+ *
*/
- }
- __pyx_L17:;
+ __pyx_r = __pyx_v_resultp;
+ goto __pyx_L0;
- /* "View.MemoryView":857
- * start = 0
+ /* "View.MemoryView":910
*
- * if have_stop: # <<<<<<<<<<<<<<
- * if stop < 0:
- * stop += shape
+ * @cname('__pyx_pybuffer_index')
+ * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<<
+ * Py_ssize_t dim) except NULL:
+ * cdef Py_ssize_t shape, stride, suboffset = -1
*/
- goto __pyx_L16;
- }
- /* "View.MemoryView":865
- * stop = shape
- * else:
- * if negative_step: # <<<<<<<<<<<<<<
- * stop = -1
- * else:
- */
- /*else*/ {
- __pyx_t_2 = (__pyx_v_negative_step != 0);
- if (__pyx_t_2) {
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_XDECREF(__pyx_t_4);
+ __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __pyx_L0:;
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":866
- * else:
- * if negative_step:
- * stop = -1 # <<<<<<<<<<<<<<
- * else:
- * stop = shape
+/* "View.MemoryView":943
+ *
+ * @cname('__pyx_memslice_transpose')
+ * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<<
+ * cdef int ndim = memslice.memview.view.ndim
+ *
*/
- __pyx_v_stop = -1L;
- /* "View.MemoryView":865
- * stop = shape
- * else:
- * if negative_step: # <<<<<<<<<<<<<<
- * stop = -1
- * else:
- */
- goto __pyx_L19;
- }
+static int __pyx_memslice_transpose(__Pyx_memviewslice *__pyx_v_memslice) {
+ int __pyx_v_ndim;
+ Py_ssize_t *__pyx_v_shape;
+ Py_ssize_t *__pyx_v_strides;
+ int __pyx_v_i;
+ int __pyx_v_j;
+ int __pyx_r;
+ int __pyx_t_1;
+ Py_ssize_t *__pyx_t_2;
+ long __pyx_t_3;
+ long __pyx_t_4;
+ Py_ssize_t __pyx_t_5;
+ Py_ssize_t __pyx_t_6;
+ int __pyx_t_7;
+ int __pyx_t_8;
+ int __pyx_t_9;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
- /* "View.MemoryView":868
- * stop = -1
- * else:
- * stop = shape # <<<<<<<<<<<<<<
+ /* "View.MemoryView":944
+ * @cname('__pyx_memslice_transpose')
+ * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0:
+ * cdef int ndim = memslice.memview.view.ndim # <<<<<<<<<<<<<<
*
- * if not have_step:
+ * cdef Py_ssize_t *shape = memslice.shape
*/
- /*else*/ {
- __pyx_v_stop = __pyx_v_shape;
- }
- __pyx_L19:;
- }
- __pyx_L16:;
+ __pyx_t_1 = __pyx_v_memslice->memview->view.ndim;
+ __pyx_v_ndim = __pyx_t_1;
- /* "View.MemoryView":870
- * stop = shape
+ /* "View.MemoryView":946
+ * cdef int ndim = memslice.memview.view.ndim
*
- * if not have_step: # <<<<<<<<<<<<<<
- * step = 1
+ * cdef Py_ssize_t *shape = memslice.shape # <<<<<<<<<<<<<<
+ * cdef Py_ssize_t *strides = memslice.strides
*
*/
- __pyx_t_2 = ((!(__pyx_v_have_step != 0)) != 0);
- if (__pyx_t_2) {
+ __pyx_t_2 = __pyx_v_memslice->shape;
+ __pyx_v_shape = __pyx_t_2;
- /* "View.MemoryView":871
+ /* "View.MemoryView":947
*
- * if not have_step:
- * step = 1 # <<<<<<<<<<<<<<
+ * cdef Py_ssize_t *shape = memslice.shape
+ * cdef Py_ssize_t *strides = memslice.strides # <<<<<<<<<<<<<<
*
*
*/
- __pyx_v_step = 1;
+ __pyx_t_2 = __pyx_v_memslice->strides;
+ __pyx_v_strides = __pyx_t_2;
- /* "View.MemoryView":870
- * stop = shape
- *
- * if not have_step: # <<<<<<<<<<<<<<
- * step = 1
+ /* "View.MemoryView":951
*
+ * cdef int i, j
+ * for i in range(ndim / 2): # <<<<<<<<<<<<<<
+ * j = ndim - 1 - i
+ * strides[i], strides[j] = strides[j], strides[i]
*/
- }
+ __pyx_t_3 = __Pyx_div_long(__pyx_v_ndim, 2);
+ __pyx_t_4 = __pyx_t_3;
+ for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_4; __pyx_t_1+=1) {
+ __pyx_v_i = __pyx_t_1;
- /* "View.MemoryView":875
- *
- * with cython.cdivision(True):
- * new_shape = (stop - start) // step # <<<<<<<<<<<<<<
- *
- * if (stop - start) - step * new_shape:
+ /* "View.MemoryView":952
+ * cdef int i, j
+ * for i in range(ndim / 2):
+ * j = ndim - 1 - i # <<<<<<<<<<<<<<
+ * strides[i], strides[j] = strides[j], strides[i]
+ * shape[i], shape[j] = shape[j], shape[i]
*/
- __pyx_v_new_shape = ((__pyx_v_stop - __pyx_v_start) / __pyx_v_step);
+ __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i);
- /* "View.MemoryView":877
- * new_shape = (stop - start) // step
- *
- * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<<
- * new_shape += 1
+ /* "View.MemoryView":953
+ * for i in range(ndim / 2):
+ * j = ndim - 1 - i
+ * strides[i], strides[j] = strides[j], strides[i] # <<<<<<<<<<<<<<
+ * shape[i], shape[j] = shape[j], shape[i]
*
*/
- __pyx_t_2 = (((__pyx_v_stop - __pyx_v_start) - (__pyx_v_step * __pyx_v_new_shape)) != 0);
- if (__pyx_t_2) {
+ __pyx_t_5 = (__pyx_v_strides[__pyx_v_j]);
+ __pyx_t_6 = (__pyx_v_strides[__pyx_v_i]);
+ (__pyx_v_strides[__pyx_v_i]) = __pyx_t_5;
+ (__pyx_v_strides[__pyx_v_j]) = __pyx_t_6;
- /* "View.MemoryView":878
- *
- * if (stop - start) - step * new_shape:
- * new_shape += 1 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":954
+ * j = ndim - 1 - i
+ * strides[i], strides[j] = strides[j], strides[i]
+ * shape[i], shape[j] = shape[j], shape[i] # <<<<<<<<<<<<<<
*
- * if new_shape < 0:
+ * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:
*/
- __pyx_v_new_shape = (__pyx_v_new_shape + 1);
+ __pyx_t_6 = (__pyx_v_shape[__pyx_v_j]);
+ __pyx_t_5 = (__pyx_v_shape[__pyx_v_i]);
+ (__pyx_v_shape[__pyx_v_i]) = __pyx_t_6;
+ (__pyx_v_shape[__pyx_v_j]) = __pyx_t_5;
- /* "View.MemoryView":877
- * new_shape = (stop - start) // step
+ /* "View.MemoryView":956
+ * shape[i], shape[j] = shape[j], shape[i]
*
- * if (stop - start) - step * new_shape: # <<<<<<<<<<<<<<
- * new_shape += 1
+ * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<<
+ * _err(ValueError, "Cannot transpose memoryview with indirect dimensions")
*
*/
+ __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_i]) >= 0) != 0);
+ if (!__pyx_t_8) {
+ } else {
+ __pyx_t_7 = __pyx_t_8;
+ goto __pyx_L6_bool_binop_done;
}
+ __pyx_t_8 = (((__pyx_v_memslice->suboffsets[__pyx_v_j]) >= 0) != 0);
+ __pyx_t_7 = __pyx_t_8;
+ __pyx_L6_bool_binop_done:;
+ if (__pyx_t_7) {
- /* "View.MemoryView":880
- * new_shape += 1
+ /* "View.MemoryView":957
*
- * if new_shape < 0: # <<<<<<<<<<<<<<
- * new_shape = 0
+ * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:
+ * _err(ValueError, "Cannot transpose memoryview with indirect dimensions") # <<<<<<<<<<<<<<
*
+ * return 1
*/
- __pyx_t_2 = ((__pyx_v_new_shape < 0) != 0);
- if (__pyx_t_2) {
+ __pyx_t_9 = __pyx_memoryview_err(__pyx_builtin_ValueError, ((char *)"Cannot transpose memoryview with indirect dimensions")); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(1, 957, __pyx_L1_error)
- /* "View.MemoryView":881
- *
- * if new_shape < 0:
- * new_shape = 0 # <<<<<<<<<<<<<<
+ /* "View.MemoryView":956
+ * shape[i], shape[j] = shape[j], shape[i]
*
+ * if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: # <<<<<<<<<<<<<<
+ * _err(ValueError, "Cannot transpose memoryview with indirect dimensions")
*
*/
- __pyx_v_new_shape = 0;
+ }
+ }
- /* "View.MemoryView":880
- * new_shape += 1
+ /* "View.MemoryView":959
+ * _err(ValueError, "Cannot transpose memoryview with indirect dimensions")
+ *
+ * return 1 # <<<<<<<<<<<<<<
*
- * if new_shape < 0: # <<<<<<<<<<<<<<
- * new_shape = 0
*
*/
- }
+ __pyx_r = 1;
+ goto __pyx_L0;
- /* "View.MemoryView":884
+ /* "View.MemoryView":943
*
+ * @cname('__pyx_memslice_transpose')
+ * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<<
+ * cdef int ndim = memslice.memview.view.ndim
*
- * dst.strides[new_ndim] = stride * step # <<<<<<<<<<<<<<
- * dst.shape[new_ndim] = new_shape
- * dst.suboffsets[new_ndim] = suboffset
*/
- (__pyx_v_dst->strides[__pyx_v_new_ndim]) = (__pyx_v_stride * __pyx_v_step);
- /* "View.MemoryView":885
+ /* function exit code */
+ __pyx_L1_error:;
+ {
+ #ifdef WITH_THREAD
+ PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
+ #endif
+ __Pyx_AddTraceback("View.MemoryView.transpose_memslice", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ #ifdef WITH_THREAD
+ __Pyx_PyGILState_Release(__pyx_gilstate_save);
+ #endif
+ }
+ __pyx_r = 0;
+ __pyx_L0:;
+ return __pyx_r;
+}
+
+/* "View.MemoryView":976
+ * cdef int (*to_dtype_func)(char *, object) except 0
*
- * dst.strides[new_ndim] = stride * step
- * dst.shape[new_ndim] = new_shape # <<<<<<<<<<<<<<
- * dst.suboffsets[new_ndim] = suboffset
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
*
*/
- (__pyx_v_dst->shape[__pyx_v_new_ndim]) = __pyx_v_new_shape;
- /* "View.MemoryView":886
- * dst.strides[new_ndim] = stride * step
- * dst.shape[new_ndim] = new_shape
- * dst.suboffsets[new_ndim] = suboffset # <<<<<<<<<<<<<<
+/* Python wrapper */
+static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self); /*proto*/
+static void __pyx_memoryviewslice___dealloc__(PyObject *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
+ __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+}
+
+static void __pyx_memoryviewslice___pyx_pf_15View_dot_MemoryView_16_memoryviewslice___dealloc__(struct __pyx_memoryviewslice_obj *__pyx_v_self) {
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__dealloc__", 0);
+
+ /* "View.MemoryView":977
*
+ * def __dealloc__(self):
+ * __PYX_XDEC_MEMVIEW(&self.from_slice, 1) # <<<<<<<<<<<<<<
*
+ * cdef convert_item_to_object(self, char *itemp):
*/
- (__pyx_v_dst->suboffsets[__pyx_v_new_ndim]) = __pyx_v_suboffset;
- }
- __pyx_L3:;
+ __PYX_XDEC_MEMVIEW((&__pyx_v_self->from_slice), 1);
- /* "View.MemoryView":889
+ /* "View.MemoryView":976
+ * cdef int (*to_dtype_func)(char *, object) except 0
*
+ * def __dealloc__(self): # <<<<<<<<<<<<<<
+ * __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
*
- * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<<
- * dst.data += start * stride
- * else:
*/
- __pyx_t_2 = (((__pyx_v_suboffset_dim[0]) < 0) != 0);
- if (__pyx_t_2) {
- /* "View.MemoryView":890
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+}
+
+/* "View.MemoryView":979
+ * __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
*
- * if suboffset_dim[0] < 0:
- * dst.data += start * stride # <<<<<<<<<<<<<<
- * else:
- * dst.suboffsets[suboffset_dim[0]] += start * stride
+ * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<<
+ * if self.to_object_func != NULL:
+ * return self.to_object_func(itemp)
*/
- __pyx_v_dst->data = (__pyx_v_dst->data + (__pyx_v_start * __pyx_v_stride));
- /* "View.MemoryView":889
+static PyObject *__pyx_memoryviewslice_convert_item_to_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("convert_item_to_object", 0);
+
+ /* "View.MemoryView":980
*
+ * cdef convert_item_to_object(self, char *itemp):
+ * if self.to_object_func != NULL: # <<<<<<<<<<<<<<
+ * return self.to_object_func(itemp)
+ * else:
+ */
+ __pyx_t_1 = ((__pyx_v_self->to_object_func != NULL) != 0);
+ if (__pyx_t_1) {
+
+ /* "View.MemoryView":981
+ * cdef convert_item_to_object(self, char *itemp):
+ * if self.to_object_func != NULL:
+ * return self.to_object_func(itemp) # <<<<<<<<<<<<<<
+ * else:
+ * return memoryview.convert_item_to_object(self, itemp)
+ */
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = __pyx_v_self->to_object_func(__pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 981, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
+
+ /* "View.MemoryView":980
*
- * if suboffset_dim[0] < 0: # <<<<<<<<<<<<<<
- * dst.data += start * stride
- * else:
+ * cdef convert_item_to_object(self, char *itemp):
+ * if self.to_object_func != NULL: # <<<<<<<<<<<<<<
+ * return self.to_object_func(itemp)
+ * else:
*/
- goto __pyx_L23;
}
- /* "View.MemoryView":892
- * dst.data += start * stride
- * else:
- * dst.suboffsets[suboffset_dim[0]] += start * stride # <<<<<<<<<<<<<<
+ /* "View.MemoryView":983
+ * return self.to_object_func(itemp)
+ * else:
+ * return memoryview.convert_item_to_object(self, itemp) # <<<<<<<<<<<<<<
*
- * if suboffset >= 0:
+ * cdef assign_item_from_object(self, char *itemp, object value):
*/
/*else*/ {
- __pyx_t_3 = (__pyx_v_suboffset_dim[0]);
- (__pyx_v_dst->suboffsets[__pyx_t_3]) = ((__pyx_v_dst->suboffsets[__pyx_t_3]) + (__pyx_v_start * __pyx_v_stride));
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_t_2 = __pyx_memoryview_convert_item_to_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 983, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_r = __pyx_t_2;
+ __pyx_t_2 = 0;
+ goto __pyx_L0;
}
- __pyx_L23:;
- /* "View.MemoryView":894
- * dst.suboffsets[suboffset_dim[0]] += start * stride
+ /* "View.MemoryView":979
+ * __PYX_XDEC_MEMVIEW(&self.from_slice, 1)
*
- * if suboffset >= 0: # <<<<<<<<<<<<<<
- * if not is_slice:
- * if new_ndim == 0:
+ * cdef convert_item_to_object(self, char *itemp): # <<<<<<<<<<<<<<
+ * if self.to_object_func != NULL:
+ * return self.to_object_func(itemp)
*/
- __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0);
- if (__pyx_t_2) {
- /* "View.MemoryView":895
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_2);
+ __Pyx_AddTraceback("View.MemoryView._memoryviewslice.convert_item_to_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+/* "View.MemoryView":985
+ * return memoryview.convert_item_to_object(self, itemp)
*
- * if suboffset >= 0:
- * if not is_slice: # <<<<<<<<<<<<<<
- * if new_ndim == 0:
- * dst.data = ( dst.data)[0] + suboffset
+ * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<<
+ * if self.to_dtype_func != NULL:
+ * self.to_dtype_func(itemp, value)
*/
- __pyx_t_2 = ((!(__pyx_v_is_slice != 0)) != 0);
- if (__pyx_t_2) {
- /* "View.MemoryView":896
- * if suboffset >= 0:
- * if not is_slice:
- * if new_ndim == 0: # <<<<<<<<<<<<<<
- * dst.data = ( dst.data)[0] + suboffset
- * else:
- */
- __pyx_t_2 = ((__pyx_v_new_ndim == 0) != 0);
- if (__pyx_t_2) {
+static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memoryviewslice_obj *__pyx_v_self, char *__pyx_v_itemp, PyObject *__pyx_v_value) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ int __pyx_t_2;
+ PyObject *__pyx_t_3 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("assign_item_from_object", 0);
- /* "View.MemoryView":897
- * if not is_slice:
- * if new_ndim == 0:
- * dst.data = ( dst.data)[0] + suboffset # <<<<<<<<<<<<<<
- * else:
- * _err_dim(IndexError, "All dimensions preceding dimension %d "
+ /* "View.MemoryView":986
+ *
+ * cdef assign_item_from_object(self, char *itemp, object value):
+ * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<<
+ * self.to_dtype_func(itemp, value)
+ * else:
*/
- __pyx_v_dst->data = ((((char **)__pyx_v_dst->data)[0]) + __pyx_v_suboffset);
+ __pyx_t_1 = ((__pyx_v_self->to_dtype_func != NULL) != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":896
- * if suboffset >= 0:
- * if not is_slice:
- * if new_ndim == 0: # <<<<<<<<<<<<<<
- * dst.data = ( dst.data)[0] + suboffset
- * else:
+ /* "View.MemoryView":987
+ * cdef assign_item_from_object(self, char *itemp, object value):
+ * if self.to_dtype_func != NULL:
+ * self.to_dtype_func(itemp, value) # <<<<<<<<<<<<<<
+ * else:
+ * memoryview.assign_item_from_object(self, itemp, value)
*/
- goto __pyx_L26;
- }
+ __pyx_t_2 = __pyx_v_self->to_dtype_func(__pyx_v_itemp, __pyx_v_value); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(1, 987, __pyx_L1_error)
- /* "View.MemoryView":899
- * dst.data = ( dst.data)[0] + suboffset
- * else:
- * _err_dim(IndexError, "All dimensions preceding dimension %d " # <<<<<<<<<<<<<<
- * "must be indexed and not sliced", dim)
+ /* "View.MemoryView":986
+ *
+ * cdef assign_item_from_object(self, char *itemp, object value):
+ * if self.to_dtype_func != NULL: # <<<<<<<<<<<<<<
+ * self.to_dtype_func(itemp, value)
* else:
*/
- /*else*/ {
+ goto __pyx_L3;
+ }
- /* "View.MemoryView":900
- * else:
- * _err_dim(IndexError, "All dimensions preceding dimension %d "
- * "must be indexed and not sliced", dim) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":989
+ * self.to_dtype_func(itemp, value)
* else:
- * suboffset_dim[0] = new_ndim
- */
- __pyx_t_3 = __pyx_memoryview_err_dim(__pyx_builtin_IndexError, ((char *)"All dimensions preceding dimension %d must be indexed and not sliced"), __pyx_v_dim); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(1, 899, __pyx_L1_error)
- }
- __pyx_L26:;
-
- /* "View.MemoryView":895
+ * memoryview.assign_item_from_object(self, itemp, value) # <<<<<<<<<<<<<<
*
- * if suboffset >= 0:
- * if not is_slice: # <<<<<<<<<<<<<<
- * if new_ndim == 0:
- * dst.data = ( dst.data)[0] + suboffset
+ * @property
*/
- goto __pyx_L25;
- }
+ /*else*/ {
+ __pyx_t_3 = __pyx_memoryview_assign_item_from_object(((struct __pyx_memoryview_obj *)__pyx_v_self), __pyx_v_itemp, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 989, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ }
+ __pyx_L3:;
- /* "View.MemoryView":902
- * "must be indexed and not sliced", dim)
- * else:
- * suboffset_dim[0] = new_ndim # <<<<<<<<<<<<<<
+ /* "View.MemoryView":985
+ * return memoryview.convert_item_to_object(self, itemp)
*
- * return 0
+ * cdef assign_item_from_object(self, char *itemp, object value): # <<<<<<<<<<<<<<
+ * if self.to_dtype_func != NULL:
+ * self.to_dtype_func(itemp, value)
*/
- /*else*/ {
- (__pyx_v_suboffset_dim[0]) = __pyx_v_new_ndim;
- }
- __pyx_L25:;
- /* "View.MemoryView":894
- * dst.suboffsets[suboffset_dim[0]] += start * stride
- *
- * if suboffset >= 0: # <<<<<<<<<<<<<<
- * if not is_slice:
- * if new_ndim == 0:
- */
- }
+ /* function exit code */
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_3);
+ __Pyx_AddTraceback("View.MemoryView._memoryviewslice.assign_item_from_object", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = 0;
+ __pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":904
- * suboffset_dim[0] = new_ndim
+/* "View.MemoryView":992
*
- * return 0 # <<<<<<<<<<<<<<
+ * @property
+ * def base(self): # <<<<<<<<<<<<<<
+ * return self.from_object
*
+ */
+
+/* Python wrapper */
+static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self); /*proto*/
+static PyObject *__pyx_pw_15View_dot_MemoryView_16_memoryviewslice_4base_1__get__(PyObject *__pyx_v_self) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
+ __pyx_r = __pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf_15View_dot_MemoryView_16_memoryviewslice_4base___get__(struct __pyx_memoryviewslice_obj *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__get__", 0);
+
+ /* "View.MemoryView":993
+ * @property
+ * def base(self):
+ * return self.from_object # <<<<<<<<<<<<<<
*
+ * __pyx_getbuffer = capsule( &__pyx_memoryview_getbuffer, "getbuffer(obj, view, flags)")
*/
- __pyx_r = 0;
+ __Pyx_XDECREF(__pyx_r);
+ __Pyx_INCREF(__pyx_v_self->from_object);
+ __pyx_r = __pyx_v_self->from_object;
goto __pyx_L0;
- /* "View.MemoryView":807
+ /* "View.MemoryView":992
+ *
+ * @property
+ * def base(self): # <<<<<<<<<<<<<<
+ * return self.from_object
*
- * @cname('__pyx_memoryview_slice_memviewslice')
- * cdef int slice_memviewslice( # <<<<<<<<<<<<<<
- * __Pyx_memviewslice *dst,
- * Py_ssize_t shape, Py_ssize_t stride, Py_ssize_t suboffset,
*/
/* function exit code */
- __pyx_L1_error:;
- {
- #ifdef WITH_THREAD
- PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
- #endif
- __Pyx_AddTraceback("View.MemoryView.slice_memviewslice", __pyx_clineno, __pyx_lineno, __pyx_filename);
- #ifdef WITH_THREAD
- __Pyx_PyGILState_Release(__pyx_gilstate_save);
- #endif
- }
- __pyx_r = -1;
__pyx_L0:;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
return __pyx_r;
}
-/* "View.MemoryView":910
- *
- * @cname('__pyx_pybuffer_index')
- * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<<
- * Py_ssize_t dim) except NULL:
- * cdef Py_ssize_t shape, stride, suboffset = -1
+/* "(tree fragment)":1
+ * def __reduce_cython__(self): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
*/
-static char *__pyx_pybuffer_index(Py_buffer *__pyx_v_view, char *__pyx_v_bufp, Py_ssize_t __pyx_v_index, Py_ssize_t __pyx_v_dim) {
- Py_ssize_t __pyx_v_shape;
- Py_ssize_t __pyx_v_stride;
- Py_ssize_t __pyx_v_suboffset;
- Py_ssize_t __pyx_v_itemsize;
- char *__pyx_v_resultp;
- char *__pyx_r;
+/* Python wrapper */
+static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
+static PyObject *__pyx_pw___pyx_memoryviewslice_1__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
+ PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
- Py_ssize_t __pyx_t_1;
- int __pyx_t_2;
- PyObject *__pyx_t_3 = NULL;
- PyObject *__pyx_t_4 = NULL;
+ __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
+ __pyx_r = __pyx_pf___pyx_memoryviewslice___reduce_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self));
+
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
+
+static PyObject *__pyx_pf___pyx_memoryviewslice___reduce_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
- __Pyx_RefNannySetupContext("pybuffer_index", 0);
+ __Pyx_RefNannySetupContext("__reduce_cython__", 0);
- /* "View.MemoryView":912
- * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,
- * Py_ssize_t dim) except NULL:
- * cdef Py_ssize_t shape, stride, suboffset = -1 # <<<<<<<<<<<<<<
- * cdef Py_ssize_t itemsize = view.itemsize
- * cdef char *resultp
+ /* "(tree fragment)":2
+ * def __reduce_cython__(self):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
+ * def __setstate_cython__(self, __pyx_state):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
*/
- __pyx_v_suboffset = -1L;
+ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __PYX_ERR(1, 2, __pyx_L1_error)
- /* "View.MemoryView":913
- * Py_ssize_t dim) except NULL:
- * cdef Py_ssize_t shape, stride, suboffset = -1
- * cdef Py_ssize_t itemsize = view.itemsize # <<<<<<<<<<<<<<
- * cdef char *resultp
- *
+ /* "(tree fragment)":1
+ * def __reduce_cython__(self): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
*/
- __pyx_t_1 = __pyx_v_view->itemsize;
- __pyx_v_itemsize = __pyx_t_1;
- /* "View.MemoryView":916
- * cdef char *resultp
- *
- * if view.ndim == 0: # <<<<<<<<<<<<<<
- * shape = view.len / itemsize
- * stride = itemsize
- */
- __pyx_t_2 = ((__pyx_v_view->ndim == 0) != 0);
- if (__pyx_t_2) {
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":917
- *
- * if view.ndim == 0:
- * shape = view.len / itemsize # <<<<<<<<<<<<<<
- * stride = itemsize
- * else:
+/* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
*/
- if (unlikely(__pyx_v_itemsize == 0)) {
- PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
- __PYX_ERR(1, 917, __pyx_L1_error)
- }
- else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_itemsize == (Py_ssize_t)-1) && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_view->len))) {
- PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
- __PYX_ERR(1, 917, __pyx_L1_error)
- }
- __pyx_v_shape = __Pyx_div_Py_ssize_t(__pyx_v_view->len, __pyx_v_itemsize);
- /* "View.MemoryView":918
- * if view.ndim == 0:
- * shape = view.len / itemsize
- * stride = itemsize # <<<<<<<<<<<<<<
- * else:
- * shape = view.shape[dim]
- */
- __pyx_v_stride = __pyx_v_itemsize;
+/* Python wrapper */
+static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/
+static PyObject *__pyx_pw___pyx_memoryviewslice_3__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
+ PyObject *__pyx_r = 0;
+ __Pyx_RefNannyDeclarations
+ __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
+ __pyx_r = __pyx_pf___pyx_memoryviewslice_2__setstate_cython__(((struct __pyx_memoryviewslice_obj *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state));
- /* "View.MemoryView":916
- * cdef char *resultp
- *
- * if view.ndim == 0: # <<<<<<<<<<<<<<
- * shape = view.len / itemsize
- * stride = itemsize
- */
- goto __pyx_L3;
- }
+ /* function exit code */
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":920
- * stride = itemsize
- * else:
- * shape = view.shape[dim] # <<<<<<<<<<<<<<
- * stride = view.strides[dim]
- * if view.suboffsets != NULL:
- */
- /*else*/ {
- __pyx_v_shape = (__pyx_v_view->shape[__pyx_v_dim]);
+static PyObject *__pyx_pf___pyx_memoryviewslice_2__setstate_cython__(CYTHON_UNUSED struct __pyx_memoryviewslice_obj *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ PyObject *__pyx_t_1 = NULL;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("__setstate_cython__", 0);
- /* "View.MemoryView":921
- * else:
- * shape = view.shape[dim]
- * stride = view.strides[dim] # <<<<<<<<<<<<<<
- * if view.suboffsets != NULL:
- * suboffset = view.suboffsets[dim]
+ /* "(tree fragment)":4
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<<
*/
- __pyx_v_stride = (__pyx_v_view->strides[__pyx_v_dim]);
+ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_1);
+ __Pyx_Raise(__pyx_t_1, 0, 0, 0);
+ __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+ __PYX_ERR(1, 4, __pyx_L1_error)
- /* "View.MemoryView":922
- * shape = view.shape[dim]
- * stride = view.strides[dim]
- * if view.suboffsets != NULL: # <<<<<<<<<<<<<<
- * suboffset = view.suboffsets[dim]
- *
+ /* "(tree fragment)":3
+ * def __reduce_cython__(self):
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
+ * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<<
+ * raise TypeError("no default __reduce__ due to non-trivial __cinit__")
*/
- __pyx_t_2 = ((__pyx_v_view->suboffsets != NULL) != 0);
- if (__pyx_t_2) {
- /* "View.MemoryView":923
- * stride = view.strides[dim]
- * if view.suboffsets != NULL:
- * suboffset = view.suboffsets[dim] # <<<<<<<<<<<<<<
- *
- * if index < 0:
- */
- __pyx_v_suboffset = (__pyx_v_view->suboffsets[__pyx_v_dim]);
+ /* function exit code */
+ __pyx_L1_error:;
+ __Pyx_XDECREF(__pyx_t_1);
+ __Pyx_AddTraceback("View.MemoryView._memoryviewslice.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
+ __pyx_r = NULL;
+ __Pyx_XGIVEREF(__pyx_r);
+ __Pyx_RefNannyFinishContext();
+ return __pyx_r;
+}
- /* "View.MemoryView":922
- * shape = view.shape[dim]
- * stride = view.strides[dim]
- * if view.suboffsets != NULL: # <<<<<<<<<<<<<<
- * suboffset = view.suboffsets[dim]
+/* "View.MemoryView":999
*
+ * @cname('__pyx_memoryview_fromslice')
+ * cdef memoryview_fromslice(__Pyx_memviewslice memviewslice, # <<<<<<<<<<<<<<
+ * int ndim,
+ * object (*to_object_func)(char *),
*/
- }
- }
- __pyx_L3:;
- /* "View.MemoryView":925
- * suboffset = view.suboffsets[dim]
- *
- * if index < 0: # <<<<<<<<<<<<<<
- * index += view.shape[dim]
- * if index < 0:
- */
- __pyx_t_2 = ((__pyx_v_index < 0) != 0);
- if (__pyx_t_2) {
+static PyObject *__pyx_memoryview_fromslice(__Pyx_memviewslice __pyx_v_memviewslice, int __pyx_v_ndim, PyObject *(*__pyx_v_to_object_func)(char *), int (*__pyx_v_to_dtype_func)(char *, PyObject *), int __pyx_v_dtype_is_object) {
+ struct __pyx_memoryviewslice_obj *__pyx_v_result = 0;
+ Py_ssize_t __pyx_v_suboffset;
+ PyObject *__pyx_v_length = NULL;
+ PyObject *__pyx_r = NULL;
+ __Pyx_RefNannyDeclarations
+ int __pyx_t_1;
+ PyObject *__pyx_t_2 = NULL;
+ PyObject *__pyx_t_3 = NULL;
+ __Pyx_TypeInfo *__pyx_t_4;
+ Py_buffer __pyx_t_5;
+ Py_ssize_t *__pyx_t_6;
+ Py_ssize_t *__pyx_t_7;
+ Py_ssize_t *__pyx_t_8;
+ Py_ssize_t __pyx_t_9;
+ int __pyx_lineno = 0;
+ const char *__pyx_filename = NULL;
+ int __pyx_clineno = 0;
+ __Pyx_RefNannySetupContext("memoryview_fromslice", 0);
- /* "View.MemoryView":926
+ /* "View.MemoryView":1007
+ * cdef _memoryviewslice result
*
- * if index < 0:
- * index += view.shape[dim] # <<<<<<<<<<<<<<
- * if index < 0:
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
- */
- __pyx_v_index = (__pyx_v_index + (__pyx_v_view->shape[__pyx_v_dim]));
-
- /* "View.MemoryView":927
- * if index < 0:
- * index += view.shape[dim]
- * if index < 0: # <<<<<<<<<<<<<<
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<<
+ * return None
*
*/
- __pyx_t_2 = ((__pyx_v_index < 0) != 0);
- if (unlikely(__pyx_t_2)) {
+ __pyx_t_1 = ((((PyObject *)__pyx_v_memviewslice.memview) == Py_None) != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":928
- * index += view.shape[dim]
- * if index < 0:
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<<
+ /* "View.MemoryView":1008
+ *
+ * if memviewslice.memview == Py_None:
+ * return None # <<<<<<<<<<<<<<
*
- * if index >= shape:
- */
- __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 928, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 928, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 928, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __PYX_ERR(1, 928, __pyx_L1_error)
-
- /* "View.MemoryView":927
- * if index < 0:
- * index += view.shape[dim]
- * if index < 0: # <<<<<<<<<<<<<<
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
*
*/
- }
+ __Pyx_XDECREF(__pyx_r);
+ __pyx_r = Py_None; __Pyx_INCREF(Py_None);
+ goto __pyx_L0;
- /* "View.MemoryView":925
- * suboffset = view.suboffsets[dim]
+ /* "View.MemoryView":1007
+ * cdef _memoryviewslice result
+ *
+ * if memviewslice.memview == Py_None: # <<<<<<<<<<<<<<
+ * return None
*
- * if index < 0: # <<<<<<<<<<<<<<
- * index += view.shape[dim]
- * if index < 0:
*/
}
- /* "View.MemoryView":930
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ /* "View.MemoryView":1013
*
- * if index >= shape: # <<<<<<<<<<<<<<
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
*
+ * result = _memoryviewslice(None, 0, dtype_is_object) # <<<<<<<<<<<<<<
+ *
+ * result.from_slice = memviewslice
*/
- __pyx_t_2 = ((__pyx_v_index >= __pyx_v_shape) != 0);
- if (unlikely(__pyx_t_2)) {
+ __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_v_dtype_is_object); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1013, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1013, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_3);
+ __Pyx_INCREF(Py_None);
+ __Pyx_GIVEREF(Py_None);
+ PyTuple_SET_ITEM(__pyx_t_3, 0, Py_None);
+ __Pyx_INCREF(__pyx_int_0);
+ __Pyx_GIVEREF(__pyx_int_0);
+ PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0);
+ __Pyx_GIVEREF(__pyx_t_2);
+ PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2);
+ __pyx_t_2 = 0;
+ __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_memoryviewslice_type), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1013, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+ __pyx_v_result = ((struct __pyx_memoryviewslice_obj *)__pyx_t_2);
+ __pyx_t_2 = 0;
- /* "View.MemoryView":931
+ /* "View.MemoryView":1015
+ * result = _memoryviewslice(None, 0, dtype_is_object)
*
- * if index >= shape:
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim) # <<<<<<<<<<<<<<
+ * result.from_slice = memviewslice # <<<<<<<<<<<<<<
+ * __PYX_INC_MEMVIEW(&memviewslice, 1)
*
- * resultp = bufp + index * stride
*/
- __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_dim); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 931, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_bounds_on_buffer_access_a, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 931, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_4);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 931, __pyx_L1_error)
- __Pyx_GOTREF(__pyx_t_3);
- __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
- __Pyx_Raise(__pyx_t_3, 0, 0, 0);
- __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
- __PYX_ERR(1, 931, __pyx_L1_error)
+ __pyx_v_result->from_slice = __pyx_v_memviewslice;
- /* "View.MemoryView":930
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ /* "View.MemoryView":1016
*
- * if index >= shape: # <<<<<<<<<<<<<<
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ * result.from_slice = memviewslice
+ * __PYX_INC_MEMVIEW(&memviewslice, 1) # <<<<<<<<<<<<<<
*
+ * result.from_object = ( memviewslice.memview).base
*/
- }
+ __PYX_INC_MEMVIEW((&__pyx_v_memviewslice), 1);
- /* "View.MemoryView":933
- * raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
+ /* "View.MemoryView":1018
+ * __PYX_INC_MEMVIEW(&memviewslice, 1)
+ *
+ * result.from_object = ( memviewslice.memview).base # <<<<<<<<<<<<<<
+ * result.typeinfo = memviewslice.memview.typeinfo
*
- * resultp = bufp + index * stride # <<<<<<<<<<<<<<
- * if suboffset >= 0:
- * resultp = ( resultp)[0] + suboffset
*/
- __pyx_v_resultp = (__pyx_v_bufp + (__pyx_v_index * __pyx_v_stride));
+ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_memviewslice.memview), __pyx_n_s_base); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1018, __pyx_L1_error)
+ __Pyx_GOTREF(__pyx_t_2);
+ __Pyx_GIVEREF(__pyx_t_2);
+ __Pyx_GOTREF(__pyx_v_result->from_object);
+ __Pyx_DECREF(__pyx_v_result->from_object);
+ __pyx_v_result->from_object = __pyx_t_2;
+ __pyx_t_2 = 0;
- /* "View.MemoryView":934
+ /* "View.MemoryView":1019
*
- * resultp = bufp + index * stride
- * if suboffset >= 0: # <<<<<<<<<<<<<<
- * resultp = ( resultp)[0] + suboffset
+ * result.from_object = ( memviewslice.memview).base
+ * result.typeinfo = memviewslice.memview.typeinfo # <<<<<<<<<<<<<<
*
+ * result.view = memviewslice.memview.view
*/
- __pyx_t_2 = ((__pyx_v_suboffset >= 0) != 0);
- if (__pyx_t_2) {
+ __pyx_t_4 = __pyx_v_memviewslice.memview->typeinfo;
+ __pyx_v_result->__pyx_base.typeinfo = __pyx_t_4;
- /* "View.MemoryView":935
- * resultp = bufp + index * stride
- * if suboffset >= 0:
- * resultp = ( resultp)[0] + suboffset # <<<<<<<<<<<<<<
+ /* "View.MemoryView":1021
+ * result.typeinfo = memviewslice.memview.typeinfo
*
- * return resultp
+ * result.view = memviewslice.memview.view # <<<<<<<<<<<<<<
+ * result.view.buf = memviewslice.data
+ * result.view.ndim = ndim
*/
- __pyx_v_resultp = ((((char **)__pyx_v_resultp)[0]) + __pyx_v_suboffset);
+ __pyx_t_5 = __pyx_v_memviewslice.memview->view;
+ __pyx_v_result->__pyx_base.view = __pyx_t_5;
- /* "View.MemoryView":934
- *
- * resultp = bufp + index * stride
- * if suboffset >= 0: # <<<<<<<<<<<<<<
- * resultp = ( resultp)[0] + suboffset
+ /* "View.MemoryView":1022
*
+ * result.view = memviewslice.memview.view
+ * result.view.buf = memviewslice.data # <<<<<<<<<<<<<<
+ * result.view.ndim = ndim
+ * (<__pyx_buffer *> &result.view).obj = Py_None
*/
- }
+ __pyx_v_result->__pyx_base.view.buf = ((void *)__pyx_v_memviewslice.data);
- /* "View.MemoryView":937
- * resultp = ( resultp)[0] + suboffset
- *
- * return resultp # <<<<<<<<<<<<<<
- *
- *
+ /* "View.MemoryView":1023
+ * result.view = memviewslice.memview.view
+ * result.view.buf = memviewslice.data
+ * result.view.ndim = ndim # <<<<<<<<<<<<<<
+ * (<__pyx_buffer *> &result.view).obj = Py_None
+ * Py_INCREF(Py_None)
*/
- __pyx_r = __pyx_v_resultp;
- goto __pyx_L0;
+ __pyx_v_result->__pyx_base.view.ndim = __pyx_v_ndim;
- /* "View.MemoryView":910
+ /* "View.MemoryView":1024
+ * result.view.buf = memviewslice.data
+ * result.view.ndim = ndim
+ * (<__pyx_buffer *> &result.view).obj = Py_None # <<<<<<<<<<<<<<
+ * Py_INCREF(Py_None)
*
- * @cname('__pyx_pybuffer_index')
- * cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, # <<<<<<<<<<<<<<
- * Py_ssize_t dim) except NULL:
- * cdef Py_ssize_t shape, stride, suboffset = -1
*/
+ ((Py_buffer *)(&__pyx_v_result->__pyx_base.view))->obj = Py_None;
- /* function exit code */
- __pyx_L1_error:;
- __Pyx_XDECREF(__pyx_t_3);
- __Pyx_XDECREF(__pyx_t_4);
- __Pyx_AddTraceback("View.MemoryView.pybuffer_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
- __pyx_r = NULL;
- __pyx_L0:;
- __Pyx_RefNannyFinishContext();
- return __pyx_r;
-}
-
-/* "View.MemoryView":943
- *
- * @cname('__pyx_memslice_transpose')
- * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0: # <<<<<<<<<<<<<<
- * cdef int ndim = memslice.memview.view.ndim
+ /* "View.MemoryView":1025
+ * result.view.ndim = ndim
+ * (<__pyx_buffer *> &result.view).obj = Py_None
+ * Py_INCREF(Py_None) # <<<<<<<<<<<<<<
*
+ * if (memviewslice.memview).flags & PyBUF_WRITABLE:
*/
+ Py_INCREF(Py_None);
-static int __pyx_memslice_transpose(__Pyx_memviewslice *__pyx_v_memslice) {
- int __pyx_v_ndim;
- Py_ssize_t *__pyx_v_shape;
- Py_ssize_t *__pyx_v_strides;
- int __pyx_v_i;
- int __pyx_v_j;
- int __pyx_r;
- int __pyx_t_1;
- Py_ssize_t *__pyx_t_2;
- long __pyx_t_3;
- long __pyx_t_4;
- Py_ssize_t __pyx_t_5;
- Py_ssize_t __pyx_t_6;
- int __pyx_t_7;
- int __pyx_t_8;
- int __pyx_t_9;
- int __pyx_lineno = 0;
- const char *__pyx_filename = NULL;
- int __pyx_clineno = 0;
-
- /* "View.MemoryView":944
- * @cname('__pyx_memslice_transpose')
- * cdef int transpose_memslice(__Pyx_memviewslice *memslice) nogil except 0:
- * cdef int ndim = memslice.memview.view.ndim # <<<<<<<<<<<<<<
+ /* "View.MemoryView":1027
+ * Py_INCREF(Py_None)
*
- * cdef Py_ssize_t *shape = memslice.shape
+ * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<<
+ * result.flags = PyBUF_RECORDS
+ * else:
*/
- __pyx_t_1 = __pyx_v_memslice->memview->view.ndim;
- __pyx_v_ndim = __pyx_t_1;
+ __pyx_t_1 = ((((struct __pyx_memoryview_obj *)__pyx_v_memviewslice.memview)->flags & PyBUF_WRITABLE) != 0);
+ if (__pyx_t_1) {
- /* "View.MemoryView":946
- * cdef int ndim = memslice.memview.view.ndim
- *
- * cdef Py_ssize_t *shape = memslice.shape # <<<<<<<<<<<<<<
- * cdef Py_ssize_t *strides = memslice.strides
+ /* "View.MemoryView":1028
*
+ * if (memviewslice.memview).flags & PyBUF_WRITABLE:
+ * result.flags = PyBUF_RECORDS # <<<<<<<<<<<<<<
+ * else:
+ * result.flags = PyBUF_RECORDS_RO
*/
- __pyx_t_2 = __pyx_v_memslice->shape;
- __pyx_v_shape = __pyx_t_2;
+ __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS;
- /* "View.MemoryView":947
- *
- * cdef Py_ssize_t *shape = memslice.shape
- * cdef Py_ssize_t *strides = memslice.strides # <<<<<<<<<<<<<<
- *
+ /* "View.MemoryView":1027
+ * Py_INCREF(Py_None)
*
+ * if (memviewslice.memview).flags & PyBUF_WRITABLE: # <<<<<<<<<<<<<<
+ * result.flags = PyBUF_RECORDS
+ * else:
*/
- __pyx_t_2 = __pyx_v_memslice->strides;
- __pyx_v_strides = __pyx_t_2;
+ goto __pyx_L4;
+ }
- /* "View.MemoryView":951
+ /* "View.MemoryView":1030
+ * result.flags = PyBUF_RECORDS
+ * else:
+ * result.flags = PyBUF_RECORDS_RO # <<<<<<<<<<<<<<
*
- * cdef int i, j
- * for i in range(ndim / 2): # <<<<<<<<<<<<<<
- * j = ndim - 1 - i
- * strides[i], strides[j] = strides[j], strides[i]
- */
- __pyx_t_3 = __Pyx_div_long(__pyx_v_ndim, 2);
- __pyx_t_4 = __pyx_t_3;
- for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_4; __pyx_t_1+=1) {
- __pyx_v_i = __pyx_t_1;
-
- /* "View.MemoryView":952
- * cdef int i, j
- * for i in range(ndim / 2):
- * j = ndim - 1 - i # <<<<<<<<<<<<<<
- * strides[i], strides[j] = strides[j], strides[i]
- * shape[i], shape[j] = shape[j], shape[i]
+ * result.view.shape = result.from_slice.shape
*/
- __pyx_v_j = ((__pyx_v_ndim - 1) - __pyx_v_i);
+ /*else*/ {
+ __pyx_v_result->__pyx_base.flags = PyBUF_RECORDS_RO;
+ }
+ __pyx_L4:;
- /* "View.MemoryView":953
- * for i in range(ndim / 2):
- * j = ndim - 1 - i
- * strides[i], strides[j] = strides[j], strides[i] # <<<<<<<<<<<<<<
- * shape[i], shape[j] = shape[j], shape[i]
+ /* "View.MemoryView":1032
+ * result.flags = PyBUF_RECORDS_RO
*
- */
- __pyx_t_5 = (__pyx_v_strides[__pyx_v_j]);
- __pyx_t_6 = (__pyx_v_strides[__pyx_v_i]);
- (__pyx_v_strides[__pyx_v_i]) = __pyx_t_5;
- (__pyx_v_strides[__pyx_v_j]) = __pyx_t_6;
-
- /* "View.MemoryView":954
- * j = ndim - 1 - i
- * strides[i], strides[j] = strides[j], strides[i]
- * shape[i], shape[j] = shape[j], shape[i] # <<<<<<<<<<<<<<
+ * result.view.shape =